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

Public Member Functions

 AutoCompactTest ()
 
 ~AutoCompactTest ()
 
std::string Key (int i)
 
uint64_t Size (const Slice &start, const Slice &limit)
 
void DoReads (int n)
 

Public Attributes

std::string dbname_
 
Cachetiny_cache_
 
Options options_
 
DBdb_
 

Detailed Description

Definition at line 13 of file autocompact_test.cc.

Constructor & Destructor Documentation

§ AutoCompactTest()

leveldb::AutoCompactTest::AutoCompactTest ( )
inline

Definition at line 20 of file autocompact_test.cc.

20  {
21  dbname_ = test::TmpDir() + "/autocompact_test";
22  tiny_cache_ = NewLRUCache(100);
28  }
std::string TmpDir()
Definition: testharness.cc:60
#define ASSERT_OK(s)
Definition: testharness.h:106
Status DestroyDB(const std::string &dbname, const Options &options)
Definition: db_impl.cc:1537
static Status Open(const Options &options, const std::string &name, DB **dbptr)
Definition: db_impl.cc:1490
bool create_if_missing
Definition: options.h:45
Cache * block_cache
Definition: options.h:98
Cache * NewLRUCache(size_t capacity)
Definition: cache.cc:401
CompressionType compression
Definition: options.h:141
Here is the call graph for this function:

§ ~AutoCompactTest()

leveldb::AutoCompactTest::~AutoCompactTest ( )
inline

Definition at line 30 of file autocompact_test.cc.

30  {
31  delete db_;
32  DestroyDB(dbname_, Options());
33  delete tiny_cache_;
34  }
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

§ DoReads()

void leveldb::AutoCompactTest::DoReads ( int  n)

Definition at line 58 of file autocompact_test.cc.

58  {
59  std::string value(kValueSize, 'x');
60  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
61 
62  // Fill database
63  for (int i = 0; i < kCount; i++) {
64  ASSERT_OK(db_->Put(WriteOptions(), Key(i), value));
65  }
66  ASSERT_OK(dbi->TEST_CompactMemTable());
67 
68  // Delete everything
69  for (int i = 0; i < kCount; i++) {
70  ASSERT_OK(db_->Delete(WriteOptions(), Key(i)));
71  }
72  ASSERT_OK(dbi->TEST_CompactMemTable());
73 
74  // Get initial measurement of the space we will be reading.
75  const int64_t initial_size = Size(Key(0), Key(n));
76  const int64_t initial_other_size = Size(Key(n), Key(kCount));
77 
78  // Read until size drops significantly.
79  std::string limit_key = Key(n);
80  for (int read = 0; true; read++) {
81  ASSERT_LT(read, 100) << "Taking too long to compact";
82  Iterator* iter = db_->NewIterator(ReadOptions());
83  for (iter->SeekToFirst();
84  iter->Valid() && iter->key().ToString() < limit_key;
85  iter->Next()) {
86  // Drop data
87  }
88  delete iter;
89  // Wait a little bit to allow any triggered compactions to complete.
91  uint64_t size = Size(Key(0), Key(n));
92  fprintf(stderr, "iter %3d => %7.3f MB [other %7.3f MB]\n",
93  read+1, size/1048576.0, Size(Key(n), Key(kCount))/1048576.0);
94  if (size <= initial_size/10) {
95  break;
96  }
97  }
98 
99  // Verify that the size of the key space not touched by the reads
100  // is pretty much unchanged.
101  const int64_t final_other_size = Size(Key(n), Key(kCount));
102  ASSERT_LE(final_other_size, initial_other_size + 1048576);
103  ASSERT_GE(final_other_size, initial_other_size/5 - 1048576);
104 }
uint64_t Size(const Slice &start, const Slice &limit)
#define ASSERT_LE(a, b)
Definition: testharness.h:111
#define ASSERT_OK(s)
Definition: testharness.h:106
virtual void SleepForMicroseconds(int micros)=0
static const int kValueSize
virtual Status Put(const WriteOptions &options, const Slice &key, const Slice &value)=0
Definition: db_impl.cc:1476
std::string Key(int i)
virtual Status Delete(const WriteOptions &options, const Slice &key)=0
Definition: db_impl.cc:1482
#define ASSERT_LT(a, b)
Definition: testharness.h:112
#define ASSERT_GE(a, b)
Definition: testharness.h:109
virtual Iterator * NewIterator(const ReadOptions &options)=0
static Env * Default()
Definition: env_posix.cc:613
static const int kCount
Here is the call graph for this function:
Here is the caller graph for this function:

§ Key()

std::string leveldb::AutoCompactTest::Key ( int  i)
inline

Definition at line 36 of file autocompact_test.cc.

36  {
37  char buf[100];
38  snprintf(buf, sizeof(buf), "key%06d", i);
39  return std::string(buf);
40  }
Here is the caller graph for this function:

§ Size()

uint64_t leveldb::AutoCompactTest::Size ( const Slice start,
const Slice limit 
)
inline

Definition at line 42 of file autocompact_test.cc.

42  {
43  Range r(start, limit);
44  uint64_t size;
45  db_->GetApproximateSizes(&r, 1, &size);
46  return size;
47  }
virtual void GetApproximateSizes(const Range *range, int n, uint64_t *sizes)=0
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

§ db_

DB* leveldb::AutoCompactTest::db_

Definition at line 18 of file autocompact_test.cc.

§ dbname_

std::string leveldb::AutoCompactTest::dbname_

Definition at line 15 of file autocompact_test.cc.

§ options_

Options leveldb::AutoCompactTest::options_

Definition at line 17 of file autocompact_test.cc.

§ tiny_cache_

Cache* leveldb::AutoCompactTest::tiny_cache_

Definition at line 16 of file autocompact_test.cc.


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