Pass through sync_strategy
Allow to switch for Riak to use o_sync as the sync flag rather than sync
This commit is contained in:
parent
03d025d581
commit
196c807b5e
7 changed files with 105 additions and 29 deletions
|
@ -118,7 +118,7 @@
|
|||
terminate/2,
|
||||
code_change/3,
|
||||
book_start/1,
|
||||
book_start/3,
|
||||
book_start/4,
|
||||
book_put/5,
|
||||
book_put/6,
|
||||
book_tempput/7,
|
||||
|
@ -159,10 +159,11 @@
|
|||
%%% API
|
||||
%%%============================================================================
|
||||
|
||||
book_start(RootPath, LedgerCacheSize, JournalSize) ->
|
||||
book_start(RootPath, LedgerCacheSize, JournalSize, SyncStrategy) ->
|
||||
book_start([{root_path, RootPath},
|
||||
{cache_size, LedgerCacheSize},
|
||||
{max_journalsize, JournalSize}]).
|
||||
{max_journalsize, JournalSize},
|
||||
{sync_strategy, SyncStrategy}]).
|
||||
|
||||
book_start(Opts) ->
|
||||
gen_server:start(?MODULE, [Opts], []).
|
||||
|
@ -661,7 +662,7 @@ snapshot_store(State, SnapType) ->
|
|||
|
||||
set_options(Opts) ->
|
||||
MaxJournalSize = get_opt(max_journalsize, Opts, 10000000000),
|
||||
|
||||
SyncStrat = get_opt(sync_strategy, Opts, sync),
|
||||
WRP = get_opt(waste_retention_period, Opts),
|
||||
|
||||
AltStrategy = get_opt(reload_strategy, Opts, []),
|
||||
|
@ -680,7 +681,8 @@ set_options(Opts) ->
|
|||
max_run_length = get_opt(max_run_length, Opts),
|
||||
waste_retention_period = WRP,
|
||||
cdb_options = #cdb_options{max_size=MaxJournalSize,
|
||||
binary_mode=true}},
|
||||
binary_mode=true,
|
||||
sync_strategy=SyncStrat}},
|
||||
#penciller_options{root_path = LedgerFP,
|
||||
max_inmemory_tablesize = PCLL0CacheSize}}.
|
||||
|
||||
|
|
|
@ -107,7 +107,8 @@
|
|||
delete_point = 0 :: integer(),
|
||||
inker :: pid(),
|
||||
deferred_delete = false :: boolean(),
|
||||
waste_path :: string()}).
|
||||
waste_path :: string(),
|
||||
sync_strategy = none}).
|
||||
|
||||
|
||||
%%%============================================================================
|
||||
|
@ -222,12 +223,14 @@ init([Opts]) ->
|
|||
starting,
|
||||
#state{max_size=MaxSize,
|
||||
binary_mode=Opts#cdb_options.binary_mode,
|
||||
waste_path=Opts#cdb_options.waste_path}}.
|
||||
waste_path=Opts#cdb_options.waste_path,
|
||||
sync_strategy=Opts#cdb_options.sync_strategy}}.
|
||||
|
||||
starting({open_writer, Filename}, _From, State) ->
|
||||
leveled_log:log("CDB01", [Filename]),
|
||||
{LastPosition, HashTree, LastKey} = open_active_file(Filename),
|
||||
{ok, Handle} = file:open(Filename, [sync | ?WRITE_OPS]),
|
||||
WriteOps = set_writeops(State#state.sync_strategy),
|
||||
{ok, Handle} = file:open(Filename, WriteOps),
|
||||
{reply, ok, writer, State#state{handle=Handle,
|
||||
last_position=LastPosition,
|
||||
last_key=LastKey,
|
||||
|
@ -520,6 +523,23 @@ code_change(_OldVsn, StateName, State, _Extra) ->
|
|||
%%% Internal functions
|
||||
%%%============================================================================
|
||||
|
||||
%% Assumption is that sync should be used - it is a transaction log.
|
||||
%%
|
||||
%% When running the Riak-specific version on Erlang 16, it sets the sync flag
|
||||
%% using the o_sync keyword (as it is in posix). If using a non-Basho OTP 16
|
||||
%% sync is not possible so none will need to be passed. This is not
|
||||
%% recommended, but is allowed here to make it simpler to test against
|
||||
%% off-the-shelf OTP 16
|
||||
set_writeops(SyncStrategy) ->
|
||||
case SyncStrategy of
|
||||
sync ->
|
||||
[sync | ?WRITE_OPS];
|
||||
riak_sync ->
|
||||
[o_sync | ?WRITE_OPS];
|
||||
none ->
|
||||
?WRITE_OPS
|
||||
end.
|
||||
|
||||
|
||||
%% from_dict(FileName,ListOfKeyValueTuples)
|
||||
%% Given a filename and a dictionary, create a cdb
|
||||
|
@ -1867,6 +1887,9 @@ crc_corrupt_writer_test() ->
|
|||
?assertMatch({"Key100", "Value100"}, cdb_get(P2, "Key100")),
|
||||
ok = cdb_close(P2).
|
||||
|
||||
riak_writeops_test() ->
|
||||
?assertMatch([o_sync, binary, raw, read, write], set_writeops(riak_sync)).
|
||||
|
||||
nonsense_coverage_test() ->
|
||||
{ok, Pid} = gen_fsm:start(?MODULE, [#cdb_options{}], []),
|
||||
ok = gen_fsm:send_all_state_event(Pid, nonsense),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue