Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ttl: make ttl manually trigger stable #45869

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)

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 @@

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()

Check warning on line 172 in ttl/client/command.go

View check run for this annotation

Codecov / codecov/patch

ttl/client/command.go#L171-L172

Added lines #L171 - L172 were not covered by tests
case <-ticker.C:
response, err := c.etcdCli.Get(ctx, key)
if err != nil {
Expand All @@ -178,7 +180,15 @@
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

Check warning on line 189 in ttl/client/command.go

View check run for this annotation

Codecov / codecov/patch

ttl/client/command.go#L185-L189

Added lines #L185 - L189 were not covered by tests
}

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