Skip to content

Commit 9dfcdbe

Browse files
committed
chore: code cleaning
1 parent 2083596 commit 9dfcdbe

File tree

1 file changed

+7
-55
lines changed

1 file changed

+7
-55
lines changed

chord/chord.go

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (c *Chord) FindSuccessor(ctx context.Context, id uint64) (node.Node, error)
8585
return closestNode.FindSuccessor(ctx, id)
8686
}
8787

88-
func (c *Chord) SetSuccessor(ctx context.Context, successor node.Node) error {
88+
func (c *Chord) SetSuccessor(_ context.Context, successor node.Node) error {
8989
c.successorLock.Lock()
9090
defer c.successorLock.Unlock()
9191

@@ -100,7 +100,7 @@ func (c *Chord) SetSuccessor(ctx context.Context, successor node.Node) error {
100100
return nil
101101
}
102102

103-
func (c *Chord) SetPredecessor(ctx context.Context, predecessor node.Node) error {
103+
func (c *Chord) SetPredecessor(_ context.Context, predecessor node.Node) error {
104104
c.predecessorLock.Lock()
105105
defer c.predecessorLock.Unlock()
106106

@@ -211,55 +211,23 @@ func (c *Chord) queryLocal(id uint64, index string, query string) (string, error
211211
return value, nil
212212
}
213213

214-
func (c *Chord) insertLocal(ctx context.Context, items []node.InsertItem) error {
214+
func (c *Chord) insertLocal(_ context.Context, items []node.InsertItem) error {
215215
for _, item := range items {
216216
itemHash := util.Hash(item.Index)
217-
err := c.bm.
218-
Add(itemHash, item)
217+
err := c.bm.Add(itemHash, item)
219218
if err != nil {
220219
return err
221220
}
222-
223-
//li, ok := c.data[itemHash]
224-
//if !ok {
225-
// c.data[itemHash] = make([]Item, 0)
226-
// c.uqIdx[itemHash] = make(map[string]struct{})
227-
//
228-
// li = c.data[itemHash]
229-
//}
230-
//
231-
//// Ignore if duplicate... TODO: Might need to throw an error
232-
////_, ok = c.uqIdx[itemHash][item.Key]
233-
////if ok {
234-
//// log.Println("already have item", item.Key)
235-
//// continue
236-
////}
237-
//
238-
//secIdx := strings.Split(item.Key, " ")
239-
//li = append(li, Item{
240-
// Index: item.Index,
241-
// SecIdx: secIdx,
242-
// Key: item.Key,
243-
// Value: item.Value,
244-
//})
245-
//c.data[itemHash] = li
246-
//
247-
//// Add entry to unique index
248-
//c.uqIdx[itemHash][item.Key] = struct{}{}
249221
}
250222

251223
return nil
252224
}
253225

254-
func (c *Chord) Notify(ctx context.Context, p node.Node) ([]node.InsertItem, error) {
226+
func (c *Chord) Notify(_ context.Context, p node.Node) ([]node.InsertItem, error) {
255227
c.predecessorLock.Lock()
256228
defer c.predecessorLock.Unlock()
257229

258-
//if p.ID() != c.ID() && (c.predecessor == nil || c.predecessor.ID() != p.ID()) {
259230
if c.predecessor == nil || (util.Between(p.ID(), c.predecessor.ID(), c.ID()) && p.ID() != c.ID()) {
260-
// transfer data having <= p.ID()
261-
262-
// TODO: Transfer data
263231
if c.predecessor != nil {
264232
log.Printf("Notify: setting the predecessor from %d to %d\n", c.predecessor.ID(), p.ID())
265233
} else {
@@ -279,26 +247,16 @@ func (c *Chord) Notify(ctx context.Context, p node.Node) ([]node.InsertItem, err
279247
}
280248

281249
return insert, nil
282-
//log.Printf("transferring %+v\n", insert)
283-
//if len(insert) > 0 {
284-
// err := c.predecessor.InsertBatch(ctx, insert...)
285-
// if err != nil {
286-
// return err
287-
// }
288-
//}
289-
290-
//log.Printf("%s [%d]: (Notify) predecessor changed %d", c.Addr(), c.ID(), c.predecessor.ID())
291250
}
292251

293252
return nil, nil
294253
}
295254

296-
func (c *Chord) GetPredecessor(ctx context.Context) (node.Node, error) {
255+
func (c *Chord) GetPredecessor(_ context.Context) (node.Node, error) {
297256
if c.predecessor == nil {
298257
return nil, errors.New("no predecessor")
299258
}
300259

301-
// TODO: was NewChord(c.predecessor.Addr(), nil)
302260
return c.predecessor, nil
303261
}
304262

@@ -316,12 +274,6 @@ func (c *Chord) Join(ctx context.Context, n node.Node) error {
316274
panic(err)
317275
}
318276

319-
//sp := NewChord(reply.Addr(), nil)
320-
//sp, err := c.newNodeFn(reply.Addr())
321-
//if err != nil {
322-
// panic(err)
323-
//}
324-
325277
if reply.ID() == c.ID() {
326278
return errors.New(fmt.Sprintf("node ID [%d] already taken", c.ID()))
327279
}
@@ -545,7 +497,7 @@ func (c *Chord) StartJobs() {
545497
}()
546498
}
547499

548-
func (c *Chord) Healthz(ctx context.Context) error {
500+
func (c *Chord) Healthz(_ context.Context) error {
549501
return nil
550502
}
551503

0 commit comments

Comments
 (0)