/* old file size before transaction */
tdb_len_t old_map_size;
+
+ /* we should re-pack on commit */
+ bool need_repack;
};
return -1;
}
+ tdb->transaction->need_repack = true;
+
return 0;
}
*/
static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length)
{
+ if (tdb->flags & TDB_NOSYNC) {
+ return 0;
+ }
+
if (fsync(tdb->fd) != 0) {
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n"));
{
const struct tdb_methods *methods;
int i;
+ bool need_repack;
if (tdb->transaction == NULL) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: no transaction\n"));
SAFE_FREE(tdb->transaction->blocks);
tdb->transaction->num_blocks = 0;
- if (!(tdb->flags & TDB_NOSYNC)) {
- /* ensure the new data is on disk */
- if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
- return -1;
- }
+ /* ensure the new data is on disk */
+ if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
+ return -1;
}
tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1);
utime(tdb->name, NULL);
#endif
+ need_repack = tdb->transaction->need_repack;
+
/* use a transaction cancel to free memory and remove the
transaction locks */
tdb_transaction_cancel_internal(tdb);
+ if (need_repack) {
+ return tdb_repack(tdb);
+ }
+
return 0;
}