WIP: implemented the Erlang portion of the NIF required to suport the entire LMDB API, next up is the native C code.
This commit is contained in:
parent
af7dbbcc9a
commit
47a17d15f1
4 changed files with 1178 additions and 100 deletions
|
@ -178,6 +178,10 @@ __strerror_term(ErlNifEnv* env, int err)
|
|||
/**
|
||||
* Opens a MDB database.
|
||||
*
|
||||
* Note: mdb_dbi_open() must not be called from multiple concurrent
|
||||
* transactions. A transaction that uses this function must finish (either
|
||||
* commit or abort) before any other transaction may use this function.
|
||||
*
|
||||
* argv[0] path to directory for the database files
|
||||
* argv[1] size of database
|
||||
* argv[2] flags
|
||||
|
@ -251,6 +255,13 @@ ASYNC_NIF_DECL(
|
|||
/**
|
||||
* Closes a MDB database.
|
||||
*
|
||||
* The old database handle is returned if the database was already open.
|
||||
* The handle must only be closed once.
|
||||
* This call is not mutex protected. Handles should only be closed by
|
||||
* a single thread, and only if no other threads are going to reference
|
||||
* the database handle or one of its cursors any further. Do not close
|
||||
* a handle if an existing transaction has modified its database.
|
||||
*
|
||||
* argv[0] reference to the MDB handle resource
|
||||
*/
|
||||
ASYNC_NIF_DECL(
|
||||
|
@ -705,13 +716,36 @@ static void lmdb_unload(ErlNifEnv* env, void* priv_data)
|
|||
}
|
||||
|
||||
static ErlNifFunc nif_funcs [] = {
|
||||
{"open", 4, lmdb_open},
|
||||
{"close", 2, lmdb_close},
|
||||
{"put", 4, lmdb_put},
|
||||
{"get", 3, lmdb_get},
|
||||
{"del", 3, lmdb_del},
|
||||
{"update", 4, lmdb_update},
|
||||
{"drop", 2, lmdb_drop}
|
||||
{"env_open" 4, lmdb_env_open}, // [(Ref), Path, Bitmask, Mode]
|
||||
{"copy", 3, lmdb_copy}, // [(Ref), Env, Path]
|
||||
{"stat", 2, lmdb_stat}, // [(Ref), Env]
|
||||
{"sync", 3, lmdb_sync}, // [(Ref), Env, Force]
|
||||
{"env_close", 2, lmdb_env_close}, // [(Ref), Env]
|
||||
{"path", 2, lmdb_path}, // [(Ref), Env]
|
||||
{"set_maxdbs", 3, lmdb_set_maxdbs}, // [(Ref), Env, Dbs]
|
||||
{"txn_begin", 4, lmdb_txn_begin}, // [(Ref), Env, Parent, Bitmask]);
|
||||
{"txn_commit", 2, lmdb_txn_commit}, // [(Ref), Txn]
|
||||
{"txn_abort", 2, lmdb_txn_abort}, // [(Ref), Txn]
|
||||
{"txn_reset", 2, lmdb_txn_reset}, // [(Ref), Txn]
|
||||
{"txn_renew", 2, lmdb_txn_renew}, // [(Ref), Txn]
|
||||
{"dbi_open", 5, lmdb_dbi_open}, // [(Ref), Txn, Path, Size, Bitmask]
|
||||
{"dbi_close", 2, lmdb_dbi_close}, // [(Ref), Env, Dbi]
|
||||
{"drop", 4, lmdb_drop}, // [(Ref), Txn, Dbi, Delete]
|
||||
{"get", 3, lmdb_get}, // [(Ref), Txn, Dbi, Key]
|
||||
{"put", 4, lmdb_put}, // [(Ref), Txn, Dbi, Key, Value, Bitmask]
|
||||
{"del", 5, lmdb_del}, // [(Ref), Txn, Dbi, Key, Value]
|
||||
{"cursor_open", 3, lmdb_cursor_open}, // [(Ref), Txn, Dbi]
|
||||
{"cursor_close", 2, lmdb_cursor_close}, // [(Ref), Cursor]
|
||||
{"cursor_renew", 3, lmdb_cursor_renew}, // [(Ref), Txn, Cursor]
|
||||
{"cursor_txn", 2, lmdb_cursor_txn}, // [(Ref), Cursor]
|
||||
{"cursor_dbi", 2, lmdb_cursor_dbi}, // [(Ref), Cursor]
|
||||
{"cursor_get", 5, lmdb_cursor_get}, // [(Ref), Cursor, Key, DupValue, CursorOp]
|
||||
{"cursor_put", 5, lmdb_cursor_put}, // [(Ref), Cursor, Key, Value, Options]
|
||||
{"cursor_del", 3, lmdb_cursor_del}, // [(Ref), Cursor, Bitmask]
|
||||
{"cursor_count", 2, lmdb_cursor_count}, // [(Ref), Cursor]
|
||||
{"cmp", 5, lmdb_cmp}, // [(Ref), Txn, Dbi, A, B]
|
||||
{"dup_cmp", 5, lmdb_dup_cmp}, // [(Ref), Txn, Dbi, A, B]
|
||||
{"version", 1, lmdb_version} // [(Ref)]
|
||||
};
|
||||
|
||||
/* driver entry point */
|
||||
|
|
|
@ -71,7 +71,7 @@ static unsigned int __log2_64(uint64_t x) {
|
|||
static inline double name ## _stat_mean(struct name ## _stat *s) { \
|
||||
uint32_t t = s->h; \
|
||||
uint32_t h = (s->h + 1) % nsamples; \
|
||||
double mean = 0; \
|
||||
double mean = 0.0; \
|
||||
while (h != t) { \
|
||||
mean += s->samples[h]; \
|
||||
h = (h + 1) % nsamples; \
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
%%-------------------------------------------------------------------
|
||||
%% This file is part of LMDB - Erlang Lightning MDB API
|
||||
%%
|
||||
%% Copyright (c) 2012 by Aleph Archives. All rights reserved.
|
||||
%% Copyright (c) 2013 by Basho Technologies, Inc. All rights reserved.
|
||||
%%
|
||||
%%-------------------------------------------------------------------
|
||||
%% Redistribution and use in source and binary forms, with or without
|
||||
%% modification, are permitted only as authorized by the OpenLDAP
|
||||
%% Public License.
|
||||
%%
|
||||
%% A copy of this license is available in the file LICENSE in the
|
||||
%% top-level directory of the distribution or, alternatively, at
|
||||
%% <http://www.OpenLDAP.org/license.html>.
|
||||
%%
|
||||
%% Permission to use, copy, modify, and distribute this software for any
|
||||
%% purpose with or without fee is hereby granted, provided that the above
|
||||
%% copyright notice and this permission notice appear in all copies.
|
||||
%%
|
||||
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
%%-------------------------------------------------------------------
|
||||
|
||||
|
||||
%% Environment Flags
|
||||
-define(MDB_FIXEDMAP, 16#01).
|
||||
-define(MDB_NOSUBDIR, 16#02).
|
||||
-define(MDB_NOSYNC, 16#10000).
|
||||
-define(MDB_RDONLY, 16#20000).
|
||||
-define(MDB_NOMETASYNC, 16#40000).
|
||||
-define(MDB_WRITEMAP, 16#80000).
|
||||
-define(MDB_MAPASYNC, 16#100000).
|
1191
src/lmdb.erl
1191
src/lmdb.erl
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue