Skip to content

Commit

Permalink
ttl: make ttl manually trigger stable (#45869) (#45896)
Browse files Browse the repository at this point in the history
close #45868
  • Loading branch information
ti-chi-bot authored Aug 14, 2023
1 parent be9a60e commit 98f87e8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ttl/client/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

const (
ttlCmdKeyLeaseSeconds int64 = 60
ttlCmdKeyLeaseSeconds int64 = 180
ttlCmdKeyRequestPrefix = "/tidb/ttl/cmd/req/"
ttlCmdKeyResponsePrefix = "/tidb/ttl/cmd/resp/"
ttlCmdTypeTriggerTTLJob = "trigger_ttl_job"
Expand Down Expand Up @@ -161,13 +161,15 @@ func (c *etcdClient) waitCmdResponse(ctx context.Context, reqID string, obj inte

key := ttlCmdKeyResponsePrefix + reqID
ch := c.etcdCli.Watch(ctx, key)
ticker := time.NewTimer(time.Second)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()

var respData []byte
loop:
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
response, err := c.etcdCli.Get(ctx, key)
if err != nil {
Expand All @@ -178,7 +180,15 @@ loop:
respData = response.Kvs[0].Value
break loop
}
case resp := <-ch:
case resp, ok := <-ch:
if !ok {
logutil.BgLogger().Info("watcher is closed")
// to make ch always block
ch = make(chan clientv3.WatchResponse)
time.Sleep(time.Second)
continue loop
}

for _, event := range resp.Events {
if event.Type == clientv3.EventTypePut {
respData = event.Kv.Value
Expand Down

0 comments on commit 98f87e8

Please sign in to comment.