mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-11-04 17:19:53 +08:00 
			
		
		
		
	mdbx: Merge branch 'devel'.
This commit is contained in:
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							@@ -6,6 +6,7 @@ Chris Mikkelson <cmikk@qwest.net>
 | 
			
		||||
Claude Brisson <claude.brisson@gmail.com>
 | 
			
		||||
David Barbour <dmbarbour@gmail.com>
 | 
			
		||||
David Wilson <dw@botanicus.net>
 | 
			
		||||
dreamsxin <dreamsxin@126.com>
 | 
			
		||||
Hallvard Furuseth <hallvard@openldap.org>, <h.b.furuseth@usit.uio.no>
 | 
			
		||||
Heiko Becker <heirecka@exherbo.org>
 | 
			
		||||
Howard Chu <hyc@openldap.org>, <hyc@symas.com>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
# GNU Makefile for libmdbx, https://github.com/ReOpen/libmdbx
 | 
			
		||||
# GNU Makefile for libmdbx, https://github.com/leo-yuriev/libmdbx
 | 
			
		||||
 | 
			
		||||
########################################################################
 | 
			
		||||
# Configuration. The compiler options must enable threaded compilation.
 | 
			
		||||
@@ -53,10 +53,13 @@ TEST_OBJ	:= $(patsubst %.cc,%.o,$(TEST_SRC))
 | 
			
		||||
 | 
			
		||||
.PHONY: mdbx all install clean check coverage
 | 
			
		||||
 | 
			
		||||
all: $(LIBRARIES) $(TOOLS) test/test
 | 
			
		||||
all: $(LIBRARIES) $(TOOLS) test/test example
 | 
			
		||||
 | 
			
		||||
mdbx: libmdbx.a libmdbx.so
 | 
			
		||||
 | 
			
		||||
example: mdbx.h tutorial/sample-mdbx.c libmdbx.so
 | 
			
		||||
	$(CC) $(CFLAGS) -I. tutorial/sample-mdbx.c ./libmdbx.so -o example
 | 
			
		||||
 | 
			
		||||
tools: $(TOOLS)
 | 
			
		||||
 | 
			
		||||
install: $(LIBRARIES) $(TOOLS) $(HEADERS)
 | 
			
		||||
@@ -132,7 +135,7 @@ endif
 | 
			
		||||
ci-rule = ( CC=$$(which $1); if [ -n "$$CC" ]; then \
 | 
			
		||||
		echo -n "probe by $2 ($$(readlink -f $$(which $$CC))): " && \
 | 
			
		||||
		$(MAKE) clean >$1.log 2>$1.err && \
 | 
			
		||||
		$(MAKE) CC=$$(readlink -f $$CC) XCFLAGS="-UNDEBUG -DMDBX_DEBUG=2" check 1>$1.log 2>$1.err && echo "OK" \
 | 
			
		||||
		$(MAKE) CC=$$(readlink -f $$CC) XCFLAGS="-UNDEBUG -DMDBX_DEBUG=2 -DLIBMDBX_EXPORTS=1" check 1>$1.log 2>$1.err && echo "OK" \
 | 
			
		||||
			|| ( echo "FAILED"; cat $1.err >&2; exit 1 ); \
 | 
			
		||||
	else echo "no $2 ($1) for probe"; fi; )
 | 
			
		||||
ci:
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ _libmdbx_ является развитием "Lightning Memory-Mapped Database"
 | 
			
		||||
известной под аббревиатурой
 | 
			
		||||
[LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database).
 | 
			
		||||
Изначально доработка производилась в составе проекта
 | 
			
		||||
[ReOpenLDAP](https://github.com/ReOpen/ReOpenLDAP). Примерно за год
 | 
			
		||||
[ReOpenLDAP](https://github.com/leo-yuriev/ReOpenLDAP). Примерно за год
 | 
			
		||||
работы внесенные изменения приобрели самостоятельную ценность. Осенью
 | 
			
		||||
2015 доработанный движок был выделен в отдельный проект, который был
 | 
			
		||||
[представлен на конференции Highload++
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							@@ -42,7 +42,7 @@
 | 
			
		||||
- [ ] Валидатор страниц по CRC32, плюс контроль номер транзакии под модулю 2^32.
 | 
			
		||||
- [ ] Валидатор страниц по t1ha c контролем снимков/версий БД на основе Merkle Tree.
 | 
			
		||||
- [ ] Возможность хранения ключей внутри data (libfptu).
 | 
			
		||||
- [ ] Асинхронная фиксация (https://github.com/ReOpen/libmdbx/issues/5).
 | 
			
		||||
- [ ] Асинхронная фиксация (https://github.com/leo-yuriev/libmdbx/issues/5).
 | 
			
		||||
- [ ] (Пере)Выделять память под IDL-списки с учетом реального кол-ва страниц, т.е. max(MDB_IDL_UM_MAX/MDB_IDL_UM_MAX, npages).
 | 
			
		||||
 | 
			
		||||
-----------------------------------------------------------------------
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
tutorial/sample-mdbx.c
 | 
			
		||||
AUTHORS
 | 
			
		||||
LICENSE
 | 
			
		||||
Makefile
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								mdbx.h
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								mdbx.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/*
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
 | 
			
		||||
 * and other libmdbx authors: please see AUTHORS file.
 | 
			
		||||
 * All rights reserved.
 | 
			
		||||
@@ -70,7 +70,9 @@
 | 
			
		||||
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#include <winnt.h>
 | 
			
		||||
typedef unsigned mode_t;
 | 
			
		||||
#ifndef __mode_t_defined
 | 
			
		||||
typedef unsigned short mode_t;
 | 
			
		||||
#endif
 | 
			
		||||
typedef HANDLE mdbx_filehandle_t;
 | 
			
		||||
typedef DWORD mdbx_pid_t;
 | 
			
		||||
typedef DWORD mdbx_tid_t;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								src/mdbx.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/mdbx.c
									
									
									
									
									
								
							@@ -4757,6 +4757,14 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, int lck_rc) {
 | 
			
		||||
                meta.mm_txnid_a, mdbx_durable_str(&meta));
 | 
			
		||||
    }
 | 
			
		||||
    mdbx_ensure(env, meta.mm_geo.now >= meta.mm_geo.next);
 | 
			
		||||
  } else {
 | 
			
		||||
    /* geo-params not pre-configured by user,
 | 
			
		||||
     * get current values from a meta. */
 | 
			
		||||
    env->me_dbgeo.now = pgno2bytes(env, meta.mm_geo.now);
 | 
			
		||||
    env->me_dbgeo.lower = pgno2bytes(env, meta.mm_geo.lower);
 | 
			
		||||
    env->me_dbgeo.upper = pgno2bytes(env, meta.mm_geo.upper);
 | 
			
		||||
    env->me_dbgeo.grow = pgno2bytes(env, meta.mm_geo.grow);
 | 
			
		||||
    env->me_dbgeo.shrink = pgno2bytes(env, meta.mm_geo.shrink);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  uint64_t filesize_before_mmap;
 | 
			
		||||
@@ -4943,7 +4951,8 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, int lck_rc) {
 | 
			
		||||
/****************************************************************************/
 | 
			
		||||
 | 
			
		||||
/* Open and/or initialize the lock region for the environment. */
 | 
			
		||||
static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname, int mode) {
 | 
			
		||||
static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname,
 | 
			
		||||
                                 mode_t mode) {
 | 
			
		||||
  assert(env->me_fd != INVALID_HANDLE_VALUE);
 | 
			
		||||
  assert(env->me_lfd == INVALID_HANDLE_VALUE);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,66 +0,0 @@
 | 
			
		||||
/* sample-mdb.txt - MDB toy/sample
 | 
			
		||||
 *
 | 
			
		||||
 * Do a line-by-line comparison of this and sample-bdb.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>.
 | 
			
		||||
 * Copyright 2012-2015 Howard Chu, Symas Corp.
 | 
			
		||||
 * Copyright 2015,2016 Peter-Service R&D LLC.
 | 
			
		||||
 * 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>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "mdbx.h"
 | 
			
		||||
 | 
			
		||||
int main(int argc,char * argv[])
 | 
			
		||||
{
 | 
			
		||||
	int rc;
 | 
			
		||||
	MDBX_env *env;
 | 
			
		||||
	MDBX_dbi dbi;
 | 
			
		||||
	MDBX_val key, data;
 | 
			
		||||
	MDBX_txn *txn;
 | 
			
		||||
	MDBX_cursor *cursor;
 | 
			
		||||
	char sval[32];
 | 
			
		||||
 | 
			
		||||
	/* Note: Most error checking omitted for simplicity */
 | 
			
		||||
 | 
			
		||||
	rc = mdbx_env_create(&env);
 | 
			
		||||
	rc = mdbx_env_open(env, "./testdb", 0, 0664);
 | 
			
		||||
	rc = mdbx_txn_begin(env, NULL, 0, &txn);
 | 
			
		||||
	rc = mdbx_dbi_open(txn, NULL, 0, &dbi);
 | 
			
		||||
 | 
			
		||||
	key.iov_len = sizeof(int);
 | 
			
		||||
	key.iov_base = sval;
 | 
			
		||||
	data.iov_len = sizeof(sval);
 | 
			
		||||
	data.iov_base = sval;
 | 
			
		||||
 | 
			
		||||
	sprintf(sval, "%03x %d foo bar", 32, 3141592);
 | 
			
		||||
	rc = mdbx_put(txn, dbi, &key, &data, 0);
 | 
			
		||||
	rc = mdbx_txn_commit(txn);
 | 
			
		||||
	if (rc) {
 | 
			
		||||
		fprintf(stderr, "mdbx_txn_commit: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
		goto leave;
 | 
			
		||||
	}
 | 
			
		||||
	rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
 | 
			
		||||
	rc = mdbx_cursor_open(txn, dbi, &cursor);
 | 
			
		||||
	while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) == 0) {
 | 
			
		||||
		printf("key: %p %.*s, data: %p %.*s\n",
 | 
			
		||||
			key.iov_base,  (int) key.iov_len,  (char *) key.iov_base,
 | 
			
		||||
			data.iov_base, (int) data.iov_len, (char *) data.iov_base);
 | 
			
		||||
	}
 | 
			
		||||
	mdbx_cursor_close(cursor);
 | 
			
		||||
	mdbx_txn_abort(txn);
 | 
			
		||||
leave:
 | 
			
		||||
	mdbx_dbi_close(env, dbi);
 | 
			
		||||
	mdbx_env_close(env);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										112
									
								
								tutorial/sample-mdbx.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								tutorial/sample-mdbx.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
			
		||||
/* sample-mdb.txt - MDB toy/sample
 | 
			
		||||
 *
 | 
			
		||||
 * Do a line-by-line comparison of this and sample-bdb.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright 2017 Ilya Shipitsin <chipitsine@gmail.com>.
 | 
			
		||||
 * Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>.
 | 
			
		||||
 * Copyright 2012-2015 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>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "mdbx.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[]) {
 | 
			
		||||
  (void)argc;
 | 
			
		||||
  (void)argv;
 | 
			
		||||
 | 
			
		||||
  int rc;
 | 
			
		||||
  MDBX_env *env = NULL;
 | 
			
		||||
  MDBX_dbi dbi = 0;
 | 
			
		||||
  MDBX_val key, data;
 | 
			
		||||
  MDBX_txn *txn = NULL;
 | 
			
		||||
  MDBX_cursor *cursor = NULL;
 | 
			
		||||
  char sval[32];
 | 
			
		||||
 | 
			
		||||
  rc = mdbx_env_create(&env);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_env_create: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  rc = mdbx_env_open(env, "./example-db",
 | 
			
		||||
                     MDBX_NOSUBDIR | MDBX_COALESCE | MDBX_LIFORECLAIM, 0664);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_env_open: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  rc = mdbx_txn_begin(env, NULL, 0, &txn);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_txn_begin: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
  rc = mdbx_dbi_open(txn, NULL, 0, &dbi);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_dbi_open: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  key.iov_len = sizeof(int);
 | 
			
		||||
  key.iov_base = sval;
 | 
			
		||||
  data.iov_len = sizeof(sval);
 | 
			
		||||
  data.iov_base = sval;
 | 
			
		||||
 | 
			
		||||
  sprintf(sval, "%03x %d foo bar", 32, 3141592);
 | 
			
		||||
  rc = mdbx_put(txn, dbi, &key, &data, 0);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_put: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
  rc = mdbx_txn_commit(txn);
 | 
			
		||||
  if (rc) {
 | 
			
		||||
    fprintf(stderr, "mdbx_txn_commit: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
  txn = NULL;
 | 
			
		||||
 | 
			
		||||
  rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_txn_begin: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
  rc = mdbx_cursor_open(txn, dbi, &cursor);
 | 
			
		||||
  if (rc != MDBX_SUCCESS) {
 | 
			
		||||
    fprintf(stderr, "mdbx_cursor_open: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int found = 0;
 | 
			
		||||
  while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) == 0) {
 | 
			
		||||
    printf("key: %p %.*s, data: %p %.*s\n", key.iov_base, (int)key.iov_len,
 | 
			
		||||
           (char *)key.iov_base, data.iov_base, (int)data.iov_len,
 | 
			
		||||
           (char *)data.iov_base);
 | 
			
		||||
    found += 1;
 | 
			
		||||
  }
 | 
			
		||||
  if (rc != MDBX_NOTFOUND || found == 0) {
 | 
			
		||||
    fprintf(stderr, "mdbx_cursor_get: (%d) %s\n", rc, mdbx_strerror(rc));
 | 
			
		||||
    goto bailout;
 | 
			
		||||
  } else {
 | 
			
		||||
    rc = MDBX_SUCCESS;
 | 
			
		||||
  }
 | 
			
		||||
bailout:
 | 
			
		||||
  if (cursor)
 | 
			
		||||
    mdbx_cursor_close(cursor);
 | 
			
		||||
  if (txn)
 | 
			
		||||
    mdbx_txn_abort(txn);
 | 
			
		||||
  if (dbi)
 | 
			
		||||
    mdbx_dbi_close(env, dbi);
 | 
			
		||||
  if (env)
 | 
			
		||||
    mdbx_env_close(env);
 | 
			
		||||
  return (rc != MDBX_SUCCESS) ? EXIT_FAILURE : EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user