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

refactor(general): add epoch.Manager.MaybeGenerateRangeCheckpoint #3727

Merged

Conversation

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.14%. Comparing base (cb455c6) to head (95b042b).
Report is 67 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3727      +/-   ##
==========================================
+ Coverage   75.86%   77.14%   +1.28%     
==========================================
  Files         470      476       +6     
  Lines       37301    28864    -8437     
==========================================
- Hits        28299    22268    -6031     
+ Misses       7071     4668    -2403     
+ Partials     1931     1928       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julio-lopez julio-lopez force-pushed the fix/maybe-generate-range-checkpoints branch from 40414e0 to b8bff96 Compare March 22, 2024 04:56
@julio-lopez julio-lopez force-pushed the fix/maybe-generate-range-checkpoints branch from f87b9da to 95b042b Compare March 22, 2024 17:53
Copy link
Contributor

@chaitalisg chaitalisg left a comment

Choose a reason for hiding this comment

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

Good test coverage!
LGTM!

// MaybeGenerateRangeCheckpoint may create a new range index for all the
// individual epochs covered by the new range. If there are not enough epochs
// to create a new range, then a range index is not created.
func (e *Manager) MaybeGenerateRangeCheckpoint(ctx context.Context) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was wondering if extending the function's return value to include a bool indicating whether a range checkpoint was actually generated, alongside the existing error. This could enhance decision-making in caller functions. Thoughts?

func (e *Manager) MaybeGenerateRangeCheckpoint(ctx context.Context) (/*generated*/bool, error) {
...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not (yet) sure it is needed as part of the actual functionality. The primary caller is "repo maintenance", and maintenance cares about whether or not there was an error in order to stop.

Or what use case did you have in mind?

Either way, we can iterate in a separate PR.

Copy link
Collaborator

@plar plar Mar 22, 2024

Choose a reason for hiding this comment

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

I just don’t know where this function will be called, but I saw from the code that it either does something or doesn’t do it if the error is nil. I thought that this information might be useful, in any case it would be easier to ignore on the caller side than to change the function later. I would say that this flag answers the question: MaybeYes or MaybeNo? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I understand what you are saying.

The Maybe prefixes are meant to indicate (at the call site) that the function may not perform the actual operation at this time, and that's "OK"; because either:

  • the system is already in the desired state and no transition / change is needed; or
  • it is not necessary that the operation is performed at this time to continue execution.

In the current use case (in a following PR), the caller does not need to know whether or not the operation was executed to make a decision based on that. It DOES need to know if there was an error, because in that case it seems safer to abort.
If it becomes necessary (from the caller) to know whether or not the operation was performed, then yes, we'll add a return value as you suggest.

Copy link
Contributor

@redgoat650 redgoat650 left a comment

Choose a reason for hiding this comment

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

Looks good to me

@@ -624,6 +643,24 @@ func (e *Manager) maybeGenerateNextRangeCheckpointAsync(ctx context.Context, cs
})
}

func getRangeToCompact(cs CurrentSnapshot, p Parameters) (low, high int, compactRange bool) {
latestSettled := cs.WriteEpoch - numUnsettledEpochs
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor readability suggestion) I realize this is just a refactor of existing logic, but perhaps we can make a new helper

(cs *CurrentSnapshot) getLastSettledEpochNumber() int {
   return cs.WriteEpoch - numUnsettledEpochs
}

and we can reuse that here, as well as in cs.isSettledEpochNumber()?

func (cs *CurrentSnapshot) isSettledEpochNumber(epoch int) bool {
	return epoch <= cs.getLastSettledEpochNumber()
}

For me it's easier to interpret the significance of that subtraction operation if it's described by a helper function name 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. It can be done in a separate PR.

@julio-lopez julio-lopez merged commit fdb6d3c into kopia:master Mar 22, 2024
28 checks passed
@julio-lopez julio-lopez deleted the fix/maybe-generate-range-checkpoints branch March 22, 2024 22:29
julio-lopez added a commit that referenced this pull request Mar 27, 2024
…3651)

Perform index epoch compaction and cleanup during repository maintenance

* refactor: rename maintenance task for deleting superseded indexes
* maintenance task to cleanup epoch markers
* maintenance task to advance write index epoch
* maintenance task to compact epoch ranges
* quick maintenance task to compact a single (index) epoch
* full maintenance task to compact a single (index) epoch

Ref:
- #3638
- #3639

Followup to:
- #3603
- #3645

Related helpers and changes:
- #3721
- #3735
- #3709
- #3728
- #3727
- #3726
Lyndon-Li pushed a commit to Lyndon-Li/kopia that referenced this pull request Mar 29, 2024
…opia#3651)

Perform index epoch compaction and cleanup during repository maintenance

* refactor: rename maintenance task for deleting superseded indexes
* maintenance task to cleanup epoch markers
* maintenance task to advance write index epoch
* maintenance task to compact epoch ranges
* quick maintenance task to compact a single (index) epoch
* full maintenance task to compact a single (index) epoch

Ref:
- kopia#3638
- kopia#3639

Followup to:
- kopia#3603
- kopia#3645

Related helpers and changes:
- kopia#3721
- kopia#3735
- kopia#3709
- kopia#3728
- kopia#3727
- kopia#3726
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

Successfully merging this pull request may close these issues.

None yet

4 participants