Skip to content

Commit

Permalink
etcd: add WithRequireLeader in lease and txn
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Jan 22, 2025
1 parent ae6df14 commit ab7c0a5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/election/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (l *Lease) KeepAlive(ctx context.Context) {
if l == nil {
return
}
ctx, cancel := context.WithCancel(ctx)
ctx, cancel := context.WithCancel(clientv3.WithRequireLeader(ctx))
defer cancel()
timeCh := l.keepAliveWorker(ctx, l.leaseTimeout/3)
defer log.Info("lease keep alive stopped", zap.String("purpose", l.Purpose))
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/kv/etcd_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ type etcdTxn struct {
func (kv *etcdKVBase) RunInTxn(ctx context.Context, f func(txn Txn) error) error {
txn := &etcdTxn{
kv: kv,
ctx: ctx,
ctx: clientv3.WithRequireLeader(ctx),
}
err := f(txn)
if err != nil {
Expand Down

0 comments on commit ab7c0a5

Please sign in to comment.