BackupableDBTest thread-safe

Summary: We need to lock accesses to some TestEnv variables. Otherwise we get failures like http://ci-builds.fb.com/job/rocksdb_asan_check/657/console

Test Plan: make check

Reviewers: dhruba, haobo, sdong

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D18489
main
Igor Canadi 11 years ago
parent 15c3991933
commit 7984b9bbb0
  1. 15
      utilities/backupable/backupable_db_test.cc

@ -11,12 +11,14 @@
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include "port/port.h"
#include "rocksdb/types.h" #include "rocksdb/types.h"
#include "rocksdb/transaction_log.h" #include "rocksdb/transaction_log.h"
#include "utilities/utility_db.h" #include "utilities/utility_db.h"
#include "utilities/backupable_db.h" #include "utilities/backupable_db.h"
#include "util/testharness.h" #include "util/testharness.h"
#include "util/random.h" #include "util/random.h"
#include "util/mutexlock.h"
#include "util/testutil.h" #include "util/testutil.h"
#include "util/auto_roll_logger.h" #include "util/auto_roll_logger.h"
@ -161,6 +163,7 @@ class TestEnv : public EnvWrapper {
Status NewSequentialFile(const std::string& f, Status NewSequentialFile(const std::string& f,
unique_ptr<SequentialFile>* r, unique_ptr<SequentialFile>* r,
const EnvOptions& options) { const EnvOptions& options) {
MutexLock l(&mutex_);
if (dummy_sequential_file_) { if (dummy_sequential_file_) {
r->reset(new TestEnv::DummySequentialFile()); r->reset(new TestEnv::DummySequentialFile());
return Status::OK(); return Status::OK();
@ -171,6 +174,7 @@ class TestEnv : public EnvWrapper {
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r, Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r,
const EnvOptions& options) { const EnvOptions& options) {
MutexLock l(&mutex_);
written_files_.push_back(f); written_files_.push_back(f);
if (limit_written_files_ <= 0) { if (limit_written_files_ <= 0) {
return Status::NotSupported("Sorry, can't do this"); return Status::NotSupported("Sorry, can't do this");
@ -180,32 +184,41 @@ class TestEnv : public EnvWrapper {
} }
virtual Status DeleteFile(const std::string& fname) override { virtual Status DeleteFile(const std::string& fname) override {
MutexLock l(&mutex_);
ASSERT_GT(limit_delete_files_, 0U); ASSERT_GT(limit_delete_files_, 0U);
limit_delete_files_--; limit_delete_files_--;
return EnvWrapper::DeleteFile(fname); return EnvWrapper::DeleteFile(fname);
} }
void AssertWrittenFiles(std::vector<std::string>& should_have_written) { void AssertWrittenFiles(std::vector<std::string>& should_have_written) {
MutexLock l(&mutex_);
sort(should_have_written.begin(), should_have_written.end()); sort(should_have_written.begin(), should_have_written.end());
sort(written_files_.begin(), written_files_.end()); sort(written_files_.begin(), written_files_.end());
ASSERT_TRUE(written_files_ == should_have_written); ASSERT_TRUE(written_files_ == should_have_written);
} }
void ClearWrittenFiles() { void ClearWrittenFiles() {
MutexLock l(&mutex_);
written_files_.clear(); written_files_.clear();
} }
void SetLimitWrittenFiles(uint64_t limit) { void SetLimitWrittenFiles(uint64_t limit) {
MutexLock l(&mutex_);
limit_written_files_ = limit; limit_written_files_ = limit;
} }
void SetLimitDeleteFiles(uint64_t limit) { limit_delete_files_ = limit; } void SetLimitDeleteFiles(uint64_t limit) {
MutexLock l(&mutex_);
limit_delete_files_ = limit;
}
void SetDummySequentialFile(bool dummy_sequential_file) { void SetDummySequentialFile(bool dummy_sequential_file) {
MutexLock l(&mutex_);
dummy_sequential_file_ = dummy_sequential_file; dummy_sequential_file_ = dummy_sequential_file;
} }
private: private:
port::Mutex mutex_;
bool dummy_sequential_file_ = false; bool dummy_sequential_file_ = false;
std::vector<std::string> written_files_; std::vector<std::string> written_files_;
uint64_t limit_written_files_ = 1000000; uint64_t limit_written_files_ = 1000000;

Loading…
Cancel
Save