| 3718 | } |
| 3719 | |
| 3720 | fdb_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 | |
| 3752 | fdb_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 |
no test coverage detected