示例#1
0
static void unlock_write_txn(int nEnv, char syncForce, char *commit)
{
	int i;

	if (!g_tsd_wmdb)
		return;

	++g_tsd_wmdb->usageCount;
	if (*commit || syncForce)
	{
		if (mdb_txn_commit(g_tsd_wmdb->txn) != MDB_SUCCESS)
			mdb_txn_abort(g_tsd_wmdb->txn);
		g_tsd_wmdb->txn = NULL;
		g_tsd_wmdb->usageCount = 0;
		
		if (syncForce)
			mdb_env_sync(g_tsd_wmdb->env,1);

		if (syncForce)
			++g_pd->syncNumbers[nEnv];
		*commit = 1;
	}
	// else
	// 	DBG("UNLOCK %u",g_tsd_wmdb->usageCount);
	g_tsd_cursync = g_pd->syncNumbers[nEnv];
	g_tsd_wmdb = NULL;
}
示例#2
0
文件: jmdb.c 项目: cirnoworks/jmdb
/*
 * Class:     jmdb_DatabaseWrapper
 * Method:    envSync
 * Signature: (JZ)V
 */
JNIEXPORT void JNICALL Java_jmdb_DatabaseWrapper_envSync(JNIEnv *vm,
		jclass clazz, jlong envL, jboolean force) {
	MDB_env *envC = (MDB_env*) envL;
	int code = mdb_env_sync(envC, force);
	if (code) {
		throwDatabaseException(vm, code);
	}
}
示例#3
0
void db_sync(db_t db, int force){
	int r = mdb_env_sync(db->env, force);
	// lmdb refuses to sync envs opened with mdb_readonly
	// I am not bothering with figuring out if fdatasync is broken on your platform
	if(EACCES == r)
		r = fdatasync(db->fd);
	if(MDB_SUCCESS != r)
		fprintf(stderr, "%d: mdb_env_sync(): %s (%d)\n", (int)getpid(), mdb_strerror(r), r);
	assert(MDB_SUCCESS == r);
}
示例#4
0
文件: config.c 项目: benegon/openldap
/* perform periodic syncs */
static void *
mdb_checkpoint( void *ctx, void *arg )
{
	struct re_s *rtask = arg;
	struct mdb_info *mdb = rtask->arg;

	mdb_env_sync( mdb->mi_dbenv, 1 );
	ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
	ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
	ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
	return NULL;
}
示例#5
0
static int
mdb_db_close( BackendDB *be, ConfigReply *cr )
{
	int rc;
	struct mdb_info *mdb = (struct mdb_info *) be->be_private;

	/* monitor handling */
	(void)mdb_monitor_db_close( be );

	mdb->mi_flags &= ~MDB_IS_OPEN;

	if( mdb->mi_dbenv ) {
		mdb_reader_flush( mdb->mi_dbenv );
	}

	if ( mdb->mi_dbenv ) {
		if ( mdb->mi_dbis[0] ) {
			int i;

			mdb_attr_dbs_close( mdb );
			for ( i=0; i<MDB_NDB; i++ )
				mdb_dbi_close( mdb->mi_dbenv, mdb->mi_dbis[i] );

			/* force a sync, but not if we were ReadOnly,
			 * and not in Quick mode.
			 */
			if (!(slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY))) {
				rc = mdb_env_sync( mdb->mi_dbenv, 1 );
				if( rc != 0 ) {
					Debug( LDAP_DEBUG_ANY,
						"mdb_db_close: database \"%s\": "
						"mdb_env_sync failed: %s (%d).\n",
						be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
				}
			}
		}

		mdb_env_close( mdb->mi_dbenv );
		mdb->mi_dbenv = NULL;
	}

	if ( mdb->mi_search_stack ) {
		ch_free( mdb->mi_search_stack );
		mdb->mi_search_stack = NULL;
	}

	return 0;
}
示例#6
0
文件: init.c 项目: vmware/lightwave
/*
 * Close all opened DBs and free environment
 */
DWORD
VmDirMDBShutdownDB(
    PVDIR_DB_HANDLE hDB
    )
{
    PVDIR_MDB_DB pDB = (PVDIR_MDB_DB)hDB;

    VmDirLog( LDAP_DEBUG_TRACE, "MDBShutdownDB: Begin" );

    VmDirLogDBStats(pDB);

    if (pDB->mdbEnv != NULL)
    {
        MDBCloseDBs(pDB);

        VmDirMDBShutdownIndexDB(pDB);

        // force buffer sync
        mdb_env_sync(pDB->mdbEnv, 1);

        mdb_env_close(pDB->mdbEnv);
        pDB->mdbEnv = NULL;
    }

    if (pDB->mdbEntryDB.pMdbDataFiles)
    {
        VMDIR_SAFE_FREE_MEMORY(pDB->mdbEntryDB.pMdbDataFiles->pszDBFile);
        VMDIR_SAFE_FREE_MEMORY(pDB->mdbEntryDB.pMdbDataFiles->pszDBName);
        VMDIR_SAFE_FREE_MEMORY(pDB->mdbEntryDB.pMdbDataFiles);
    }
    VMDIR_SAFE_FREE_MEMORY(pDB->pszDBPath);
    VMDIR_SAFE_FREE_MEMORY(pDB);

    VmDirLog( LDAP_DEBUG_TRACE, "MDBShutdownDB: End" );

    return 0;
}
示例#7
0
void kvdb_lmdb_flush(kvdb_t *kvdb)
{
    /*kvdb_lmdb_t *lmdb = (kvdb_lmdb_t*)kvdb;*/
    kvenv_lmdb_t *kvenv_lmdb = (kvenv_lmdb_t*)kvdb->kvenv;
    mdb_env_sync(kvenv_lmdb->env, 1);
}
示例#8
0
int main(int argc,char * argv[])
{
	int i = 0, j = 0, rc;
	MDB_env *env;
	MDB_dbi dbi;
	MDB_val key, data;
	MDB_txn *txn;
	MDB_stat mst;
	MDB_cursor *cursor;
	int count;
	int *values;
	char sval[32] = "";
	int env_oflags;
	struct stat db_stat, exe_stat;

	(void) argc;
	(void) argv;
	srand(time(NULL));

	count = (rand()%384) + 64;
	values = (int *)malloc(count*sizeof(int));

	for(i = 0;i<count;i++) {
		values[i] = rand()%1024;
	}

	E(mdb_env_create(&env));
	E(mdb_env_set_maxreaders(env, 1));
	E(mdb_env_set_mapsize(env, 10485760));
	E(mdb_env_set_maxdbs(env, 4));

	E(stat("/proc/self/exe", &exe_stat)?errno:0);
	E(stat(DBPATH "/.", &db_stat)?errno:0);
	env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
	if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
		/* LY: Assume running inside a CI-environment:
		 *  1) don't use FIXEDMAP to avoid EBUSY in case collision,
		 *     which could be inspired by address space randomisation feature.
		 *  2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
		 */
		env_oflags = 0;
	}
	/* LY: especially here we always needs MDB_NOSYNC
	 * for testing mdbx_env_close_ex() and "redo-to-steady" on open. */
	env_oflags |= MDB_NOSYNC;
	E(mdb_env_open(env, DBPATH, env_oflags, 0664));

	E(mdb_txn_begin(env, NULL, 0, &txn));
	if (mdb_dbi_open(txn, "id1", MDB_CREATE, &dbi) == MDB_SUCCESS)
		E(mdb_drop(txn, dbi, 1));
	E(mdb_dbi_open(txn, "id1", MDB_CREATE, &dbi));

	key.mv_size = sizeof(int);
	key.mv_data = sval;
	data.mv_size = sizeof(sval);
	data.mv_data = sval;

	printf("Adding %d values\n", count);
	for (i=0;i<count;i++) {
		sprintf(sval, "%03x %d foo bar", values[i], values[i]);
		if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE)))
			j++;
	}
	if (j) printf("%d duplicates skipped\n", j);
	E(mdb_txn_commit(txn));
	E(mdb_env_stat(env, &mst));

	printf("check-preset-a\n");
	E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
	E(mdb_cursor_open(txn, dbi, &cursor));
	int present_a = 0;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
		printf("key: %p %.*s, data: %p %.*s\n",
			key.mv_data,  (int) key.mv_size,  (char *) key.mv_data,
			data.mv_data, (int) data.mv_size, (char *) data.mv_data);
		++present_a;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_a == count - j, "mismatch");
	mdb_cursor_close(cursor);
	mdb_txn_abort(txn);
	mdb_env_sync(env, 1);

	int deleted = 0;
	key.mv_data = sval;
	for (i = count - 1; i > -1; i -= (rand()%5)) {
		txn=NULL;
		E(mdb_txn_begin(env, NULL, 0, &txn));
		sprintf(sval, "%03x ", values[i]);
		if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
			mdb_txn_abort(txn);
		} else {
			E(mdb_txn_commit(txn));
			deleted++;
		}
	}
	free(values);
	printf("Deleted %d values\n", deleted);

	printf("check-preset-b.cursor-next\n");
	E(mdb_env_stat(env, &mst));
	E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
	E(mdb_cursor_open(txn, dbi, &cursor));
	int present_b = 0;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++present_b;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_b == present_a - deleted, "mismatch");

	printf("check-preset-b.cursor-prev\n");
	j = 1;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++j;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_b == j, "mismatch");
	mdb_cursor_close(cursor);
	mdb_txn_abort(txn);

	mdb_dbi_close(env, dbi);
	/********************* LY: kept DB dirty ****************/
	mdbx_env_close_ex(env, 1);
	E(mdb_env_create(&env));
	E(mdb_env_set_maxdbs(env, 4));
	E(mdb_env_open(env, DBPATH, env_oflags, 0664));

	printf("check-preset-c.cursor-next\n");
	E(mdb_env_stat(env, &mst));
	E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
	E(mdb_dbi_open(txn, "id1", 0, &dbi));
	E(mdb_cursor_open(txn, dbi, &cursor));
	int present_c = 0;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++present_c;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	printf("Rolled back %d deletion(s)\n", present_c - (present_a - deleted));
	CHECK(present_c > present_a - deleted, "mismatch");

	printf("check-preset-d.cursor-prev\n");
	j = 1;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++j;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_c == j, "mismatch");
	mdb_cursor_close(cursor);
	mdb_txn_abort(txn);

	mdb_dbi_close(env, dbi);
	mdbx_env_close_ex(env, 0);

	return 0;
}
示例#9
0
 int LMDBStore::sync()
 {
     int rc = mdb_env_sync(env, 1);
     return (rc == 0 ? HCAT_SUCCESS : HCAT_FAIL);
 }
示例#10
0
int main(int argc,char * argv[])
{
	int i = 0, j = 0, rc;
	MDB_env *env;
	MDB_dbi dbi;
	MDB_val key, data;
	MDB_txn *txn;
	MDB_stat mst;
	MDB_cursor *cursor;
	int count;
	int *values;
	char sval[32] = "";

	srand(time(NULL));

	count = (rand()%384) + 64;
	values = (int *)malloc(count*sizeof(int));

	for(i = 0;i<count;i++) {
		values[i] = rand()%1024;
	}

	E(mdb_env_create(&env));

	E(mdb_env_set_maxreaders(env, 1));
	E(mdb_env_set_mapsize(env, 10485760));
	E(mdb_env_set_maxdbs(env, 4));
	E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));

	E(mdb_txn_begin(env, NULL, 0, &txn));
	if (mdb_dbi_open(txn, "id1", MDB_CREATE, &dbi) == MDB_SUCCESS)
		E(mdb_drop(txn, dbi, 1));
	E(mdb_dbi_open(txn, "id1", MDB_CREATE, &dbi));

	key.mv_size = sizeof(int);
	key.mv_data = sval;
	data.mv_size = sizeof(sval);
	data.mv_data = sval;

	printf("Adding %d values\n", count);
	for (i=0;i<count;i++) {
		sprintf(sval, "%03x %d foo bar", values[i], values[i]);
		if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE)))
			j++;
	}
	if (j) printf("%d duplicates skipped\n", j);
	E(mdb_txn_commit(txn));
	E(mdb_env_stat(env, &mst));

	printf("check-preset-a\n");
	E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
	E(mdb_cursor_open(txn, dbi, &cursor));
	int present_a = 0;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
		printf("key: %p %.*s, data: %p %.*s\n",
			key.mv_data,  (int) key.mv_size,  (char *) key.mv_data,
			data.mv_data, (int) data.mv_size, (char *) data.mv_data);
		++present_a;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_a == count - j, "mismatch");
	mdb_cursor_close(cursor);
	mdb_txn_abort(txn);
	mdb_env_sync(env, 1);

	j=0;
	key.mv_data = sval;
	for (i= count - 1; i > -1; i-= (rand()%5)) {
		j++;
		txn=NULL;
		E(mdb_txn_begin(env, NULL, 0, &txn));
		sprintf(sval, "%03x ", values[i]);
		if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
			j--;
			mdb_txn_abort(txn);
		} else {
			E(mdb_txn_commit(txn));
		}
	}
	free(values);
	printf("Deleted %d values\n", j);

	printf("check-preset-b.cursor-next\n");
	E(mdb_env_stat(env, &mst));
	E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
	E(mdb_cursor_open(txn, dbi, &cursor));
	int present_b = 0;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++present_b;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_b == present_a - j, "mismatch");

	printf("check-preset-b.cursor-prev\n");
	j = 1;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++j;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_b == j, "mismatch");
	mdb_cursor_close(cursor);
	mdb_txn_abort(txn);

	mdb_dbi_close(env, dbi);
	/********************* LY: kept DB dirty ****************/
	mdb_env_close_ex(env, 1);
	E(mdb_env_create(&env));
	E(mdb_env_set_maxdbs(env, 4));
	E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));

	printf("check-preset-c.cursor-next\n");
	E(mdb_env_stat(env, &mst));
	E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
	E(mdb_dbi_open(txn, "id1", 0, &dbi));
	E(mdb_cursor_open(txn, dbi, &cursor));
	int present_c = 0;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++present_c;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_c == present_a, "mismatch");

	printf("check-preset-d.cursor-prev\n");
	j = 1;
	while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		++j;
	}
	CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
	CHECK(present_c == j, "mismatch");
	mdb_cursor_close(cursor);
	mdb_txn_abort(txn);

	mdb_dbi_close(env, dbi);
	mdb_env_close_ex(env, 0);

	return 0;
}
示例#11
0
void counter_sync(counter_t *lc) {
    mdb_env_sync(lc->env, 1);
}
示例#12
0
文件: wbench.c 项目: ReOpen/libmdbx
static void wbench(int flags, int mb, int count, int salt)
{
	MDB_env *env;
	MDB_dbi dbi;
	MDB_txn *txn;
	MDB_val key, data;
	unsigned key_value = salt;
	char data_value[777];
	int i, rc;
	struct t0 start;
	struct info ra, rd, rs, rt;

	mkdir(DBPATH, 0755);
	unlink(DBPATH "/data.mdb");
	unlink(DBPATH "/lock.mdb");

	printf("\nProbing %d Mb, %d items, flags:", mb, count);
	if (flags & MDB_NOSYNC)
		printf(" NOSYNC");
	if (flags & MDB_NOMETASYNC)
		printf(" NOMETASYNC");
	if (flags & MDB_WRITEMAP)
		printf(" WRITEMAP");
	if (flags & MDB_MAPASYNC)
		printf(" MAPASYNC");
#if defined(MDBX_COALESCE) && defined(MDBX_LIFORECLAIM)
	if (flags & MDBX_COALESCE)
		printf(" COALESCE");
	if (flags & MDBX_LIFORECLAIM)
		printf(" LIFO");
#endif
	printf(" 0x%X\n", flags);

	E(mdb_env_create(&env));
	E(mdb_env_set_mapsize(env, (1ull << 20) * mb));
	E(mdb_env_open(env, DBPATH, flags, 0664));

	key.mv_size = sizeof(key_value);
	key.mv_data = &key_value;
	data.mv_size = sizeof(data_value);
	data.mv_data = &data_value;

	printf("\tAdding %d values...", count);
	fflush(stdout);
	key_value = salt;
	t0(&start);
	for(i = 0; i < count; ++i) {
		E(mdb_txn_begin(env, NULL, 0, &txn));
		E(mdb_dbi_open(txn, NULL, 0, &dbi));

		snprintf(data_value, sizeof(data_value), "value=%u", key_value);
		E(mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE));
		E(mdb_txn_commit(txn));

		key_value = key_value * 1664525 + 1013904223;
	}
	measure(&start, &ra);
	print(&ra);

	printf("\tDeleting %d values...", count);
	fflush(stdout);
	key_value = salt;
	t0(&start);
	for(i = 0; i < count; ++i) {
		E(mdb_txn_begin(env, NULL, 0, &txn));
		E(mdb_dbi_open(txn, NULL, 0, &dbi));

		E(mdb_del(txn, dbi, &key, NULL));
		E(mdb_txn_commit(txn));

		key_value = key_value * 1664525 + 1013904223;
	}
	measure(&start, &rd);
	print(&rd);

	printf("\tCheckpoint...");
	fflush(stdout);
	t0(&start);
	mdb_env_sync(env, 1);
	measure(&start, &rs);
	print(&rs);

	mdb_env_close(env);
	rt.wall_s = ra.wall_s + rd.wall_s + rs.wall_s;
	rt.cpu_sys_s = ra.cpu_sys_s + rd.cpu_sys_s + rs.cpu_sys_s;
	rt.cpu_user_s = ra.cpu_user_s + rd.cpu_user_s + rs.cpu_user_s;
	rt.iops_r = ra.iops_r + rd.iops_r + rs.iops_r;
	rt.iops_w = ra.iops_w + rd.iops_w + rs.iops_w;
	rt.iops_pf = ra.iops_pf + rd.iops_pf + rs.iops_pf;
	printf("Total ");
	print(&rt);

	fprintf(stderr, "flags: ");
	if (flags & MDB_NOSYNC)
		fprintf(stderr, " NOSYNC");
	if (flags & MDB_NOMETASYNC)
		fprintf(stderr, " NOMETASYNC");
	if (flags & MDB_WRITEMAP)
		fprintf(stderr, " WRITEMAP");
	if (flags & MDB_MAPASYNC)
		fprintf(stderr, " MAPASYNC");
#if defined(MDBX_COALESCE) && defined(MDBX_LIFORECLAIM)
	if (flags & MDBX_COALESCE)
		fprintf(stderr, " COALESCE");
	if (flags & MDBX_LIFORECLAIM)
		fprintf(stderr, " LIFO");
#endif
	fprintf(stderr, "\t%.3f\t%.3f\t%.3f\t%.3f\n", rt.iops_w / 1000.0, rt.cpu_user_s, rt.cpu_sys_s, rt.wall_s);

}