leveldb
Classes | Typedefs | Functions | Variables
leveldb::anonymous_namespace{db_test.cc} Namespace Reference

Classes

class  AtomicCounter
 
struct  MTState
 
struct  MTThread
 

Typedefs

typedef std::map< std::string, std::string > KVMap
 

Functions

void DelayMilliseconds (int millis)
 
static void MTThreadBody (void *arg)
 

Variables

static const int kNumThreads = 4
 
static const int kTestSeconds = 10
 
static const int kNumKeys = 1000
 

Class Documentation

§ leveldb::anonymous_namespace{db_test.cc}::MTState

struct leveldb::anonymous_namespace{db_test.cc}::MTState

Definition at line 1765 of file db_test.cc.

Collaboration diagram for leveldb::anonymous_namespace{db_test.cc}::MTState:
Class Members
AtomicPointer counter[kNumThreads]
AtomicPointer stop
DBTest * test
AtomicPointer thread_done[kNumThreads]

§ leveldb::anonymous_namespace{db_test.cc}::MTThread

struct leveldb::anonymous_namespace{db_test.cc}::MTThread

Definition at line 1772 of file db_test.cc.

Collaboration diagram for leveldb::anonymous_namespace{db_test.cc}::MTThread:
Class Members
int id
MTState * state

Typedef Documentation

§ KVMap

typedef std::map<std::string, std::string> leveldb::anonymous_namespace{db_test.cc}::KVMap

Definition at line 1857 of file db_test.cc.

Function Documentation

§ DelayMilliseconds()

void leveldb::anonymous_namespace{db_test.cc}::DelayMilliseconds ( int  millis)

Definition at line 52 of file db_test.cc.

52  {
53  Env::Default()->SleepForMicroseconds(millis * 1000);
54 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ MTThreadBody()

static void leveldb::anonymous_namespace{db_test.cc}::MTThreadBody ( void *  arg)
static

Definition at line 1777 of file db_test.cc.

1777  {
1778  MTThread* t = reinterpret_cast<MTThread*>(arg);
1779  int id = t->id;
1780  DB* db = t->state->test->db_;
1781  uintptr_t counter = 0;
1782  fprintf(stderr, "... starting thread %d\n", id);
1783  Random rnd(1000 + id);
1784  std::string value;
1785  char valbuf[1500];
1786  while (t->state->stop.Acquire_Load() == NULL) {
1787  t->state->counter[id].Release_Store(reinterpret_cast<void*>(counter));
1788 
1789  int key = rnd.Uniform(kNumKeys);
1790  char keybuf[20];
1791  snprintf(keybuf, sizeof(keybuf), "%016d", key);
1792 
1793  if (rnd.OneIn(2)) {
1794  // Write values of the form <key, my id, counter>.
1795  // We add some padding for force compactions.
1796  snprintf(valbuf, sizeof(valbuf), "%d.%d.%-1000d",
1797  key, id, static_cast<int>(counter));
1798  ASSERT_OK(db->Put(WriteOptions(), Slice(keybuf), Slice(valbuf)));
1799  } else {
1800  // Read a value and verify that it matches the pattern written above.
1801  Status s = db->Get(ReadOptions(), Slice(keybuf), &value);
1802  if (s.IsNotFound()) {
1803  // Key has not yet been written
1804  } else {
1805  // Check that the writer thread counter is >= the counter in the value
1806  ASSERT_OK(s);
1807  int k, w, c;
1808  ASSERT_EQ(3, sscanf(value.c_str(), "%d.%d.%d", &k, &w, &c)) << value;
1809  ASSERT_EQ(k, key);
1810  ASSERT_GE(w, 0);
1811  ASSERT_LT(w, kNumThreads);
1812  ASSERT_LE(static_cast<uintptr_t>(c), reinterpret_cast<uintptr_t>(
1813  t->state->counter[w].Acquire_Load()));
1814  }
1815  }
1816  counter++;
1817  }
1818  t->state->thread_done[id].Release_Store(t);
1819  fprintf(stderr, "... stopping thread %d after %d ops\n", id, int(counter));
1820 }
#define ASSERT_LE(a, b)
Definition: testharness.h:111
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_LT(a, b)
Definition: testharness.h:112
#define ASSERT_GE(a, b)
Definition: testharness.h:109
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

§ kNumKeys

const int leveldb::anonymous_namespace{db_test.cc}::kNumKeys = 1000
static

Definition at line 1763 of file db_test.cc.

§ kNumThreads

const int leveldb::anonymous_namespace{db_test.cc}::kNumThreads = 4
static

Definition at line 1761 of file db_test.cc.

§ kTestSeconds

const int leveldb::anonymous_namespace{db_test.cc}::kTestSeconds = 10
static

Definition at line 1762 of file db_test.cc.