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

Drop unnecessary expire time check in ttl event handler #385

Merged
merged 1 commit into from
Dec 18, 2024
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
27 changes: 8 additions & 19 deletions pkg/logstructured/logstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,29 +325,18 @@ func (l *LogStructured) handleTTLEvents(ctx context.Context, rwMutex *sync.RWMut
return true
}

l.deleteTTLEvent(ctx, rwMutex, queue, store, eventKV)
return true
}

func (l *LogStructured) deleteTTLEvent(ctx context.Context, rwMutex *sync.RWMutex, queue workqueue.DelayingInterface, store map[string]*ttlEventKV, preEventKV *ttlEventKV) {
logrus.Tracef("TTL delete key=%v, modRev=%v", preEventKV.key, preEventKV.modRevision)
_, _, _, err := l.Delete(ctx, preEventKV.key, preEventKV.modRevision)
logrus.Tracef("TTL delete key=%v, modRev=%v", eventKV.key, eventKV.modRevision)
if _, _, _, err := l.Delete(ctx, eventKV.key, eventKV.modRevision); err != nil {
logrus.Errorf("TTL delete trigger failed for key=%v: %v, requeuing", eventKV.key, err)
queue.AddAfter(eventKV.key, retryInterval)
return true
}

rwMutex.Lock()
defer rwMutex.Unlock()
curEventKV := store[preEventKV.key]
if expires := time.Until(preEventKV.expiredAt); expires > 0 {
logrus.Tracef("TTL changed for key=%v, ttl=%v, requeuing", curEventKV.key, expires)
queue.AddAfter(curEventKV.key, expires)
return
}
if err != nil {
logrus.Errorf("TTL delete trigger failed for key=%v: %v, requeuing", curEventKV.key, err)
queue.AddAfter(curEventKV.key, retryInterval)
return
}
delete(store, eventKV.key)

delete(store, curEventKV.key)
return true
}

// ttlEvents starts a goroutine to do a ListWatch on the root prefix. First it lists
Expand Down
Loading