diff --git a/rebar.config.script b/rebar.config.script index 413b50d..01c1b67 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -1,11 +1,4 @@ %% -*- erlang-mode -*- -case os:getenv("ERLANG_ROCKSDB_OPTS") of - false -> - true = os:putenv("ERLANG_ROCKSDB_OPTS", "-DWITH_BUNDLE_LZ4=ON"); - _ -> - %% If manually set, we assume it's throught through - skip -end. case os:getenv("DEBUG") of "true" -> Opts = proplists:get_value(erl_opts, CONFIG, []), diff --git a/src/mnesia_rocksdb.erl b/src/mnesia_rocksdb.erl index 8cb4b6d..e7b1e2f 100644 --- a/src/mnesia_rocksdb.erl +++ b/src/mnesia_rocksdb.erl @@ -346,14 +346,11 @@ semantics(_Alias, index_fun) -> fun index_f/4; semantics(_Alias, _) -> undefined. is_index_consistent(Alias, {Tab, index, PosInfo}) -> - case info(Alias, Tab, {index_consistent, PosInfo}) of - true -> true; - _ -> false - end. + mnesia_rocksdb_admin:read_info(Alias, Tab, {index_consistent, PosInfo}, false). -index_is_consistent(_Alias, {Tab, index, PosInfo}, Bool) +index_is_consistent(Alias, {Tab, index, PosInfo}, Bool) when is_boolean(Bool) -> - mrdb:write_info(Tab, {index_consistent, PosInfo}, Bool). + mnesia_rocksdb_admin:write_info(Alias, Tab, {index_consistent, PosInfo}, Bool). %% PRIVATE FUN @@ -454,8 +451,13 @@ close_table(Alias, Tab) -> error -> ok; _ -> - ok = mnesia_rocksdb_admin:prep_close(Alias, Tab), - close_table_(Alias, Tab) + case get(mnesia_dumper_dets) of + undefined -> + ok = mnesia_rocksdb_admin:prep_close(Alias, Tab), + close_table_(Alias, Tab); + _ -> + ok + end end. close_table_(Alias, Tab) -> @@ -798,7 +800,7 @@ handle_call({create_table, Tab, Props}, _From, exit:{aborted, Error} -> {reply, {aborted, Error}, St} end; -handle_call({load_table, _LoadReason, Props}, _From, +handle_call({load_table, _LoadReason, Props}, {Pid,_}, #st{alias = Alias, tab = Tab} = St) -> {ok, _Ref} = mnesia_rocksdb_admin:load_table(Alias, Tab, Props), {reply, ok, St#st{status = active}}; @@ -826,7 +828,7 @@ handle_call({delete, Key}, _From, St) -> handle_call({match_delete, Pat}, _From, #st{tab = Tab} = St) -> Res = mrdb:match_delete(get_ref(Tab), Pat), {reply, Res, St}; -handle_call(close_table, _From, #st{alias = Alias, tab = Tab} = St) -> +handle_call(close_table, {Pid,_}, #st{alias = Alias, tab = Tab} = St) -> _ = mnesia_rocksdb_admin:close_table(Alias, Tab), {reply, ok, St#st{status = undefined}}; handle_call(delete_table, _From, #st{alias = Alias, tab = Tab} = St) -> diff --git a/src/mnesia_rocksdb_admin.erl b/src/mnesia_rocksdb_admin.erl index d99ef2a..5c1cd43 100644 --- a/src/mnesia_rocksdb_admin.erl +++ b/src/mnesia_rocksdb_admin.erl @@ -280,9 +280,12 @@ write_info(Alias, Tab, K, V) -> write_info_(get_ref({admin, Alias}), Tab, K, V). write_info_(Ref, Tab, K, V) -> + write_info_encv(Ref, Tab, K, term_to_binary(V)). + +write_info_encv(Ref, Tab, K, V) -> EncK = mnesia_rocksdb_lib:encode_key({info,Tab,K}, sext), maybe_write_standalone_info(Ref, K, V), - mrdb:rdb_put(Ref, EncK, term_to_binary(V), []). + mrdb:rdb_put(Ref, EncK, V, []). maybe_write_standalone_info(Ref, K, V) -> case Ref of @@ -510,12 +513,17 @@ intersection(A, B) -> -spec handle_req(alias(), req(), backend(), st()) -> gen_server_reply(). handle_req(Alias, {create_table, Name, Props}, Backend, St) -> - case create_trec(Alias, Name, Props, Backend, St) of - {ok, NewCf} -> - St1 = update_cf(Alias, Name, NewCf, St), - {reply, {ok, NewCf}, St1}; - {error, _} = Error -> - {reply, Error, St} + case find_cf(Alias, Name, Backend, St) of + {ok, TRec} -> + {reply, {ok, TRec}, St}; + error -> + case create_trec(Alias, Name, Props, Backend, St) of + {ok, NewCf} -> + St1 = update_cf(Alias, Name, NewCf, St), + {reply, {ok, NewCf}, St1}; + {error, _} = Error -> + {reply, Error, St} + end end; handle_req(Alias, {load_table, Name, Props}, Backend, St) -> try @@ -1223,7 +1231,18 @@ load_info_(Res, I, ARef, Tab) -> DecK = mnesia_rocksdb_lib:decode_key(K), case read_info_(ARef, Tab, DecK, undefined) of undefined -> - write_info_(ARef, Tab, DecK, V); + write_info_encv(ARef, Tab, DecK, V); + <<131,_/binary>> = Value -> + %% Due to a previous bug, info values could be double-encoded with binary_to_term() + try binary_to_term(Value) of + _DecVal -> + %% We haven't been storing erlang-term encoded data as info, + %% so assume this is double-encoded and correct + write_info_encv(ARef, Tab, DecK, Value) + catch + error:_ -> + skip + end; _ -> skip end,