mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
Use a single write txn
This commit is contained in:
parent
a054a194e8
commit
4d02c741b1
1 changed files with 30 additions and 5 deletions
|
|
@ -1110,6 +1110,7 @@ struct MDB_env {
|
||||||
MDB_meta *me_metas[2]; /**< pointers to the two meta pages */
|
MDB_meta *me_metas[2]; /**< pointers to the two meta pages */
|
||||||
void *me_pbuf; /**< scratch area for DUPSORT put() */
|
void *me_pbuf; /**< scratch area for DUPSORT put() */
|
||||||
MDB_txn *me_txn; /**< current write transaction */
|
MDB_txn *me_txn; /**< current write transaction */
|
||||||
|
MDB_txn *me_txn0; /**< prealloc'd write transaction */
|
||||||
size_t me_mapsize; /**< size of the data memory map */
|
size_t me_mapsize; /**< size of the data memory map */
|
||||||
off_t me_size; /**< current file size */
|
off_t me_size; /**< current file size */
|
||||||
pgno_t me_maxpg; /**< me_mapsize / me_psize */
|
pgno_t me_maxpg; /**< me_mapsize / me_psize */
|
||||||
|
|
@ -2607,6 +2608,10 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
|
||||||
}
|
}
|
||||||
size = tsize + env->me_maxdbs * (sizeof(MDB_db)+1);
|
size = tsize + env->me_maxdbs * (sizeof(MDB_db)+1);
|
||||||
if (!(flags & MDB_RDONLY)) {
|
if (!(flags & MDB_RDONLY)) {
|
||||||
|
if (!parent) {
|
||||||
|
txn = env->me_txn0;
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
size += env->me_maxdbs * sizeof(MDB_cursor *);
|
size += env->me_maxdbs * sizeof(MDB_cursor *);
|
||||||
/* child txns use parent's dbiseqs */
|
/* child txns use parent's dbiseqs */
|
||||||
if (!parent)
|
if (!parent)
|
||||||
|
|
@ -2634,6 +2639,7 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
|
||||||
}
|
}
|
||||||
txn->mt_env = env;
|
txn->mt_env = env;
|
||||||
|
|
||||||
|
ok:
|
||||||
if (parent) {
|
if (parent) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
txn->mt_u.dirty_list = malloc(sizeof(MDB_ID2)*MDB_IDL_UM_SIZE);
|
txn->mt_u.dirty_list = malloc(sizeof(MDB_ID2)*MDB_IDL_UM_SIZE);
|
||||||
|
|
@ -2676,9 +2682,10 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
|
||||||
} else {
|
} else {
|
||||||
rc = mdb_txn_renew0(txn);
|
rc = mdb_txn_renew0(txn);
|
||||||
}
|
}
|
||||||
if (rc)
|
if (rc) {
|
||||||
free(txn);
|
if (txn != env->me_txn0)
|
||||||
else {
|
free(txn);
|
||||||
|
} else {
|
||||||
*ret = txn;
|
*ret = txn;
|
||||||
DPRINTF(("begin txn %"Z"u%c %p on mdbenv %p, root page %"Z"u",
|
DPRINTF(("begin txn %"Z"u%c %p on mdbenv %p, root page %"Z"u",
|
||||||
txn->mt_txnid, (txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w',
|
txn->mt_txnid, (txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w',
|
||||||
|
|
@ -2805,7 +2812,8 @@ mdb_txn_abort(MDB_txn *txn)
|
||||||
if ((txn->mt_flags & MDB_TXN_RDONLY) && txn->mt_u.reader)
|
if ((txn->mt_flags & MDB_TXN_RDONLY) && txn->mt_u.reader)
|
||||||
txn->mt_u.reader->mr_pid = 0;
|
txn->mt_u.reader->mr_pid = 0;
|
||||||
|
|
||||||
free(txn);
|
if (txn != txn->mt_env->me_txn0)
|
||||||
|
free(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Save the freelist as of this transaction to the freeDB.
|
/** Save the freelist as of this transaction to the freeDB.
|
||||||
|
|
@ -3358,7 +3366,8 @@ done:
|
||||||
|
|
||||||
if (env->me_txns)
|
if (env->me_txns)
|
||||||
UNLOCK_MUTEX_W(env);
|
UNLOCK_MUTEX_W(env);
|
||||||
free(txn);
|
if (txn != env->me_txn0)
|
||||||
|
free(txn);
|
||||||
|
|
||||||
return MDB_SUCCESS;
|
return MDB_SUCCESS;
|
||||||
|
|
||||||
|
|
@ -4489,6 +4498,22 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
|
||||||
if (!((flags & MDB_RDONLY) ||
|
if (!((flags & MDB_RDONLY) ||
|
||||||
(env->me_pbuf = calloc(1, env->me_psize))))
|
(env->me_pbuf = calloc(1, env->me_psize))))
|
||||||
rc = ENOMEM;
|
rc = ENOMEM;
|
||||||
|
if (!(flags & MDB_RDONLY)) {
|
||||||
|
MDB_txn *txn;
|
||||||
|
int tsize = sizeof(MDB_txn), size = tsize + env->me_maxdbs *
|
||||||
|
(sizeof(MDB_db)+sizeof(MDB_cursor)+sizeof(unsigned int)+1);
|
||||||
|
txn = calloc(1, size);
|
||||||
|
if (txn) {
|
||||||
|
txn->mt_dbs = (MDB_db *)((char *)txn + tsize);
|
||||||
|
txn->mt_cursors = (MDB_cursor **)(txn->mt_dbs + env->me_maxdbs);
|
||||||
|
txn->mt_dbiseqs = (unsigned int *)(txn->mt_cursors + env->me_maxdbs);
|
||||||
|
txn->mt_dbflags = (unsigned char *)(txn->mt_dbiseqs + env->me_maxdbs);
|
||||||
|
txn->mt_env = env;
|
||||||
|
env->me_txn0 = txn;
|
||||||
|
} else {
|
||||||
|
rc = ENOMEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue