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): move index cleanup out to refreshAttempt #3603

Merged
merged 4 commits into from
Feb 16, 2024

Conversation

julio-lopez
Copy link
Collaborator

@julio-lopez julio-lopez commented Feb 1, 2024

Refactoring related to #3638 to simplify later PRs as much as possible.

These changes are mostly code movement except for a functional change noted below.


Changes

Move index compaction and cleanup out of refreshAttemptLocked, and perform it in refreshLocked after refreshAttempLock succeeds. See inline comments.

Refactor: Introduce an allowWritesOnLoadHelper to check whether or not writes can be performed when loading the indexes. Currently this is only a function of whether the storage is in read-only mode. In the near future, an explicit flag will be added to control this behavior.

Functional change: Avoid single epoch compaction when writes are disallowed, that is when using read-only storage. Currently, the epoch manager will attempt to perform single epoch compactions, when it is time to do so, even on read-only storage.


Ref:

Copy link

codecov bot commented Feb 7, 2024

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (cb455c6) 75.86% compared to head (84da027) 77.14%.
Report is 13 commits behind head on master.

Files Patch % Lines
cli/command_snapshot_migrate.go 0.00% 6 Missing ⚠️
cli/command_server_start.go 37.50% 4 Missing and 1 partial ⚠️
internal/epoch/epoch_manager.go 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3603      +/-   ##
==========================================
+ Coverage   75.86%   77.14%   +1.27%     
==========================================
  Files         470      470              
  Lines       37301    28440    -8861     
==========================================
- Hits        28299    21940    -6359     
+ Misses       7071     4570    -2501     
+ Partials     1931     1930       -1     

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

@julio-lopez julio-lopez changed the title Draft/no index cleanup on load refactor(general): move index compaction and cleanup out of refreshAttemptLocked Feb 7, 2024
@julio-lopez julio-lopez changed the title refactor(general): move index compaction and cleanup out of refreshAttemptLocked refactor(general): move index cleanup out to refreshAttempt Feb 7, 2024
Comment on lines +474 to +478
e.maybeGenerateNextRangeCheckpointAsync(ctx, cs, p)
e.maybeStartCleanupAsync(ctx, cs, p)
e.maybeOptimizeRangeCheckpointsAsync(ctx, cs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is code movement only. These were at the end of refreshAttemptLocked so putting them here has no functional changes, they just happened to be called right after refreshAttemptLocked returns, instead of the last calls steps refreshAttemptLocked.

Comment on lines -698 to -700
e.maybeGenerateNextRangeCheckpointAsync(ctx, cs, p)
e.maybeStartCleanupAsync(ctx, cs, p)
e.maybeOptimizeRangeCheckpointsAsync(ctx, cs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to the only caller, see comment above.

@@ -948,7 +960,7 @@ func (e *Manager) getIndexesFromEpochInternal(ctx context.Context, cs CurrentSna
uncompactedBlobs = ue
}

if epochSettled {
if epochSettled && e.allowWritesOnLoad() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a functional change. It avoids advancing epoch when writes are disallowed.

Before: it attempted to advance the epoch (by writing a blob to the storage), even on read-only storage.

After: prevents advancing epochs when writes are disallowed on index loads, for example, when using read-only storage.

@@ -678,12 +704,6 @@ func (e *Manager) refreshAttemptLocked(ctx context.Context) error {
len(ues[cs.WriteEpoch+1]),
cs.ValidUntil.Format(time.RFC3339Nano))

if !e.st.IsReadOnly() && shouldAdvance(cs.UncompactedEpochSets[cs.WriteEpoch], p.MinEpochDuration, p.EpochAdvanceOnCountThreshold, p.EpochAdvanceOnTotalSizeBytesThreshold) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to caller.
This was done "almost" at the end, but before returning an error in some cases.
It should not make a difference in practice though.

return e.maybeCompactAndCleanupLocked(ctx, p)
}

func (e *Manager) maybeCompactAndCleanupLocked(ctx context.Context, p *Parameters) 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.

The goal of this function is to group the epoch cleanup tasks that are performed during index loads, so it is simpler to manage.

The long term objective is to remove this code path from index loading altogether.

@julio-lopez
Copy link
Collaborator Author

Before:
eim-load-before

After:
eim-load-after

Introduces an `allowWritesOnLoadHelper` to check whether or not writes
can be performed when loading the indexes. Currently this is only
a function of whether the storage is in read-only mode. In the near
future, an explicit flag will be added to control this behavior.
Functional change: prevents compacting single epochs when writes are
disallowed, that is when using read-only storage. Currently, the epoch
manager will attempt to perform single-epoch compactions for all
eligible epochs, even on read-only storage.

Ref: kopia#3225
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.

Change looks good to me

@julio-lopez
Copy link
Collaborator Author

@ashmrtn FYI

@julio-lopez julio-lopez merged commit 1892a9f into kopia:master Feb 16, 2024
26 of 28 checks passed
@julio-lopez julio-lopez deleted the draft/no-index-cleanup-on-load branch February 16, 2024 18:25
julio-lopez added a commit to kastenhq/kopia that referenced this pull request Mar 12, 2024
julio-lopez added a commit that referenced this pull request Mar 12, 2024
Extracted from #3651.

Thanks to @plar and @redgoat650 for the suggestions.

Ref:

- #3603
- #3645
- #3638
- #3639
Lyndon-Li pushed a commit to Lyndon-Li/kopia that referenced this pull request Mar 18, 2024
Refactor: move index compaction and cleanup out of refreshAttemptLocked

Introduces an `allowWritesOnLoadHelper` to check whether or not writes
can be performed when loading the indexes. Currently this is only
a function of whether the storage is in read-only mode. In the near
future, an explicit flag will be added to control this behavior.

Fix epoch manager: avoid single-epoch compaction when writes are disallowed.
Functional change: prevents compacting single epochs when writes are
disallowed, that is when using read-only storage. Currently, the epoch
manager will attempt to perform single-epoch compactions for all
eligible epochs, even on read-only storage.

Ref:
- kopia#3224
- kopia#3225
- kopia#3638
- kopia#3639
Lyndon-Li pushed a commit to Lyndon-Li/kopia that referenced this pull request Mar 22, 2024
Refactor: move index compaction and cleanup out of refreshAttemptLocked

Introduces an `allowWritesOnLoadHelper` to check whether or not writes
can be performed when loading the indexes. Currently this is only
a function of whether the storage is in read-only mode. In the near
future, an explicit flag will be added to control this behavior.

Fix epoch manager: avoid single-epoch compaction when writes are disallowed.
Functional change: prevents compacting single epochs when writes are
disallowed, that is when using read-only storage. Currently, the epoch
manager will attempt to perform single-epoch compactions for all
eligible epochs, even on read-only storage.

Ref:
- kopia#3224
- kopia#3225
- kopia#3638
- kopia#3639
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

2 participants