Skip to content

Commit b8fd84e

Browse files
echlebekNikki Attea
authored and
Nikki Attea
committed
Fix a bug that broke keepalives and check TTL (#3377)
As a result of refactoring, keepalive leases were being stored in the wrong key prefix. Signed-off-by: Eric Chlebek <[email protected]>
1 parent 424e51e commit b8fd84e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

backend/liveness/liveness.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func EtcdFactory(ctx context.Context, client *clientv3.Client) Factory {
102102
type SwitchSet struct {
103103
client *clientv3.Client
104104
prefix string
105-
leaseKey string
105+
leasePrefix string
106106
notifyDead EventFunc
107107
notifyAlive EventFunc
108108
logger logrus.FieldLogger
@@ -132,7 +132,7 @@ func NewSwitchSet(client *clientv3.Client, name string, dead, alive EventFunc, l
132132
return &SwitchSet{
133133
client: client,
134134
prefix: path.Join(SwitchPrefix, name),
135-
leaseKey: path.Join(SwitchPrefix, "lease", name),
135+
leasePrefix: path.Join(SwitchPrefix, "lease", name),
136136
notifyDead: dead,
137137
notifyAlive: alive,
138138
logger: logger,
@@ -220,7 +220,8 @@ func (t *SwitchSet) ping(ctx context.Context, id string, ttl int64, alive bool)
220220
}
221221

222222
func (t *SwitchSet) getLeaseID(ctx context.Context, ttl int64, switchID string) (clientv3.LeaseID, []clientv3.Op, error) {
223-
resp, err := t.client.Get(ctx, t.leaseKey)
223+
leaseKey := path.Join(t.leasePrefix, switchID)
224+
resp, err := t.client.Get(ctx, leaseKey)
224225
if err != nil {
225226
return 0, nil, err
226227
}
@@ -239,7 +240,7 @@ func (t *SwitchSet) getLeaseID(ctx context.Context, ttl int64, switchID string)
239240
return 0, nil, err
240241
}
241242
leaseID = lease.ID
242-
ops = append(ops, clientv3.OpPut(t.leaseKey, fmt.Sprintf("%x", lease.ID)))
243+
ops = append(ops, clientv3.OpPut(leaseKey, fmt.Sprintf("%x", lease.ID)))
243244
}
244245
return leaseID, ops, nil
245246
}
@@ -355,7 +356,7 @@ func (t *SwitchSet) handleEvent(ctx context.Context, event *clientv3.Event) {
355356
}
356357

357358
t.logger.Debugf("creating a lease for %s with TTL %d", key, leaseTTL)
358-
leaseID, leaseOps, err := t.getLeaseID(ctx, leaseTTL, path.Base(key))
359+
leaseID, leaseOps, err := t.getLeaseID(ctx, leaseTTL, strings.TrimPrefix(key, t.prefix))
359360
if err != nil {
360361
t.logger.WithError(err).Errorf("error while granting lease for %s", key)
361362
return

0 commit comments

Comments
 (0)