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

Function _fdb_compact_file

src/forestdb.cc:6162–6471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6160}
6161
6162fdb_status _fdb_compact_file(fdb_kvs_handle *handle,
6163 struct filemgr *new_file,
6164 struct btreeblk_handle *new_bhandle,
6165 struct docio_handle *new_dhandle,
6166 struct hbtrie *new_trie,
6167 struct hbtrie *new_seqtrie,
6168 struct btree *new_seqtree,
6169 struct btree *new_staletree,
6170 bid_t marker_bid,
6171 bool clone_docs)
6172{
6173 union wal_flush_items flush_items;
6174 char *old_filename = NULL;
6175 size_t old_filename_len = 0;
6176 struct filemgr *old_file;
6177 struct btree *new_idtree = NULL;
6178 bid_t dirty_idtree_root, dirty_seqtree_root;
6179 fdb_seqnum_t seqnum;
6180 uint64_t new_file_kv_info_offset = BLK_NOT_FOUND;
6181
6182 // Copy the old file's seqnum to the new file.
6183 // (KV instances' seq numbers will be copied along with the KV header)
6184 // Note that the sequence numbers and KV header data in the new file will be
6185 // corrected in _fdb_compact_move_docs_upto_marker() for compact_upto case
6186 // (i.e., marker_bid != -1).
6187 seqnum = filemgr_get_seqnum(handle->file);
6188 filemgr_set_seqnum(new_file, seqnum);
6189 if (handle->kvs) {
6190 // multi KV instance mode .. copy KV header data to new file
6191 fdb_kvs_header_copy(handle, new_file, new_dhandle,
6192 &new_file_kv_info_offset, true);
6193 }
6194
6195 // sync dirty root nodes
6196 filemgr_get_dirty_root(handle->file, &dirty_idtree_root,
6197 &dirty_seqtree_root);
6198 if (dirty_idtree_root != BLK_NOT_FOUND) {
6199 handle->trie->root_bid = dirty_idtree_root;
6200 }
6201 if (handle->config.seqtree_opt == FDB_SEQTREE_USE &&
6202 dirty_seqtree_root != BLK_NOT_FOUND) {
6203 if (handle->kvs) {
6204 handle->seqtrie->root_bid = dirty_seqtree_root;
6205 } else {
6206 btree_init_from_bid(handle->seqtree,
6207 handle->seqtree->blk_handle,
6208 handle->seqtree->blk_ops,
6209 handle->seqtree->kv_ops,
6210 handle->seqtree->blksize,
6211 dirty_seqtree_root);
6212 }
6213 }
6214
6215 // flush WAL and set DB header
6216 wal_commit(&handle->file->global_txn, handle->file, NULL,
6217 &handle->log_callback);
6218 wal_flush(handle->file, (void*)handle,
6219 _fdb_wal_flush_func, _fdb_wal_get_old_offset, &flush_items);

Callers 1

fdb_compact_fileFunction · 0.85

Calls 15

filemgr_get_seqnumFunction · 0.85
filemgr_set_seqnumFunction · 0.85
fdb_kvs_header_copyFunction · 0.85
filemgr_get_dirty_rootFunction · 0.85
btree_init_from_bidFunction · 0.85
wal_commitFunction · 0.85
wal_flushFunction · 0.85
wal_set_dirty_statusFunction · 0.85
fdb_kvs_header_appendFunction · 0.85
filemgr_get_posFunction · 0.85
fdb_set_file_headerFunction · 0.85

Tested by

no test coverage detected