fault_injection_test: add more logging and makes synchronization slightly stronger

Summary:
We see failure of the test in travis but I can't repro it.
Add more logging in failure cases to help us figure out which failure it is.
Also makes synchronization slightly stronger, though there isn't seem to be a problem without it

Test Plan: Run the test

Reviewers: rven, yhchiang, igor

Reviewed By: igor

Subscribers: leveldb, dhruba

Differential Revision: https://reviews.facebook.net/D32319
main
sdong 10 years ago
parent c4fb83441c
commit 1b43ab58d9
  1. 28
      db/fault_injection_test.cc

@ -72,8 +72,11 @@ Status Truncate(const std::string& filename, uint64_t length) {
unique_ptr<SequentialFile> orig_file; unique_ptr<SequentialFile> orig_file;
const EnvOptions options; const EnvOptions options;
Status s = env->NewSequentialFile(filename, &orig_file, options); Status s = env->NewSequentialFile(filename, &orig_file, options);
if (!s.ok()) if (!s.ok()) {
fprintf(stderr, "Cannot truncate file %s: %s\n", filename.c_str(),
s.ToString().c_str());
return s; return s;
}
char* scratch = new char[length]; char* scratch = new char[length];
rocksdb::Slice result; rocksdb::Slice result;
@ -87,10 +90,16 @@ Status Truncate(const std::string& filename, uint64_t length) {
if (s.ok()) { if (s.ok()) {
s = env->RenameFile(tmp_name, filename); s = env->RenameFile(tmp_name, filename);
} else { } else {
fprintf(stderr, "Cannot renmae file %s to %s: %s\n", tmp_name.c_str(),
filename.c_str(), s.ToString().c_str());
env->DeleteFile(tmp_name); env->DeleteFile(tmp_name);
} }
} }
} }
if (!s.ok()) {
fprintf(stderr, "Cannot truncate file %s: %s\n", filename.c_str(),
s.ToString().c_str());
}
delete[] scratch; delete[] scratch;
@ -194,6 +203,10 @@ class FaultInjectionTestEnv : public EnvWrapper {
virtual Status DeleteFile(const std::string& f) { virtual Status DeleteFile(const std::string& f) {
Status s = EnvWrapper::DeleteFile(f); Status s = EnvWrapper::DeleteFile(f);
if (!s.ok()) {
fprintf(stderr, "Cannot delete file %s: %s\n", f.c_str(),
s.ToString().c_str());
}
ASSERT_OK(s); ASSERT_OK(s);
if (s.ok()) { if (s.ok()) {
UntrackFile(f); UntrackFile(f);
@ -275,7 +288,7 @@ class FaultInjectionTestEnv : public EnvWrapper {
MutexLock l(&mutex_); MutexLock l(&mutex_);
db_file_state_.clear(); db_file_state_.clear();
dir_to_new_files_since_last_sync_.clear(); dir_to_new_files_since_last_sync_.clear();
SetFilesystemActive(true); SetFilesystemActiveNoLock(true);
} }
void UntrackFile(const std::string& f) { void UntrackFile(const std::string& f) {
@ -295,8 +308,15 @@ class FaultInjectionTestEnv : public EnvWrapper {
// system reset. Setting to inactive will freeze our saved filesystem state so // system reset. Setting to inactive will freeze our saved filesystem state so
// that it will stop being recorded. It can then be reset back to the state at // that it will stop being recorded. It can then be reset back to the state at
// the time of the reset. // the time of the reset.
bool IsFilesystemActive() const { return filesystem_active_; } bool IsFilesystemActive() {
void SetFilesystemActive(bool active) { filesystem_active_ = active; } MutexLock l(&mutex_);
return filesystem_active_;
}
void SetFilesystemActiveNoLock(bool active) { filesystem_active_ = active; }
void SetFilesystemActive(bool active) {
MutexLock l(&mutex_);
SetFilesystemActiveNoLock(active);
}
private: private:
port::Mutex mutex_; port::Mutex mutex_;

Loading…
Cancel
Save