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

Fix garbage collector interval and backoff resets #1663

Merged
merged 4 commits into from Nov 29, 2023

Conversation

chriskdon
Copy link
Contributor

@chriskdon chriskdon commented Nov 28, 2023

Fixes #1659

Resets nextInterval back to the configured interval when backoffInterval.Reset() is called on a successful garbage collection run.

It also fixes a different problem I discovered while writing tests. backoffInterval.Reset() must be called after initialization according to these docs:

Reset the interval back to the initial retry interval and restarts the timer. Reset must be called before using b.

When this is not done, the InitialInterval value is ignored, and the default 500ms is used until the first GC iteration completes successfully and backoffInterval.Reset() is called. I assume this is unintentional behaviour?


I haven't written much Go, so please feel free to nitpick the PR. I'm open to any suggestions. 😅

@chriskdon chriskdon requested a review from a team as a code owner November 28, 2023 02:31
@github-actions github-actions bot added area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Nov 28, 2023
Copy link

github-actions bot commented Nov 28, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@@ -111,6 +111,7 @@ func startGarbageCollectorWithMaxElapsedTime(ctx context.Context, gc GarbageColl
backoffInterval.InitialInterval = interval
backoffInterval.MaxInterval = max(MaxGCInterval, interval)
backoffInterval.MaxElapsedTime = maxElapsedTime
backoffInterval.Reset()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the other issue I discovered during testing. Without this, the initial interval used by the backoff will be the default 500ms until backoffInterval.Reset() is called. This is an edge case, but it can cause the wrong initial value to be used if the first iteration of the GC has an error.

type testGC struct{}
// Fake garbage collector that returns a new incremented revision each time
// TxIDBefore is called.
type fakeGC struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the testGC to be more fake-like so it could be used to test different scenarios. In my case, I need it to intermittently fail and then recover. If you'd prefer a special, more straightforward GC implementation just for the new test, I'm happy to change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is great 👍🏻

@chriskdon
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻 good find, great contribution and excellent PR description and commit history. LGTM!

type testGC struct{}
// Fake garbage collector that returns a new incremented revision each time
// TxIDBefore is called.
type fakeGC struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is great 👍🏻

@vroldanbet vroldanbet added this pull request to the merge queue Nov 29, 2023
Merged via the queue into authzed:main with commit 59e2696 Nov 29, 2023
20 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Garbage collector interval not reset after transient error recovery
2 participants