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

Clarification on TTL Change Logic in logstructured.go #382

Closed
Yuyz0112 opened this issue Dec 16, 2024 · 2 comments
Closed

Clarification on TTL Change Logic in logstructured.go #382

Yuyz0112 opened this issue Dec 16, 2024 · 2 comments

Comments

@Yuyz0112
Copy link

Hi,

I am reviewing KINE’s code to understand its TTL implementation and came across the following snippet:
https://github.com/k3s-io/kine/blob/master/pkg/logstructured/logstructured.go#L338-L343

I noticed that the condition for entering the if block (TTL changed for key) is based on the value of preEventKV.expiredAt rather than curEventKV.expiredAt.

Could you please clarify why the comparison uses preEventKV.expiredAt instead of curEventKV.expiredAt? Wouldn’t it make more sense to use the current state (curEventKV) to determine if the TTL has changed during delete?

Thank you for your help!

@brandond
Copy link
Member

brandond commented Dec 16, 2024

Perhaps. With other changes from #238 I'm not sure that this block is actually needed any longer.

The DelayingQueue interface does not allow delaying the processing of an entry; the scheduled time for entry to be popped from the queue is only updated if it would cause the entry to be processed SOONER, not later. Ref:
https://github.com/kubernetes/client-go/blob/master/util/workqueue/delaying_queue.go#L347

The intent of these checks is to ensure that the event has not been enqueued with a longer TTL before attempting a delete. handleTTLEvents always retrieves the most recent event from the map before calling deleteTTLEvent on it, and validates the time remaining. If there has somehow been a more recent update to the key made in between when the event is returned by loadTTLEventKV, and when deleteTTLEvent actually attempts to delete the entry, the delete will fail because the resourceVersion has changed. The error path will be taken and the entry re-enqueued, at which point the correct time until expiry will be observed. Given that, I am not sure we need to check the current or previous expiration again here in deleteTTLEvent.

@Yuyz0112
Copy link
Author

@brandond Thanks for the clarification! I also think this if-block is not needed anymore while reading the code, maybe leaving it here at this moment is ok. I'm going to close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants