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

Classes

struct  State
 

Public Member Functions

 ConcurrentTest ()
 
void WriteStep (Random *rnd)
 
void ReadStep (Random *rnd)
 

Static Private Member Functions

static uint64_t key (Key key)
 
static uint64_t gen (Key key)
 
static uint64_t hash (Key key)
 
static uint64_t HashNumbers (uint64_t k, uint64_t g)
 
static Key MakeKey (uint64_t k, uint64_t g)
 
static bool IsValidKey (Key k)
 
static Key RandomTarget (Random *rnd)
 

Private Attributes

State current_
 
Arena arena_
 
SkipList< Key, Comparatorlist_
 

Static Private Attributes

static const uint32_t K = 4
 

Detailed Description

Definition at line 149 of file skiplist_test.cc.

Constructor & Destructor Documentation

§ ConcurrentTest()

leveldb::ConcurrentTest::ConcurrentTest ( )
inline

Definition at line 214 of file skiplist_test.cc.

214 : list_(Comparator(), &arena_) { }
SkipList< Key, Comparator > list_

Member Function Documentation

§ gen()

static uint64_t leveldb::ConcurrentTest::gen ( Key  key)
inlinestaticprivate

Definition at line 154 of file skiplist_test.cc.

154 { return (key >> 8) & 0xffffffffu; }
static uint64_t key(Key key)

§ hash()

static uint64_t leveldb::ConcurrentTest::hash ( Key  key)
inlinestaticprivate

Definition at line 155 of file skiplist_test.cc.

155 { return key & 0xff; }
static uint64_t key(Key key)

§ HashNumbers()

static uint64_t leveldb::ConcurrentTest::HashNumbers ( uint64_t  k,
uint64_t  g 
)
inlinestaticprivate

Definition at line 157 of file skiplist_test.cc.

157  {
158  uint64_t data[2] = { k, g };
159  return Hash(reinterpret_cast<char*>(data), sizeof(data), 0);
160  }
uint32_t Hash(const char *data, size_t n, uint32_t seed)
Definition: hash.cc:18
Here is the call graph for this function:

§ IsValidKey()

static bool leveldb::ConcurrentTest::IsValidKey ( Key  k)
inlinestaticprivate

Definition at line 169 of file skiplist_test.cc.

169  {
170  return hash(k) == (HashNumbers(key(k), gen(k)) & 0xff);
171  }
static uint64_t HashNumbers(uint64_t k, uint64_t g)
static uint64_t hash(Key key)
static uint64_t key(Key key)
static uint64_t gen(Key key)

§ key()

static uint64_t leveldb::ConcurrentTest::key ( Key  key)
inlinestaticprivate

Definition at line 153 of file skiplist_test.cc.

153 { return (key >> 40); }
static uint64_t key(Key key)

§ MakeKey()

static Key leveldb::ConcurrentTest::MakeKey ( uint64_t  k,
uint64_t  g 
)
inlinestaticprivate

Definition at line 162 of file skiplist_test.cc.

162  {
163  assert(sizeof(Key) == sizeof(uint64_t));
164  assert(k <= K); // We sometimes pass K to seek to the end of the skiplist
165  assert(g <= 0xffffffffu);
166  return ((k << 40) | (g << 8) | (HashNumbers(k, g) & 0xff));
167  }
uint64_t Key
static uint64_t HashNumbers(uint64_t k, uint64_t g)
static const uint32_t K

§ RandomTarget()

static Key leveldb::ConcurrentTest::RandomTarget ( Random rnd)
inlinestaticprivate

Definition at line 173 of file skiplist_test.cc.

173  {
174  switch (rnd->Next() % 10) {
175  case 0:
176  // Seek to beginning
177  return MakeKey(0, 0);
178  case 1:
179  // Seek to end
180  return MakeKey(K, 0);
181  default:
182  // Seek to middle
183  return MakeKey(rnd->Next() % K, 0);
184  }
185  }
static Key MakeKey(uint64_t k, uint64_t g)
static const uint32_t K
Here is the call graph for this function:

§ ReadStep()

void leveldb::ConcurrentTest::ReadStep ( Random rnd)
inline

Definition at line 225 of file skiplist_test.cc.

225  {
226  // Remember the initial committed state of the skiplist.
227  State initial_state;
228  for (int k = 0; k < K; k++) {
229  initial_state.Set(k, current_.Get(k));
230  }
231 
232  Key pos = RandomTarget(rnd);
233  SkipList<Key, Comparator>::Iterator iter(&list_);
234  iter.Seek(pos);
235  while (true) {
236  Key current;
237  if (!iter.Valid()) {
238  current = MakeKey(K, 0);
239  } else {
240  current = iter.key();
241  ASSERT_TRUE(IsValidKey(current)) << current;
242  }
243  ASSERT_LE(pos, current) << "should not go backwards";
244 
245  // Verify that everything in [pos,current) was not present in
246  // initial_state.
247  while (pos < current) {
248  ASSERT_LT(key(pos), K) << pos;
249 
250  // Note that generation 0 is never inserted, so it is ok if
251  // <*,0,*> is missing.
252  ASSERT_TRUE((gen(pos) == 0) ||
253  (gen(pos) > static_cast<Key>(initial_state.Get(key(pos))))
254  ) << "key: " << key(pos)
255  << "; gen: " << gen(pos)
256  << "; initgen: "
257  << initial_state.Get(key(pos));
258 
259  // Advance to next key in the valid key space
260  if (key(pos) < key(current)) {
261  pos = MakeKey(key(pos) + 1, 0);
262  } else {
263  pos = MakeKey(key(pos), gen(pos) + 1);
264  }
265  }
266 
267  if (!iter.Valid()) {
268  break;
269  }
270 
271  if (rnd->Next() % 2) {
272  iter.Next();
273  pos = MakeKey(key(pos), gen(pos) + 1);
274  } else {
275  Key new_target = RandomTarget(rnd);
276  if (new_target > pos) {
277  pos = new_target;
278  iter.Seek(new_target);
279  }
280  }
281  }
282  }
uint64_t Key
#define ASSERT_LE(a, b)
Definition: testharness.h:111
SkipList< Key, Comparator > list_
static Key RandomTarget(Random *rnd)
static Key MakeKey(uint64_t k, uint64_t g)
#define ASSERT_LT(a, b)
Definition: testharness.h:112
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static uint64_t key(Key key)
static uint64_t gen(Key key)
static bool IsValidKey(Key k)
static const uint32_t K
Here is the call graph for this function:
Here is the caller graph for this function:

§ WriteStep()

void leveldb::ConcurrentTest::WriteStep ( Random rnd)
inline

Definition at line 217 of file skiplist_test.cc.

217  {
218  const uint32_t k = rnd->Next() % K;
219  const intptr_t g = current_.Get(k) + 1;
220  const Key key = MakeKey(k, g);
221  list_.Insert(key);
222  current_.Set(k, g);
223  }
uint64_t Key
SkipList< Key, Comparator > list_
void Set(int k, intptr_t v)
static Key MakeKey(uint64_t k, uint64_t g)
static uint64_t key(Key key)
static const uint32_t K
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

§ arena_

Arena leveldb::ConcurrentTest::arena_
private

Definition at line 207 of file skiplist_test.cc.

§ current_

State leveldb::ConcurrentTest::current_
private

Definition at line 205 of file skiplist_test.cc.

§ K

const uint32_t leveldb::ConcurrentTest::K = 4
staticprivate

Definition at line 151 of file skiplist_test.cc.

§ list_

SkipList<Key, Comparator> leveldb::ConcurrentTest::list_
private

Definition at line 211 of file skiplist_test.cc.


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