Stopped unnecessary seek for last_key
When rolling we already know the last_key - no need to seek for it on startup. The time it takes for this seek needs to be considered with regards to startup time. Can we do without knowing lastkey?
This commit is contained in:
parent
44cf5788ab
commit
0ddaaf9ac3
3 changed files with 17 additions and 6 deletions
|
@ -240,7 +240,7 @@ starting({open_writer, Filename}, _From, State) ->
|
||||||
hashtree=HashTree}};
|
hashtree=HashTree}};
|
||||||
starting({open_reader, Filename}, _From, State) ->
|
starting({open_reader, Filename}, _From, State) ->
|
||||||
leveled_log:log("CDB02", [Filename]),
|
leveled_log:log("CDB02", [Filename]),
|
||||||
{Handle, Index, LastKey} = open_for_readonly(Filename),
|
{Handle, Index, LastKey} = open_for_readonly(Filename, false),
|
||||||
{reply, ok, reader, State#state{handle=Handle,
|
{reply, ok, reader, State#state{handle=Handle,
|
||||||
last_key=LastKey,
|
last_key=LastKey,
|
||||||
filename=Filename,
|
filename=Filename,
|
||||||
|
@ -333,6 +333,7 @@ rolling({key_check, Key}, _From, State) ->
|
||||||
rolling({get_positions, _SampleSize}, _From, State) ->
|
rolling({get_positions, _SampleSize}, _From, State) ->
|
||||||
{reply, [], rolling, State};
|
{reply, [], rolling, State};
|
||||||
rolling({return_hashtable, IndexList, HashTreeBin}, _From, State) ->
|
rolling({return_hashtable, IndexList, HashTreeBin}, _From, State) ->
|
||||||
|
SW = os:timestamp(),
|
||||||
Handle = State#state.handle,
|
Handle = State#state.handle,
|
||||||
{ok, BasePos} = file:position(Handle, State#state.last_position),
|
{ok, BasePos} = file:position(Handle, State#state.last_position),
|
||||||
NewName = determine_new_filename(State#state.filename),
|
NewName = determine_new_filename(State#state.filename),
|
||||||
|
@ -341,7 +342,8 @@ rolling({return_hashtable, IndexList, HashTreeBin}, _From, State) ->
|
||||||
file:close(Handle),
|
file:close(Handle),
|
||||||
ok = rename_for_read(State#state.filename, NewName),
|
ok = rename_for_read(State#state.filename, NewName),
|
||||||
leveled_log:log("CDB03", [NewName]),
|
leveled_log:log("CDB03", [NewName]),
|
||||||
{NewHandle, Index, LastKey} = open_for_readonly(NewName),
|
{NewHandle, Index, LastKey} = open_for_readonly(NewName,
|
||||||
|
State#state.last_key),
|
||||||
case State#state.deferred_delete of
|
case State#state.deferred_delete of
|
||||||
true ->
|
true ->
|
||||||
{reply, ok, delete_pending, State#state{handle=NewHandle,
|
{reply, ok, delete_pending, State#state{handle=NewHandle,
|
||||||
|
@ -349,6 +351,7 @@ rolling({return_hashtable, IndexList, HashTreeBin}, _From, State) ->
|
||||||
filename=NewName,
|
filename=NewName,
|
||||||
hash_index=Index}};
|
hash_index=Index}};
|
||||||
false ->
|
false ->
|
||||||
|
leveled_log:log_timer("CDB18", [], SW),
|
||||||
{reply, ok, reader, State#state{handle=NewHandle,
|
{reply, ok, reader, State#state{handle=NewHandle,
|
||||||
last_key=LastKey,
|
last_key=LastKey,
|
||||||
filename=NewName,
|
filename=NewName,
|
||||||
|
@ -788,10 +791,16 @@ rename_for_read(Filename, NewName) ->
|
||||||
leveled_log:log("CDB08", [Filename, NewName, filelib:is_file(NewName)]),
|
leveled_log:log("CDB08", [Filename, NewName, filelib:is_file(NewName)]),
|
||||||
file:rename(Filename, NewName).
|
file:rename(Filename, NewName).
|
||||||
|
|
||||||
open_for_readonly(Filename) ->
|
open_for_readonly(Filename, LastKeyKnown) ->
|
||||||
{ok, Handle} = file:open(Filename, [binary, raw, read]),
|
{ok, Handle} = file:open(Filename, [binary, raw, read]),
|
||||||
Index = load_index(Handle),
|
Index = load_index(Handle),
|
||||||
LastKey = find_lastkey(Handle, Index),
|
LastKey =
|
||||||
|
case LastKeyKnown of
|
||||||
|
false ->
|
||||||
|
find_lastkey(Handle, Index);
|
||||||
|
LastKeyKnown ->
|
||||||
|
LastKeyKnown
|
||||||
|
end,
|
||||||
{Handle, Index, LastKey}.
|
{Handle, Index, LastKey}.
|
||||||
|
|
||||||
load_index(Handle) ->
|
load_index(Handle) ->
|
||||||
|
|
|
@ -297,7 +297,9 @@
|
||||||
{info, "CDB scan from start ~w in file with end ~w and last_key ~w"}},
|
{info, "CDB scan from start ~w in file with end ~w and last_key ~w"}},
|
||||||
{"CDB17",
|
{"CDB17",
|
||||||
{info, "After ~w PUTs total write time is ~w total sync time is ~w "
|
{info, "After ~w PUTs total write time is ~w total sync time is ~w "
|
||||||
++ "and max write time is ~w and max sync time is ~w"}}
|
++ "and max write time is ~w and max sync time is ~w"}},
|
||||||
|
{"CDB18",
|
||||||
|
{info, "Handled return and write of hashtable"}}
|
||||||
])).
|
])).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ many_put_fetch_head(_Config) ->
|
||||||
testutil:check_forobject(Bookie1, TestObject),
|
testutil:check_forobject(Bookie1, TestObject),
|
||||||
ok = leveled_bookie:book_close(Bookie1),
|
ok = leveled_bookie:book_close(Bookie1),
|
||||||
StartOpts2 = [{root_path, RootPath},
|
StartOpts2 = [{root_path, RootPath},
|
||||||
{max_journalsize, 1000000000},
|
{max_journalsize, 500000000},
|
||||||
{max_pencillercachesize, 32000},
|
{max_pencillercachesize, 32000},
|
||||||
{sync_strategy, testutil:sync_strategy()}],
|
{sync_strategy, testutil:sync_strategy()}],
|
||||||
{ok, Bookie2} = leveled_bookie:book_start(StartOpts2),
|
{ok, Bookie2} = leveled_bookie:book_start(StartOpts2),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue