Compare commits

...

11 Commits

Author SHA1 Message Date
Leo Yuriev
5bb92a4277 mdbx: add fallthrough for modern gcc.
Change-Id: I948adc0e534dd9ba42b7d64e8105870cc77f82e6
2018-06-21 20:09:27 +03:00
Leo Yuriev
c381573d1f mdbx-tests: include <sys/sysmacros.h> for modern glibc.
Change-Id: I9ac297c6c029b2d88faaa84aab5180dc9d6a5d7a
2018-06-21 20:05:09 +03:00
Leo Yuriev
31873e8e2c mdbx-ci: migrate to Circle-CI 2.0
Change-Id: If8b77d070277cf88dfe81f5bf33dd33466dca0d9
2018-06-21 19:51:23 +03:00
Leo Yuriev
e94d6efec6 mdbx: update Project Status. 2018-05-10 14:09:37 +03:00
Leo Yuriev
7eb1b36309 mdbx: minor fixup comments and warnings. 2018-05-04 17:26:04 +03:00
Leo Yuriev
0c4b39bd11 mdbx: fix wrong freeDB search.
Avoid search freeDB while tree is updating.
Bug was inherited from LMDB.
https://github.com/leo-yuriev/libmdbx/issues/31
2018-05-04 17:22:59 +03:00
Howard Chu
2bccc85ff8 mdbx: backport - can't use fakepage mp_ptrs directly (ITS#8819). 2018-05-04 17:15:43 +03:00
Howard Chu
df08b5144c mdbx: backport - fix regression in 0.9.19 (ITS#8760). 2018-05-04 17:14:14 +03:00
Hallvard Furuseth
9baca673ac mdbx: backport - XCURSOR_REFRESH() fixups/cleanup.
* Check NUMKEYS(), similar to f34b61f9471d1c03fe0517b9d817c50c920e378a
  "ITS#8722 fix FIRST_DUP/LAST_DUP cursor bounds check".
* Move XCURSOR_INITED() into XCURSOR_REFRESH().  This adds a check in
  mdb_cursor_put, below /* converted, write the original data first */.
* Factor mc_ki[] out to XCURSOR_REFRESH().
* Replace an mc_pg[] with mp which is equal (mdb_cursor_del0).

* This checks XCURSOR_INITED() and fixes the mn_flags check.
2018-05-04 17:12:42 +03:00
Leo Yuriev
55893f8c39 mdbx: fix check make target (minor). 2018-05-04 16:59:54 +03:00
Howard Chu
70042069eb mdbx: backport - fix FIRST_DUP/LAST_DUP cursor bounds check (ITS#8722). 2018-05-04 16:57:30 +03:00
15 changed files with 74 additions and 56 deletions

9
.circleci/config.yml Normal file
View File

@@ -0,0 +1,9 @@
version: 2
jobs:
build:
docker:
- image: circleci/buildpack-deps:artful
steps:
- checkout
- run: make all lmdb
- run: make check

View File

@@ -71,7 +71,7 @@ clean:
tests: $(TESTS)
check: tests
check: tests mdbx_chk
[ -d testdb ] || mkdir testdb && rm -f testdb/* \
&& echo "*** LMDB-TEST-0" && ./mtest0 && ./mdbx_chk -v testdb \
&& echo "*** LMDB-TEST-1" && ./mtest1 && ./mdbx_chk -v testdb \

View File

@@ -5,8 +5,16 @@ Extended LMDB, aka "Расширенная LMDB".
*The Future will Positive. Всё будет хорошо.*
[![Build Status](https://travis-ci.org/leo-yuriev/libmdbx.svg?branch=stable%2F0.0)](https://travis-ci.org/leo-yuriev/libmdbx)
English version by Google [is here](https://translate.googleusercontent.com/translate_c?act=url&ie=UTF8&sl=ru&tl=en&u=https://github.com/leo-yuriev/libmdbx/tree/stable%2F0.0).
## Project Status for now
- The stable versions (the _stable/*_ branches) of are frozen, i.e. no new features or API changes, but only bug fixes.
- The next (the _devel_ branch) version **is under active development**, i.e. current API and set of features are extreme volatile.
- The immediate goal of development is formation of the stable API and the stable internal database format, which allows realise all planned features.
- Planned features: Integrity check by Merkle tree, Support for raw block devices, Separate place for large data items, Using "roaring bitmaps" for garbage collector, Non-linear page reclaiming, Asynchronous lazy data flush to disk(s), etc.
-----
English version by Google [is here](https://translate.googleusercontent.com/translate_c?act=url&ie=UTF8&sl=ru&tl=en&u=https://github.com/leo-yuriev/libmdbx/tree/stable%2F0.0).
## Кратко

View File

@@ -1,14 +0,0 @@
machine:
timezone:
Europe/Moscow
database:
override:
compile:
override:
- make all lmdb
test:
override:
- make check

84
mdb.c
View File

@@ -44,10 +44,8 @@
# define _GNU_SOURCE
#endif
/* LY: Please do not ask us for Windows support, just never!
* But you can make a fork for Windows, or become maintainer for FreeBSD... */
#ifndef __gnu_linux__
# warning "This version of ReOpenMDBX supports only GNU Linux"
# warning "This version of libmdbx supports only GNU Linux"
#endif
#include <stddef.h>
@@ -56,21 +54,21 @@
#include "./defs.h"
#if !__GNUC_PREREQ(4,2)
/* LY: Actualy ReOpenMDBX was not tested with compilers
/* LY: Actualy libmdbx was not tested with compilers
* older than GCC 4.4 (from RHEL6).
* But you could remove this #error and try to continue at your own risk.
* In such case please don't rise up an issues related ONLY to old compilers.
*/
# warning "ReOpenMDBX required at least GCC 4.2 compatible C/C++ compiler."
# warning "libmdbx required at least GCC 4.2 compatible C/C++ compiler."
#endif
#if !__GLIBC_PREREQ(2,12)
/* LY: Actualy ReOpenMDBX was not tested with something
/* LY: Actualy libmdbx was not tested with something
* older than glibc 2.12 (from RHEL6).
* But you could remove this #error and try to continue at your own risk.
* In such case please don't rise up an issues related ONLY to old systems.
*/
# warning "ReOpenMDBX required at least GLIBC 2.12."
# warning "libmdbx required at least GLIBC 2.12."
#endif
#if MDB_DEBUG
@@ -1026,17 +1024,19 @@ typedef struct MDB_xcursor {
unsigned char mx_dbflag;
} MDB_xcursor;
/** Check if there is an inited xcursor, so #XCURSOR_REFRESH() is proper */
/** Check if there is an inited xcursor */
#define XCURSOR_INITED(mc) \
((mc)->mc_xcursor && ((mc)->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED))
/** Update sub-page pointer, if any, in \b mc->mc_xcursor. Needed
/** Update the xcursor's sub-page pointer, if any, in \b mc. Needed
* when the node which contains the sub-page may have moved. Called
* with \b mp = mc->mc_pg[mc->mc_top], \b ki = mc->mc_ki[mc->mc_top].
* with leaf page \b mp = mc->mc_pg[\b top].
*/
#define XCURSOR_REFRESH(mc, mp, ki) do { \
#define XCURSOR_REFRESH(mc, top, mp) do { \
MDB_page *xr_pg = (mp); \
MDB_node *xr_node = NODEPTR(xr_pg, ki); \
MDB_node *xr_node; \
if (!XCURSOR_INITED(mc) || (mc)->mc_ki[top] >= NUMKEYS(xr_pg)) break; \
xr_node = NODEPTR(xr_pg, (mc)->mc_ki[top]); \
if ((xr_node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA) \
(mc)->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(xr_node); \
} while (0)
@@ -2138,6 +2138,10 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp, int flags)
/* If mc is updating the freeDB, then the freelist cannot play
* catch-up with itself by growing while trying to save it. */
flags &= ~(MDBX_ALLOC_GC | MDBX_ALLOC_KICK | MDBX_COALESCE | MDBX_LIFORECLAIM);
} else if (unlikely(txn->mt_dbs[FREE_DBI].md_entries == 0)) {
/* avoid (recursive) search inside empty tree and while tree is updating,
* https://github.com/leo-yuriev/libmdbx/issues/31 */
flags &= ~MDBX_ALLOC_GC;
}
}
@@ -2608,8 +2612,8 @@ done:
if (m2 == mc) continue;
if (m2->mc_pg[mc->mc_top] == mp) {
m2->mc_pg[mc->mc_top] = np;
if (XCURSOR_INITED(m2) && IS_LEAF(np))
XCURSOR_REFRESH(m2, np, m2->mc_ki[mc->mc_top]);
if (IS_LEAF(np))
XCURSOR_REFRESH(m2, mc->mc_top, np);
}
}
}
@@ -6673,6 +6677,11 @@ fetchm:
rc = MDB_INCOMPATIBLE;
break;
}
if (mc->mc_ki[mc->mc_top] >= NUMKEYS(mc->mc_pg[mc->mc_top])) {
mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]);
rc = MDB_NOTFOUND;
break;
}
{
MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) {
@@ -7023,7 +7032,8 @@ more:
offset *= 4; /* space for 4 more */
break;
}
/* FALLTHRU: Big enough MDB_DUPFIXED sub-page */
/* Big enough MDB_DUPFIXED sub-page */
/* fallthrough */
case MDB_CURRENT | MDB_NODUPDATA:
case MDB_CURRENT:
fp->mp_flags |= P_DIRTY;
@@ -7074,8 +7084,9 @@ prep_subDB:
} else {
memcpy((char *)mp + mp->mp_upper + PAGEBASE, (char *)fp + fp->mp_upper + PAGEBASE,
olddata.mv_size - fp->mp_upper - PAGEBASE);
memcpy((char *)(&mp->mp_ptrs), (char *)(&fp->mp_ptrs), NUMKEYS(fp) * sizeof(mp->mp_ptrs[0]));
for (i=0; i<NUMKEYS(fp); i++)
mp->mp_ptrs[i] = fp->mp_ptrs[i] + offset;
mp->mp_ptrs[i] += offset;
}
}
@@ -7203,8 +7214,7 @@ new_sub:
if (m3->mc_ki[i] >= mc->mc_ki[i] && insert_key) {
m3->mc_ki[i]++;
}
if (XCURSOR_INITED(m3))
XCURSOR_REFRESH(m3, mp, m3->mc_ki[i]);
XCURSOR_REFRESH(m3, i, mp);
}
}
}
@@ -7245,7 +7255,6 @@ put_sub:
MDB_xcursor *mx = mc->mc_xcursor;
unsigned i = mc->mc_top;
MDB_page *mp = mc->mc_pg[i];
int nkeys = NUMKEYS(mp);
for (m2 = mc->mc_txn->mt_cursors[mc->mc_dbi]; m2; m2=m2->mc_next) {
if (m2 == mc || m2->mc_snum < mc->mc_snum) continue;
@@ -7253,8 +7262,8 @@ put_sub:
if (m2->mc_pg[i] == mp) {
if (m2->mc_ki[i] == mc->mc_ki[i]) {
mdb_xcursor_init2(m2, mx, dupdata_flag);
} else if (!insert_key && m2->mc_ki[i] < nkeys) {
XCURSOR_REFRESH(m2, mp, m2->mc_ki[i]);
} else if (!insert_key) {
XCURSOR_REFRESH(m2, i, mp);
}
}
}
@@ -7364,12 +7373,7 @@ mdb_cursor_del(MDB_cursor *mc, unsigned flags)
if (m2 == mc || m2->mc_snum < mc->mc_snum) continue;
if (!(m2->mc_flags & C_INITIALIZED)) continue;
if (m2->mc_pg[mc->mc_top] == mp) {
MDB_node *n2 = leaf;
if (m2->mc_ki[mc->mc_top] != mc->mc_ki[mc->mc_top]) {
n2 = NODEPTR(mp, m2->mc_ki[mc->mc_top]);
if (n2->mn_flags & F_SUBDATA) continue;
}
m2->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(n2);
XCURSOR_REFRESH(m2, mc->mc_top, mp);
}
}
}
@@ -8273,8 +8277,8 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
m3->mc_ki[csrc->mc_top-1]++;
}
if (XCURSOR_INITED(m3) && IS_LEAF(mps))
XCURSOR_REFRESH(m3, m3->mc_pg[csrc->mc_top], m3->mc_ki[csrc->mc_top]);
if (IS_LEAF(mps))
XCURSOR_REFRESH(m3, csrc->mc_top, m3->mc_pg[csrc->mc_top]);
}
} else
/* Adding on the right, bump others down */
@@ -8295,8 +8299,8 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
} else {
m3->mc_ki[csrc->mc_top]--;
}
if (XCURSOR_INITED(m3) && IS_LEAF(mps))
XCURSOR_REFRESH(m3, m3->mc_pg[csrc->mc_top], m3->mc_ki[csrc->mc_top]);
if (IS_LEAF(mps))
XCURSOR_REFRESH(m3, csrc->mc_top, m3->mc_pg[csrc->mc_top]);
}
}
}
@@ -8494,8 +8498,8 @@ mdb_page_merge(MDB_cursor *csrc, MDB_cursor *cdst)
m3->mc_ki[top-1] > csrc->mc_ki[top-1]) {
m3->mc_ki[top-1]--;
}
if (XCURSOR_INITED(m3) && IS_LEAF(psrc))
XCURSOR_REFRESH(m3, m3->mc_pg[top], m3->mc_ki[top]);
if (IS_LEAF(psrc))
XCURSOR_REFRESH(m3, top, m3->mc_pg[top]);
}
}
{
@@ -8757,8 +8761,7 @@ mdb_cursor_del0(MDB_cursor *mc)
} else if (m3->mc_ki[mc->mc_top] > ki) {
m3->mc_ki[mc->mc_top]--;
}
if (XCURSOR_INITED(m3))
XCURSOR_REFRESH(m3, m3->mc_pg[mc->mc_top], m3->mc_ki[mc->mc_top]);
XCURSOR_REFRESH(m3, mc->mc_top, mp);
}
}
}
@@ -9299,8 +9302,8 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
m3->mc_ki[ptop] >= mc->mc_ki[ptop]) {
m3->mc_ki[ptop]++;
}
if (XCURSOR_INITED(m3) && IS_LEAF(mp))
XCURSOR_REFRESH(m3, m3->mc_pg[mc->mc_top], m3->mc_ki[mc->mc_top]);
if (IS_LEAF(mp))
XCURSOR_REFRESH(m3, mc->mc_top, m3->mc_pg[mc->mc_top]);
}
}
mdb_debug("mp left: %d, rp left: %d", SIZELEFT(mp), SIZELEFT(rp));
@@ -10205,8 +10208,11 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned flags, MDB_dbi *dbi)
MDB_node *node = NODEPTR(mc.mc_pg[mc.mc_top], mc.mc_ki[mc.mc_top]);
if (unlikely((node->mn_flags & (F_DUPDATA|F_SUBDATA)) != F_SUBDATA))
return MDB_INCOMPATIBLE;
} else if (! (rc == MDB_NOTFOUND && (flags & MDB_CREATE))) {
return rc;
} else {
if (rc != MDB_NOTFOUND || !(flags & MDB_CREATE))
return rc;
if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY))
return EACCES;
}
/* Done here so we cannot fail after creating a new DB */

View File

@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
break;
case 'l':
list = 1;
/*FALLTHROUGH*/;
/* fallthrough */
case 'a':
if (subname)
usage(prog);

View File

@@ -21,6 +21,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#include <pthread.h>

View File

@@ -20,6 +20,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -23,6 +23,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -23,6 +23,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -23,6 +23,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -23,6 +23,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -23,6 +23,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -18,6 +18,7 @@
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)

View File

@@ -18,6 +18,7 @@
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/sysmacros.h>
#include "mdbx.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)