Skip to content

Commit 404a79b

Browse files
committed
Review feedback
1 parent f1891f0 commit 404a79b

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

ring/ingester_lifecycle.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ func (r *IngesterRegistration) Unregister() {
117117

118118
func (r *IngesterRegistration) loop() {
119119
defer r.wait.Done()
120-
tokens := r.pickTokens()
120+
tokens, err := r.pickTokens()
121+
if err != nil {
122+
log.Fatalf("Failed to pick tokens in consul: %v", err)
123+
}
121124

122125
if !r.skipUnregister {
123126
defer r.unregister()
@@ -126,7 +129,7 @@ func (r *IngesterRegistration) loop() {
126129
r.heartbeat(tokens)
127130
}
128131

129-
func (r *IngesterRegistration) pickTokens() []uint32 {
132+
func (r *IngesterRegistration) pickTokens() ([]uint32, error) {
130133
var tokens []uint32
131134
pickTokens := func(in interface{}) (out interface{}, retry bool, err error) {
132135
var ringDesc *Desc
@@ -158,11 +161,10 @@ func (r *IngesterRegistration) pickTokens() []uint32 {
158161
return ringDesc, true, nil
159162
}
160163
if err := r.consul.CAS(consulKey, descFactory, pickTokens); err != nil {
161-
log.Fatalf("Failed to pick tokens in consul: %v", err)
162-
return nil
164+
return nil, err
163165
}
164166
log.Infof("Ingester added to consul")
165-
return tokens
167+
return tokens, nil
166168
}
167169

168170
func (r *IngesterRegistration) heartbeat(tokens []uint32) {

ring/mock_consul_client_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ func newMockConsulClient() ConsulClient {
2525
}
2626

2727
func copyKVPair(in *consul.KVPair) *consul.KVPair {
28-
value := make([]byte, len(in.Value))
29-
copy(value, in.Value)
30-
return &consul.KVPair{
31-
Key: in.Key,
32-
CreateIndex: in.CreateIndex,
33-
ModifyIndex: in.ModifyIndex,
34-
LockIndex: in.LockIndex,
35-
Flags: in.Flags,
36-
Value: value,
37-
Session: in.Session,
38-
}
28+
out := *in
29+
out.Value = make([]byte, len(in.Value))
30+
copy(out.Value, in.Value)
31+
return &out
3932
}
4033

4134
// periodic loop to wake people up, so they can honour timeouts

0 commit comments

Comments
 (0)