MCPcopy Create free account
hub / github.com/couchbase/forestdb / _fdb_commit

Function _fdb_commit

src/forestdb.cc:3720–3908  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3718}
3719
3720fdb_status _fdb_commit(fdb_kvs_handle *handle, fdb_commit_opt_t opt, bool sync)
3721{
3722 if (!handle) {
3723 return FDB_RESULT_INVALID_HANDLE;
3724 }
3725
3726 fdb_txn *txn = handle->fhandle->root->txn;
3727 fdb_txn *earliest_txn;
3728 file_status_t fstatus;
3729 fdb_status fs = FDB_RESULT_SUCCESS;
3730 bool wal_flushed = false;
3731 bid_t dirty_idtree_root, dirty_seqtree_root;
3732 union wal_flush_items flush_items;
3733 fdb_status wr = FDB_RESULT_SUCCESS;
3734 LATENCY_STAT_START();
3735
3736 if (handle->kvs) {
3737 if (handle->kvs->type == KVS_SUB) {
3738 // deny commit on sub handle
3739 return FDB_RESULT_INVALID_HANDLE;
3740 }
3741 }
3742 if (handle->config.flags & FDB_OPEN_FLAG_RDONLY) {
3743 return fdb_log(&handle->log_callback, FDB_RESULT_RONLY_VIOLATION,
3744 "Warning: Commit is not allowed on the read-only DB file '%s'.",
3745 handle->file->filename);
3746 }
3747
3748 if (!atomic_cas_uint8_t(&handle->handle_busy, 0, 1)) {
3749 return FDB_RESULT_HANDLE_BUSY;
3750 }
3751
3752fdb_commit_start:
3753 fdb_check_file_reopen(handle, NULL);
3754 filemgr_mutex_lock(handle->file);
3755 fdb_sync_db_header(handle);
3756
3757 if (filemgr_is_rollback_on(handle->file)) {
3758 filemgr_mutex_unlock(handle->file);
3759 atomic_cas_uint8_t(&handle->handle_busy, 1, 0);
3760 return FDB_RESULT_FAIL_BY_ROLLBACK;
3761 }
3762
3763 fstatus = filemgr_get_file_status(handle->file);
3764 if (fstatus == FILE_REMOVED_PENDING) {
3765 // we must not commit this file
3766 // file status was changed by other thread .. start over
3767 filemgr_mutex_unlock(handle->file);
3768 goto fdb_commit_start;
3769 }
3770
3771 fs = btreeblk_end(handle->bhandle);
3772 if (fs != FDB_RESULT_SUCCESS) {
3773 filemgr_mutex_unlock(handle->file);
3774 atomic_cas_uint8_t(&handle->handle_busy, 1, 0);
3775 return fs;
3776 }
3777

Callers 6

fdb_status fdb_rollbackFunction · 0.85
fdb_status fdb_setFunction · 0.85
fdb_status fdb_commitFunction · 0.85
fdb_kvs_rollbackFunction · 0.85

Calls 15

fdb_logFunction · 0.85
atomic_cas_uint8_tFunction · 0.85
fdb_check_file_reopenFunction · 0.85
filemgr_mutex_lockFunction · 0.85
fdb_sync_db_headerFunction · 0.85
filemgr_is_rollback_onFunction · 0.85
filemgr_mutex_unlockFunction · 0.85
btreeblk_endFunction · 0.85
wal_commitFunction · 0.85
wal_get_dirty_statusFunction · 0.85
wal_set_dirty_statusFunction · 0.85
filemgr_get_dirty_rootFunction · 0.85

Tested by

no test coverage detected