usual. This allows for smooth crash recovery with no administrator
intervention.
- - if TDB1_NOSYNC is passed to flags in tdb1_open then transactions are
+ - if TDB_NOSYNC is passed to flags in tdb1_open then transactions are
still available, but no transaction recovery area is used and no
fsync/msync calls are made.
- - if TDB1_ALLOW_NESTING is passed to flags in tdb open, or added using
+ - if TDB_ALLOW_NESTING is passed to flags in tdb open, or added using
tdb1_add_flags() transaction nesting is enabled.
- It resets the TDB1_DISALLOW_NESTING flag, as both cannot be used together.
- The default is that transaction nesting is allowed.
- Note: this default may change in future versions of tdb.
+ The default is that transaction nesting is NOT allowed.
Beware. when transactions are nested a transaction successfully
completed with tdb1_transaction_commit() can be silently unrolled later.
-
- - if TDB1_DISALLOW_NESTING is passed to flags in tdb open, or added using
- tdb1_add_flags() transaction nesting is disabled.
- It resets the TDB1_ALLOW_NESTING flag, as both cannot be used together.
- An attempt create a nested transaction will fail with TDB_ERR_EINVAL.
- The default is that transaction nesting is allowed.
- Note: this default may change in future versions of tdb.
*/
*/
static int transaction1_oob(struct tdb1_context *tdb, tdb1_off_t len, int probe)
{
- if (len <= tdb->map_size) {
+ if (len <= tdb->file->map_size) {
return 0;
}
tdb->last_error = TDB_ERR_IO;
static int _tdb1_transaction_start(struct tdb1_context *tdb)
{
/* some sanity checks */
- if (tdb->read_only || (tdb->flags & TDB1_INTERNAL) || tdb->traverse_read) {
+ if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
"tdb1_transaction_start: cannot start a"
" transaction on a read-only or"
/* cope with nested tdb1_transaction_start() calls */
if (tdb->transaction != NULL) {
- if (!(tdb->flags & TDB1_ALLOW_NESTING)) {
+ if (!(tdb->flags & TDB_ALLOW_NESTING)) {
tdb->last_error = TDB_ERR_EINVAL;
return -1;
}
/* get a read lock from the freelist to the end of file. This
is upgraded to a write lock during the commit */
if (tdb1_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, true) == -1) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- "tdb1_transaction_start: failed to get hash locks");
+ if (errno != EAGAIN && errno != EINTR) {
+ tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
+ "tdb1_transaction_start:"
+ " failed to get hash locks");
+ }
goto fail_allrecord_lock;
}
/* make sure we know about any file expansions already done by
anyone else */
- tdb->methods->tdb1_oob(tdb, tdb->map_size + 1, 1);
- tdb->transaction->old_map_size = tdb->map_size;
+ tdb->methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
+ tdb->transaction->old_map_size = tdb->file->map_size;
/* finally hook the io methods, replacing them with
transaction specific methods */
*/
static int transaction1_sync(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t length)
{
- if (tdb->flags & TDB1_NOSYNC) {
+ if (tdb->flags & TDB_NOSYNC) {
return 0;
}
#if HAVE_FDATASYNC
- if (fdatasync(tdb->fd) != 0) {
+ if (fdatasync(tdb->file->fd) != 0) {
#else
- if (fsync(tdb->fd) != 0) {
+ if (fsync(tdb->file->fd) != 0) {
#endif
tdb->last_error = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
"tdb1_transaction: fsync failed");
return -1;
}
#if HAVE_MMAP
- if (tdb->map_ptr) {
+ if (tdb->file->map_ptr) {
tdb1_off_t moffset = offset & ~(tdb->page_size-1);
- if (msync(moffset + (char *)tdb->map_ptr,
+ if (msync(moffset + (char *)tdb->file->map_ptr,
length + (offset - moffset), MS_SYNC) != 0) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
"tdb1_transaction:"
return 0;
}
- tdb->map_size = tdb->transaction->old_map_size;
+ tdb->file->map_size = tdb->transaction->old_map_size;
/* free all the transaction blocks */
for (i=0;i<tdb->transaction->num_blocks;i++) {
/* round up to a multiple of page size */
*recovery_max_size = TDB1_ALIGN(sizeof(rec) + *recovery_size, tdb->page_size) - sizeof(rec);
- *recovery_offset = tdb->map_size;
+ *recovery_offset = tdb->file->map_size;
recovery_head = *recovery_offset;
if (methods->tdb1_expand_file(tdb, tdb->transaction->old_map_size,
- (tdb->map_size - tdb->transaction->old_map_size) +
+ (tdb->file->map_size - tdb->transaction->old_map_size) +
sizeof(rec) + *recovery_max_size) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_recovery_allocate:"
}
/* remap the file (if using mmap) */
- methods->tdb1_oob(tdb, tdb->map_size + 1, 1);
+ methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
/* we have to reset the old map size so that we don't try to expand the file
again in the transaction commit, which would destroy the recovery area */
- tdb->transaction->old_map_size = tdb->map_size;
+ tdb->transaction->old_map_size = tdb->file->map_size;
/* write the recovery header offset and sync - we can sync without a race here
as the magic ptr in the recovery record has not been set */
/* upgrade the main transaction lock region to a write lock */
if (tdb1_allrecord_upgrade(tdb) == -1) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- "tdb1_transaction_prepare_commit:"
- " failed to upgrade hash locks");
+ if (errno != EAGAIN && errno != EINTR) {
+ tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
+ "tdb1_transaction_prepare_commit:"
+ " failed to upgrade hash locks");
+ }
_tdb1_transaction_cancel(tdb);
return -1;
}
/* get the open lock - this prevents new users attaching to the database
during the commit */
if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- "tdb1_transaction_prepare_commit:"
- " failed to get open lock");
+ if (errno != EAGAIN && errno != EINTR) {
+ tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
+ "tdb1_transaction_prepare_commit:"
+ " failed to get open lock");
+ }
_tdb1_transaction_cancel(tdb);
return -1;
}
- if (!(tdb->flags & TDB1_NOSYNC)) {
+ if (!(tdb->flags & TDB_NOSYNC)) {
/* write the recovery data to the end of the file */
if (transaction1_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
tdb->transaction->prepared = true;
/* expand the file to the new size if needed */
- if (tdb->map_size != tdb->transaction->old_map_size) {
+ if (tdb->file->map_size != tdb->transaction->old_map_size) {
if (methods->tdb1_expand_file(tdb, tdb->transaction->old_map_size,
- tdb->map_size -
+ tdb->file->map_size -
tdb->transaction->old_map_size) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_transaction_prepare_commit:"
_tdb1_transaction_cancel(tdb);
return -1;
}
- tdb->map_size = tdb->transaction->old_map_size;
- methods->tdb1_oob(tdb, tdb->map_size + 1, 1);
+ tdb->file->map_size = tdb->transaction->old_map_size;
+ methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1);
}
/* Keep the open lock until the actual commit */
tdb->transaction->num_blocks = 0;
/* ensure the new data is on disk */
- if (transaction1_sync(tdb, 0, tdb->map_size) == -1) {
+ if (transaction1_sync(tdb, 0, tdb->file->map_size) == -1) {
return -1;
}
free(data);
- if (transaction1_sync(tdb, 0, tdb->map_size) == -1) {
+ if (transaction1_sync(tdb, 0, tdb->file->map_size) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_transaction_recover: failed to sync recovery");
return -1;