diff --git a/src/leveled_log.erl b/src/leveled_log.erl index d435c4f..c3746c5 100644 --- a/src/leveled_log.erl +++ b/src/leveled_log.erl @@ -139,7 +139,7 @@ {info, "Timeout of snapshot with pid=~w at SQN=~w at TS ~w " ++ "set to timeout=~w"}}, {"P0039", - {info, "Failed to relase pid=~w " + {info, "Failed to release pid=~w " ++ "leaving SnapshotCount=~w and MinSQN=~w"}}, {"PC001", diff --git a/src/leveled_penciller.erl b/src/leveled_penciller.erl index 9994991..22d8b11 100644 --- a/src/leveled_penciller.erl +++ b/src/leveled_penciller.erl @@ -331,7 +331,7 @@ init([PCLopts]) -> PCLopts#penciller_options.start_snapshot, PCLopts#penciller_options.snapshot_query, PCLopts#penciller_options.bookies_mem} of - {undefined, true, Query, BookiesMem} -> + {undefined, _Snapshot=true, Query, BookiesMem} -> SrcPenciller = PCLopts#penciller_options.source_penciller, LongRunning = PCLopts#penciller_options.snapshot_longrunning, {ok, State} = pcl_registersnapshot(SrcPenciller, @@ -342,7 +342,7 @@ init([PCLopts]) -> leveled_log:log("P0001", [self()]), {ok, State#state{is_snapshot=true, source_penciller=SrcPenciller}}; - {_RootPath, false, _Q, _BM} -> + {_RootPath, _Snapshot=false, _Q, _BM} -> start_from_file(PCLopts) end. @@ -544,7 +544,9 @@ handle_call(doom, _From, State) -> handle_cast({manifest_change, NewManifest}, State) -> NewManSQN = leveled_pmanifest:get_manifest_sqn(NewManifest), ok = leveled_pclerk:clerk_promptdeletions(State#state.clerk, NewManSQN), - {noreply, State#state{manifest = NewManifest, work_ongoing=false}}; + UpdManifest = leveled_pmanifest:merge_snapshot(State#state.manifest, + NewManifest), + {noreply, State#state{manifest = UpdManifest, work_ongoing=false}}; handle_cast({release_snapshot, Snapshot}, State) -> Manifest0 = leveled_pmanifest:release_snapshot(State#state.manifest, Snapshot), diff --git a/src/leveled_pmanifest.erl b/src/leveled_pmanifest.erl index 61e227e..8fc4dba 100644 --- a/src/leveled_pmanifest.erl +++ b/src/leveled_pmanifest.erl @@ -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) ->