mirror of
https://github.com/vxcontrol/lualibs-lightningmdb.git
synced 2026-07-01 08:12:09 -04:00
clean up, add support for vxbuild-cross build system
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
*.so
|
||||
*.o
|
||||
*.src.rock
|
||||
temp/
|
||||
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Shmulik Regev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,74 +0,0 @@
|
||||
# makefile for lightning library for Lua
|
||||
# based on lpack's
|
||||
|
||||
# change these to reflect your Lua installation
|
||||
BASE_DIR ?= /usr/local
|
||||
LUAINC ?= $(BASE_DIR)/include
|
||||
LUALIB ?= $(BASE_DIR)/lib
|
||||
LUABIN ?= $(BASE_DIR)/bin/lua
|
||||
|
||||
LMDB_INCDIR= /usr/local/include
|
||||
LMDB_LIBDIR= /usr/local/lib
|
||||
|
||||
# probably no need to change anything below here
|
||||
platform=$(shell uname)
|
||||
|
||||
ifeq ($(platform),Linux)
|
||||
PLATFORM_CFLAGS= -fPIC
|
||||
else
|
||||
PLATFORM_CFLAGS=
|
||||
endif
|
||||
|
||||
ifeq ($(platform),Darwin)
|
||||
PLATFORM_LDFLAGS= -undefined dynamic_lookup
|
||||
else
|
||||
PLATFORM_LDFLAGS=
|
||||
endif
|
||||
|
||||
WARN= -pedantic -Wall
|
||||
CFLAGS= $(INCS) $(WARN) $G -g -O2 $(PLATFORM_CFLAGS) -DUSE_GLOBALS
|
||||
LDFLAGS= -L$(LUALIB) -L$(LMDB_LIBDIR) -llmdb $(PLATFORM_LDFLAGS)
|
||||
INCS= -I$(LUAINC) -I$(LMDB_INCDIR)
|
||||
|
||||
MYNAME= lightningmdb
|
||||
MYLIB= $(MYNAME)
|
||||
T= $(MYNAME).so
|
||||
OBJS= $(MYLIB).o
|
||||
TEST= test.lua
|
||||
|
||||
all: test
|
||||
|
||||
test: $T
|
||||
$(LUABIN) $(TEST)
|
||||
|
||||
o: $(MYLIB).o
|
||||
|
||||
so: $T
|
||||
|
||||
$T: $(OBJS)
|
||||
$(CC) -o $@ -shared $(OBJS) $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $T core core.* a.out
|
||||
|
||||
doc:
|
||||
@echo "$(MYNAME) library:"
|
||||
@fgrep '/**' $(MYLIB).c | cut -f2 -d/ | tr -d '*' | sort | column
|
||||
|
||||
# distribution
|
||||
|
||||
D= $(MYNAME)
|
||||
A= $(MYLIB).tar.gz
|
||||
TOTAR= Makefile,README.md,$(MYLIB).c,test*.lua
|
||||
|
||||
tar: clean
|
||||
tar zcvf $A -C .. $D/{$(TOTAR)}
|
||||
|
||||
distr: tar
|
||||
touch -r $A .stamp
|
||||
|
||||
diff: clean
|
||||
tar zxf $(FTP)/$A
|
||||
diff $D .
|
||||
|
||||
# eof
|
||||
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
Copyright 2011-2019 Howard Chu, Symas Corp.
|
||||
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>.
|
||||
|
||||
OpenLDAP is a registered trademark of the OpenLDAP Foundation.
|
||||
|
||||
Individual files and/or contributed packages may be copyright by
|
||||
other parties and/or subject to additional restrictions.
|
||||
|
||||
This work also contains materials derived from public sources.
|
||||
|
||||
Additional information about OpenLDAP can be obtained at
|
||||
<http://www.openldap.org/>.
|
||||
@@ -0,0 +1,47 @@
|
||||
The OpenLDAP Public License
|
||||
Version 2.8, 17 August 2003
|
||||
|
||||
Redistribution and use of this software and associated documentation
|
||||
("Software"), with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
1. Redistributions in source form must retain copyright statements
|
||||
and notices,
|
||||
|
||||
2. Redistributions in binary form must reproduce applicable copyright
|
||||
statements and notices, this list of conditions, and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution, and
|
||||
|
||||
3. Redistributions must contain a verbatim copy of this document.
|
||||
|
||||
The OpenLDAP Foundation may revise this license from time to time.
|
||||
Each revision is distinguished by a version number. You may use
|
||||
this Software under terms of this license revision or under the
|
||||
terms of any subsequent revision of the license.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS
|
||||
CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S)
|
||||
OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The names of the authors and copyright holders must not be used in
|
||||
advertising or otherwise to promote the sale, use or other dealing
|
||||
in this Software without specific, written prior permission. Title
|
||||
to copyright in this Software shall at all times remain with copyright
|
||||
holders.
|
||||
|
||||
OpenLDAP is a registered trademark of the OpenLDAP Foundation.
|
||||
|
||||
Copyright 1999-2003 The OpenLDAP Foundation, Redwood City,
|
||||
California, USA. All Rights Reserved. Permission to copy and
|
||||
distribute verbatim copies of this document is granted.
|
||||
@@ -0,0 +1,2 @@
|
||||
lightningmdb ace3c05 2018-05-26 from https://github.com/shmul/lightningmdb (MIT License)
|
||||
lmdb 0.9.70 2015-12-19 from https://www.pcre.org/ (The OpenLDAP Public License)
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
P=linux32 C="-m32 -fPIC" L="-m32 -s -static-libgcc ../../bin/$P/liblmdb.a" \
|
||||
D=lightningmdb.so A=liblightningmdb.a ./build.sh
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
P=linux64 C="-fPIC" L="-s -static-libgcc ../../bin/$P/liblmdb.a" \
|
||||
D=lightningmdb.so A=liblightningmdb.a ./build.sh
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
[ `uname` = Linux ] && { export X=i686-w64-mingw32-; }
|
||||
P=mingw32 C="-fPIC" L="-s -static-libgcc ../../bin/$P/lmdb.a ../../bin/$P/luajit.a" \
|
||||
D=lightningmdb.dll A=lightningmdb.a ./build.sh
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
[ `uname` = Linux ] && { export X=x86_64-w64-mingw32-; }
|
||||
P=mingw64 C="-fPIC" L="-s -static-libgcc ../../bin/$P/lmdb.a ../../bin/$P/luajit.a" \
|
||||
D=lightningmdb.dll A=lightningmdb.a ./build.sh
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
[ `uname` = Linux ] && { export X=x86_64-apple-darwin19-; export CC=clang; }
|
||||
P=osx64 C="-arch x86_64 -fPIC" L="-arch x86_64 ../../bin/$P/liblmdb.a -undefined dynamic_lookup" \
|
||||
D=lightningmdb.so A=liblightningmdb.a ./build.sh
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
[ "$CC" ] || CC=gcc
|
||||
mkdir -p ../../bin/$P/clib
|
||||
CD="-Isrc -Ilmdb -I../lua-headers -DUSE_GLOBALS"
|
||||
${X}${CC} -c -O2 $C $CD src/lightningmdb.c
|
||||
${X}${CC} *.o -shared -o ../../bin/$P/clib/$D $L
|
||||
rm -f ../../bin/$P/$A
|
||||
${X}ar rcs ../../bin/$P/$A *.o
|
||||
rm *.o
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,200 @@
|
||||
/** @file midl.h
|
||||
* @brief LMDB ID List header file.
|
||||
*
|
||||
* This file was originally part of back-bdb but has been
|
||||
* modified for use in libmdb. Most of the macros defined
|
||||
* in this file are unused, just left over from the original.
|
||||
*
|
||||
* This file is only used internally in libmdb and its definitions
|
||||
* are not exposed publicly.
|
||||
*/
|
||||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 2000-2019 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2001-2019 Howard Chu, Symas Corp.
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
#ifndef _MDB_MIDL_H_
|
||||
#define _MDB_MIDL_H_
|
||||
|
||||
#include "lmdb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup internal LMDB Internals
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup idls ID List Management
|
||||
* @{
|
||||
*/
|
||||
/** A generic unsigned ID number. These were entryIDs in back-bdb.
|
||||
* Preferably it should have the same size as a pointer.
|
||||
*/
|
||||
typedef mdb_size_t MDB_ID;
|
||||
|
||||
/** An IDL is an ID List, a sorted array of IDs. The first
|
||||
* element of the array is a counter for how many actual
|
||||
* IDs are in the list. In the original back-bdb code, IDLs are
|
||||
* sorted in ascending order. For libmdb IDLs are sorted in
|
||||
* descending order.
|
||||
*/
|
||||
typedef MDB_ID *MDB_IDL;
|
||||
|
||||
/* IDL sizes - likely should be even bigger
|
||||
* limiting factors: sizeof(ID), thread stack size
|
||||
*/
|
||||
#define MDB_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
|
||||
#define MDB_IDL_DB_SIZE (1<<MDB_IDL_LOGN)
|
||||
#define MDB_IDL_UM_SIZE (1<<(MDB_IDL_LOGN+1))
|
||||
|
||||
#define MDB_IDL_DB_MAX (MDB_IDL_DB_SIZE-1)
|
||||
#define MDB_IDL_UM_MAX (MDB_IDL_UM_SIZE-1)
|
||||
|
||||
#define MDB_IDL_SIZEOF(ids) (((ids)[0]+1) * sizeof(MDB_ID))
|
||||
#define MDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 )
|
||||
#define MDB_IDL_CPY( dst, src ) (memcpy( dst, src, MDB_IDL_SIZEOF( src ) ))
|
||||
#define MDB_IDL_FIRST( ids ) ( (ids)[1] )
|
||||
#define MDB_IDL_LAST( ids ) ( (ids)[(ids)[0]] )
|
||||
|
||||
/** Current max length of an #mdb_midl_alloc()ed IDL */
|
||||
#define MDB_IDL_ALLOCLEN( ids ) ( (ids)[-1] )
|
||||
|
||||
/** Append ID to IDL. The IDL must be big enough. */
|
||||
#define mdb_midl_xappend(idl, id) do { \
|
||||
MDB_ID *xidl = (idl), xlen = ++(xidl[0]); \
|
||||
xidl[xlen] = (id); \
|
||||
} while (0)
|
||||
|
||||
/** Search for an ID in an IDL.
|
||||
* @param[in] ids The IDL to search.
|
||||
* @param[in] id The ID to search for.
|
||||
* @return The index of the first ID greater than or equal to \b id.
|
||||
*/
|
||||
unsigned mdb_midl_search( MDB_IDL ids, MDB_ID id );
|
||||
|
||||
/** Allocate an IDL.
|
||||
* Allocates memory for an IDL of the given size.
|
||||
* @return IDL on success, NULL on failure.
|
||||
*/
|
||||
MDB_IDL mdb_midl_alloc(int num);
|
||||
|
||||
/** Free an IDL.
|
||||
* @param[in] ids The IDL to free.
|
||||
*/
|
||||
void mdb_midl_free(MDB_IDL ids);
|
||||
|
||||
/** Shrink an IDL.
|
||||
* Return the IDL to the default size if it has grown larger.
|
||||
* @param[in,out] idp Address of the IDL to shrink.
|
||||
*/
|
||||
void mdb_midl_shrink(MDB_IDL *idp);
|
||||
|
||||
/** Make room for num additional elements in an IDL.
|
||||
* @param[in,out] idp Address of the IDL.
|
||||
* @param[in] num Number of elements to make room for.
|
||||
* @return 0 on success, ENOMEM on failure.
|
||||
*/
|
||||
int mdb_midl_need(MDB_IDL *idp, unsigned num);
|
||||
|
||||
/** Append an ID onto an IDL.
|
||||
* @param[in,out] idp Address of the IDL to append to.
|
||||
* @param[in] id The ID to append.
|
||||
* @return 0 on success, ENOMEM if the IDL is too large.
|
||||
*/
|
||||
int mdb_midl_append( MDB_IDL *idp, MDB_ID id );
|
||||
|
||||
/** Append an IDL onto an IDL.
|
||||
* @param[in,out] idp Address of the IDL to append to.
|
||||
* @param[in] app The IDL to append.
|
||||
* @return 0 on success, ENOMEM if the IDL is too large.
|
||||
*/
|
||||
int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app );
|
||||
|
||||
/** Append an ID range onto an IDL.
|
||||
* @param[in,out] idp Address of the IDL to append to.
|
||||
* @param[in] id The lowest ID to append.
|
||||
* @param[in] n Number of IDs to append.
|
||||
* @return 0 on success, ENOMEM if the IDL is too large.
|
||||
*/
|
||||
int mdb_midl_append_range( MDB_IDL *idp, MDB_ID id, unsigned n );
|
||||
|
||||
/** Merge an IDL onto an IDL. The destination IDL must be big enough.
|
||||
* @param[in] idl The IDL to merge into.
|
||||
* @param[in] merge The IDL to merge.
|
||||
*/
|
||||
void mdb_midl_xmerge( MDB_IDL idl, MDB_IDL merge );
|
||||
|
||||
/** Sort an IDL.
|
||||
* @param[in,out] ids The IDL to sort.
|
||||
*/
|
||||
void mdb_midl_sort( MDB_IDL ids );
|
||||
|
||||
/** An ID2 is an ID/pointer pair.
|
||||
*/
|
||||
typedef struct MDB_ID2 {
|
||||
MDB_ID mid; /**< The ID */
|
||||
void *mptr; /**< The pointer */
|
||||
} MDB_ID2;
|
||||
|
||||
/** An ID2L is an ID2 List, a sorted array of ID2s.
|
||||
* The first element's \b mid member is a count of how many actual
|
||||
* elements are in the array. The \b mptr member of the first element is unused.
|
||||
* The array is sorted in ascending order by \b mid.
|
||||
*/
|
||||
typedef MDB_ID2 *MDB_ID2L;
|
||||
|
||||
/** Search for an ID in an ID2L.
|
||||
* @param[in] ids The ID2L to search.
|
||||
* @param[in] id The ID to search for.
|
||||
* @return The index of the first ID2 whose \b mid member is greater than or equal to \b id.
|
||||
*/
|
||||
unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id );
|
||||
|
||||
|
||||
/** Insert an ID2 into a ID2L.
|
||||
* @param[in,out] ids The ID2L to insert into.
|
||||
* @param[in] id The ID2 to insert.
|
||||
* @return 0 on success, -1 if the ID was already present in the ID2L.
|
||||
*/
|
||||
int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id );
|
||||
|
||||
/** Append an ID2 into a ID2L.
|
||||
* @param[in,out] ids The ID2L to append into.
|
||||
* @param[in] id The ID2 to append.
|
||||
* @return 0 on success, -2 if the ID2L is too big.
|
||||
*/
|
||||
int mdb_mid2l_append( MDB_ID2L ids, MDB_ID2 *id );
|
||||
|
||||
#ifdef MDB_VL32
|
||||
typedef struct MDB_ID3 {
|
||||
MDB_ID mid; /**< The ID */
|
||||
void *mptr; /**< The pointer */
|
||||
unsigned int mcnt; /**< Number of pages */
|
||||
unsigned int mref; /**< Refcounter */
|
||||
} MDB_ID3;
|
||||
|
||||
typedef MDB_ID3 *MDB_ID3L;
|
||||
|
||||
unsigned mdb_mid3l_search( MDB_ID3L ids, MDB_ID id );
|
||||
int mdb_mid3l_insert( MDB_ID3L ids, MDB_ID3 *id );
|
||||
|
||||
#endif /* MDB_VL32 */
|
||||
/** @} */
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _MDB_MIDL_H_ */
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#if LUA_VERSION_NUM<=501
|
||||
#if LUA_VERSION_NUM<=500
|
||||
typedef luaL_reg lua_reg_t;
|
||||
# define lua_type_error luaL_typerror
|
||||
void lua_set_funcs(lua_State *L, const char *libname,const lua_reg_t *l) {
|
||||
@@ -44,7 +44,7 @@ int lua_type_error(lua_State *L,int narg,const char *tname) {
|
||||
#define TXN "lightningmdb_txn"
|
||||
#define CURSOR "lightningmdb_cursor"
|
||||
|
||||
#define setfield_enum(x) lua_pushinteger(L,x); lua_setfield(L,-2,#x)
|
||||
#define setfield_enum(x) lua_pushnumber(L,x); lua_setfield(L,-2,#x)
|
||||
|
||||
#define DEFINE_register_methods(x,X) \
|
||||
void x##_register(lua_State* L) { \
|
||||
@@ -112,17 +112,17 @@ DEFINE_check(cursor,CURSOR)
|
||||
|
||||
static int stat_to_table(lua_State *L,MDB_stat *stat) {
|
||||
lua_newtable(L);
|
||||
lua_pushinteger(L,stat->ms_psize);
|
||||
lua_pushnumber(L,stat->ms_psize);
|
||||
lua_setfield(L,-2,"ms_psize");
|
||||
lua_pushinteger(L,stat->ms_depth);
|
||||
lua_pushnumber(L,stat->ms_depth);
|
||||
lua_setfield(L,-2,"ms_depth");
|
||||
lua_pushinteger(L,stat->ms_branch_pages);
|
||||
lua_pushnumber(L,stat->ms_branch_pages);
|
||||
lua_setfield(L,-2,"ms_branch_pages");
|
||||
lua_pushinteger(L,stat->ms_leaf_pages);
|
||||
lua_pushnumber(L,stat->ms_leaf_pages);
|
||||
lua_setfield(L,-2,"ms_leaf_pages");
|
||||
lua_pushinteger(L,stat->ms_overflow_pages);
|
||||
lua_pushnumber(L,stat->ms_overflow_pages);
|
||||
lua_setfield(L,-2,"ms_overflow_pages");
|
||||
lua_pushinteger(L,stat->ms_entries);
|
||||
lua_pushnumber(L,stat->ms_entries);
|
||||
lua_setfield(L,-2,"ms_entries");
|
||||
return 1;
|
||||
}
|
||||
@@ -176,15 +176,15 @@ static int env_info(lua_State *L) {
|
||||
mdb_env_info(env,&info);
|
||||
lua_newtable(L);
|
||||
|
||||
lua_pushinteger(L,info.me_mapsize);
|
||||
lua_pushnumber(L,info.me_mapsize);
|
||||
lua_setfield(L,-2,"me_mapsize");
|
||||
lua_pushinteger(L,info.me_last_pgno);
|
||||
lua_pushnumber(L,info.me_last_pgno);
|
||||
lua_setfield(L,-2,"ms_last_pgno");
|
||||
lua_pushinteger(L,info.me_last_txnid);
|
||||
lua_pushnumber(L,info.me_last_txnid);
|
||||
lua_setfield(L,-2,"me_last_txnid");
|
||||
lua_pushinteger(L,info.me_maxreaders);
|
||||
lua_pushnumber(L,info.me_maxreaders);
|
||||
lua_setfield(L,-2,"me_maxreaders");
|
||||
lua_pushinteger(L,info.me_numreaders);
|
||||
lua_pushnumber(L,info.me_numreaders);
|
||||
lua_setfield(L,-2,"me_numreaders");
|
||||
return 1;
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
FROM phusion/baseimage:0.9.19
|
||||
|
||||
ENV lua_ver 5.1
|
||||
ENV luarocks_ver 2.3.0
|
||||
ENV lmdb_ver 0.9.19
|
||||
|
||||
|
||||
RUN apt-get update -y && apt-get install -y unzip curl make git
|
||||
|
||||
RUN apt-get install -y lua${lua_ver} liblua${lua_ver} liblua${lua_ver}-dev
|
||||
|
||||
# Install luarocks
|
||||
RUN cd /tmp && \
|
||||
curl -L -O http://luarocks.org/releases/luarocks-${luarocks_ver}.tar.gz && \
|
||||
tar zxpf luarocks-${luarocks_ver}.tar.gz && \
|
||||
rm luarocks-${luarocks_ver}.tar.gz && \
|
||||
cd luarocks-${luarocks_ver} && \
|
||||
./configure --prefix=/usr && \
|
||||
make bootstrap && \
|
||||
cd /tmp && \
|
||||
rm -r /tmp/luarocks-${luarocks_ver}
|
||||
|
||||
RUN cd /tmp && \
|
||||
curl -L -O https://github.com/LMDB/lmdb/archive/LMDB_${lmdb_ver}.tar.gz && \
|
||||
tar -xzf LMDB_${lmdb_ver}.tar.gz && \
|
||||
rm LMDB_${lmdb_ver}.tar.gz && \
|
||||
cd lmdb-LMDB_${lmdb_ver}/libraries/liblmdb && \
|
||||
make all install && \
|
||||
ldconfig && \
|
||||
cd /tmp && \
|
||||
rm -r /tmp/lmdb-LMDB_${lmdb_ver}
|
||||
|
||||
ENV HOME /root
|
||||
RUN mkdir -p $HOME/lightningmdb/temp
|
||||
WORKDIR $HOME/lightningmdb
|
||||
|
||||
COPY *.lua *.c Makefile *.rockspec $HOME/lightningmdb/
|
||||
RUN make BASE_DIR=/usr LUAINC=/usr/include/lua${lua_ver}
|
||||
@@ -1,38 +0,0 @@
|
||||
FROM phusion/baseimage:0.9.19
|
||||
ENV lua_ver 5.2
|
||||
ENV luarocks_ver 2.3.0
|
||||
ENV lmdb_ver 0.9.19
|
||||
|
||||
|
||||
RUN apt-get update -y && apt-get install -y unzip curl make git
|
||||
|
||||
RUN apt-get install -y lua${lua_ver} liblua${lua_ver} liblua${lua_ver}-dev
|
||||
|
||||
# Install luarocks
|
||||
RUN cd /tmp && \
|
||||
curl -L -O http://luarocks.org/releases/luarocks-${luarocks_ver}.tar.gz && \
|
||||
tar zxpf luarocks-${luarocks_ver}.tar.gz && \
|
||||
rm luarocks-${luarocks_ver}.tar.gz && \
|
||||
cd luarocks-${luarocks_ver} && \
|
||||
./configure --prefix=/usr && \
|
||||
make bootstrap && \
|
||||
cd /tmp && \
|
||||
rm -r /tmp/luarocks-${luarocks_ver}
|
||||
|
||||
RUN cd /tmp && \
|
||||
curl -L -O https://github.com/LMDB/lmdb/archive/LMDB_${lmdb_ver}.tar.gz && \
|
||||
tar -xzf LMDB_${lmdb_ver}.tar.gz && \
|
||||
rm LMDB_${lmdb_ver}.tar.gz && \
|
||||
cd lmdb-LMDB_${lmdb_ver}/libraries/liblmdb && \
|
||||
make all install && \
|
||||
ldconfig && \
|
||||
cd /tmp && \
|
||||
rm -r /tmp/lmdb-LMDB_${lmdb_ver}
|
||||
|
||||
|
||||
ENV HOME /root
|
||||
RUN mkdir -p $HOME/lightningmdb/temp
|
||||
WORKDIR $HOME/lightningmdb
|
||||
|
||||
COPY *.lua *.c Makefile *.rockspec $HOME/lightningmdb/
|
||||
RUN make BASE_DIR=/usr LUAINC=/usr/include/lua${lua_ver}
|
||||
@@ -1,38 +0,0 @@
|
||||
FROM phusion/baseimage:0.9.19
|
||||
ENV lua_ver 5.3
|
||||
ENV luarocks_ver 2.3.0
|
||||
ENV lmdb_ver 0.9.19
|
||||
|
||||
|
||||
RUN apt-get update -y && apt-get install -y unzip curl make git
|
||||
|
||||
RUN apt-get install -y lua${lua_ver} liblua${lua_ver} liblua${lua_ver}-dev
|
||||
|
||||
# Install luarocks
|
||||
RUN cd /tmp && \
|
||||
curl -L -O http://luarocks.org/releases/luarocks-${luarocks_ver}.tar.gz && \
|
||||
tar zxpf luarocks-${luarocks_ver}.tar.gz && \
|
||||
rm luarocks-${luarocks_ver}.tar.gz && \
|
||||
cd luarocks-${luarocks_ver} && \
|
||||
./configure --prefix=/usr && \
|
||||
make bootstrap && \
|
||||
cd /tmp && \
|
||||
rm -r /tmp/luarocks-${luarocks_ver}
|
||||
|
||||
RUN cd /tmp && \
|
||||
curl -L -O https://github.com/LMDB/lmdb/archive/LMDB_${lmdb_ver}.tar.gz && \
|
||||
tar -xzf LMDB_${lmdb_ver}.tar.gz && \
|
||||
rm LMDB_${lmdb_ver}.tar.gz && \
|
||||
cd lmdb-LMDB_${lmdb_ver}/libraries/liblmdb && \
|
||||
make all install && \
|
||||
ldconfig && \
|
||||
cd /tmp && \
|
||||
rm -r /tmp/lmdb-LMDB_${lmdb_ver}
|
||||
|
||||
|
||||
ENV HOME /root
|
||||
RUN mkdir -p $HOME/lightningmdb/temp
|
||||
WORKDIR $HOME/lightningmdb
|
||||
|
||||
COPY *.lua *.c Makefile *.rockspec $HOME/lightningmdb/
|
||||
RUN make BASE_DIR=/usr LUAINC=/usr/include/lua${lua_ver} LUABIN=/usr/bin/lua5.3
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Usage: docker/build_container.sh lua5.2
|
||||
#
|
||||
|
||||
platform=$1
|
||||
if [ -z "$platform" ] ; then
|
||||
echo "Usage: $0 <platform_name> [docker build params]"
|
||||
echo ""
|
||||
echo "Example: $0 lua5.2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
# Docker repo name
|
||||
echo $platform
|
||||
repo="lightningmdb.$platform"
|
||||
|
||||
projectrootrelative="$(dirname $0)/.."
|
||||
projectroot=$(cd $projectrootrelative && pwd) # Get the absolute path
|
||||
dockerfile="$projectroot/docker/Dockerfile-$platform"
|
||||
if [ ! -f "$dockerfile" ] ; then
|
||||
echo "Missing docker file: $dockerfile"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
docker build --file=$dockerfile --tag=$repo:$platform $@ $projectroot
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Usage: docker/run_tests_in_container.sh lua5.2
|
||||
#
|
||||
|
||||
platform=$1
|
||||
if [ -z "$platform" ] ; then
|
||||
echo "Usage: $0 <platform_name> [docker build params]"
|
||||
echo ""
|
||||
echo "Example: $0 lua5.2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
# Docker repo name
|
||||
repo=lightningmdb
|
||||
|
||||
projectrootrelative="$(dirname $0)/.."
|
||||
projectroot=$(cd $projectrootrelative && pwd) # Get the absolute path
|
||||
dockerfile="$projectroot/docker/Dockerfile-$platform"
|
||||
if [ ! -f "$dockerfile" ] ; then
|
||||
echo "Missing docker file: $dockerfile"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
containername="lightningmdb_test_$platform"
|
||||
docker run --name=$containername $repo:$platform
|
||||
retval=$?
|
||||
docker rm $containername
|
||||
|
||||
exit $retval
|
||||
@@ -1,4 +1,24 @@
|
||||
require "test_common"
|
||||
require "lightningmdb_common_test"
|
||||
|
||||
local function pt(t)
|
||||
for k,v in pairs(t) do
|
||||
print(k,v)
|
||||
end
|
||||
end
|
||||
|
||||
local function ps(e)
|
||||
print("--- env stat")
|
||||
pt(e:stat())
|
||||
print("---")
|
||||
end
|
||||
|
||||
local function test_setup(dir_)
|
||||
local dir = "./temp/"..dir_
|
||||
os.execute("mkdir -p "..dir)
|
||||
os.execute("rm -rf "..dir.."/data.mdb")
|
||||
os.execute("rm -rf "..dir.."/lock.mdb")
|
||||
return dir
|
||||
end
|
||||
|
||||
local function cursor_pairs(cursor_,key_,op_)
|
||||
return coroutine.wrap(
|
||||
@@ -1,35 +0,0 @@
|
||||
package = "Lightningmdb"
|
||||
version = "0.9.22.1-1"
|
||||
source = {
|
||||
dir = "lightningmdb-"..version,
|
||||
url = "https://github.com/shmul/lightningmdb/archive/"..version..".zip"
|
||||
}
|
||||
description = {
|
||||
summary = "A thin wrapper around OpenLDAP Lightning Memory-Mapped Database (LMDB).",
|
||||
detailed = [[
|
||||
LMDB is a key-value embedded store that is a part of the OpenLDAP project. This rock provides a Lua interface to to it.
|
||||
]],
|
||||
homepage = "https://github.com/shmul/lightningmdb",
|
||||
license = "MIT/X11" -- or whatever you like
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
external_dependencies = {
|
||||
LMDB = {
|
||||
header = "lmdb.h",
|
||||
library = "lmdb",
|
||||
}
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
lightningmdb = {
|
||||
sources = {"lightningmdb.c"},
|
||||
defines = {"USE_GLOBALS"},
|
||||
libraries = {"lmdb"},
|
||||
incdirs = {"$(LMDB_INCDIR)"},
|
||||
libdirs = {"$(LMDB_LIBDIR)"}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package = "Lightningmdb"
|
||||
version = "scm-1"
|
||||
source = {
|
||||
url = "git://github.com/shmul/lightningdbm.git"
|
||||
}
|
||||
description = {
|
||||
summary = "A thin wrapper around OpenLDAP Lightning Memory-Mapped Database (LMDB).",
|
||||
detailed = [[
|
||||
LMDB is a key-value embedded store that is a part of the OpenLDAP project. This rock provides a Lua interface to to it.
|
||||
]],
|
||||
homepage = "https://github.com/shmul/lightningmdb",
|
||||
license = "MIT/X11" -- or whatever you like
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
external_dependencies = {
|
||||
LMDB = {
|
||||
header = "lmdb.h",
|
||||
library = "lmdb",
|
||||
}
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
lightningmdb = {
|
||||
sources = {"lightningmdb.c"},
|
||||
defines = {"USE_GLOBALS"},
|
||||
libraries = {"lmdb"},
|
||||
incdirs = {"$(LMDB_INCDIR)"},
|
||||
libdirs = {"$(LMDB_LIBDIR)"}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# General
|
||||
|
||||
Lightningmdb is a thin wrapper around [OpenLDAP Lightning Memory-Mapped Database (LMDB)](http://symas.com/) .
|
||||
Lightningmdb is a thin wrapper around [OpenLDAP Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/) .
|
||||
|
||||
|
||||
# Installation
|
||||
@@ -8,7 +8,7 @@ Lightningmdb is a thin wrapper around [OpenLDAP Lightning Memory-Mapped Database
|
||||
## Prerequisites
|
||||
|
||||
* Lua 5.1.x or greater. It should be compatible with Luajit though it wasn't thoroughly tested.
|
||||
* [OpenLDAP Lightning Memory-Mapped Database (LMDB)](http://symas.com/). A clone of just the LMDB code is also available on [Github](https://github.com/LMDB/lmdb)
|
||||
* [OpenLDAP Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/). A clone of just the LMDB code is also available on [Github](https://github.com/LMDB/lmdb)
|
||||
|
||||
## Building
|
||||
### LMDB
|
||||
@@ -31,7 +31,7 @@ make install
|
||||
A set of docker files are provided also, primarily for building the library against multiple Lua versions. Run `./docker/build_container.sh lua5.1` to test that the library successfully builds with Lua 5.1 (versions 5.2 and 5.3 are supported as well).
|
||||
|
||||
# Usage
|
||||
Every attempt was made to honor the original naming convention. The documentation is therefore scarce and the [database's documentation](http://www.lmdb.tech/doc/) should be used.
|
||||
Every attempt was made to honor the original naming convention. The documentation is therefore scarce and the [database's documentation](http://symas.com/mdb/doc/) should be used.
|
||||
|
||||
5 lua _objects_ are wrapping the access to the DB. Their mappings to the LMDB functions/constants is provided below.
|
||||
|
||||
@@ -123,7 +123,7 @@ beyond the end of s will always return nil values.
|
||||
# License
|
||||
|
||||
* Lightningmdb is distributed under the MIT license.
|
||||
* [OpenLDAP Lightning Memory-Mapped Database (LMDB)](https://www.symas.com/symas-open-source-licenses) is distributed under the OpenLDAP Public license.
|
||||
* [OpenLDAP Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/) is distributed under the OpenLDAP Public license.
|
||||
* lpack's code was placed under the public domain by its author.
|
||||
|
||||
## MIT License
|
||||
@@ -0,0 +1,7 @@
|
||||
lightningmdb_lib=require "lightningmdb"
|
||||
|
||||
lightningmdb = _VERSION>="Lua 5.2" and lightningmdb_lib or lightningmdb
|
||||
MDB = setmetatable({}, {__index = function(t, k)
|
||||
return lightningmdb["MDB_" .. k]
|
||||
end})
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
require "lightningmdb_common_test"
|
||||
|
||||
local function pt(t)
|
||||
for k,v in pairs(t) do
|
||||
print(k,v)
|
||||
end
|
||||
end
|
||||
|
||||
local function ps(e)
|
||||
print("--- env stat")
|
||||
pt(e:stat())
|
||||
print("---")
|
||||
end
|
||||
|
||||
local function test_setup(dir_)
|
||||
local dir = "./temp/"..dir_
|
||||
os.execute("mkdir -p "..dir)
|
||||
os.execute("rm -rf "..dir.."/data.mdb")
|
||||
os.execute("rm -rf "..dir.."/lock.mdb")
|
||||
return dir
|
||||
end
|
||||
|
||||
local function basic_test()
|
||||
print("Lightning MDB version:",lightningmdb.version())
|
||||
print("Lightning error:",lightningmdb.strerror(0))
|
||||
|
||||
print("-- globals --")
|
||||
pt(lightningmdb)
|
||||
|
||||
-- env
|
||||
local e = lightningmdb.env_create()
|
||||
print(e)
|
||||
local dir = test_setup("foo")
|
||||
print(e:open(dir,0,420))
|
||||
print("fixedmap",MDB.FIXEDMAP)
|
||||
print("read only",MDB.RDONLY)
|
||||
|
||||
print("-- stats --")
|
||||
pt(e:stat())
|
||||
|
||||
print("-- info --")
|
||||
pt(e:info())
|
||||
print("get_path",e:get_path())
|
||||
|
||||
|
||||
--txn
|
||||
local t = e:txn_begin(nil,0)
|
||||
print("txn",t)
|
||||
t:commit()
|
||||
t = e:txn_begin(nil,0)
|
||||
print("txn",t)
|
||||
t:reset()
|
||||
t:renew()
|
||||
--t:abort()
|
||||
local db = t:dbi_open(nil,0)
|
||||
print(string.format("-- txn stat [%d] --",t:id()))
|
||||
pt(t:stat(db))
|
||||
t:abort()
|
||||
e:close()
|
||||
end
|
||||
|
||||
local function grow_db()
|
||||
print("--- grow_db ---")
|
||||
local num_pages = 5
|
||||
local e
|
||||
|
||||
local dir = test_setup("bar")
|
||||
|
||||
local function grow()
|
||||
e = lightningmdb.env_create()
|
||||
num_pages = num_pages * 2
|
||||
print(e:set_mapsize(num_pages*4096))
|
||||
print(e:open(dir,0,420))
|
||||
end
|
||||
|
||||
grow()
|
||||
local t = e:txn_begin(nil,0)
|
||||
local db = t:dbi_open(nil,MDB.DUPSORT)
|
||||
for i=1,600 do
|
||||
local rc,err = t:put(db,"hello "..i,"cruel world",MDB.NODUPDATA)
|
||||
if not rc then
|
||||
if err:find("MDB_MAP_FULL",1,true) then
|
||||
print("making more room at",i)
|
||||
t:abort()
|
||||
e:close()
|
||||
|
||||
grow()
|
||||
t = e:txn_begin(nil,0)
|
||||
db = t:dbi_open(nil,MDB.DUPSORT)
|
||||
else
|
||||
print(rc,err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function cursor_pairs(cursor_,key_,op_)
|
||||
return coroutine.wrap(
|
||||
function()
|
||||
local k = key_
|
||||
repeat
|
||||
k,v = cursor_:get(k,op_ or MDB.NEXT)
|
||||
if k then
|
||||
coroutine.yield(k,v)
|
||||
end
|
||||
until not k
|
||||
end)
|
||||
end
|
||||
|
||||
local function mtest()
|
||||
print("--- mtest2")
|
||||
local count = math.random(10)+15
|
||||
local values = {}
|
||||
math.randomseed(os.time())
|
||||
for i=1,count do
|
||||
values[i] = math.random(1024)
|
||||
end
|
||||
|
||||
local e = lightningmdb.env_create()
|
||||
e:set_mapsize(10485760)
|
||||
local dir = test_setup("testdb")
|
||||
e:open(dir,MDB.FIXEDMAP,420)
|
||||
local t = e:txn_begin(nil,0)
|
||||
local d = t:dbi_open(nil,0)
|
||||
|
||||
print("adding values:",count)
|
||||
local j = 0
|
||||
for i,v in ipairs(values) do
|
||||
local rc = t:put(d,string.format("%03x",v),string.format("%d foo bar",v),
|
||||
MDB.NOOVERWRITE)
|
||||
if not rc then
|
||||
j = j + 1
|
||||
end
|
||||
end
|
||||
|
||||
print(j,"duplicates skipped")
|
||||
t:commit()
|
||||
ps(e)
|
||||
|
||||
t = e:txn_begin(nil,0)
|
||||
c = t:cursor_open(d)
|
||||
local k
|
||||
|
||||
|
||||
for k,v in cursor_pairs(c) do
|
||||
print(k,v)
|
||||
end
|
||||
|
||||
c:close()
|
||||
t:abort()
|
||||
math.randomseed(os.time())
|
||||
j = 0
|
||||
for i=count,1,-math.random(5) do
|
||||
j = j + 1
|
||||
t = e:txn_begin(nil,0)
|
||||
local key = string.format("%03x",values[i])
|
||||
if not t:del(d,key,nil) then
|
||||
j = j - 1
|
||||
t:abort()
|
||||
else
|
||||
t:commit()
|
||||
end
|
||||
end
|
||||
|
||||
print("deleted",j,"values")
|
||||
ps(e)
|
||||
t = e:txn_begin(nil,0)
|
||||
c = t:cursor_open(d)
|
||||
print("cursor next")
|
||||
local key
|
||||
for k,v in cursor_pairs(c,nil,MDB.NEXT) do
|
||||
print(k,v)
|
||||
key = k
|
||||
end
|
||||
|
||||
print("cursor prev")
|
||||
|
||||
for k,v in cursor_pairs(c,key,MDB.PREV) do
|
||||
print(k,v)
|
||||
end
|
||||
|
||||
c:close()
|
||||
e:dbi_close(d)
|
||||
|
||||
t:abort()
|
||||
e:close()
|
||||
end
|
||||
|
||||
local function mtest2()
|
||||
print("--- mtest2")
|
||||
|
||||
local count = math.random(10)+15
|
||||
local values = {}
|
||||
math.randomseed(os.time())
|
||||
for i=1,count do
|
||||
values[i] = math.random(1024)
|
||||
end
|
||||
|
||||
local e = lightningmdb.env_create()
|
||||
e:set_mapsize(10485760)
|
||||
e:set_maxdbs(4)
|
||||
local dir = test_setup("testdb")
|
||||
e:open(dir,MDB.FIXEDMAP + MDB.NOSYNC,420)
|
||||
local t = e:txn_begin(nil,0)
|
||||
local d = t:dbi_open("id1",MDB.CREATE)
|
||||
|
||||
print("adding values:",count)
|
||||
local j = 0
|
||||
for i,v in ipairs(values) do
|
||||
local rc = t:put(d,string.format("%03x",v),string.format("%d foo bar",v),
|
||||
MDB.NOOVERWRITE)
|
||||
if not rc then
|
||||
j = j + 1
|
||||
end
|
||||
end
|
||||
|
||||
print(j,"duplicates skipped")
|
||||
t:commit()
|
||||
ps(e)
|
||||
|
||||
t = e:txn_begin(nil,0)
|
||||
c = t:cursor_open(d)
|
||||
local k
|
||||
|
||||
|
||||
for k,v in cursor_pairs(c) do
|
||||
print(k,v)
|
||||
end
|
||||
|
||||
c:close()
|
||||
t:abort()
|
||||
math.randomseed(os.time())
|
||||
j = 0
|
||||
for i=count,1,-math.random(5) do
|
||||
j = j + 1
|
||||
t = e:txn_begin(nil,0)
|
||||
local key = string.format("%03x",values[i])
|
||||
if not t:del(d,key,nil) then
|
||||
j = j - 1
|
||||
t:abort()
|
||||
else
|
||||
t:commit()
|
||||
end
|
||||
end
|
||||
|
||||
print("deleted",j,"values")
|
||||
|
||||
ps(e)
|
||||
t = e:txn_begin(nil,0)
|
||||
c = t:cursor_open(d)
|
||||
print("cursor next")
|
||||
local key
|
||||
for k,v in cursor_pairs(c,nil,MDB.NEXT) do
|
||||
print(k,v)
|
||||
key = k
|
||||
end
|
||||
|
||||
print("cursor prev")
|
||||
|
||||
for k,v in cursor_pairs(c,key,MDB.PREV) do
|
||||
print(k,v)
|
||||
end
|
||||
|
||||
c:close()
|
||||
e:dbi_close(d)
|
||||
|
||||
t:abort()
|
||||
e:close()
|
||||
end
|
||||
|
||||
local function mtest3()
|
||||
print("--- mtest3")
|
||||
|
||||
local count = math.random(10)+15
|
||||
local values = {}
|
||||
math.randomseed(os.time())
|
||||
for i=1,count do
|
||||
values[i] = math.random(1024)
|
||||
end
|
||||
|
||||
local e = lightningmdb.env_create()
|
||||
e:set_mapsize(10485760)
|
||||
e:set_maxdbs(4)
|
||||
local dir = test_setup("testdb")
|
||||
e:open(dir,MDB.FIXEDMAP + MDB.NOSYNC,420)
|
||||
|
||||
local t = e:txn_begin(nil,0)
|
||||
local d = t:dbi_open("id2",MDB.CREATE+MDB.DUPSORT)
|
||||
|
||||
print("adding values:",count)
|
||||
local j = 0
|
||||
for i,v in ipairs(values) do
|
||||
if i%5==0 then
|
||||
v = values[i-1]
|
||||
end
|
||||
local rc = t:put(d,string.format("%03x",v),string.format("%d foo bar",v),
|
||||
MDB.NODUPDATA)
|
||||
if not rc then
|
||||
j = j + 1
|
||||
end
|
||||
end
|
||||
if j>0 then
|
||||
print("duplicate skipped",j)
|
||||
end
|
||||
t:commit()
|
||||
ps(e)
|
||||
|
||||
t = e:txn_begin(nil,0)
|
||||
c = t:cursor_open(d)
|
||||
|
||||
for k,v in cursor_pairs(c,nil,MDB.NEXT) do
|
||||
print(k,v)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
basic_test()
|
||||
grow_db()
|
||||
|
||||
mtest()
|
||||
mtest2()
|
||||
mtest3()
|
||||
@@ -1,80 +0,0 @@
|
||||
require "test_common"
|
||||
|
||||
local function basic_test()
|
||||
print("Lightning MDB version:",lightningmdb.version())
|
||||
print("Lightning error:",lightningmdb.strerror(0))
|
||||
|
||||
print("-- globals --")
|
||||
pt(lightningmdb)
|
||||
|
||||
-- env
|
||||
local e = lightningmdb.env_create()
|
||||
print(e)
|
||||
local dir = test_setup("foo")
|
||||
print(e:open(dir,0,420))
|
||||
print("fixedmap",MDB.FIXEDMAP)
|
||||
print("read only",MDB.RDONLY)
|
||||
|
||||
print("-- stats --")
|
||||
pt(e:stat())
|
||||
|
||||
print("-- info --")
|
||||
pt(e:info())
|
||||
print("get_path",e:get_path())
|
||||
|
||||
|
||||
--txn
|
||||
local t = e:txn_begin(nil,0)
|
||||
print("txn",t)
|
||||
t:commit()
|
||||
t = e:txn_begin(nil,0)
|
||||
print("txn",t)
|
||||
t:reset()
|
||||
t:renew()
|
||||
--t:abort()
|
||||
local db = t:dbi_open(nil,0)
|
||||
print(string.format("-- txn stat [%d] --",t:id()))
|
||||
pt(t:stat(db))
|
||||
t:abort()
|
||||
e:close()
|
||||
end
|
||||
|
||||
local function grow_db()
|
||||
print("--- grow_db ---")
|
||||
local num_pages = 5
|
||||
local e
|
||||
|
||||
local dir = test_setup("bar")
|
||||
|
||||
local function grow()
|
||||
e = lightningmdb.env_create()
|
||||
num_pages = num_pages * 2
|
||||
print(e:set_mapsize(num_pages*4096))
|
||||
print(e:open(dir,0,420))
|
||||
end
|
||||
|
||||
grow()
|
||||
local t = e:txn_begin(nil,0)
|
||||
local db = t:dbi_open(nil,MDB.DUPSORT)
|
||||
for i=1,600 do
|
||||
local rc,err = t:put(db,"hello "..i,"cruel world",MDB.NODUPDATA)
|
||||
if not rc then
|
||||
if err:find("MDB_MAP_FULL",1,true) then
|
||||
print("making more room at",i)
|
||||
t:abort()
|
||||
e:close()
|
||||
|
||||
grow()
|
||||
t = e:txn_begin(nil,0)
|
||||
db = t:dbi_open(nil,MDB.DUPSORT)
|
||||
else
|
||||
print(rc,err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
basic_test()
|
||||
grow_db()
|
||||
|
||||
print("\n\n\n**** If you are seeing this, all is good (at least as far as lightningmdb is concerned). ****")
|
||||
@@ -1,26 +0,0 @@
|
||||
lightningmdb_lib=require "lightningmdb"
|
||||
|
||||
lightningmdb = _VERSION>="Lua 5.2" and lightningmdb_lib or lightningmdb
|
||||
MDB = setmetatable({}, {__index = function(t, k)
|
||||
return lightningmdb["MDB_" .. k]
|
||||
end})
|
||||
|
||||
function pt(t)
|
||||
for k,v in pairs(t) do
|
||||
print(k,v)
|
||||
end
|
||||
end
|
||||
|
||||
function ps(e)
|
||||
print("--- env stat")
|
||||
pt(e:stat())
|
||||
print("---")
|
||||
end
|
||||
|
||||
function test_setup(dir_)
|
||||
local dir = "./temp/"..dir_
|
||||
os.execute("mkdir -p "..dir)
|
||||
os.execute("rm -rf "..dir.."/data.mdb")
|
||||
os.execute("rm -rf "..dir.."/lock.mdb")
|
||||
return dir
|
||||
end
|
||||
Reference in New Issue
Block a user