-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add transaction logs and basic conflict resolution #403
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
769c44e
Add transaction logs and basic conflict resolution
paraseba ecaebf1
Add conflict detection and resolution unit tests
paraseba 9ad3688
No public fields in ChangeSet
paraseba a0a3d13
Faster path finding
paraseba a1d625a
Fix compiler warnings
paraseba 553b3d5
Partial successful rebase maintain the right parent snapshot
paraseba c1178a7
Ruff
paraseba 61d447c
Update icechunk/src/conflicts/detector.rs
paraseba 94e9c64
Document code
paraseba fc07fc9
disable ruff in CI
paraseba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
use async_trait::async_trait; | ||
|
||
use crate::{ | ||
change_set::ChangeSet, format::transaction_log::TransactionLog, | ||
repository::RepositoryResult, Repository, | ||
}; | ||
|
||
use super::{detector::ConflictDetector, Conflict, ConflictResolution, ConflictSolver}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum VersionSelection { | ||
Fail, | ||
UseOurs, | ||
UseTheirs, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct BasicConflictSolver { | ||
pub on_user_attributes_conflict: VersionSelection, | ||
pub on_chunk_conflict: VersionSelection, | ||
pub fail_on_delete_of_updated_array: bool, | ||
pub fail_on_delete_of_updated_group: bool, | ||
} | ||
|
||
impl Default for BasicConflictSolver { | ||
fn default() -> Self { | ||
Self { | ||
on_user_attributes_conflict: VersionSelection::UseOurs, | ||
on_chunk_conflict: VersionSelection::UseOurs, | ||
fail_on_delete_of_updated_array: false, | ||
fail_on_delete_of_updated_group: false, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ConflictSolver for BasicConflictSolver { | ||
async fn solve( | ||
&self, | ||
previous_change: &TransactionLog, | ||
previous_repo: &Repository, | ||
current_changes: ChangeSet, | ||
current_repo: &Repository, | ||
) -> RepositoryResult<ConflictResolution> { | ||
match ConflictDetector | ||
.solve(previous_change, previous_repo, current_changes, current_repo) | ||
.await? | ||
{ | ||
res @ ConflictResolution::Patched(_) => Ok(res), | ||
ConflictResolution::Unsolvable { reason, unmodified } => { | ||
self.solve_conflicts( | ||
previous_change, | ||
previous_repo, | ||
unmodified, | ||
current_repo, | ||
reason, | ||
) | ||
.await | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl BasicConflictSolver { | ||
async fn solve_conflicts( | ||
&self, | ||
_previous_change: &TransactionLog, | ||
_previous_repo: &Repository, | ||
current_changes: ChangeSet, | ||
_current_repo: &Repository, | ||
conflicts: Vec<Conflict>, | ||
) -> RepositoryResult<ConflictResolution> { | ||
use Conflict::*; | ||
let unsolvable = conflicts.iter().any( | ||
|conflict| { | ||
matches!( | ||
conflict, | ||
NewNodeConflictsWithExistingNode(_) | | ||
NewNodeInInvalidGroup(_) | | ||
ZarrMetadataDoubleUpdate(_) | | ||
ZarrMetadataUpdateOfDeletedArray(_) | | ||
UserAttributesUpdateOfDeletedNode(_) | | ||
ChunksUpdatedInDeletedArray{..} | | ||
ChunksUpdatedInUpdatedArray{..} | ||
) || | ||
matches!(conflict, | ||
UserAttributesDoubleUpdate{..} if self.on_user_attributes_conflict == VersionSelection::Fail | ||
) || | ||
matches!(conflict, | ||
ChunkDoubleUpdate{..} if self.on_chunk_conflict == VersionSelection::Fail | ||
) || | ||
matches!(conflict, | ||
DeleteOfUpdatedArray(_) if self.fail_on_delete_of_updated_array | ||
) || | ||
matches!(conflict, | ||
DeleteOfUpdatedGroup(_) if self.fail_on_delete_of_updated_group | ||
) | ||
}, | ||
); | ||
|
||
if unsolvable { | ||
return Ok(ConflictResolution::Unsolvable { | ||
reason: conflicts, | ||
unmodified: current_changes, | ||
}); | ||
} | ||
|
||
let mut current_changes = current_changes; | ||
for conflict in conflicts { | ||
match conflict { | ||
ChunkDoubleUpdate { node_id, chunk_coordinates, .. } => { | ||
match self.on_chunk_conflict { | ||
VersionSelection::UseOurs => { | ||
// this is a no-op, our change will override the conflicting change | ||
} | ||
VersionSelection::UseTheirs => { | ||
current_changes.drop_chunk_changes(&node_id, |coord| chunk_coordinates.contains(coord)) | ||
} | ||
// we can panic here because we have returned from the function if there | ||
// were any unsolvable conflicts | ||
#[allow(clippy::panic)] | ||
VersionSelection::Fail => panic!("Bug in conflict resolution: ChunkDoubleUpdate flagged as unrecoverable") | ||
} | ||
} | ||
UserAttributesDoubleUpdate { node_id, .. } => { | ||
match self.on_user_attributes_conflict { | ||
VersionSelection::UseOurs => { | ||
// this is a no-op, our change will override the conflicting change | ||
} | ||
VersionSelection::UseTheirs => { | ||
current_changes.undo_user_attributes_update(&node_id); | ||
} | ||
// we can panic here because we have returned from the function if there | ||
// were any unsolvable conflicts | ||
#[allow(clippy::panic)] | ||
VersionSelection::Fail => panic!("Bug in conflict resolution: UserAttributesDoubleUpdate flagged as unrecoverable") | ||
} | ||
} | ||
DeleteOfUpdatedArray(_) => { | ||
assert!(!self.fail_on_delete_of_updated_array); | ||
// this is a no-op, the solution is to still delete the array | ||
} | ||
DeleteOfUpdatedGroup(_) => { | ||
assert!(!self.fail_on_delete_of_updated_group); | ||
// this is a no-op, the solution is to still delete the group | ||
} | ||
// we can panic here because we have returned from the function if there | ||
// were any unsolvable conflicts | ||
#[allow(clippy::panic)] | ||
_ => panic!("bug in conflict resolution, conflict: {:?}", conflict), | ||
} | ||
} | ||
|
||
Ok(ConflictResolution::Patched(current_changes)) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying we will never actually hit this code path in normal usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this possibility is filtered out above, but the compilers doesn't know it.