Skip to content

Commit cdc01c3

Browse files
authored
Make fdb_estimate_space_used work in bottom-up mode (couchbase#12)
1 parent d94628b commit cdc01c3

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/forestdb.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,7 @@ fdb_status _fdb_open(fdb_kvs_handle *handle,
22882288
handle->bottom_up_build_entries = (struct list*)malloc(sizeof(struct list));
22892289
list_init(handle->bottom_up_build_entries);
22902290
handle->num_bottom_up_build_entries = 0;
2291+
handle->space_used_for_bottom_up_build = 0;
22912292
} else {
22922293
handle->bottom_up_build_entries = NULL;
22932294
}
@@ -4273,6 +4274,7 @@ fdb_status fdb_set(fdb_kvs_handle *handle, fdb_doc *doc)
42734274
fdb_kvs_handle* root_handle = handle->fhandle->root;
42744275
list_push_back(root_handle->bottom_up_build_entries, &bub_entry->le);
42754276
root_handle->num_bottom_up_build_entries++;
4277+
root_handle->space_used_for_bottom_up_build += doc->size_ondisk;
42764278

42774279
} else {
42784280
if (handle->kvs) {
@@ -4763,7 +4765,7 @@ fdb_status _fdb_bottom_up_index_build(fdb_kvs_handle *handle)
47634765
struct kvs_stat stat_dst;
47644766
stat_dst.ndocs = num_entries;
47654767
stat_dst.ndeletes = 0;
4766-
stat_dst.datasize = handle->file->wal->datasize;
4768+
stat_dst.datasize = handle->space_used_for_bottom_up_build;
47674769
stat_dst.nlivenodes = handle->bhandle->nlivenodes;
47684770
stat_dst.deltasize = 0;
47694771
_kvs_stat_set(handle->file, 0, stat_dst);
@@ -8393,6 +8395,10 @@ size_t fdb_estimate_space_used(fdb_file_handle *fhandle)
83938395
ret += nlivenodes * handle->config.blocksize;
83948396
ret += wal_get_datasize(handle->file);
83958397

8398+
if (handle->config.bottom_up_index_build) {
8399+
ret += handle->fhandle->root->space_used_for_bottom_up_build;
8400+
}
8401+
83968402
return ret;
83978403
}
83988404

src/internal_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ struct _fdb_kvs_handle {
443443
* The number of entries in `bottom_up_build_entries`.
444444
*/
445445
uint64_t num_bottom_up_build_entries;
446+
/**
447+
* The amount of data appended in bottom-up mode.
448+
*/
449+
uint64_t space_used_for_bottom_up_build;
446450
};
447451

448452
struct bottom_up_build_entry {

tests/functional/fdb_functional_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5253,6 +5253,9 @@ void bottom_up_build_test()
52535253
s = fdb_set_kv(default_db, key, strlen(key), value, value_len);
52545254
TEST_CHK(s == FDB_RESULT_SUCCESS);
52555255
}
5256+
size_t space_used = fdb_estimate_space_used(dbfile);
5257+
TEST_CHK(space_used > 0);
5258+
52565259
s = fdb_commit(dbfile, FDB_COMMIT_MANUAL_WAL_FLUSH);
52575260

52585261
s = fdb_kvs_close(default_db);

tools/dump_common.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void print_header(fdb_kvs_handle *db)
144144
datasize_wal = wal_get_datasize(db->file);
145145

146146
printf(" # documents in the main index: %" _F64
147-
", %" _F64 "deleted / "
147+
", %" _F64 " deleted / "
148148
"in WAL: %" _F64 " (insert), %" _F64 " (remove)\n",
149149
ndocs, ndeletes, ndocs_wal_inserted, ndocs_wal_deleted);
150150
printf(" # live index nodes: %" _F64 " (%" _F64 " bytes)\n",
@@ -188,7 +188,7 @@ void print_header(fdb_kvs_handle *db)
188188
}
189189

190190
printf(" # documents in the main index: %" _F64
191-
", %" _F64 "deleted / "
191+
", %" _F64 " deleted / "
192192
"in WAL: %" _F64 " (insert), %" _F64 " (remove)\n",
193193
ndocs, ndeletes, ndocs_wal_inserted, ndocs_wal_deleted);
194194
printf(" # live index nodes: %" _F64 " (%" _F64 " bytes)\n",

0 commit comments

Comments
 (0)