Skip to content

Commit

Permalink
[WIP] Expose last updater.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Nov 21, 2024
1 parent d110b02 commit 13bf17b
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 77 deletions.
3 changes: 3 additions & 0 deletions bindings/generator/api/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .common import (
U64,
DateTime,
DeviceID,
EntryName,
ErrorVariant,
FsPath,
Expand Down Expand Up @@ -316,6 +317,7 @@ class File:
is_placeholder: bool
need_sync: bool
size: SizeInt
last_updater: DeviceID

class Folder:
confinement_point: Optional[VlobID]
Expand All @@ -326,6 +328,7 @@ class Folder:
base_version: VersionInt
is_placeholder: bool
need_sync: bool
last_update: DeviceID


async def workspace_stat_entry(
Expand Down
4 changes: 4 additions & 0 deletions libparsec/crates/client/src/workspace/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub(super) fn merge_local_file_manifest(
need_sync: _,
// Ignore `updated`: we don't merge data that change on each sync
updated: _,
last_updater: _,
parent: local_parent,
size: local_size,
blocksize: local_blocksize,
Expand Down Expand Up @@ -275,6 +276,7 @@ pub(super) fn merge_local_folder_manifest(
local_confinement_points: _,
// Ignored, we don't merge data that change on each sync
updated: _,
last_updater: _,
} = local;

// 0) Sanity checks, caller is responsible to handle them properly !
Expand Down Expand Up @@ -370,12 +372,14 @@ pub(super) fn merge_local_folder_manifest(
updated: merged_updated,
children: merged_children,
speculative: merged_speculative,
last_updater: merged_last_updater,
} = &mut merge_in_progress;

*merged_speculative = false;
*merged_parent = local.parent;
*merged_need_sync = local.need_sync;
*merged_updated = local.updated;
*merged_last_updater = local.last_updater;
local.children.clone_into(merged_children);

return MergeLocalFolderManifestOutcome::Merged(Arc::new(merge_in_progress));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ async fn handle_conflict_and_update_store(
size,
blocksize,
blocks,
last_updater,
} = child_manifest.as_ref();

let mut conflicting =
Expand All @@ -462,6 +463,7 @@ async fn handle_conflict_and_update_store(
conflicting.updated = *updated;
conflicting.size = *size;
conflicting.blocksize = *blocksize;
conflicting.last_updater = *last_updater;
blocks.clone_into(&mut conflicting.blocks);

(child_manifest.base.id, Arc::new(conflicting))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl FolderReader {
base_version: self.manifest.base.version,
is_placeholder: self.manifest.base.version == 0,
need_sync: self.manifest.need_sync,
last_updater: self.manifest.last_updater,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum EntryStat {
is_placeholder: bool,
need_sync: bool,
size: SizeInt,
last_updater: DeviceID,
},
// Here Folder can also be the root of the workspace (i.e. WorkspaceManifest)
Folder {
Expand All @@ -40,6 +41,7 @@ pub enum EntryStat {
base_version: VersionInt,
is_placeholder: bool,
need_sync: bool,
last_updater: DeviceID,
},
}

Expand Down Expand Up @@ -145,6 +147,7 @@ pub(crate) async fn stat_entry_by_id(
base_version: manifest.base.version,
is_placeholder: manifest.base.version == 0,
need_sync: manifest.need_sync,
last_updater: manifest.last_updater,
},
ArcLocalChildManifest::File(manifest) => {
// If the file may be currently opened with un-flushed modifications.
Expand Down Expand Up @@ -174,6 +177,7 @@ pub(crate) async fn stat_entry_by_id(
is_placeholder: manifest.base.version == 0,
need_sync: manifest.need_sync,
size: manifest.size,
last_updater: manifest.last_updater,
}
}
};
Expand Down Expand Up @@ -216,6 +220,7 @@ pub(crate) async fn stat_entry(
base_version: manifest.base.version,
is_placeholder: manifest.base.version == 0,
need_sync: manifest.need_sync,
last_updater: manifest.last_updater,
},
ArcLocalChildManifest::File(manifest) => {
// If the file may be currently opened with un-flushed modifications.
Expand Down Expand Up @@ -245,6 +250,7 @@ pub(crate) async fn stat_entry(
is_placeholder: manifest.base.version == 0,
need_sync: manifest.need_sync,
size: manifest.size,
last_updater: manifest.last_updater,
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,12 @@ async fn non_placeholder(
size,
blocksize,
blocks,
last_updater,
} = conflicted_manifest.as_ref();
p_assert_eq!(*parent, before_sync_bar_txt_manifest.parent);
p_assert_eq!(*need_sync, before_sync_bar_txt_manifest.need_sync);
p_assert_eq!(*updated, before_sync_bar_txt_manifest.updated);
p_assert_eq!(*last_updater, before_sync_bar_txt_manifest.last_updater);
p_assert_eq!(*size, before_sync_bar_txt_manifest.size);
p_assert_eq!(*blocksize, before_sync_bar_txt_manifest.blocksize);
p_assert_eq!(*blocks, before_sync_bar_txt_manifest.blocks);
Expand Down Expand Up @@ -414,10 +416,12 @@ async fn non_placeholder(
size,
blocksize,
blocks,
last_updater,
} = conflicted_manifest.as_ref();
p_assert_eq!(*parent, before_sync_bar_txt_manifest.parent);
p_assert_eq!(*need_sync, before_sync_bar_txt_manifest.need_sync);
p_assert_eq!(*updated, before_sync_bar_txt_manifest.updated);
p_assert_eq!(*last_updater, before_sync_bar_txt_manifest.last_updater);
p_assert_eq!(*size, before_sync_bar_txt_manifest.size);
p_assert_eq!(*blocksize, before_sync_bar_txt_manifest.blocksize);
p_assert_eq!(*blocks, before_sync_bar_txt_manifest.blocks);
Expand Down
5 changes: 5 additions & 0 deletions libparsec/crates/client/tests/unit/workspace/merge_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async fn no_remote_change(
raw_size: NonZeroU64::new(10).unwrap(),
access: Some(remote.blocks[0].clone()),
}]],
last_updater: remote.author,
};
match kind {
"same_version" => (),
Expand Down Expand Up @@ -132,6 +133,7 @@ async fn remote_only_change(
size: remote.size,
blocksize: remote.blocksize,
blocks: vec![],
last_updater: remote.author,
};

remote.version = 2;
Expand All @@ -157,6 +159,7 @@ async fn remote_only_change(
size: 0,
blocksize: Blocksize::try_from(512 * 1024).unwrap(),
blocks: vec![],
last_updater: "bob@dev1".parse().unwrap(),
};

match kind {
Expand Down Expand Up @@ -314,6 +317,7 @@ async fn local_and_remote_changes(
raw_size: NonZeroU64::new(10).unwrap(),
access: Some(remote.blocks[0].clone()),
}]],
last_updater: remote.author,
};

remote.version = 2;
Expand All @@ -335,6 +339,7 @@ async fn local_and_remote_changes(
raw_size: NonZeroU64::new(10).unwrap(),
access: Some(remote.blocks[0].clone()),
}]],
last_updater: remote.author,
};

let expected = match kind {
Expand Down
12 changes: 10 additions & 2 deletions libparsec/crates/client/tests/unit/workspace/merge_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async fn no_remote_change(
local_confinement_points: HashSet::new(),
remote_confinement_points: HashSet::new(),
speculative: false,
last_updater: remote.author,
};
match kind {
"same_version" => (),
Expand Down Expand Up @@ -129,6 +130,7 @@ async fn no_remote_change_but_local_uses_outdated_prevent_sync_pattern(
local_confinement_points: HashSet::new(),
remote_confinement_points: HashSet::new(),
speculative: false,
last_updater: remote.author,
};

match kind {
Expand Down Expand Up @@ -237,6 +239,7 @@ async fn remote_only_change(
local_confinement_points: HashSet::new(),
remote_confinement_points: HashSet::new(),
speculative: false,
last_updater: remote.author,
};

remote.version = 2;
Expand All @@ -261,6 +264,7 @@ async fn remote_only_change(
local_confinement_points: HashSet::new(),
remote_confinement_points: HashSet::new(),
speculative: false,
last_updater: "bob@dev1".parse().unwrap(),
};

let prevent_sync_pattern = Regex::from_glob_pattern("*.tmp").unwrap();
Expand Down Expand Up @@ -632,6 +636,7 @@ async fn local_and_remote_changes(
local_confinement_points: HashSet::new(),
remote_confinement_points: HashSet::new(),
speculative: false,
last_updater: remote.author,
};

remote.version = 2;
Expand All @@ -656,6 +661,7 @@ async fn local_and_remote_changes(
local_confinement_points: HashSet::new(),
remote_confinement_points: HashSet::new(),
speculative: false,
last_updater: "bob@dev1".parse().unwrap(),
};

let prevent_sync_pattern = Regex::from_glob_pattern("*.tmp").unwrap();
Expand Down Expand Up @@ -1424,6 +1430,7 @@ async fn local_and_remote_changes(
expected.parent = local.base.id;
expected.base.parent = local.base.id;


let local_child_id = VlobID::from_hex("a1d7229d7e44418a8a4e4fd821003fd3").unwrap();
let remote_child_id = VlobID::from_hex("9a20331879744a149f55bc3ba16e8225").unwrap();

Expand All @@ -1443,6 +1450,7 @@ async fn local_and_remote_changes(
// So in the end we must do a merge between local and remote changes,
// which leads to a conflict !
remote.author = local_author;
expected.last_updater = local_author;

expected.base.author = local_author;
expected
Expand Down Expand Up @@ -2237,8 +2245,8 @@ async fn local_and_remote_changes(
local.need_sync = false;
// ...the remote hasn't anything important to merge, but this should
// refresh the confinement in local with the new prevent sync pattern.
remote.author = local_author;

remote.author = local_author;
expected.last_updater = local_author;
// Given the remote is from ourself, the merge considers we already know
// about it and hence acknowledges it and preserve the local children.
// However the new prevent sync pattern means the local child is now
Expand Down
12 changes: 12 additions & 0 deletions libparsec/crates/client/tests/unit/workspace/read_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async fn ok_with_local_cache(#[values(true, false)] target_is_root: bool, env: &
is_placeholder: false,
need_sync: false,
size: 11,
last_updater: alice.device_id,
},
),
(
Expand All @@ -64,6 +65,7 @@ async fn ok_with_local_cache(#[values(true, false)] target_is_root: bool, env: &
base_version: 1,
is_placeholder: false,
need_sync: false,
last_updater: alice.device_id,
},
),
];
Expand All @@ -84,6 +86,7 @@ async fn ok_with_local_cache(#[values(true, false)] target_is_root: bool, env: &
is_placeholder: false,
need_sync: false,
size: 0,
last_updater: alice.device_id,
},
),
(
Expand All @@ -97,6 +100,7 @@ async fn ok_with_local_cache(#[values(true, false)] target_is_root: bool, env: &
base_version: 1,
is_placeholder: false,
need_sync: false,
last_updater: alice.device_id,
},
),
];
Expand Down Expand Up @@ -200,6 +204,7 @@ async fn ok_no_local_cache(#[values(true, false)] target_is_root: bool, env: &Te
is_placeholder: false,
need_sync: false,
size: 11,
last_updater: alice.device_id,
},
),
(
Expand All @@ -213,6 +218,7 @@ async fn ok_no_local_cache(#[values(true, false)] target_is_root: bool, env: &Te
base_version: 1,
is_placeholder: false,
need_sync: false,
last_updater: alice.device_id,
},
),
];
Expand All @@ -233,6 +239,7 @@ async fn ok_no_local_cache(#[values(true, false)] target_is_root: bool, env: &Te
is_placeholder: false,
need_sync: false,
size: 0,
last_updater: alice.device_id,
},
),
(
Expand All @@ -246,6 +253,7 @@ async fn ok_no_local_cache(#[values(true, false)] target_is_root: bool, env: &Te
base_version: 1,
is_placeholder: false,
need_sync: false,
last_updater: alice.device_id,
},
),
];
Expand Down Expand Up @@ -435,6 +443,7 @@ async fn read_folder_with_confined_entries(
is_placeholder: false,
need_sync: false,
size: 0,
last_updater: alice.device_id,
},
),
(
Expand All @@ -448,6 +457,7 @@ async fn read_folder_with_confined_entries(
base_version: 1,
is_placeholder: false,
need_sync: false,
last_updater: alice.device_id,
},
),
];
Expand Down Expand Up @@ -572,6 +582,7 @@ async fn read_folder_containing_under_modification_file(
is_placeholder: false,
need_sync: true,
size: expected_size,
last_updater: alice.device_id,
},
),
(
Expand All @@ -585,6 +596,7 @@ async fn read_folder_containing_under_modification_file(
base_version: 1,
is_placeholder: false,
need_sync: false,
last_updater: alice.device_id,
},
),
];
Expand Down
Loading

0 comments on commit 13bf17b

Please sign in to comment.