Sync manifest file when initializing it
Summary: Now we don't sync manifest file when initializing it, so DB cannot be safely reopened before the first mem table flush. Fix it by syncing it. This fixes fault_injection_test. Test Plan: make all check Reviewers: rven, yhchiang, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D32001
This commit is contained in:
parent
ae82849bc9
commit
4e48753b73
@ -348,6 +348,9 @@ Status DBImpl::NewDB() {
|
|||||||
std::string record;
|
std::string record;
|
||||||
new_db.EncodeTo(&record);
|
new_db.EncodeTo(&record);
|
||||||
s = log.AddRecord(record);
|
s = log.AddRecord(record);
|
||||||
|
if (s.ok()) {
|
||||||
|
s = SyncManifest(env_, &db_options_, log.file());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
// Make "CURRENT" file that points to the new manifest file.
|
// Make "CURRENT" file that points to the new manifest file.
|
||||||
|
@ -9274,6 +9274,7 @@ TEST(DBTest, WriteSingleThreadEntry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(DBTest, DisableDataSyncTest) {
|
TEST(DBTest, DisableDataSyncTest) {
|
||||||
|
env_->sync_counter_.store(0);
|
||||||
// iter 0 -- no sync
|
// iter 0 -- no sync
|
||||||
// iter 1 -- sync
|
// iter 1 -- sync
|
||||||
for (int iter = 0; iter < 2; ++iter) {
|
for (int iter = 0; iter < 2; ++iter) {
|
||||||
|
@ -511,8 +511,6 @@ TEST(FaultInjectionTest, FaultTest) {
|
|||||||
int num_pre_sync = rnd.Uniform(kMaxNumValues);
|
int num_pre_sync = rnd.Uniform(kMaxNumValues);
|
||||||
int num_post_sync = rnd.Uniform(kMaxNumValues);
|
int num_post_sync = rnd.Uniform(kMaxNumValues);
|
||||||
|
|
||||||
// TODO(t6007549) Figure out why this fails and then re-enable the test.
|
|
||||||
#if 0
|
|
||||||
PartialCompactTestPreFault(num_pre_sync, num_post_sync);
|
PartialCompactTestPreFault(num_pre_sync, num_post_sync);
|
||||||
PartialCompactTestReopenWithFault(RESET_DROP_UNSYNCED_DATA,
|
PartialCompactTestReopenWithFault(RESET_DROP_UNSYNCED_DATA,
|
||||||
num_pre_sync,
|
num_pre_sync,
|
||||||
@ -520,7 +518,6 @@ TEST(FaultInjectionTest, FaultTest) {
|
|||||||
|
|
||||||
NoWriteTestPreFault();
|
NoWriteTestPreFault();
|
||||||
NoWriteTestReopenWithFault(RESET_DROP_UNSYNCED_DATA);
|
NoWriteTestReopenWithFault(RESET_DROP_UNSYNCED_DATA);
|
||||||
#endif
|
|
||||||
|
|
||||||
PartialCompactTestPreFault(num_pre_sync, num_post_sync);
|
PartialCompactTestPreFault(num_pre_sync, num_post_sync);
|
||||||
// No new files created so we expect all values since no files will be
|
// No new files created so we expect all values since no files will be
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "db/dbformat.h"
|
#include "db/dbformat.h"
|
||||||
#include "rocksdb/env.h"
|
#include "rocksdb/env.h"
|
||||||
#include "util/logging.h"
|
#include "util/logging.h"
|
||||||
|
#include "util/stop_watch.h"
|
||||||
|
|
||||||
namespace rocksdb {
|
namespace rocksdb {
|
||||||
|
|
||||||
@ -329,4 +330,16 @@ Status SetIdentityFile(Env* env, const std::string& dbname) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status SyncManifest(Env* env, const DBOptions* db_options, WritableFile* file) {
|
||||||
|
if (db_options->disableDataSync) {
|
||||||
|
return Status::OK();
|
||||||
|
} else if (db_options->use_fsync) {
|
||||||
|
StopWatch sw(env, db_options->statistics.get(), MANIFEST_FILE_SYNC_MICROS);
|
||||||
|
return file->Fsync();
|
||||||
|
} else {
|
||||||
|
StopWatch sw(env, db_options->statistics.get(), MANIFEST_FILE_SYNC_MICROS);
|
||||||
|
return file->Sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
@ -25,6 +25,7 @@ namespace rocksdb {
|
|||||||
|
|
||||||
class Env;
|
class Env;
|
||||||
class Directory;
|
class Directory;
|
||||||
|
class WritableFile;
|
||||||
|
|
||||||
enum FileType {
|
enum FileType {
|
||||||
kLogFile,
|
kLogFile,
|
||||||
@ -137,4 +138,8 @@ extern Status SetCurrentFile(Env* env, const std::string& dbname,
|
|||||||
// Make the IDENTITY file for the db
|
// Make the IDENTITY file for the db
|
||||||
extern Status SetIdentityFile(Env* env, const std::string& dbname);
|
extern Status SetIdentityFile(Env* env, const std::string& dbname);
|
||||||
|
|
||||||
|
// Sync manifest file `file`.
|
||||||
|
extern Status SyncManifest(Env* env, const DBOptions* db_options,
|
||||||
|
WritableFile* file);
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
@ -1691,16 +1691,8 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s.ok() && db_options_->disableDataSync == false) {
|
if (s.ok()) {
|
||||||
if (db_options_->use_fsync) {
|
s = SyncManifest(env_, db_options_, descriptor_log_->file());
|
||||||
StopWatch sw(env_, db_options_->statistics.get(),
|
|
||||||
MANIFEST_FILE_SYNC_MICROS);
|
|
||||||
s = descriptor_log_->file()->Fsync();
|
|
||||||
} else {
|
|
||||||
StopWatch sw(env_, db_options_->statistics.get(),
|
|
||||||
MANIFEST_FILE_SYNC_MICROS);
|
|
||||||
s = descriptor_log_->file()->Sync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
Log(InfoLogLevel::ERROR_LEVEL, db_options_->info_log,
|
Log(InfoLogLevel::ERROR_LEVEL, db_options_->info_log,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user