Skip to content

Commit

Permalink
Flush before Fsync()/Sync()
Browse files Browse the repository at this point in the history
Summary: Calling Fsync()/Sync() on a file should give the guarantee that whatever you written to the file is now persisted. This is currently not the case, since we might have some data left in application cache as we do Fsync()/Sync(). For example, BuildTable() calls Fsync() without the flush, assuming all sst data is now persisted, but it's actually not. This may result in big inconsistencies.

Test Plan: no test

Reviewers: sdong, dhruba, haobo, ljin, yhchiang

Reviewed By: sdong

CC: leveldb

Differential Revision: https://reviews.facebook.net/D18159
  • Loading branch information
igorcanadi committed Apr 22, 2014
1 parent ba16c1f commit c2da9e5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ class PosixWritableFile : public WritableFile {
}

virtual Status Sync() {
Status s = Flush();
if (!s.ok()) {
return s;
}
TEST_KILL_RANDOM(rocksdb_kill_odds);
if (pending_sync_ && fdatasync(fd_) < 0) {
return IOError(filename_, errno);
Expand All @@ -771,6 +775,10 @@ class PosixWritableFile : public WritableFile {
}

virtual Status Fsync() {
Status s = Flush();
if (!s.ok()) {
return s;
}
TEST_KILL_RANDOM(rocksdb_kill_odds);
if (pending_fsync_ && fsync(fd_) < 0) {
return IOError(filename_, errno);
Expand Down

0 comments on commit c2da9e5

Please sign in to comment.