mdbx: change mdbx_dbi_close() API.

This commit is contained in:
Leo Yuriev 2017-05-10 20:27:30 +03:00
parent e8a430999c
commit 533e01cc93
2 changed files with 19 additions and 11 deletions

2
mdbx.h
View File

@ -1124,7 +1124,7 @@ LIBMDBX_API int mdbx_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned *flags);
* [in] env An environment handle returned by mdbx_env_create() * [in] env An environment handle returned by mdbx_env_create()
* [in] dbi A database handle returned by mdbx_dbi_open() * [in] dbi A database handle returned by mdbx_dbi_open()
*/ */
LIBMDBX_API void mdbx_dbi_close(MDB_env *env, MDB_dbi dbi); LIBMDBX_API int mdbx_dbi_close(MDB_env *env, MDB_dbi dbi);
/* Empty or delete+close a database. /* Empty or delete+close a database.
* *

View File

@ -8801,6 +8801,8 @@ int mdbx_dbi_open(MDB_txn *txn, const char *name, unsigned flags,
return rc; return rc;
} }
/* FIXME: locking to avoid races ? */
/* Done here so we cannot fail after creating a new DB */ /* Done here so we cannot fail after creating a new DB */
if (unlikely((namedup = mdbx_strdup(name)) == NULL)) if (unlikely((namedup = mdbx_strdup(name)) == NULL))
return MDBX_ENOMEM; return MDBX_ENOMEM;
@ -8868,19 +8870,23 @@ int __cold mdbx_dbi_stat(MDB_txn *txn, MDB_dbi dbi, MDBX_stat *arg,
return mdbx_stat0(txn->mt_env, &txn->mt_dbs[dbi], arg); return mdbx_stat0(txn->mt_env, &txn->mt_dbs[dbi], arg);
} }
void mdbx_dbi_close(MDB_env *env, MDB_dbi dbi) { int mdbx_dbi_close(MDB_env *env, MDB_dbi dbi) {
char *ptr; char *ptr;
if (dbi < CORE_DBS || dbi >= env->me_maxdbs) if (unlikely(dbi < CORE_DBS || dbi >= env->me_maxdbs))
return; return MDBX_EINVAL;
/* FIXME: locking to avoid races ? */
ptr = env->me_dbxs[dbi].md_name.mv_data; ptr = env->me_dbxs[dbi].md_name.mv_data;
/* If there was no name, this was already closed */ /* If there was no name, this was already closed */
if (ptr) { if (unlikely(!ptr))
return MDB_BAD_DBI;
env->me_dbxs[dbi].md_name.mv_data = NULL; env->me_dbxs[dbi].md_name.mv_data = NULL;
env->me_dbxs[dbi].md_name.mv_size = 0; env->me_dbxs[dbi].md_name.mv_size = 0;
env->me_dbflags[dbi] = 0; env->me_dbflags[dbi] = 0;
env->me_dbiseqs[dbi]++; env->me_dbiseqs[dbi]++;
free(ptr); free(ptr);
} return MDB_SUCCESS;
} }
int mdbx_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned *flags) { int mdbx_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned *flags) {
@ -9015,6 +9021,8 @@ int mdbx_drop(MDB_txn *txn, MDB_dbi dbi, int del) {
if (unlikely(rc)) if (unlikely(rc))
return rc; return rc;
/* FIXME: locking to avoid races ? */
rc = mdbx_drop0(mc, mc->mc_db->md_flags & MDB_DUPSORT); rc = mdbx_drop0(mc, mc->mc_db->md_flags & MDB_DUPSORT);
/* Invalidate the dropped DB's cursors */ /* Invalidate the dropped DB's cursors */
for (m2 = txn->mt_cursors[dbi]; m2; m2 = m2->mc_next) for (m2 = txn->mt_cursors[dbi]; m2; m2 = m2->mc_next)