leveldb
Public Types | Public Member Functions | Public Attributes | List of all members
leveldb::FaultInjectionTest Class Reference
Collaboration diagram for leveldb::FaultInjectionTest:
Collaboration graph
[legend]

Public Types

enum  ExpectedVerifResult { VAL_EXPECT_NO_ERROR, VAL_EXPECT_ERROR }
 
enum  ResetMethod { RESET_DROP_UNSYNCED_DATA, RESET_DELETE_UNSYNCED_FILES }
 

Public Member Functions

 FaultInjectionTest ()
 
 ~FaultInjectionTest ()
 
void ReuseLogs (bool reuse)
 
void Build (int start_idx, int num_vals)
 
Status ReadValue (int i, std::string *val) const
 
Status Verify (int start_idx, int num_vals, ExpectedVerifResult expected) const
 
Slice Key (int i, std::string *storage) const
 
Slice Value (int k, std::string *storage) const
 
Status OpenDB ()
 
void CloseDB ()
 
void DeleteAllData ()
 
void ResetDBState (ResetMethod reset_method)
 
void PartialCompactTestPreFault (int num_pre_sync, int num_post_sync)
 
void PartialCompactTestReopenWithFault (ResetMethod reset_method, int num_pre_sync, int num_post_sync)
 
void NoWriteTestPreFault ()
 
void NoWriteTestReopenWithFault (ResetMethod reset_method)
 
void DoTest ()
 

Public Attributes

FaultInjectionTestEnvenv_
 
std::string dbname_
 
Cachetiny_cache_
 
Options options_
 
DBdb_
 

Detailed Description

Definition at line 359 of file fault_injection_test.cc.

Member Enumeration Documentation

§ ExpectedVerifResult

§ ResetMethod

Constructor & Destructor Documentation

§ FaultInjectionTest()

leveldb::FaultInjectionTest::FaultInjectionTest ( )
inline

Definition at line 370 of file fault_injection_test.cc.

371  : env_(new FaultInjectionTestEnv),
372  tiny_cache_(NewLRUCache(100)),
373  db_(NULL) {
374  dbname_ = test::TmpDir() + "/fault_test";
375  DestroyDB(dbname_, Options()); // Destroy any db from earlier run
376  options_.reuse_logs = true;
377  options_.env = env_;
378  options_.paranoid_checks = true;
381  }
std::string TmpDir()
Definition: testharness.cc:60
Status DestroyDB(const std::string &dbname, const Options &options)
Definition: db_impl.cc:1537
FaultInjectionTestEnv * env_
bool create_if_missing
Definition: options.h:45
Cache * block_cache
Definition: options.h:98
Cache * NewLRUCache(size_t capacity)
Definition: cache.cc:401
bool paranoid_checks
Definition: options.h:57
Here is the call graph for this function:

§ ~FaultInjectionTest()

leveldb::FaultInjectionTest::~FaultInjectionTest ( )
inline

Definition at line 383 of file fault_injection_test.cc.

383  {
384  CloseDB();
385  DestroyDB(dbname_, Options());
386  delete tiny_cache_;
387  delete env_;
388  }
Status DestroyDB(const std::string &dbname, const Options &options)
Definition: db_impl.cc:1537
FaultInjectionTestEnv * env_
Here is the call graph for this function:

Member Function Documentation

§ Build()

void leveldb::FaultInjectionTest::Build ( int  start_idx,
int  num_vals 
)
inline

Definition at line 394 of file fault_injection_test.cc.

394  {
395  std::string key_space, value_space;
396  WriteBatch batch;
397  for (int i = start_idx; i < start_idx + num_vals; i++) {
398  Slice key = Key(i, &key_space);
399  batch.Clear();
400  batch.Put(key, Value(i, &value_space));
401  WriteOptions options;
402  ASSERT_OK(db_->Write(options, &batch));
403  }
404  }
#define ASSERT_OK(s)
Definition: testharness.h:106
Slice Value(int k, std::string *storage) const
Slice Key(int i, std::string *storage) const
virtual Status Write(const WriteOptions &options, WriteBatch *updates)=0
Here is the call graph for this function:

§ CloseDB()

void leveldb::FaultInjectionTest::CloseDB ( )
inline

Definition at line 457 of file fault_injection_test.cc.

457  {
458  delete db_;
459  db_ = NULL;
460  }

§ DeleteAllData()

void leveldb::FaultInjectionTest::DeleteAllData ( )
inline

Definition at line 462 of file fault_injection_test.cc.

462  {
463  Iterator* iter = db_->NewIterator(ReadOptions());
464  WriteOptions options;
465  for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
466  ASSERT_OK(db_->Delete(WriteOptions(), iter->key()));
467  }
468 
469  delete iter;
470  }
#define ASSERT_OK(s)
Definition: testharness.h:106
virtual Status Delete(const WriteOptions &options, const Slice &key)=0
Definition: db_impl.cc:1482
virtual Iterator * NewIterator(const ReadOptions &options)=0
Here is the call graph for this function:

§ DoTest()

void leveldb::FaultInjectionTest::DoTest ( )
inline

Definition at line 512 of file fault_injection_test.cc.

512  {
513  Random rnd(0);
514  ASSERT_OK(OpenDB());
515  for (size_t idx = 0; idx < kNumIterations; idx++) {
516  int num_pre_sync = rnd.Uniform(kMaxNumValues);
517  int num_post_sync = rnd.Uniform(kMaxNumValues);
518 
519  PartialCompactTestPreFault(num_pre_sync, num_post_sync);
521  num_pre_sync,
522  num_post_sync);
523 
526 
527  PartialCompactTestPreFault(num_pre_sync, num_post_sync);
528  // No new files created so we expect all values since no files will be
529  // dropped.
531  num_pre_sync + num_post_sync,
532  0);
533 
536  }
537  }
static const size_t kNumIterations
static const int kMaxNumValues
#define ASSERT_OK(s)
Definition: testharness.h:106
void NoWriteTestReopenWithFault(ResetMethod reset_method)
void PartialCompactTestReopenWithFault(ResetMethod reset_method, int num_pre_sync, int num_post_sync)
void PartialCompactTestPreFault(int num_pre_sync, int num_post_sync)
Here is the call graph for this function:

§ Key()

Slice leveldb::FaultInjectionTest::Key ( int  i,
std::string *  storage 
) const
inline

Definition at line 437 of file fault_injection_test.cc.

437  {
438  char buf[100];
439  snprintf(buf, sizeof(buf), "%016d", i);
440  storage->assign(buf, strlen(buf));
441  return Slice(*storage);
442  }

§ NoWriteTestPreFault()

void leveldb::FaultInjectionTest::NoWriteTestPreFault ( )
inline

Definition at line 503 of file fault_injection_test.cc.

503  {
504  }

§ NoWriteTestReopenWithFault()

void leveldb::FaultInjectionTest::NoWriteTestReopenWithFault ( ResetMethod  reset_method)
inline

Definition at line 506 of file fault_injection_test.cc.

506  {
507  CloseDB();
508  ResetDBState(reset_method);
509  ASSERT_OK(OpenDB());
510  }
#define ASSERT_OK(s)
Definition: testharness.h:106
void ResetDBState(ResetMethod reset_method)

§ OpenDB()

Status leveldb::FaultInjectionTest::OpenDB ( )
inline

Definition at line 450 of file fault_injection_test.cc.

450  {
451  delete db_;
452  db_ = NULL;
453  env_->ResetState();
454  return DB::Open(options_, dbname_, &db_);
455  }
FaultInjectionTestEnv * env_
static Status Open(const Options &options, const std::string &name, DB **dbptr)
Definition: db_impl.cc:1490
Here is the call graph for this function:

§ PartialCompactTestPreFault()

void leveldb::FaultInjectionTest::PartialCompactTestPreFault ( int  num_pre_sync,
int  num_post_sync 
)
inline

Definition at line 485 of file fault_injection_test.cc.

485  {
486  DeleteAllData();
487  Build(0, num_pre_sync);
488  db_->CompactRange(NULL, NULL);
489  Build(num_pre_sync, num_post_sync);
490  }
virtual void CompactRange(const Slice *begin, const Slice *end)=0
void Build(int start_idx, int num_vals)
Here is the call graph for this function:

§ PartialCompactTestReopenWithFault()

void leveldb::FaultInjectionTest::PartialCompactTestReopenWithFault ( ResetMethod  reset_method,
int  num_pre_sync,
int  num_post_sync 
)
inline

Definition at line 492 of file fault_injection_test.cc.

494  {
495  env_->SetFilesystemActive(false);
496  CloseDB();
497  ResetDBState(reset_method);
498  ASSERT_OK(OpenDB());
500  ASSERT_OK(Verify(num_pre_sync, num_post_sync, FaultInjectionTest::VAL_EXPECT_ERROR));
501  }
#define ASSERT_OK(s)
Definition: testharness.h:106
FaultInjectionTestEnv * env_
Status Verify(int start_idx, int num_vals, ExpectedVerifResult expected) const
void ResetDBState(ResetMethod reset_method)
Here is the call graph for this function:

§ ReadValue()

Status leveldb::FaultInjectionTest::ReadValue ( int  i,
std::string *  val 
) const
inline

Definition at line 406 of file fault_injection_test.cc.

406  {
407  std::string key_space, value_space;
408  Slice key = Key(i, &key_space);
409  Value(i, &value_space);
410  ReadOptions options;
411  return db_->Get(options, key, val);
412  }
virtual Status Get(const ReadOptions &options, const Slice &key, std::string *value)=0
Slice Value(int k, std::string *storage) const
Slice Key(int i, std::string *storage) const
Here is the call graph for this function:

§ ResetDBState()

void leveldb::FaultInjectionTest::ResetDBState ( ResetMethod  reset_method)
inline

Definition at line 472 of file fault_injection_test.cc.

472  {
473  switch (reset_method) {
476  break;
479  break;
480  default:
481  assert(false);
482  }
483  }
#define ASSERT_OK(s)
Definition: testharness.h:106
FaultInjectionTestEnv * env_
Here is the call graph for this function:

§ ReuseLogs()

void leveldb::FaultInjectionTest::ReuseLogs ( bool  reuse)
inline

Definition at line 390 of file fault_injection_test.cc.

390  {
391  options_.reuse_logs = reuse;
392  }

§ Value()

Slice leveldb::FaultInjectionTest::Value ( int  k,
std::string *  storage 
) const
inline

Definition at line 445 of file fault_injection_test.cc.

445  {
446  Random r(k);
447  return test::RandomString(&r, kValueSize, storage);
448  }
static const int kValueSize
Slice RandomString(Random *rnd, int len, std::string *dst)
Definition: testutil.cc:12
Here is the call graph for this function:

§ Verify()

Status leveldb::FaultInjectionTest::Verify ( int  start_idx,
int  num_vals,
ExpectedVerifResult  expected 
) const
inline

Definition at line 414 of file fault_injection_test.cc.

415  {
416  std::string val;
417  std::string value_space;
418  Status s;
419  for (int i = start_idx; i < start_idx + num_vals && s.ok(); i++) {
420  Value(i, &value_space);
421  s = ReadValue(i, &val);
422  if (expected == VAL_EXPECT_NO_ERROR) {
423  if (s.ok()) {
424  ASSERT_EQ(value_space, val);
425  }
426  } else if (s.ok()) {
427  fprintf(stderr, "Expected an error at %d, but was OK\n", i);
428  s = Status::IOError(dbname_, "Expected value error:");
429  } else {
430  s = Status::OK(); // An expected error
431  }
432  }
433  return s;
434  }
Status ReadValue(int i, std::string *val) const
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static Status OK()
Definition: status.h:32
Slice Value(int k, std::string *storage) const
static Status IOError(const Slice &msg, const Slice &msg2=Slice())
Definition: status.h:47
Here is the call graph for this function:

Member Data Documentation

§ db_

DB* leveldb::FaultInjectionTest::db_

Definition at line 368 of file fault_injection_test.cc.

§ dbname_

std::string leveldb::FaultInjectionTest::dbname_

Definition at line 365 of file fault_injection_test.cc.

§ env_

FaultInjectionTestEnv* leveldb::FaultInjectionTest::env_

Definition at line 364 of file fault_injection_test.cc.

§ options_

Options leveldb::FaultInjectionTest::options_

Definition at line 367 of file fault_injection_test.cc.

§ tiny_cache_

Cache* leveldb::FaultInjectionTest::tiny_cache_

Definition at line 366 of file fault_injection_test.cc.


The documentation for this class was generated from the following file: