Returning snapshots

If the clerk updates the manifest - it might not recognise changes to
the manifest made since the clerk took the manifest.  So the penciller
must merge its view of the snapshots back in to the updated manifest
This commit is contained in:
martinsumner 2017-04-19 22:46:37 +01:00
parent fa9daf8696
commit 4d12dfe0ab
3 changed files with 17 additions and 6 deletions

View file

@ -37,6 +37,7 @@
mergefile_selector/2,
add_snapshot/3,
release_snapshot/2,
merge_snapshot/2,
ready_to_delete/2,
check_for_work/2,
is_basement/2,
@ -266,18 +267,26 @@ mergefile_selector(Manifest, LevelIdx) ->
{_SK, ME} = lists:nth(random:uniform(length(Level)), Level),
ME.
%% When the cllerk returns an update manifest to the penciller, the penciller
%% should restore its view of the snapshots to that manifest
merge_snapshot(PencillerManifest, ClerkManifest) ->
ClerkManifest#manifest{snapshots =
PencillerManifest#manifest.snapshots,
min_snapshot_sqn =
PencillerManifest#manifest.min_snapshot_sqn}.
add_snapshot(Manifest, Pid, Timeout) ->
SnapEntry = {Pid, Manifest#manifest.manifest_sqn, seconds_now(), Timeout},
SnapList0 = [SnapEntry|Manifest#manifest.snapshots],
ManSQN = Manifest#manifest.manifest_sqn,
case Manifest#manifest.min_snapshot_sqn of
0 ->
Manifest#manifest{snapshots = SnapList0,
min_snapshot_sqn = ManSQN};
N ->
N0 = min(N, ManSQN),
Manifest#manifest{snapshots = SnapList0, min_snapshot_sqn = N0}
Manifest#manifest{snapshots = SnapList0,
min_snapshot_sqn = N0}
end.
release_snapshot(Manifest, Pid) ->