diff --git a/doc/index.html b/doc/index.html deleted file mode 100644 index aee6928..0000000 --- a/doc/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - -The mnesia_rocksdb application - - - - - - -<h2>This page uses frames</h2> -<p>Your browser does not accept frames. -<br>You should go to the <a href="overview-summary.html">non-frame version</a> instead. -</p> - - - \ No newline at end of file diff --git a/doc/mnesia_rocksdb.html b/doc/mnesia_rocksdb.html deleted file mode 100644 index fb5d9a0..0000000 --- a/doc/mnesia_rocksdb.html +++ /dev/null @@ -1,529 +0,0 @@ - - - - -Module mnesia_rocksdb - - - - -
- -

Module mnesia_rocksdb

-rocksdb storage backend for Mnesia. - -

Behaviours: gen_server, mnesia_backend_type.

- -

Description

rocksdb storage backend for Mnesia.

- - This module implements a mnesia backend callback plugin. - It's specifically documented to try to explain the workings of - backend plugins. - -

Data Types

- -

alias()

-

alias() = atom()

- - -

data_tab()

-

data_tab() = atom()

- - -

error()

-

error() = {error, any()}

- - -

index_info()

-

index_info() = {index_pos(), index_type()}

- - -

index_pos()

-

index_pos() = integer() | {atom()}

- - -

index_tab()

-

index_tab() = {data_tab(), index, index_info()}

- - -

index_type()

-

index_type() = ordered

- - -

retainer_name()

-

retainer_name() = any()

- - -

retainer_tab()

-

retainer_tab() = {data_tab(), retainer, retainer_name()}

- - -

table()

-

table() = data_tab() | index_tab() | retainer_tab()

- - -

table_type()

-

table_type() = set | ordered_set | bag

- - -

Function Index

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
add_aliases/1
check_definition/4
close_table/2
code_change/3
create_schema/1
create_schema/2
create_table/3
decode_key/1
decode_key/2
decode_val/1
decode_val/3
default_alias/0
delete/3
delete_table/2
encode_key/1
encode_key/2
encode_val/1
encode_val/2
first/2
fixtable/3
handle_call/3
handle_cast/2
handle_info/2
index_is_consistent/3
info/3
init/1
init_backend/0Called by mnesia_schema in order to intialize the backend.
insert/3
is_index_consistent/2
ix_listvals/3
ix_prefixes/3
last/2
load_table/4
lookup/3
match_delete/3
next/3
prev/3
real_suffixes/0
receive_data/5
receive_done/4
receiver_first_message/4
register/0Equivalent to register(rocksdb_copies). -
register/1Convenience function for registering a mnesia_rocksdb backend plugin.
remove_aliases/1
repair_continuation/2
select/1
select/3
select/4
semantics/2
sender_handle_info/5
sender_init/4
show_table/1A debug function that shows the rocksdb table content.
show_table/2
slot/3
start_proc/6
sync_close_table/2
terminate/2
tmp_suffixes/0
update_counter/4
validate_key/6
validate_record/6
- -

Function Details

- -

add_aliases/1

-
-

add_aliases(Aliases) -> any()

-

-
- -

check_definition/4

-
-

check_definition(Alias, Tab, Nodes, Props) -> any()

-

-
- -

close_table/2

-
-

close_table(Alias, Tab) -> any()

-

-
- -

code_change/3

-
-

code_change(FromVsn, St, Extra) -> any()

-

-
- -

create_schema/1

-
-

create_schema(Nodes) -> any()

-

-
- -

create_schema/2

-
-

create_schema(Nodes, Aliases) -> any()

-

-
- -

create_table/3

-
-

create_table(Alias, Tab, Props) -> any()

-

-
- -

decode_key/1

-
-

decode_key(Key) -> any()

-

-
- -

decode_key/2

-
-

decode_key(Key, Metadata) -> any()

-

-
- -

decode_val/1

-
-

decode_val(Val) -> any()

-

-
- -

decode_val/3

-
-

decode_val(Val, Key, Metadata) -> any()

-

-
- -

default_alias/0

-
-

default_alias() -> any()

-

-
- -

delete/3

-
-

delete(Alias, Tab, Key) -> any()

-

-
- -

delete_table/2

-
-

delete_table(Alias, Tab) -> any()

-

-
- -

encode_key/1

-
-

encode_key(Key) -> any()

-

-
- -

encode_key/2

-
-

encode_key(Key, Metadata) -> any()

-

-
- -

encode_val/1

-
-

encode_val(Val) -> any()

-

-
- -

encode_val/2

-
-

encode_val(Val, Metadata) -> any()

-

-
- -

first/2

-
-

first(Alias, Tab) -> any()

-

-
- -

fixtable/3

-
-

fixtable(Alias, Tab, Bool) -> any()

-

-
- -

handle_call/3

-
-

handle_call(M, From, St) -> any()

-

-
- -

handle_cast/2

-
-

handle_cast(X1, St) -> any()

-

-
- -

handle_info/2

-
-

handle_info(EXIT, St) -> any()

-

-
- -

index_is_consistent/3

-
-

index_is_consistent(Alias, X2, Bool) -> any()

-

-
- -

info/3

-
-

info(Alias, Tab, Item) -> any()

-

-
- -

init/1

-
-

init(X1) -> any()

-

-
- -

init_backend/0

-
-

init_backend() -> any()

-

-

Called by mnesia_schema in order to intialize the backend

- -

This is called when the backend is registered with the first alias, or ...

- -

See OTP issue #425 (16 Feb 2021). This callback is supposed to be called -before first use of the backend, but unfortunately, it is only called at -mnesia startup and when a backend module is registered MORE THAN ONCE. -This means we need to handle this function being called multiple times.

- -

The bug has been fixed as of OTP 24.0-rc3

- -

If processes need to be started, this can be done using - mnesia_ext_sup:start_proc(Name, Mod, F, Args [, Opts]) -where Opts are parameters for the supervised child:

- - * restart (default: transient) - * shutdown (default: 120000) - * type (default: worker) - * modules (default: [Mod])

- -

insert/3

-
-

insert(Alias, Tab, Obj) -> any()

-

-
- -

is_index_consistent/2

-
-

is_index_consistent(Alias, X2) -> any()

-

-
- -

ix_listvals/3

-
-

ix_listvals(Tab, Pos, Obj) -> any()

-

-
- -

ix_prefixes/3

-
-

ix_prefixes(Tab, Pos, Obj) -> any()

-

-
- -

last/2

-
-

last(Alias, Tab) -> any()

-

-
- -

load_table/4

-
-

load_table(Alias, Tab, LoadReason, Props) -> any()

-

-
- -

lookup/3

-
-

lookup(Alias, Tab, Key) -> any()

-

-
- -

match_delete/3

-
-

match_delete(Alias, Tab, Pat) -> any()

-

-
- -

next/3

-
-

next(Alias, Tab, Key) -> any()

-

-
- -

prev/3

-
-

prev(Alias, Tab, Key) -> any()

-

-
- -

real_suffixes/0

-
-

real_suffixes() -> any()

-

-
- -

receive_data/5

-
-

receive_data(Data, Alias, Tab, Sender, State) -> any()

-

-
- -

receive_done/4

-
-

receive_done(Alias, Tab, Sender, State) -> any()

-

-
- -

receiver_first_message/4

-
-

receiver_first_message(Pid, Msg, Alias, Tab) -> any()

-

-
- -

register/0

-
-

register() -> {ok, alias()} | {error, term()}

-

-

Equivalent to register(rocksdb_copies).

- - -

register/1

-
-

register(Alias::alias()) -> {ok, alias()} | error()

-

-

Convenience function for registering a mnesia_rocksdb backend plugin

- - The function used to register a plugin is mnesia_schema:add_backend_type(Alias, Module) - where Module implements a backend_type behavior. Alias is an atom, and is used - in the same way as ram_copies etc. The default alias is rocksdb_copies.

- -

remove_aliases/1

-
-

remove_aliases(Aliases) -> any()

-

-
- -

repair_continuation/2

-
-

repair_continuation(Cont, Ms) -> any()

-

-
- -

select/1

-
-

select(Cont) -> any()

-

-
- -

select/3

-
-

select(Alias, Tab, Ms) -> any()

-

-
- -

select/4

-
-

select(Alias, IxTab, Ms, Limit) -> any()

-

-
- -

semantics/2

-
-

semantics(Alias, X2) -> any()

-

-
- -

sender_handle_info/5

-
-

sender_handle_info(Msg, Alias, Tab, ReceiverPid, Cont) -> any()

-

-
- -

sender_init/4

-
-

sender_init(Alias, Tab, RemoteStorage, Pid) -> any()

-

-
- -

show_table/1

-
-

show_table(Tab) -> any()

-

-

A debug function that shows the rocksdb table content

- -

show_table/2

-
-

show_table(Tab, Limit) -> any()

-

-
- -

slot/3

-
-

slot(Alias, Tab, Pos) -> any()

-

-
- -

start_proc/6

-
-

start_proc(Alias, Tab, Type, ProcName, Props, RdbOpts) -> any()

-

-
- -

sync_close_table/2

-
-

sync_close_table(Alias, Tab) -> any()

-

-
- -

terminate/2

-
-

terminate(Reason, St) -> any()

-

-
- -

tmp_suffixes/0

-
-

tmp_suffixes() -> any()

-

-
- -

update_counter/4

-
-

update_counter(Alias, Tab, C, Val) -> any()

-

-
- -

validate_key/6

-
-

validate_key(Alias, Tab, RecName, Arity, Type, Key) -> any()

-

-
- -

validate_record/6

-
-

validate_record(Alias, Tab, RecName, Arity, Type, Obj) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mnesia_rocksdb_admin.html b/doc/mnesia_rocksdb_admin.html deleted file mode 100644 index 82dd924..0000000 --- a/doc/mnesia_rocksdb_admin.html +++ /dev/null @@ -1,294 +0,0 @@ - - - - -Module mnesia_rocksdb_admin - - - - -
- -

Module mnesia_rocksdb_admin

- - -

Behaviours: gen_server.

- -

Data Types

- -

alias()

-

alias() = atom()

- - -

backend()

-

backend() = #{db_ref := db_ref(), cf_info := #{table() := cf()}}

- - -

cf()

-

cf() = mrdb:db_ref()

- - -

db_ref()

-

db_ref() = rocksdb:db_handle()

- - -

gen_server_noreply()

-

gen_server_noreply() = {noreply, st()} | {stop, reason(), st()}

- - -

gen_server_reply()

-

gen_server_reply() = {reply, reply(), st()} | {stop, reason(), reply(), st()}

- - -

properties()

-

properties() = [{atom(), any()}]

- - -

reason()

-

reason() = any()

- - -

reply()

-

reply() = any()

- - -

req()

-

req() = {create_table, table(), properties()} | {delete_table, table()} | {load_table, table(), properties()} | {related_resources, table()} | {get_ref, table()} | {add_aliases, [alias()]} | {write_table_property, tabname(), tuple()} | {remove_aliases, [alias()]} | {migrate, [{tabname(), map()}], rpt()} | {prep_close, table()} | {close_table, table()} | {clear_table, table() | cf()}

- - -

rpt()

-

rpt() = undefined | map()

- - -

st()

-

st() = #st{backends = #{alias() => backend()}, standalone = #{{alias(), table()} := cf()}, default_opts = [{atom(), term()}]}

- - -

table()

-

table() = tabname() | {admin, alias()} | {tabname(), index, any()} | {tabname(), retainer, any()}

- - -

tabname()

-

tabname() = atom()

- - -

Function Index

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
add_aliases/1
clear_table/1
close_table/2
code_change/3
create_table/3
delete_table/2
ensure_started/0
get_cached_env/2
get_ref/1
get_ref/2
handle_call/3
handle_cast/2
handle_info/2
init/1
load_table/3
meta/0
migrate_standalone/2
migrate_standalone/3
prep_close/2
read_info/1
read_info/2
read_info/4
related_resources/2
remove_aliases/1
request_ref/2
set_and_cache_env/2
start_link/0
terminate/2
write_info/4
write_table_property/3
- -

Function Details

- -

add_aliases/1

-
-

add_aliases(Aliases) -> any()

-

-
- -

clear_table/1

-
-

clear_table(Name) -> any()

-

-
- -

close_table/2

-
-

close_table(Alias, Name) -> any()

-

-
- -

code_change/3

-
-

code_change(FromVsn, St, Extra) -> any()

-

-
- -

create_table/3

-
-

create_table(Alias, Name, Props) -> any()

-

-
- -

delete_table/2

-
-

delete_table(Alias::alias(), Name::tabname()) -> ok

-

-
- -

ensure_started/0

-
-

ensure_started() -> ok

-

-
- -

get_cached_env/2

-
-

get_cached_env(Key, Default) -> any()

-

-
- -

get_ref/1

-
-

get_ref(Name) -> any()

-

-
- -

get_ref/2

-
-

get_ref(Name, Default) -> any()

-

-
- -

handle_call/3

-
-

handle_call(Req::{alias(), req()}, From::any(), St::st()) -> gen_server_reply()

-

-
- -

handle_cast/2

-
-

handle_cast(Msg::any(), St::st()) -> gen_server_noreply()

-

-
- -

handle_info/2

-
-

handle_info(Msg::any(), St::st()) -> gen_server_noreply()

-

-
- -

init/1

-
-

init(X1) -> any()

-

-
- -

load_table/3

-
-

load_table(Alias, Name, Props) -> any()

-

-
- -

meta/0

-
-

meta() -> any()

-

-
- -

migrate_standalone/2

-
-

migrate_standalone(Alias, Tabs) -> any()

-

-
- -

migrate_standalone/3

-
-

migrate_standalone(Alias, Tabs, Rpt0) -> any()

-

-
- -

prep_close/2

-
-

prep_close(Alias, Tab) -> any()

-

-
- -

read_info/1

-
-

read_info(TRec) -> any()

-

-
- -

read_info/2

-
-

read_info(Alias, Tab) -> any()

-

-
- -

read_info/4

-
-

read_info(Alias, Tab, K, Default) -> any()

-

-
- -

related_resources/2

-
-

related_resources(Alias, Name) -> any()

-

-
- -

remove_aliases/1

-
-

remove_aliases(Aliases) -> any()

-

-
- -

request_ref/2

-
-

request_ref(Alias, Name) -> any()

-

-
- -

set_and_cache_env/2

-
-

set_and_cache_env(Key, Value) -> any()

-

-
- -

start_link/0

-
-

start_link() -> any()

-

-
- -

terminate/2

-
-

terminate(X1, St) -> any()

-

-
- -

write_info/4

-
-

write_info(Alias, Tab, K, V) -> any()

-

-
- -

write_table_property/3

-
-

write_table_property(Alias, Tab, Prop) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mnesia_rocksdb_app.html b/doc/mnesia_rocksdb_app.html deleted file mode 100644 index bd763b9..0000000 --- a/doc/mnesia_rocksdb_app.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - -Module mnesia_rocksdb_app - - - - -
- -

Module mnesia_rocksdb_app

- - -

Behaviours: application.

- -

Function Index

- - -
start/2
stop/1
- -

Function Details

- -

start/2

-
-

start(StartType, StartArgs) -> any()

-

-
- -

stop/1

-
-

stop(State) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mnesia_rocksdb_lib.html b/doc/mnesia_rocksdb_lib.html deleted file mode 100644 index 5f6a873..0000000 --- a/doc/mnesia_rocksdb_lib.html +++ /dev/null @@ -1,181 +0,0 @@ - - - - -Module mnesia_rocksdb_lib - - - - -
- -

Module mnesia_rocksdb_lib

-RocksDB update wrappers, in separate module for easy tracing and mocking. - - -

Description

RocksDB update wrappers, in separate module for easy tracing and mocking. - -

Function Index

- - - - - - - - - - - - - - - - - - - - - - -
check_encoding/2
create_mountpoint/1
data_mountpoint/1
decode/2
decode_key/1
decode_key/2
decode_val/1
decode_val/3
default_encoding/3
delete/3
encode/2
encode_key/1
encode_key/2
encode_val/1
encode_val/2
keypos/1
open_rocksdb/3
put/4
tabname/1
valid_key_type/2
valid_obj_type/2
write/3
- -

Function Details

- -

check_encoding/2

-
-

check_encoding(Encoding, Attributes) -> any()

-

-
- -

create_mountpoint/1

-
-

create_mountpoint(Tab) -> any()

-

-
- -

data_mountpoint/1

-
-

data_mountpoint(Tab) -> any()

-

-
- -

decode/2

-
-

decode(Val, X2) -> any()

-

-
- -

decode_key/1

-
-

decode_key(CodedKey::binary()) -> any()

-

-
- -

decode_key/2

-
-

decode_key(CodedKey, Enc) -> any()

-

-
- -

decode_val/1

-
-

decode_val(CodedVal::binary()) -> any()

-

-
- -

decode_val/3

-
-

decode_val(CodedVal, K, Ref) -> any()

-

-
- -

default_encoding/3

-
-

default_encoding(X1, Type, As) -> any()

-

-
- -

delete/3

-
-

delete(Ref, K, Opts) -> any()

-

-
- -

encode/2

-
-

encode(Value, X2) -> any()

-

-
- -

encode_key/1

-
-

encode_key(Key::any()) -> binary()

-

-
- -

encode_key/2

-
-

encode_key(Key, X2) -> any()

-

-
- -

encode_val/1

-
-

encode_val(Val::any()) -> binary()

-

-
- -

encode_val/2

-
-

encode_val(Val, Enc) -> any()

-

-
- -

keypos/1

-
-

keypos(Tab) -> any()

-

-
- -

open_rocksdb/3

-
-

open_rocksdb(MPd, RdbOpts, CFs) -> any()

-

-
- -

put/4

-
-

put(Ref, K, V, Opts) -> any()

-

-
- -

tabname/1

-
-

tabname(Tab) -> any()

-

-
- -

valid_key_type/2

-
-

valid_key_type(X1, Key) -> any()

-

-
- -

valid_obj_type/2

-
-

valid_obj_type(X1, Obj) -> any()

-

-
- -

write/3

-
-

write(X1, L, Opts) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mnesia_rocksdb_params.html b/doc/mnesia_rocksdb_params.html deleted file mode 100644 index 087b8ae..0000000 --- a/doc/mnesia_rocksdb_params.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - -Module mnesia_rocksdb_params - - - - -
- -

Module mnesia_rocksdb_params

- - -

Behaviours: gen_server.

- -

Function Index

- - - - - - - - - - -
code_change/3
delete/1
handle_call/3
handle_cast/2
handle_info/2
init/1
lookup/2
start_link/0
store/2
terminate/2
- -

Function Details

- -

code_change/3

-
-

code_change(X1, S, X3) -> any()

-

-
- -

delete/1

-
-

delete(Tab) -> any()

-

-
- -

handle_call/3

-
-

handle_call(X1, X2, S) -> any()

-

-
- -

handle_cast/2

-
-

handle_cast(X1, S) -> any()

-

-
- -

handle_info/2

-
-

handle_info(X1, S) -> any()

-

-
- -

init/1

-
-

init(X1) -> any()

-

-
- -

lookup/2

-
-

lookup(Tab, Default) -> any()

-

-
- -

start_link/0

-
-

start_link() -> any()

-

-
- -

store/2

-
-

store(Tab, Params) -> any()

-

-
- -

terminate/2

-
-

terminate(X1, X2) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mnesia_rocksdb_sup.html b/doc/mnesia_rocksdb_sup.html deleted file mode 100644 index 4a4d957..0000000 --- a/doc/mnesia_rocksdb_sup.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - -Module mnesia_rocksdb_sup - - - - -
- -

Module mnesia_rocksdb_sup

- - -

Behaviours: supervisor.

- -

Function Index

- - -
init/1
start_link/0
- -

Function Details

- -

init/1

-
-

init(X1) -> any()

-

-
- -

start_link/0

-
-

start_link() -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mnesia_rocksdb_tuning.html b/doc/mnesia_rocksdb_tuning.html deleted file mode 100644 index 1f31903..0000000 --- a/doc/mnesia_rocksdb_tuning.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - -Module mnesia_rocksdb_tuning - - - - -
- -

Module mnesia_rocksdb_tuning

- - - -

Function Index

- - - - - - - - - - - - - - - - - - -
cache/1
calc_sizes/0
calc_sizes/1
count_rdb_tabs/0
count_rdb_tabs/1
default/1
describe_env/0
get_avail_ram/0
get_maxfiles/0
get_maxfiles/1
ideal_max_files/0
ideal_max_files/1
max_files/1
rdb_indexes/0
rdb_indexes/1
rdb_tabs/0
rdb_tabs/1
write_buffer/1
- -

Function Details

- -

cache/1

-
-

cache(X1) -> any()

-

-
- -

calc_sizes/0

-
-

calc_sizes() -> any()

-

-
- -

calc_sizes/1

-
-

calc_sizes(D) -> any()

-

-
- -

count_rdb_tabs/0

-
-

count_rdb_tabs() -> any()

-

-
- -

count_rdb_tabs/1

-
-

count_rdb_tabs(Db) -> any()

-

-
- -

default/1

-
-

default(X1) -> any()

-

-
- -

describe_env/0

-
-

describe_env() -> any()

-

-
- -

get_avail_ram/0

-
-

get_avail_ram() -> any()

-

-
- -

get_maxfiles/0

-
-

get_maxfiles() -> any()

-

-
- -

get_maxfiles/1

-
-

get_maxfiles(X1) -> any()

-

-
- -

ideal_max_files/0

-
-

ideal_max_files() -> any()

-

-
- -

ideal_max_files/1

-
-

ideal_max_files(D) -> any()

-

-
- -

max_files/1

-
-

max_files(X1) -> any()

-

-
- -

rdb_indexes/0

-
-

rdb_indexes() -> any()

-

-
- -

rdb_indexes/1

-
-

rdb_indexes(Db) -> any()

-

-
- -

rdb_tabs/0

-
-

rdb_tabs() -> any()

-

-
- -

rdb_tabs/1

-
-

rdb_tabs(Db) -> any()

-

-
- -

write_buffer/1

-
-

write_buffer(X1) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/modules-frame.html b/doc/modules-frame.html deleted file mode 100644 index bebffb0..0000000 --- a/doc/modules-frame.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -The mnesia_rocksdb application - - - -

Modules

- - - - - - - - - - - - - -
mnesia_rocksdb
mnesia_rocksdb_admin
mnesia_rocksdb_app
mnesia_rocksdb_lib
mnesia_rocksdb_params
mnesia_rocksdb_sup
mnesia_rocksdb_tuning
mrdb
mrdb_index
mrdb_mutex
mrdb_mutex_serializer
mrdb_select
mrdb_stats
- - \ No newline at end of file diff --git a/doc/mrdb.html b/doc/mrdb.html deleted file mode 100644 index ec11659..0000000 --- a/doc/mrdb.html +++ /dev/null @@ -1,728 +0,0 @@ - - - - -Module mrdb - - - - -
- -

Module mrdb

-Mid-level access API for Mnesia-managed rocksdb tables. - - -

Description

Mid-level access API for Mnesia-managed rocksdb tables

- -

This module implements access functions for the mnesia_rocksdb -backend plugin. The functions are designed to also support -direct access to rocksdb with little overhead. Such direct -access will maintain existing indexes, but not support -replication.

- -

Each table has a metadata structure stored as a persistent -term for fast access. The structure of the metadata is as -follows:

- -
  #{ name       := <Logical table name>
-   , db_ref     := <Rocksdb database Ref>
-   , cf_handle  := <Rocksdb column family handle>
-   , activity   := Ongoing batch or transaction, if any (map())
-   , attr_pos   := #{AttrName := Pos}
-   , mode       := <Set to 'mnesia' for mnesia access flows>
-   , properties := <Mnesia table props in map format>
-   , type       := column_family | standalone
-   }
- -

Helper functions like as_batch(Ref, fun(R) -> ... end) and - with_iterator(Ref, fun(I) -> ... end) add some extra - convenience on top of the rocksdb API.

- - Note that no automatic provision exists to manage concurrent - updates via mnesia AND direct access to this API. It's advisable - to use ONE primary mode of access. If replication is used, - the mnesia API will support this, but direct mrdb updates will - not be replicated. -

Data Types

- -

activity()

-

activity() = tx_activity() | batch_activity()

- - -

activity_type()

-

activity_type() = mrdb_activity_type() | mnesia_activity_type()

- - -

admin_tab()

-

admin_tab() = {admin, alias()}

- - -

alias()

-

alias() = atom()

- - -

attr_pos()

-

attr_pos() = #{atom() := pos()}

- - -

batch_activity()

-

batch_activity() = #{type := batch, handle := batch_handle()}

- - -

batch_handle()

-

batch_handle() = rocksdb:batch_handle()

- - -

cf_handle()

-

cf_handle() = rocksdb:cf_handle()

- - -

db_handle()

-

db_handle() = rocksdb:db_handle()

- - -

db_ref()

-

db_ref() = #{name => table(), alias => atom(), vsn => non_neg_integer(), db_ref := db_handle(), cf_handle := cf_handle(), semantics := semantics(), encoding := encoding(), attr_pos := attr_pos(), type := column_family | standalone, status := open | closed | pre_existing, properties := properties(), mode => mnesia, ix_vals_f => fun((tuple()) -> [any()]), activity => activity(), term() => term()}

- - -

encoding()

-

encoding() = raw | sext | term | {key_encoding(), val_encoding()}

- - -

error()

-

error() = {error, any()}

- - -

index()

-

index() = {tab_name(), index, any()}

- - -

index_position()

-

index_position() = atom() | pos()

- - -

inner()

-

inner() = non_neg_integer()

- - -

iterator_action()

-

iterator_action() = first | last | next | prev | binary() | {seek, binary()} | {seek_for_prev, binary()}

- - -

itr_handle()

-

itr_handle() = rocksdb:itr_handle()

- - -

key()

-

key() = any()

- - -

key_encoding()

-

key_encoding() = raw | sext | term

- - -

mnesia_activity_type()

-

mnesia_activity_type() = transaction | sync_transaction | async_dirty | sync_dirty

- - -

mrdb_activity_type()

-

mrdb_activity_type() = tx | {tx, tx_options()} | batch

- - -

mrdb_iterator()

-

mrdb_iterator() = #mrdb_iter{i = itr_handle(), ref = db_ref()}

- - -

obj()

-

obj() = tuple()

- - -

outer()

-

outer() = non_neg_integer()

- - -

pos()

-

pos() = non_neg_integer()

- - -

properties()

-

properties() = #{record_name := atom(), attributes := [atom()], index := [{pos(), bag | ordered}]}

- - -

read_options()

-

read_options() = [{verify_checksums, boolean()} | {fill_cache, boolean()} | {iterate_upper_bound, binary()} | {iterate_lower_bound, binary()} | {tailing, boolean()} | {total_order_seek, boolean()} | {prefix_same_as_start, boolean()} | {snapshot, snapshot_handle()}]

- - -

ref_or_tab()

-

ref_or_tab() = table() | db_ref()

- - -

retainer()

-

retainer() = {tab_name(), retainer, any()}

- - -

retries()

-

retries() = outer() | {inner(), outer()}

- - -

semantics()

-

semantics() = bag | set

- - -

snapshot_handle()

-

snapshot_handle() = rocksdb:snapshot_handle()

- - -

tab_name()

-

tab_name() = atom()

- - -

table()

-

table() = atom() | admin_tab() | index() | retainer()

- - -

tx_activity()

-

tx_activity() = #{type := tx, handle := tx_handle(), attempt := undefined | retries()}

- - -

tx_handle()

-

tx_handle() = rocksdb:transaction_handle()

- - -

tx_options()

-

tx_options() = #{retries => retries(), no_snapshot => boolean()}

- - -

val_encoding()

-

val_encoding() = {value | object, term | raw} | raw

- - -

write_options()

-

write_options() = [{sync, boolean()} | {disable_wal, boolean()} | {ignore_missing_column_families, boolean()} | {no_slowdown, boolean()} | {low_pri, boolean()}]

- - -

Function Index

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
abort/1Aborts an ongoing activity/2
activity/3Run an activity (similar to //mnesia/mnesia:activity/2).
alias_of/1Returns the alias of a given table or table reference.
as_batch/2Creates a rocksdb batch context and executes the fun F in it.
as_batch/3as as_batch/2, but with the ability to pass Opts to rocksdb:write_batch/2
batch_write/2
batch_write/3
clear_table/1
current_context/0
delete/2
delete/3
delete_object/2
delete_object/3
ensure_ref/1
ensure_ref/2
first/1
first/2
fold/3
fold/4
fold/5
get_batch/1
get_ref/1
index_read/3
insert/2
insert/3
iterator/1
iterator/2
iterator_close/1
iterator_move/2
last/1
last/2
match_delete/2
new_tx/1
new_tx/2
next/2
next/3
prev/2
prev/3
rdb_delete/2
rdb_delete/3
rdb_fold/4
rdb_fold/5
rdb_get/2
rdb_get/3
rdb_iterator/1
rdb_iterator/2
rdb_iterator_move/2
rdb_put/3
rdb_put/4
read/2
read/3
read_info/1
read_info/2
release_snapshot/1release a snapshot created by snapshot/1.
select/1
select/2
select/3
snapshot/1Create a snapshot of the database instance associated with the -table reference, table name or alias.
tx_commit/1
tx_ref/2
update_counter/3
update_counter/4
with_iterator/2
with_iterator/3
with_rdb_iterator/2
with_rdb_iterator/3
write_info/3
- -

Function Details

- -

abort/1

-
-

abort(Reason) -> any()

-

-

Aborts an ongoing activity/2

- -

activity/3

-
-

activity(Type::activity_type(), Alias::alias(), F::fun(() -> Res)) -> Res

-

-

Run an activity (similar to //mnesia/mnesia:activity/2).

- - Supported activity types are: - - -

By default, transactions are combined with a snapshot with 1 retry. - The snapshot ensures that writes from concurrent transactions don't leak into the transaction context. - A transaction will be retried if it detects that the commit set conflicts with recent changes. - A mutex is used to ensure that only one of potentially conflicting mrdb transactions is run at a time. -The re-run transaction may still fail, if new transactions, or non-transaction writes interfere with -the commit set. It will then be re-run again, until the retry count is exhausted.

- -

For finer-grained retries, it's possible to set retries => {Inner, Outer}. Setting the retries to a - single number, Retries, is analogous to {0, Retries}`. Each outer retry requests amutex lock' by - waiting in a FIFO queue. Once it receives the lock, it will try the activity once + as many retries - as specified by Inner. If these fail, the activity again goes to the FIFO queue (ending up last - in line) if there are outer retries remaining. When all retries are exhaused, the activity aborts - with retry_limit. Note that transactions, being optimistic, do not request a lock on the first -attempt, but only on outer retries (the first retry is always an outer retry).

- -

Valid TxOpts are #{no_snapshot => boolean(), retries => retries()}.

- - To simplify code adaptation, tx | transaction | sync_transaction are synonyms, and - batch | async_dirty | sync_dirty are synonyms.

- -

alias_of/1

-
-

alias_of(Tab::ref_or_tab()) -> alias()

-

-

Returns the alias of a given table or table reference.

- -

as_batch/2

-
-

as_batch(Tab::ref_or_tab(), F::fun((db_ref()) -> Res)) -> Res

-

-

Creates a rocksdb batch context and executes the fun F in it.

- - %% Rocksdb batches aren't tied to a specific DbRef until written. - This can cause surprising problems if we're juggling multiple - rocksdb instances (as we do if we have standalone tables). - At the time of writing, all objects end up in the DbRef the batch - is written to, albeit not necessarily in the intended column family. - This will probably change, but no failure mode is really acceptable. - The code below ensures that separate batches are created for each - DbRef, under a unique reference stored in the pdict. When writing, - all batches are written separately to the corresponding DbRef, - and when releasing, all batches are released. This will not ensure - atomicity, but there is no way in rocksdb to achieve atomicity - across db instances. At least, data should end up where you expect. -

- -

as_batch/3

-
-

as_batch(Tab, F, Opts) -> any()

-

-

as as_batch/2, but with the ability to pass Opts to rocksdb:write_batch/2

- -

batch_write/2

-
-

batch_write(Tab, L) -> any()

-

-
- -

batch_write/3

-
-

batch_write(Tab, L, Opts) -> any()

-

-
- -

clear_table/1

-
-

clear_table(Tab) -> any()

-

-
- -

current_context/0

-
-

current_context() -> any()

-

-
- -

delete/2

-
-

delete(Tab::ref_or_tab(), Key::key()) -> ok

-

-
- -

delete/3

-
-

delete(Tab::ref_or_tab(), Key::key(), Opts::write_options()) -> ok

-

-
- -

delete_object/2

-
-

delete_object(Tab, Obj) -> any()

-

-
- -

delete_object/3

-
-

delete_object(Tab, Obj, Opts) -> any()

-

-
- -

ensure_ref/1

-
-

ensure_ref(R::ref_or_tab()) -> db_ref()

-

-
- -

ensure_ref/2

-
-

ensure_ref(Ref, R) -> any()

-

-
- -

first/1

-
-

first(Tab::ref_or_tab()) -> key() | '$end_of_table'

-

-
- -

first/2

-
-

first(Tab::ref_or_tab(), Opts::read_options()) -> key() | '$end_of_table'

-

-
- -

fold/3

-
-

fold(Tab, Fun, Acc) -> any()

-

-
- -

fold/4

-
-

fold(Tab, Fun, Acc, MatchSpec) -> any()

-

-
- -

fold/5

-
-

fold(Tab, Fun, Acc, MatchSpec, Limit) -> any()

-

-
- -

get_batch/1

-
-

get_batch(X1) -> any()

-

-
- -

get_ref/1

-
-

get_ref(Tab::table()) -> db_ref()

-

-
- -

index_read/3

-
-

index_read(Tab, Val, Ix) -> any()

-

-
- -

insert/2

-
-

insert(Tab::ref_or_tab(), Obj::obj()) -> ok

-

-
- -

insert/3

-
-

insert(Tab::ref_or_tab(), Obj0::obj(), Opts::write_options()) -> ok

-

-
- -

iterator/1

-
-

iterator(Tab::ref_or_tab()) -> {ok, mrdb_iterator()} | {error, term()}

-

-
- -

iterator/2

-
-

iterator(Tab::ref_or_tab(), Opts::read_options()) -> {ok, mrdb_iterator()} | {error, term()}

-

-
- -

iterator_close/1

-
-

iterator_close(Mrdb_iter::mrdb_iterator()) -> ok

-

-
- -

iterator_move/2

-
-

iterator_move(Mrdb_iter::mrdb_iterator(), Dir::iterator_action()) -> {ok, tuple()} | {error, any()}

-

-
- -

last/1

-
-

last(Tab::ref_or_tab()) -> key() | '$end_of_table'

-

-
- -

last/2

-
-

last(Tab::ref_or_tab(), Opts::read_options()) -> key() | '$end_of_table'

-

-
- -

match_delete/2

-
-

match_delete(Tab, Pat) -> any()

-

-
- -

new_tx/1

-
-

new_tx(Tab::table() | db_ref()) -> db_ref()

-

-
- -

new_tx/2

-
-

new_tx(Tab::ref_or_tab(), Opts::write_options()) -> db_ref()

-

-
- -

next/2

-
-

next(Tab::ref_or_tab(), K::key()) -> key() | '$end_of_table'

-

-
- -

next/3

-
-

next(Tab::ref_or_tab(), K::key(), Opts::read_options()) -> key() | '$end_of_table'

-

-
- -

prev/2

-
-

prev(Tab::ref_or_tab(), K::key()) -> key() | '$end_of_table'

-

-
- -

prev/3

-
-

prev(Tab::ref_or_tab(), K::key(), Opts::read_options()) -> key() | '$end_of_table'

-

-
- -

rdb_delete/2

-
-

rdb_delete(R, K) -> any()

-

-
- -

rdb_delete/3

-
-

rdb_delete(R, K, Opts) -> any()

-

-
- -

rdb_fold/4

-
-

rdb_fold(Tab, Fun, Acc, Prefix) -> any()

-

-
- -

rdb_fold/5

-
-

rdb_fold(Tab, Fun, Acc, Prefix, Limit) -> any()

-

-
- -

rdb_get/2

-
-

rdb_get(R, K) -> any()

-

-
- -

rdb_get/3

-
-

rdb_get(R, K, Opts) -> any()

-

-
- -

rdb_iterator/1

-
-

rdb_iterator(R) -> any()

-

-
- -

rdb_iterator/2

-
-

rdb_iterator(R, Opts) -> any()

-

-
- -

rdb_iterator_move/2

-
-

rdb_iterator_move(I, Dir) -> any()

-

-
- -

rdb_put/3

-
-

rdb_put(R, K, V) -> any()

-

-
- -

rdb_put/4

-
-

rdb_put(R, K, V, Opts) -> any()

-

-
- -

read/2

-
-

read(Tab, Key) -> any()

-

-
- -

read/3

-
-

read(Tab, Key, Opts) -> any()

-

-
- -

read_info/1

-
-

read_info(Tab) -> any()

-

-
- -

read_info/2

-
-

read_info(Tab, K) -> any()

-

-
- -

release_snapshot/1

-
-

release_snapshot(SHandle::snapshot_handle()) -> ok | error()

-

-

release a snapshot created by snapshot/1.

- -

select/1

-
-

select(Cont) -> any()

-

-
- -

select/2

-
-

select(Tab, Pat) -> any()

-

-
- -

select/3

-
-

select(Tab, Pat, Limit) -> any()

-

-
- -

snapshot/1

-
-

snapshot(Name::alias() | ref_or_tab()) -> {ok, snapshot_handle()} | error()

-

-

Create a snapshot of the database instance associated with the -table reference, table name or alias.

- - Snapshots provide consistent read-only views over the entire state of the key-value store.

- -

tx_commit/1

-
-

tx_commit(TxH::tx_handle() | db_ref()) -> ok

-

-
- -

tx_ref/2

-
-

tx_ref(Tab::ref_or_tab() | db_ref() | db_ref(), TxH::tx_handle()) -> db_ref()

-

-
- -

update_counter/3

-
-

update_counter(Tab, C, Val) -> any()

-

-
- -

update_counter/4

-
-

update_counter(Tab, C, Val, Opts) -> any()

-

-
- -

with_iterator/2

-
-

with_iterator(Tab::ref_or_tab(), Fun::fun((mrdb_iterator()) -> Res)) -> Res

-

-
- -

with_iterator/3

-
-

with_iterator(Tab::ref_or_tab(), Fun::fun((mrdb_iterator()) -> Res), Opts::read_options()) -> Res

-

-
- -

with_rdb_iterator/2

-
-

with_rdb_iterator(Tab::ref_or_tab(), Fun::fun((itr_handle()) -> Res)) -> Res

-

-
- -

with_rdb_iterator/3

-
-

with_rdb_iterator(Tab::ref_or_tab(), Fun::fun((itr_handle()) -> Res), Opts::read_options()) -> Res

-

-
- -

write_info/3

-
-

write_info(Tab, K, V) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mrdb_index.html b/doc/mrdb_index.html deleted file mode 100644 index 7603753..0000000 --- a/doc/mrdb_index.html +++ /dev/null @@ -1,71 +0,0 @@ - - - - -Module mrdb_index - - - - -
- -

Module mrdb_index

- - - -

Data Types

- -

index_value()

-

index_value() = any()

- - -

iterator_action()

-

iterator_action() = mrdb:iterator_action()

- - -

ix_iterator()

-

ix_iterator() = #mrdb_ix_iter{i = mrdb:iterator(), type = set | bag, sub = mrdb:ref() | pid()}

- - -

object()

-

object() = tuple()

- - -

Function Index

- - - - -
iterator/2
iterator_close/1
iterator_move/2
with_iterator/3
- -

Function Details

- -

iterator/2

-
-

iterator(Tab::mrdb:ref_or_tab(), IxPos::mrdb:index_position()) -> {ok, ix_iterator()} | {error, term()}

-

-
- -

iterator_close/1

-
-

iterator_close(Mrdb_ix_iter::ix_iterator()) -> ok

-

-
- -

iterator_move/2

-
-

iterator_move(Mrdb_ix_iter::ix_iterator(), Dir::iterator_action()) -> {ok, index_value(), object()} | {error, term()}

-

-
- -

with_iterator/3

-
-

with_iterator(Tab::mrdb:ref_or_tab(), IxPos::mrdb:index_position(), Fun::fun((ix_iterator()) -> Res)) -> Res

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mrdb_mutex.html b/doc/mrdb_mutex.html deleted file mode 100644 index cb6e597..0000000 --- a/doc/mrdb_mutex.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - -Module mrdb_mutex - - - - -
- -

Module mrdb_mutex

- - - -

Function Index

- -
do/2
- -

Function Details

- -

do/2

-
-

do(Rsrc, F) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mrdb_mutex_serializer.html b/doc/mrdb_mutex_serializer.html deleted file mode 100644 index 8e07aa4..0000000 --- a/doc/mrdb_mutex_serializer.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - -Module mrdb_mutex_serializer - - - - -
- -

Module mrdb_mutex_serializer

- - - -

Function Index

- - - - - - - - - -
code_change/3
done/2
handle_call/3
handle_cast/2
handle_info/2
init/1
start_link/0
terminate/2
wait/1
- -

Function Details

- -

code_change/3

-
-

code_change(FromVsn, St, Extra) -> any()

-

-
- -

done/2

-
-

done(Rsrc, Ref) -> any()

-

-
- -

handle_call/3

-
-

handle_call(X1, From, St) -> any()

-

-
- -

handle_cast/2

-
-

handle_cast(X1, St) -> any()

-

-
- -

handle_info/2

-
-

handle_info(X1, St) -> any()

-

-
- -

init/1

-
-

init(X1) -> any()

-

-
- -

start_link/0

-
-

start_link() -> any()

-

-
- -

terminate/2

-
-

terminate(X1, X2) -> any()

-

-
- -

wait/1

-
-

wait(Rsrc) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mrdb_select.html b/doc/mrdb_select.html deleted file mode 100644 index 9acf856..0000000 --- a/doc/mrdb_select.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - -Module mrdb_select - - - - -
- -

Module mrdb_select

- - - -

Function Index

- - - - - - -
continuation_info/2
fold/5
rdb_fold/5
select/1
select/3
select/4
- -

Function Details

- -

continuation_info/2

-
-

continuation_info(Item, C) -> any()

-

-
- -

fold/5

-
-

fold(Ref, Fun, Acc, MS, Limit) -> any()

-

-
- -

rdb_fold/5

-
-

rdb_fold(Ref, Fun, Acc, Prefix, Limit) -> any()

-

-
- -

select/1

-
-

select(Cont) -> any()

-

-
- -

select/3

-
-

select(Ref, MS, Limit) -> any()

-

-
- -

select/4

-
-

select(Ref, MS, AccKeys, Limit) -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/mrdb_stats.html b/doc/mrdb_stats.html deleted file mode 100644 index b4220fd..0000000 --- a/doc/mrdb_stats.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - -Module mrdb_stats - - - - -
- -

Module mrdb_stats

-Statistics API for the mnesia_rocksdb plugin. - - -

Description

Statistics API for the mnesia_rocksdb plugin

- - Some counters are maintained for each active alias. Currently, the following - counters are supported: - * inner_retries - * outer_retries - -

Data Types

- -

alias()

-

alias() = mnesia_rocksdb:alias()

- - -

counter()

-

counter() = atom()

- - -

counters()

-

counters() = #{counter() := integer()}

- - -

db_ref()

-

db_ref() = mrdb:db_ref()

- - -

increment()

-

increment() = integer()

- - -

Function Index

- - - - -
get/1Fetches all known counters for Alias, in the form of a map, - #{Counter => Value}.
get/2Fetches the integer value of the known counter Ctr for Alias.
incr/3Increment Ctr counter for Alias` with increment `N.
new/0
- -

Function Details

- -

get/1

-
-

get(Alias::alias() | db_ref()) -> counters()

-

-

Fetches all known counters for Alias, in the form of a map, - #{Counter => Value}.

- -

get/2

-
-

get(Alias::alias() | db_ref(), Ctr::counter()) -> integer()

-

-

Fetches the integer value of the known counter Ctr for Alias.

- -

incr/3

-
-

incr(Alias::alias() | db_ref(), Ctr::counter(), N::increment()) -> ok

-

-

Increment Ctr counter for Alias` with increment `N.

- - Note that the first argument may also be a db_ref() map, - corresponding to mrdb:get_ref({admin, Alias}).

- -

new/0

-
-

new() -> any()

-

-
-
- - -

Generated by EDoc

- - diff --git a/doc/overview-summary.html b/doc/overview-summary.html deleted file mode 100644 index 328774c..0000000 --- a/doc/overview-summary.html +++ /dev/null @@ -1,254 +0,0 @@ - - - - -Mnesia Rocksdb - Rocksdb backend plugin for Mnesia - - - - - -

Mnesia Rocksdb - Rocksdb backend plugin for Mnesia -

-

Copyright © 2013-21 Klarna AB

-

Authors: Ulf Wiger (ulf@wiger.net).

- - -

The Mnesia DBMS, part of Erlang/OTP, supports 'backend plugins', making -it possible to utilize more capable key-value stores than the dets -module (limited to 2 GB per table). Unfortunately, this support is -undocumented. Below, some informal documentation for the plugin system -is provided.

- -

Table of Contents

-
    -
  1. Usage
  2. -
      -
    1. Prerequisites
    2. -
    3. Getting started
    4. -
    5. Special features
    6. -
    7. Customization
    8. -
    9. Handling of errors in write operations
    10. -
    11. Caveats
    12. -
    -
  3. Mnesia backend plugins
  4. -
      -
    1. Background
    2. -
    3. Design
    4. -
    -
  5. Mnesia index plugins
  6. -
  7. Rocksdb
  8. -
- -

Usage

- -

Prerequisites

- - - -

Getting started

- -

Call mnesia_rocksdb:register() immediately after -starting mnesia.

- -

Put {rocksdb_copies, [node()]} into the table definitions of -tables you want to be in RocksDB.

- -

Special features

- -

RocksDB tables support efficient selects on prefix keys.

- -

The backend uses the sext module (see -https://github.com/uwiger/sext) for mapping between Erlang terms and the -binary data stored in the tables. This provides two useful properties:

- - - -

This means that a prefix key identifies the start of the sequence of -entries whose keys match the prefix. The backend uses this to optimize -selects on prefix keys.

- -

### Customization

- -

RocksDB supports a number of customization options. These can be specified -by providing a {Key, Value} list named rocksdb_opts under user_properties, -for example:

- -
mnesia:create_table(foo, [{rocksdb_copies, [node()]},
-                          ...
-                          {user_properties,
-                              [{rocksdb_opts, [{max_open_files, 1024}]}]
-                          }])
- -

Consult the RocksDB documentation -for information on configuration parameters. Also see the section below on handling write errors.

- -The default configuration for tables in mnesia_rocksdb is: -
default_open_opts() ->
-    [ {create_if_missing, true}
-      , {cache_size,
-         list_to_integer(get_env_default("ROCKSDB_CACHE_SIZE", "32212254"))}
-      , {block_size, 1024}
-      , {max_open_files, 100}
-      , {write_buffer_size,
-         list_to_integer(get_env_default(
-                           "ROCKSDB_WRITE_BUFFER_SIZE", "4194304"))}
-      , {compression,
-         list_to_atom(get_env_default("ROCKSDB_COMPRESSION", "true"))}
-      , {use_bloomfilter, true}
-    ].
- -

It is also possible, for larger databases, to produce a tuning parameter file. -This is experimental, and mostly copied from mnesia_leveldb. Consult the -source code in mnesia_rocksdb_tuning.erl and mnesia_rocksdb_params.erl. -Contributions are welcome.

- -

Caveats

- -

Avoid placing bag tables in RocksDB. Although they work, each write -requires additional reads, causing substantial runtime overheads. There -are better ways to represent and process bag data (see above about -prefix keys).

- -

The mnesia:table_info(T, size) call always returns zero for RocksDB -tables. RocksDB itself does not track the number of elements in a table, and -although it is possible to make the mnesia_rocksdb backend maintain a size -counter, it incurs a high runtime overhead for writes and deletes since it -forces them to first do a read to check the existence of the key. If you -depend on having an up to date size count at all times, you need to maintain -it yourself. If you only need the size occasionally, you may traverse the -table to count the elements.

- -

Mnesia backend plugins

- -

Background

- -

Mnesia was initially designed to be a RAM-only DBMS, and Erlang's -ets tables were developed for this purpose. In order to support -persistence, e.g. for configuration data, a disk-based version of ets -(called dets) was created. The dets API mimicks the ets API, -and dets is quite convenient and fast for (nowadays) small datasets. -However, using a 32-bit bucket system, it is limited to 2GB of data. -It also doesn't support ordered sets. When used in Mnesia, dets-based -tables are called disc_only_copies.

- -

To circumvent these limitations, another table type, called disc_copies -was added. This is a combination of ets and disk_log, where Mnesia -periodically snapshots the ets data to a log file on disk, and meanwhile -maintains a log of updates, which can be applied at startup. These tables -are quite performant (especially on read access), but all data is kept in -RAM, which can become a serious limitation.

- -

A backend plugin system was proposed by Ulf Wiger in 2016, and further -developed with Klarna's support, to finally become included in OTP 19. -Klarna uses a LevelDb backend, but Aeternity, in 2017, instead chose -to implement a Rocksdb backend plugin.

- -

Design

- -

As backend plugins were added on a long-since legacy-stable Mnesia, -they had to conform to the existing code structure. For this reason, -the plugin callbacks hook into the already present low-level access -API in the mnesia_lib module. As a consequence, backend plugins have -the same access semantics and granularity as ets and dets. This -isn't much of a disadvantage for key-value stores like LevelDb and RocksDB, -but a more serious issue is that the update part of this API is called -on after the point of no return. That is, Mnesia does not expect -these updates to fail, and has no recourse if they do. As an aside, -this could also happen if a disc_only_copies table exceeds the 2 GB -limit (mnesia will not check it, and dets will not complain, but simply -drop the update.)

- -

Mnesia index plugins

- -

When adding support for backend plugins, index plugins were also added. Unfortunately, they remain undocumented.

- -

An index plugin can be added in one of two ways:

- -
    -
  1. When creating a schema, provide {index_plugins, [{Name, Module, Function}]} options.
  2. -
  3. Call the function mnesia_schema:add_index_plugin(Name, Module, Function)
  4. -
- -

Name must be an atom wrapped as a 1-tuple, e.g. {words}.

- -

The plugin callback is called as Module:Function(Table, Pos, Obj), where Pos=={words} in -our example. It returns a list of index terms.

- -

Example

- -

Given the following index plugin implementation:

- -
-module(words).
--export([words_f/3]).
-
-words_f(_,_,Obj) when is_tuple(Obj) ->
-    words_(tuple_to_list(Obj)).
-
-words_(Str) when is_binary(Str) ->
-    string:lexemes(Str, [$\s, $\n, [$\r,$\n]]);
-words_(L) when is_list(L) ->
-    lists:flatmap(fun words_/1, L);
-words_(_) ->
-    [].
- -

We can register the plugin and use it in table definitions:

- -
Eshell V12.1.3  (abort with ^G)
-1> mnesia:start().
-ok
-2> mnesia_schema:add_index_plugin({words}, words, words_f).
-{atomic,ok}
-3> mnesia:create_table(i, [{index, [{words}]}]).
-{atomic,ok}
- -

Note that in this case, we had neither a backend plugin, nor even a persistent schema. -Index plugins can be used with all table types. The registered indexing function (arity 3) must exist -as an exported function along the node's code path.

- -

To see what happens when we insert an object, we can turn on call trace.

- -
4> dbg:tracer().
-{ok,<0.108.0>}
-5> dbg:tp(words, x).
-{ok,[{matched,nonode@nohost,3},{saved,x}]}
-6> dbg:p(all,[c]).
-{ok,[{matched,nonode@nohost,60}]}
-7> mnesia:dirty_write({i,<<"one two">>, [<<"three">>, <<"four">>]}).
-(<0.84.0>) call words:words_f(i,{words},{i,<<"one two">>,[<<"three">>,<<"four">>]})
-(<0.84.0>) returned from words:words_f/3 -> [<<"one">>,<<"two">>,<<"three">>,
-                                             <<"four">>]
-(<0.84.0>) call words:words_f(i,{words},{i,<<"one two">>,[<<"three">>,<<"four">>]})
-(<0.84.0>) returned from words:words_f/3 -> [<<"one">>,<<"two">>,<<"three">>,
-                                             <<"four">>]
-ok
-8> dbg:ctp('_'), dbg:stop().
-ok
-9> mnesia:dirty_index_read(i, <<"one">>, {words}).
-[{i,<<"one two">>,[<<"three">>,<<"four">>]}]
- -

(The fact that the indexing function is called twice, seems like a performance bug.)

- -

We can observe that the indexing callback is able to operate on the whole object. -It needs to be side-effect free and efficient, since it will be called at least once for each update -(if an old object exists in the table, the indexing function will be called on it too, before it is -replaced by the new object.)

- -

Rocksdb

- -

Usage

- -
- -

Generated by EDoc

- -