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

Function fdb_kvs_rollback

src/kv_instance.cc:2100–2281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2098}
2099
2100fdb_status fdb_kvs_rollback(fdb_kvs_handle **handle_ptr, fdb_seqnum_t seqnum)
2101{
2102 fdb_config config;
2103 fdb_kvs_config kvs_config;
2104 fdb_kvs_handle *handle_in, *handle, *super_handle;
2105 fdb_status fs;
2106 fdb_seqnum_t old_seqnum;
2107 fdb_file_handle *fhandle;
2108 char *kvs_name;
2109
2110 if (!handle_ptr) {
2111 return FDB_RESULT_INVALID_HANDLE;
2112 }
2113
2114 handle_in = *handle_ptr;
2115 if (!handle_in->kvs) {
2116 return FDB_RESULT_INVALID_ARGS;
2117 }
2118 super_handle = handle_in->kvs->root;
2119 fhandle = handle_in->fhandle;
2120 config = handle_in->config;
2121 kvs_config = handle_in->kvs_config;
2122
2123 if (handle_in->config.flags & FDB_OPEN_FLAG_RDONLY) {
2124 return fdb_log(&handle_in->log_callback,
2125 FDB_RESULT_RONLY_VIOLATION,
2126 "Warning: Rollback is not allowed on "
2127 "the read-only DB file '%s'.",
2128 handle_in->file->filename);
2129 }
2130
2131 filemgr_mutex_lock(handle_in->file);
2132 filemgr_set_rollback(handle_in->file, 1); // disallow writes operations
2133 // All transactions should be closed before rollback
2134 if (wal_txn_exists(handle_in->file)) {
2135 filemgr_set_rollback(handle_in->file, 0);
2136 filemgr_mutex_unlock(handle_in->file);
2137 return FDB_RESULT_FAIL_BY_TRANSACTION;
2138 }
2139
2140 // If compaction is running, wait until it is aborted.
2141 // TODO: Find a better way of waiting for the compaction abortion.
2142 unsigned int sleep_time = 10000; // 10 ms.
2143 file_status_t fstatus = filemgr_get_file_status(handle_in->file);
2144 while (fstatus == FILE_COMPACT_OLD) {
2145 filemgr_mutex_unlock(handle_in->file);
2146 decaying_usleep(&sleep_time, 1000000);
2147 filemgr_mutex_lock(handle_in->file);
2148 fstatus = filemgr_get_file_status(handle_in->file);
2149 }
2150 if (fstatus == FILE_REMOVED_PENDING) {
2151 filemgr_mutex_unlock(handle_in->file);
2152 fdb_check_file_reopen(handle_in, NULL);
2153 } else {
2154 filemgr_mutex_unlock(handle_in->file);
2155 }
2156
2157 fdb_sync_db_header(handle_in);

Callers 1

fdb_status fdb_rollbackFunction · 0.85

Calls 15

fdb_logFunction · 0.85
filemgr_mutex_lockFunction · 0.85
filemgr_set_rollbackFunction · 0.85
wal_txn_existsFunction · 0.85
filemgr_mutex_unlockFunction · 0.85
decaying_usleepFunction · 0.85
fdb_check_file_reopenFunction · 0.85
fdb_sync_db_headerFunction · 0.85
_fdb_kvs_get_nameFunction · 0.85
_fdb_kvs_removeFunction · 0.85
atomic_init_uint8_tFunction · 0.85
_fdb_kvs_openFunction · 0.85

Tested by

no test coverage detected