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

Public Member Functions

 RecoveryTest ()
 
 ~RecoveryTest ()
 
DBImpldbfull () const
 
Envenv () const
 
bool CanAppend ()
 
void Close ()
 
void Open (Options *options=NULL)
 
Status Put (const std::string &k, const std::string &v)
 
std::string Get (const std::string &k, const Snapshot *snapshot=NULL)
 
std::string ManifestFileName ()
 
std::string LogName (uint64_t number)
 
size_t DeleteLogFiles ()
 
uint64_t FirstLogFile ()
 
std::vector< uint64_t > GetFiles (FileType t)
 
int NumLogs ()
 
int NumTables ()
 
uint64_t FileSize (const std::string &fname)
 
void CompactMemTable ()
 
void MakeLogFile (uint64_t lognum, SequenceNumber seq, Slice key, Slice val)
 

Private Attributes

std::string dbname_
 
Envenv_
 
DBdb_
 

Detailed Description

Definition at line 18 of file recovery_test.cc.

Constructor & Destructor Documentation

§ RecoveryTest()

leveldb::RecoveryTest::RecoveryTest ( )
inline

Definition at line 20 of file recovery_test.cc.

20  : env_(Env::Default()), db_(NULL) {
21  dbname_ = test::TmpDir() + "/recovery_test";
22  DestroyDB(dbname_, Options());
23  Open();
24  }
void Open(Options *options=NULL)
std::string TmpDir()
Definition: testharness.cc:60
Status DestroyDB(const std::string &dbname, const Options &options)
Definition: db_impl.cc:1537
static Env * Default()
Definition: env_posix.cc:613
Here is the call graph for this function:

§ ~RecoveryTest()

leveldb::RecoveryTest::~RecoveryTest ( )
inline

Definition at line 26 of file recovery_test.cc.

26  {
27  Close();
28  DestroyDB(dbname_, Options());
29  }
Status DestroyDB(const std::string &dbname, const Options &options)
Definition: db_impl.cc:1537
Here is the call graph for this function:

Member Function Documentation

§ CanAppend()

bool leveldb::RecoveryTest::CanAppend ( )
inline

Definition at line 34 of file recovery_test.cc.

34  {
35  WritableFile* tmp;
36  Status s = env_->NewAppendableFile(CurrentFileName(dbname_), &tmp);
37  delete tmp;
38  if (s.IsNotSupportedError()) {
39  return false;
40  } else {
41  return true;
42  }
43  }
std::string CurrentFileName(const std::string &dbname)
Definition: filename.cc:50
virtual Status NewAppendableFile(const std::string &fname, WritableFile **result)
Definition: env.cc:12
Here is the call graph for this function:
Here is the caller graph for this function:

§ Close()

void leveldb::RecoveryTest::Close ( )
inline

Definition at line 45 of file recovery_test.cc.

45  {
46  delete db_;
47  db_ = NULL;
48  }
Here is the caller graph for this function:

§ CompactMemTable()

void leveldb::RecoveryTest::CompactMemTable ( )
inline

Definition at line 135 of file recovery_test.cc.

135  {
137  }
Status TEST_CompactMemTable()
Definition: db_impl.cc:621
DBImpl * dbfull() const
Here is the call graph for this function:
Here is the caller graph for this function:

§ dbfull()

DBImpl* leveldb::RecoveryTest::dbfull ( ) const
inline

Definition at line 31 of file recovery_test.cc.

31 { return reinterpret_cast<DBImpl*>(db_); }
Here is the caller graph for this function:

§ DeleteLogFiles()

size_t leveldb::RecoveryTest::DeleteLogFiles ( )
inline

Definition at line 95 of file recovery_test.cc.

95  {
96  std::vector<uint64_t> logs = GetFiles(kLogFile);
97  for (size_t i = 0; i < logs.size(); i++) {
98  ASSERT_OK(env_->DeleteFile(LogName(logs[i]))) << LogName(logs[i]);
99  }
100  return logs.size();
101  }
#define ASSERT_OK(s)
Definition: testharness.h:106
std::vector< uint64_t > GetFiles(FileType t)
std::string LogName(uint64_t number)
virtual Status DeleteFile(const std::string &fname)=0
Here is the call graph for this function:
Here is the caller graph for this function:

§ env()

Env* leveldb::RecoveryTest::env ( ) const
inline

Definition at line 32 of file recovery_test.cc.

32 { return env_; }
Here is the caller graph for this function:

§ FileSize()

uint64_t leveldb::RecoveryTest::FileSize ( const std::string &  fname)
inline

Definition at line 129 of file recovery_test.cc.

129  {
130  uint64_t result;
131  ASSERT_OK(env_->GetFileSize(fname, &result)) << fname;
132  return result;
133  }
#define ASSERT_OK(s)
Definition: testharness.h:106
virtual Status GetFileSize(const std::string &fname, uint64_t *file_size)=0
Here is the call graph for this function:
Here is the caller graph for this function:

§ FirstLogFile()

uint64_t leveldb::RecoveryTest::FirstLogFile ( )
inline

Definition at line 103 of file recovery_test.cc.

103  {
104  return GetFiles(kLogFile)[0];
105  }
std::vector< uint64_t > GetFiles(FileType t)
Here is the call graph for this function:
Here is the caller graph for this function:

§ Get()

std::string leveldb::RecoveryTest::Get ( const std::string &  k,
const Snapshot snapshot = NULL 
)
inline

Definition at line 70 of file recovery_test.cc.

70  {
71  std::string result;
72  Status s = db_->Get(ReadOptions(), k, &result);
73  if (s.IsNotFound()) {
74  result = "NOT_FOUND";
75  } else if (!s.ok()) {
76  result = s.ToString();
77  }
78  return result;
79  }
std::string ToString() const
Definition: status.cc:36
virtual Status Get(const ReadOptions &options, const Slice &key, std::string *value)=0
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetFiles()

std::vector<uint64_t> leveldb::RecoveryTest::GetFiles ( FileType  t)
inline

Definition at line 107 of file recovery_test.cc.

107  {
108  std::vector<std::string> filenames;
109  ASSERT_OK(env_->GetChildren(dbname_, &filenames));
110  std::vector<uint64_t> result;
111  for (size_t i = 0; i < filenames.size(); i++) {
112  uint64_t number;
113  FileType type;
114  if (ParseFileName(filenames[i], &number, &type) && type == t) {
115  result.push_back(number);
116  }
117  }
118  return result;
119  }
bool ParseFileName(const std::string &fname, uint64_t *number, FileType *type)
Definition: filename.cc:80
#define ASSERT_OK(s)
Definition: testharness.h:106
FileType
Definition: filename.h:20
virtual Status GetChildren(const std::string &dir, std::vector< std::string > *result)=0
Here is the call graph for this function:
Here is the caller graph for this function:

§ LogName()

std::string leveldb::RecoveryTest::LogName ( uint64_t  number)
inline

Definition at line 91 of file recovery_test.cc.

91  {
92  return LogFileName(dbname_, number);
93  }
std::string LogFileName(const std::string &name, uint64_t number)
Definition: filename.cc:27
Here is the call graph for this function:
Here is the caller graph for this function:

§ MakeLogFile()

void leveldb::RecoveryTest::MakeLogFile ( uint64_t  lognum,
SequenceNumber  seq,
Slice  key,
Slice  val 
)
inline

Definition at line 140 of file recovery_test.cc.

140  {
141  std::string fname = LogFileName(dbname_, lognum);
142  WritableFile* file;
143  ASSERT_OK(env_->NewWritableFile(fname, &file));
144  log::Writer writer(file);
145  WriteBatch batch;
146  batch.Put(key, val);
147  WriteBatchInternal::SetSequence(&batch, seq);
148  ASSERT_OK(writer.AddRecord(WriteBatchInternal::Contents(&batch)));
149  ASSERT_OK(file->Flush());
150  delete file;
151  }
#define ASSERT_OK(s)
Definition: testharness.h:106
static void SetSequence(WriteBatch *batch, SequenceNumber seq)
Definition: write_batch.cc:94
virtual Status NewWritableFile(const std::string &fname, WritableFile **result)=0
std::string LogFileName(const std::string &name, uint64_t number)
Definition: filename.cc:27
static Slice Contents(const WriteBatch *batch)
Here is the call graph for this function:
Here is the caller graph for this function:

§ ManifestFileName()

std::string leveldb::RecoveryTest::ManifestFileName ( )
inline

Definition at line 81 of file recovery_test.cc.

81  {
82  std::string current;
84  size_t len = current.size();
85  if (len > 0 && current[len-1] == '\n') {
86  current.resize(len - 1);
87  }
88  return dbname_ + "/" + current;
89  }
#define ASSERT_OK(s)
Definition: testharness.h:106
std::string CurrentFileName(const std::string &dbname)
Definition: filename.cc:50
Status ReadFileToString(Env *env, const std::string &fname, std::string *data)
Definition: env.cc:72
Here is the call graph for this function:
Here is the caller graph for this function:

§ NumLogs()

int leveldb::RecoveryTest::NumLogs ( )
inline

Definition at line 121 of file recovery_test.cc.

121  {
122  return GetFiles(kLogFile).size();
123  }
std::vector< uint64_t > GetFiles(FileType t)
Here is the call graph for this function:
Here is the caller graph for this function:

§ NumTables()

int leveldb::RecoveryTest::NumTables ( )
inline

Definition at line 125 of file recovery_test.cc.

125  {
126  return GetFiles(kTableFile).size();
127  }
std::vector< uint64_t > GetFiles(FileType t)
Here is the call graph for this function:
Here is the caller graph for this function:

§ Open()

void leveldb::RecoveryTest::Open ( Options options = NULL)
inline

Definition at line 50 of file recovery_test.cc.

50  {
51  Close();
52  Options opts;
53  if (options != NULL) {
54  opts = *options;
55  } else {
56  opts.reuse_logs = true; // TODO(sanjay): test both ways
57  opts.create_if_missing = true;
58  }
59  if (opts.env == NULL) {
60  opts.env = env_;
61  }
62  ASSERT_OK(DB::Open(opts, dbname_, &db_));
63  ASSERT_EQ(1, NumLogs());
64  }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
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:
Here is the caller graph for this function:

§ Put()

Status leveldb::RecoveryTest::Put ( const std::string &  k,
const std::string &  v 
)
inline

Definition at line 66 of file recovery_test.cc.

66  {
67  return db_->Put(WriteOptions(), k, v);
68  }
virtual Status Put(const WriteOptions &options, const Slice &key, const Slice &value)=0
Definition: db_impl.cc:1476
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

§ db_

DB* leveldb::RecoveryTest::db_
private

Definition at line 156 of file recovery_test.cc.

§ dbname_

std::string leveldb::RecoveryTest::dbname_
private

Definition at line 154 of file recovery_test.cc.

§ env_

Env* leveldb::RecoveryTest::env_
private

Definition at line 155 of file recovery_test.cc.


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