Permalink
Browse files

[BP] MB-20284:Auto commit on close iff file had new data

If there was no data written calling fdb_commit unncessarily
causes file size to grow when auto_commit option is enabled.

Change-Id: I7fa98f4bf082874b7b8a024e9d65b0a56d2a55b8
Reviewed-on: http://review.couchbase.org/66241
Well-Formed: buildbot <build@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
  • Loading branch information...
hisundar authored and chiyoung committed Jul 26, 2016
1 parent 7e4d980 commit fee2123917889ab8d27471063bdb8ad5d9ebd22a
Showing with 59 additions and 4 deletions.
  1. +8 −4 src/forestdb.cc
  2. +51 −0 tests/functional/fdb_functional_test.cc
View
@@ -7445,10 +7445,14 @@ fdb_status fdb_close(fdb_file_handle *fhandle)
if (fhandle->root->config.auto_commit &&
filemgr_get_ref_count(fhandle->root->file) == 1) {
// auto commit mode & the last handle referring the file
// commit file before close
fs = fdb_commit(fhandle, FDB_COMMIT_NORMAL);
if (fs != FDB_RESULT_SUCCESS) {
return fs;
// commit file before close only if WAL has unflushed data..
if (wal_get_dirty_status(fhandle->root->file) == FDB_WAL_DIRTY) {
// Since auto-commit ensures WAL flushed commit, if WAL is dirty
// then it means that there is uncommitted data present
fs = fdb_commit(fhandle, FDB_COMMIT_MANUAL_WAL_FLUSH);
if (fs != FDB_RESULT_SUCCESS) {
return fs;
}
}
}
@@ -3675,6 +3675,56 @@ void auto_commit_test()
TEST_RESULT("auto commit test");
}
void auto_commit_space_used_test()
{
TEST_INIT();
memleak_start();
fdb_file_handle *dbfile;
fdb_kvs_handle *db;
fdb_status status;
fdb_config fconfig;
fdb_kvs_config kvs_config;
int ntimes = 4;
int i;
char fname[32];
// remove previous func_test test files
int r = system(SHELL_DEL" func_test* > errorlog.txt");
(void)r;
fconfig = fdb_get_default_config();
fconfig.buffercache_size= 0;
fconfig.auto_commit = true;
fconfig = fdb_get_default_config();
kvs_config = fdb_get_default_kvs_config();
for (i = ntimes; i; --i) {
sprintf(fname, "./func_test1");
status = fdb_open(&dbfile, fname, &fconfig);
TEST_CHK(status == FDB_RESULT_SUCCESS);
status = fdb_kvs_open(dbfile, &db, "justonekv", &kvs_config);
TEST_CHK(status == FDB_RESULT_SUCCESS);
fdb_file_info finfo;
status = fdb_get_file_info(dbfile, &finfo);
TEST_CHK(status == FDB_RESULT_SUCCESS);
// Since V3 magic number, 7 blocks are used:
// 4 superblocks + KV name header + Stale-tree root node + DB header
TEST_CHK(finfo.file_size == fconfig.blocksize * 7);
status = fdb_close(dbfile);
TEST_CHK(status == FDB_RESULT_SUCCESS);
}
fdb_shutdown();
memleak_end();
TEST_RESULT("auto_commit space used on close test");
}
void last_wal_flush_header_test()
{
TEST_INIT();
@@ -4831,6 +4881,7 @@ int main(){
flush_before_commit_test();
flush_before_commit_multi_writers_test();
auto_commit_test();
auto_commit_space_used_test();
last_wal_flush_header_test();
long_key_test();
multi_thread_client_shutdown(NULL);

0 comments on commit fee2123

Please sign in to comment.