leveldb
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
leveldb Namespace Reference

Namespaces

 anonymous_namespace{bloom.cc}
 
 anonymous_namespace{cache.cc}
 
 anonymous_namespace{comparator.cc}
 
 anonymous_namespace{db_bench.cc}
 
 anonymous_namespace{db_impl.cc}
 
 anonymous_namespace{db_iter.cc}
 
 anonymous_namespace{db_test.cc}
 
 anonymous_namespace{dumpfile.cc}
 
 anonymous_namespace{env_posix.cc}
 
 anonymous_namespace{fault_injection_test.cc}
 
 anonymous_namespace{iterator.cc}
 
 anonymous_namespace{leveldbutil.cc}
 
 anonymous_namespace{memenv.cc}
 
 anonymous_namespace{merger.cc}
 
 anonymous_namespace{repair.cc}
 
 anonymous_namespace{table_test.cc}
 
 anonymous_namespace{two_level_iterator.cc}
 
 anonymous_namespace{version_set.cc}
 
 anonymous_namespace{write_batch.cc}
 
 config
 
 crc32c
 
 log
 
 test
 

Classes

class  Arena
 
class  ArenaTest
 
class  AutoCompactTest
 
class  Benchmark
 
class  Block
 
class  BlockBuilder
 
class  BlockConstructor
 
struct  BlockContents
 
class  BlockHandle
 
class  BloomTest
 
class  Cache
 
class  CacheTest
 
class  Coding
 
class  Compaction
 
class  Comparator
 
class  ConcurrentTest
 
class  Constructor
 
class  CorruptionTest
 
class  DB
 
class  DBConstructor
 
class  DBImpl
 
class  DBTest
 
class  Env
 
class  EnvPosixTest
 
class  EnvWrapper
 
class  FaultInjectionTest
 
class  FaultInjectionTestEnv
 
class  FileLock
 
struct  FileMetaData
 
class  FileNameTest
 
class  FilterBlockBuilder
 
class  FilterBlockReader
 
class  FilterBlockTest
 
class  FilterPolicy
 
class  FindFileTest
 
class  Footer
 
class  FormatTest
 
class  Harness
 
class  HASH
 
class  Histogram
 
class  InternalFilterPolicy
 
class  InternalKey
 
class  InternalKeyComparator
 
class  Iterator
 
class  IteratorWrapper
 
class  KeyConvertingIterator
 
class  Logger
 
class  LookupKey
 
class  MemEnvTest
 
class  MemTable
 
class  MemTableConstructor
 
class  MemTableIterator
 
class  MemTableTest
 
class  ModelDB
 
class  MutexLock
 
struct  Options
 
struct  ParsedInternalKey
 
class  PosixLogger
 
class  Random
 
class  RandomAccessFile
 
struct  Range
 
struct  ReadOptions
 
class  RecoveryTest
 
class  SequentialFile
 
class  SkipList
 
class  SkipTest
 
class  Slice
 
class  Snapshot
 
class  SnapshotImpl
 
class  SnapshotList
 
class  SpecialEnv
 
struct  State
 
class  Status
 
class  StringSink
 
class  StringSource
 
class  Table
 
struct  TableAndFile
 
class  TableBuilder
 
class  TableCache
 
class  TableConstructor
 
class  TableTest
 
struct  TestArgs
 
class  TestHashFilter
 
class  TestState
 
class  TestWritableFile
 
class  Version
 
class  VersionEdit
 
class  VersionEditTest
 
class  VersionSet
 
class  WritableFile
 
class  WriteBatch
 
class  WriteBatchInternal
 
class  WriteBatchTest
 
struct  WriteOptions
 

Typedefs

typedef uint64_t SequenceNumber
 
typedef uint64_t Key
 
typedef std::map< std::string, std::string, STLLessThan > KVMap
 

Enumerations

enum  ValueType { kTypeDeletion = 0x0, kTypeValue = 0x1 }
 
enum  FileType {
  kLogFile, kDBLockFile, kTableFile, kDescriptorFile,
  kCurrentFile, kTempFile, kInfoLogFile
}
 
enum  Tag {
  kComparator = 1, kLogNumber = 2, kNextFileNumber = 3, kLastSequence = 4,
  kCompactPointer = 5, kDeletedFile = 6, kNewFile = 7, kPrevLogNumber = 9
}
 
enum  CompressionType { kNoCompression = 0x0, kSnappyCompression = 0x1 }
 
enum  TestType { TABLE_TEST, BLOCK_TEST, MEMTABLE_TEST, DB_TEST }
 

Functions

 TEST (AutoCompactTest, ReadAll)
 
 TEST (AutoCompactTest, ReadHalf)
 
Status BuildTable (const std::string &dbname, Env *env, const Options &options, TableCache *table_cache, Iterator *iter, FileMetaData *meta)
 
 TEST (CorruptionTest, Recovery)
 
 TEST (CorruptionTest, RecoverWriteError)
 
 TEST (CorruptionTest, NewFileErrorDuringWrite)
 
 TEST (CorruptionTest, TableFile)
 
 TEST (CorruptionTest, TableFileRepair)
 
 TEST (CorruptionTest, TableFileIndexData)
 
 TEST (CorruptionTest, MissingDescriptor)
 
 TEST (CorruptionTest, SequenceNumberRecovery)
 
 TEST (CorruptionTest, CorruptedDescriptor)
 
 TEST (CorruptionTest, CompactionInputError)
 
 TEST (CorruptionTest, CompactionInputErrorParanoid)
 
 TEST (CorruptionTest, UnrelatedKeys)
 
template<class T , class V >
static void ClipToRange (T *ptr, V minvalue, V maxvalue)
 
Options SanitizeOptions (const std::string &dbname, const InternalKeyComparator *icmp, const InternalFilterPolicy *ipolicy, const Options &src)
 
Status DestroyDB (const std::string &dbname, const Options &options)
 
IteratorNewDBIterator (DBImpl *db, const Comparator *user_key_comparator, Iterator *internal_iter, SequenceNumber sequence, uint32_t seed)
 
static std::string RandomString (Random *rnd, int len)
 
 TEST (DBTest, Empty)
 
 TEST (DBTest, ReadWrite)
 
 TEST (DBTest, PutDeleteGet)
 
 TEST (DBTest, GetFromImmutableLayer)
 
 TEST (DBTest, GetFromVersions)
 
 TEST (DBTest, GetMemUsage)
 
 TEST (DBTest, GetSnapshot)
 
 TEST (DBTest, GetLevel0Ordering)
 
 TEST (DBTest, GetOrderedByLevels)
 
 TEST (DBTest, GetPicksCorrectFile)
 
 TEST (DBTest, GetEncountersEmptyLevel)
 
 TEST (DBTest, IterEmpty)
 
 TEST (DBTest, IterSingle)
 
 TEST (DBTest, IterMulti)
 
 TEST (DBTest, IterSmallAndLargeMix)
 
 TEST (DBTest, IterMultiWithDelete)
 
 TEST (DBTest, Recover)
 
 TEST (DBTest, RecoveryWithEmptyLog)
 
 TEST (DBTest, RecoverDuringMemtableCompaction)
 
static std::string Key (int i)
 
 TEST (DBTest, MinorCompactionsHappen)
 
 TEST (DBTest, RecoverWithLargeLog)
 
 TEST (DBTest, CompactionsGenerateMultipleFiles)
 
 TEST (DBTest, RepeatedWritesToSameKey)
 
 TEST (DBTest, SparseMerge)
 
static bool Between (uint64_t val, uint64_t low, uint64_t high)
 
 TEST (DBTest, ApproximateSizes)
 
 TEST (DBTest, ApproximateSizes_MixOfSmallAndLarge)
 
 TEST (DBTest, IteratorPinsRef)
 
 TEST (DBTest, Snapshot)
 
 TEST (DBTest, HiddenValuesAreRemoved)
 
 TEST (DBTest, DeletionMarkers1)
 
 TEST (DBTest, DeletionMarkers2)
 
 TEST (DBTest, OverlapInLevel0)
 
 TEST (DBTest, L0_CompactionBug_Issue44_a)
 
 TEST (DBTest, L0_CompactionBug_Issue44_b)
 
 TEST (DBTest, ComparatorCheck)
 
 TEST (DBTest, CustomComparator)
 
 TEST (DBTest, ManualCompaction)
 
 TEST (DBTest, DBOpen_Options)
 
 TEST (DBTest, Locking)
 
 TEST (DBTest, NoSpace)
 
 TEST (DBTest, NonWritableFileSystem)
 
 TEST (DBTest, WriteSyncError)
 
 TEST (DBTest, ManifestWriteError)
 
 TEST (DBTest, MissingSSTFile)
 
 TEST (DBTest, StillReadSST)
 
 TEST (DBTest, FilesDeletedAfterCompaction)
 
 TEST (DBTest, BloomFilter)
 
 TEST (DBTest, MultiThreaded)
 
static std::string RandomKey (Random *rnd)
 
static bool CompareIterators (int step, DB *model, DB *db, const Snapshot *model_snap, const Snapshot *db_snap)
 
 TEST (DBTest, Randomized)
 
std::string MakeKey (unsigned int num)
 
void BM_LogAndApply (int iters, int num_base_files)
 
static uint64_t PackSequenceAndType (uint64_t seq, ValueType t)
 
void AppendInternalKey (std::string *result, const ParsedInternalKey &key)
 
size_t InternalKeyEncodingLength (const ParsedInternalKey &key)
 
bool ParseInternalKey (const Slice &internal_key, ParsedInternalKey *result)
 
Slice ExtractUserKey (const Slice &internal_key)
 
ValueType ExtractValueType (const Slice &internal_key)
 
static std::string IKey (const std::string &user_key, uint64_t seq, ValueType vt)
 
static std::string Shorten (const std::string &s, const std::string &l)
 
static std::string ShortSuccessor (const std::string &s)
 
static void TestKey (const std::string &key, uint64_t seq, ValueType vt)
 
 TEST (FormatTest, InternalKey_EncodeDecode)
 
 TEST (FormatTest, InternalKeyShortSeparator)
 
 TEST (FormatTest, InternalKeyShortestSuccessor)
 
Status DumpFile (Env *env, const std::string &fname, WritableFile *dst)
 
 TEST (FaultInjectionTest, FaultTestNoLogReuse)
 
 TEST (FaultInjectionTest, FaultTestWithLogReuse)
 
Status WriteStringToFileSync (Env *env, const Slice &data, const std::string &fname)
 
static std::string MakeFileName (const std::string &name, uint64_t number, const char *suffix)
 
std::string LogFileName (const std::string &name, uint64_t number)
 
std::string TableFileName (const std::string &name, uint64_t number)
 
std::string SSTTableFileName (const std::string &name, uint64_t number)
 
std::string DescriptorFileName (const std::string &dbname, uint64_t number)
 
std::string CurrentFileName (const std::string &dbname)
 
std::string LockFileName (const std::string &dbname)
 
std::string TempFileName (const std::string &dbname, uint64_t number)
 
std::string InfoLogFileName (const std::string &dbname)
 
std::string OldInfoLogFileName (const std::string &dbname)
 
bool ParseFileName (const std::string &fname, uint64_t *number, FileType *type)
 
Status SetCurrentFile (Env *env, const std::string &dbname, uint64_t descriptor_number)
 
 TEST (FileNameTest, Parse)
 
 TEST (FileNameTest, Construction)
 
static Slice GetLengthPrefixedSlice (const char *data)
 
static const char * EncodeKey (std::string *scratch, const Slice &target)
 
 TEST (RecoveryTest, ManifestReused)
 
 TEST (RecoveryTest, LargeManifestCompacted)
 
 TEST (RecoveryTest, NoLogFiles)
 
 TEST (RecoveryTest, LogFileReuse)
 
 TEST (RecoveryTest, MultipleMemTables)
 
 TEST (RecoveryTest, MultipleLogFiles)
 
Status RepairDB (const std::string &dbname, const Options &options)
 
 TEST (SkipTest, Empty)
 
 TEST (SkipTest, InsertAndLookup)
 
 TEST (SkipTest, ConcurrentWithoutThreads)
 
static void ConcurrentReader (void *arg)
 
static void RunConcurrent (int run)
 
 TEST (SkipTest, Concurrent1)
 
 TEST (SkipTest, Concurrent2)
 
 TEST (SkipTest, Concurrent3)
 
 TEST (SkipTest, Concurrent4)
 
 TEST (SkipTest, Concurrent5)
 
static void DeleteEntry (const Slice &key, void *value)
 
static void UnrefEntry (void *arg1, void *arg2)
 
static bool GetInternalKey (Slice *input, InternalKey *dst)
 
static bool GetLevel (Slice *input, int *level)
 
static void TestEncodeDecode (const VersionEdit &edit)
 
 TEST (VersionEditTest, EncodeDecode)
 
static int TargetFileSize (const Options *options)
 
static int64_t MaxGrandParentOverlapBytes (const Options *options)
 
static int64_t ExpandedCompactionByteSizeLimit (const Options *options)
 
static double MaxBytesForLevel (const Options *options, int level)
 
static uint64_t MaxFileSizeForLevel (const Options *options, int level)
 
static int64_t TotalFileSize (const std::vector< FileMetaData *> &files)
 
int FindFile (const InternalKeyComparator &icmp, const std::vector< FileMetaData *> &files, const Slice &key)
 
static bool AfterFile (const Comparator *ucmp, const Slice *user_key, const FileMetaData *f)
 
static bool BeforeFile (const Comparator *ucmp, const Slice *user_key, const FileMetaData *f)
 
bool SomeFileOverlapsRange (const InternalKeyComparator &icmp, bool disjoint_sorted_files, const std::vector< FileMetaData *> &files, const Slice *smallest_user_key, const Slice *largest_user_key)
 
static IteratorGetFileIterator (void *arg, const ReadOptions &options, const Slice &file_value)
 
static void SaveValue (void *arg, const Slice &ikey, const Slice &v)
 
static bool NewestFirst (FileMetaData *a, FileMetaData *b)
 
 TEST (FindFileTest, Empty)
 
 TEST (FindFileTest, Single)
 
 TEST (FindFileTest, Multiple)
 
 TEST (FindFileTest, MultipleNullBoundaries)
 
 TEST (FindFileTest, OverlapSequenceChecks)
 
 TEST (FindFileTest, OverlappingFiles)
 
static std::string PrintContents (WriteBatch *b)
 
 TEST (WriteBatchTest, Empty)
 
 TEST (WriteBatchTest, Multiple)
 
 TEST (WriteBatchTest, Corruption)
 
 TEST (WriteBatchTest, Append)
 
EnvNewMemEnv (Env *base_env)
 
 TEST (MemEnvTest, Basics)
 
 TEST (MemEnvTest, ReadWrite)
 
 TEST (MemEnvTest, Locks)
 
 TEST (MemEnvTest, Misc)
 
 TEST (MemEnvTest, LargeWrite)
 
 TEST (MemEnvTest, DBTest)
 
CacheNewLRUCache (size_t capacity)
 
const ComparatorBytewiseComparator ()
 
void Log (Logger *info_log, const char *format,...)
 
Status WriteStringToFile (Env *env, const Slice &data, const std::string &fname)
 
Status ReadFileToString (Env *env, const std::string &fname, std::string *data)
 
const FilterPolicyNewBloomFilterPolicy (int bits_per_key)
 
IteratorNewEmptyIterator ()
 
IteratorNewErrorIterator (const Status &status)
 
bool operator== (const Slice &x, const Slice &y)
 
bool operator!= (const Slice &x, const Slice &y)
 
static const char * DecodeEntry (const char *p, const char *limit, uint32_t *shared, uint32_t *non_shared, uint32_t *value_length)
 
 TEST (FilterBlockTest, EmptyBuilder)
 
 TEST (FilterBlockTest, SingleChunk)
 
 TEST (FilterBlockTest, MultiChunk)
 
Status ReadBlock (RandomAccessFile *file, const ReadOptions &options, const BlockHandle &handle, BlockContents *result)
 
IteratorNewMergingIterator (const Comparator *cmp, Iterator **list, int n)
 
static void DeleteBlock (void *arg, void *ignored)
 
static void DeleteCachedBlock (const Slice &key, void *value)
 
static void ReleaseBlock (void *arg, void *h)
 
static std::string Reverse (const Slice &key)
 
static void Increment (const Comparator *cmp, std::string *key)
 
 TEST (Harness, Empty)
 
 TEST (Harness, ZeroRestartPointsInBlock)
 
 TEST (Harness, SimpleEmptyKey)
 
 TEST (Harness, SimpleSingle)
 
 TEST (Harness, SimpleMulti)
 
 TEST (Harness, SimpleSpecialKey)
 
 TEST (Harness, Randomized)
 
 TEST (Harness, RandomizedLongDB)
 
 TEST (MemTableTest, Simple)
 
static bool Between (uint64_t val, uint64_t low, uint64_t high)
 
 TEST (TableTest, ApproximateOffsetOfPlain)
 
static bool SnappyCompressionSupported ()
 
 TEST (TableTest, ApproximateOffsetOfCompressed)
 
IteratorNewTwoLevelIterator (Iterator *index_iter, BlockFunction block_function, void *arg, const ReadOptions &options)
 
IteratorNewTwoLevelIterator (Iterator *index_iter, Iterator *(*block_function)(void *arg, const ReadOptions &options, const Slice &index_value), void *arg, const ReadOptions &options)
 
 TEST (ArenaTest, Empty)
 
 TEST (ArenaTest, Simple)
 
static Slice Key (int i, char *buffer)
 
 TEST (BloomTest, EmptyFilter)
 
 TEST (BloomTest, Small)
 
static int NextLength (int length)
 
 TEST (BloomTest, VaryingLengths)
 
static std::string EncodeKey (int k)
 
static int DecodeKey (const Slice &k)
 
static void * EncodeValue (uintptr_t v)
 
static int DecodeValue (void *v)
 
 TEST (CacheTest, HitAndMiss)
 
 TEST (CacheTest, Erase)
 
 TEST (CacheTest, EntriesArePinned)
 
 TEST (CacheTest, EvictionPolicy)
 
 TEST (CacheTest, UseExceedsCacheSize)
 
 TEST (CacheTest, HeavyEntries)
 
 TEST (CacheTest, NewId)
 
 TEST (CacheTest, Prune)
 
void EncodeFixed32 (char *buf, uint32_t value)
 
void EncodeFixed64 (char *buf, uint64_t value)
 
void PutFixed32 (std::string *dst, uint32_t value)
 
void PutFixed64 (std::string *dst, uint64_t value)
 
char * EncodeVarint32 (char *dst, uint32_t v)
 
void PutVarint32 (std::string *dst, uint32_t v)
 
char * EncodeVarint64 (char *dst, uint64_t v)
 
void PutVarint64 (std::string *dst, uint64_t v)
 
void PutLengthPrefixedSlice (std::string *dst, const Slice &value)
 
int VarintLength (uint64_t v)
 
const char * GetVarint32PtrFallback (const char *p, const char *limit, uint32_t *value)
 
bool GetVarint32 (Slice *input, uint32_t *value)
 
const char * GetVarint64Ptr (const char *p, const char *limit, uint64_t *value)
 
bool GetVarint64 (Slice *input, uint64_t *value)
 
const char * GetLengthPrefixedSlice (const char *p, const char *limit, Slice *result)
 
bool GetLengthPrefixedSlice (Slice *input, Slice *result)
 
const char * GetVarint32Ptr (const char *p, const char *limit, uint32_t *v)
 
uint32_t DecodeFixed32 (const char *ptr)
 
uint64_t DecodeFixed64 (const char *ptr)
 
 TEST (Coding, Fixed32)
 
 TEST (Coding, Fixed64)
 
 TEST (Coding, EncodingOutput)
 
 TEST (Coding, Varint32)
 
 TEST (Coding, Varint64)
 
 TEST (Coding, Varint32Overflow)
 
 TEST (Coding, Varint32Truncation)
 
 TEST (Coding, Varint64Overflow)
 
 TEST (Coding, Varint64Truncation)
 
 TEST (Coding, Strings)
 
static void InitModule ()
 
static Status DoWriteStringToFile (Env *env, const Slice &data, const std::string &fname, bool should_sync)
 
static void InitDefaultEnv ()
 
static void SetBool (void *ptr)
 
 TEST (EnvPosixTest, RunImmediately)
 
 TEST (EnvPosixTest, RunMany)
 
static void ThreadBody (void *arg)
 
 TEST (EnvPosixTest, StartThread)
 
uint32_t Hash (const char *data, size_t n, uint32_t seed)
 
 TEST (HASH, SignedUnsignedIssue)
 
void AppendNumberTo (std::string *str, uint64_t num)
 
void AppendEscapedStringTo (std::string *str, const Slice &value)
 
std::string NumberToString (uint64_t num)
 
std::string EscapeString (const Slice &value)
 
bool ConsumeDecimalNumber (Slice *in, uint64_t *val)
 

Variables

static const int kValueSize = 200 * 1024
 
static const int kTotalSize = 100 * 1024 * 1024
 
static const int kCount = kTotalSize / kValueSize
 
static const int kValueSize = 1000
 
const int kNumNonTableCacheFiles = 10
 
static const ValueType kValueTypeForSeek = kTypeValue
 
static const SequenceNumber kMaxSequenceNumber
 
static const int kValueSize = 1000
 
static const int kMaxNumValues = 2000
 
static const size_t kNumIterations = 3
 
static const size_t kHeader = 12
 
static const int kMajorVersion = 1
 
static const int kMinorVersion = 19
 
static const size_t kFilterBaseLg = 11
 
static const size_t kFilterBase = 1 << kFilterBaseLg
 
static const uint64_t kTableMagicNumber = 0xdb4775248b80fb57ull
 
static const size_t kBlockTrailerSize = 5
 
static ReverseKeyComparator reverse_key_comparator
 
static const TestArgs kTestArgList []
 
static const int kNumTestArgs = sizeof(kTestArgList) / sizeof(kTestArgList[0])
 
static const int kBlockSize = 4096
 
static const int kVerbose = 1
 
static port::OnceType once = LEVELDB_ONCE_INIT
 
static const Comparatorbytewise
 
static pthread_once_t once = PTHREAD_ONCE_INIT
 
static Envdefault_env
 
static const int kDelayMicros = 100000
 

Class Documentation

§ leveldb::ArenaTest

class leveldb::ArenaTest

Definition at line 12 of file arena_test.cc.

§ leveldb::BlockContents

struct leveldb::BlockContents

Definition at line 86 of file format.h.

Collaboration diagram for leveldb::BlockContents:
Class Members
bool cachable
Slice data
bool heap_allocated

§ leveldb::Coding

class leveldb::Coding

Definition at line 11 of file coding_test.cc.

§ leveldb::FileNameTest

class leveldb::FileNameTest

Definition at line 14 of file filename_test.cc.

§ leveldb::FilterBlockTest

class leveldb::FilterBlockTest

Definition at line 41 of file filter_block_test.cc.

Collaboration diagram for leveldb::FilterBlockTest:
Class Members
TestHashFilter policy_

§ leveldb::FormatTest

class leveldb::FormatTest

Definition at line 47 of file dbformat_test.cc.

§ leveldb::HASH

class leveldb::HASH

Definition at line 10 of file hash_test.cc.

§ leveldb::MemTableTest

class leveldb::MemTableTest

Definition at line 760 of file table_test.cc.

§ leveldb::SkipTest

class leveldb::SkipTest

Definition at line 29 of file skiplist_test.cc.

§ leveldb::State

struct leveldb::State

Definition at line 67 of file env_test.cc.

Class Members
Mutex mu
int num_running
int val

§ leveldb::TableAndFile

struct leveldb::TableAndFile

Definition at line 14 of file table_cache.cc.

Collaboration diagram for leveldb::TableAndFile:
Class Members
RandomAccessFile * file
Table * table

§ leveldb::TableTest

class leveldb::TableTest

Definition at line 798 of file table_test.cc.

§ leveldb::TestArgs

struct leveldb::TestArgs

Definition at line 406 of file table_test.cc.

Class Members
int restart_interval
bool reverse_compare
TestType type

§ leveldb::VersionEditTest

class leveldb::VersionEditTest

Definition at line 20 of file version_edit_test.cc.

§ leveldb::WriteBatchTest

class leveldb::WriteBatchTest

Definition at line 55 of file write_batch_test.cc.

Typedef Documentation

§ Key

typedef uint64_t leveldb::Key

Definition at line 15 of file skiplist_test.cc.

§ KVMap

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

Definition at line 137 of file table_test.cc.

§ SequenceNumber

typedef uint64_t leveldb::SequenceNumber

Definition at line 63 of file dbformat.h.

Enumeration Type Documentation

§ CompressionType

Enumerator
kNoCompression 
kSnappyCompression 

Definition at line 23 of file options.h.

23  {
24  // NOTE: do not change the values of existing entries, as these are
25  // part of the persistent format on disk.
26  kNoCompression = 0x0,
27  kSnappyCompression = 0x1
28 };

§ FileType

Enumerator
kLogFile 
kDBLockFile 
kTableFile 
kDescriptorFile 
kCurrentFile 
kTempFile 
kInfoLogFile 

Definition at line 20 of file filename.h.

§ Tag

Enumerator
kComparator 
kLogNumber 
kNextFileNumber 
kLastSequence 
kCompactPointer 
kDeletedFile 
kNewFile 
kPrevLogNumber 

Definition at line 14 of file version_edit.cc.

§ TestType

Enumerator
TABLE_TEST 
BLOCK_TEST 
MEMTABLE_TEST 
DB_TEST 

Definition at line 399 of file table_test.cc.

§ ValueType

Enumerator
kTypeDeletion 
kTypeValue 

Definition at line 51 of file dbformat.h.

51  {
52  kTypeDeletion = 0x0,
53  kTypeValue = 0x1
54 };

Function Documentation

§ AfterFile()

static bool leveldb::AfterFile ( const Comparator ucmp,
const Slice user_key,
const FileMetaData f 
)
static

Definition at line 107 of file version_set.cc.

108  {
109  // NULL user_key occurs before all keys and is therefore never after *f
110  return (user_key != NULL &&
111  ucmp->Compare(*user_key, f->largest.user_key()) > 0);
112 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ AppendEscapedStringTo()

void leveldb::AppendEscapedStringTo ( std::string *  str,
const Slice value 
)

Definition at line 22 of file logging.cc.

22  {
23  for (size_t i = 0; i < value.size(); i++) {
24  char c = value[i];
25  if (c >= ' ' && c <= '~') {
26  str->push_back(c);
27  } else {
28  char buf[10];
29  snprintf(buf, sizeof(buf), "\\x%02x",
30  static_cast<unsigned int>(c) & 0xff);
31  str->append(buf);
32  }
33  }
34 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ AppendInternalKey()

void leveldb::AppendInternalKey ( std::string *  result,
const ParsedInternalKey key 
)

Definition at line 18 of file dbformat.cc.

18  {
19  result->append(key.user_key.data(), key.user_key.size());
20  PutFixed64(result, PackSequenceAndType(key.sequence, key.type));
21 }
void PutFixed64(std::string *dst, uint64_t value)
Definition: coding.cc:41
static uint64_t PackSequenceAndType(uint64_t seq, ValueType t)
Definition: dbformat.cc:12
Here is the call graph for this function:
Here is the caller graph for this function:

§ AppendNumberTo()

void leveldb::AppendNumberTo ( std::string *  str,
uint64_t  num 
)

Definition at line 16 of file logging.cc.

16  {
17  char buf[30];
18  snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num);
19  str->append(buf);
20 }
Here is the caller graph for this function:

§ BeforeFile()

static bool leveldb::BeforeFile ( const Comparator ucmp,
const Slice user_key,
const FileMetaData f 
)
static

Definition at line 114 of file version_set.cc.

115  {
116  // NULL user_key occurs after all keys and is therefore never before *f
117  return (user_key != NULL &&
118  ucmp->Compare(*user_key, f->smallest.user_key()) < 0);
119 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ Between() [1/2]

static bool leveldb::Between ( uint64_t  val,
uint64_t  low,
uint64_t  high 
)
static

Definition at line 787 of file table_test.cc.

787  {
788  bool result = (val >= low) && (val <= high);
789  if (!result) {
790  fprintf(stderr, "Value %llu is not in range [%llu, %llu]\n",
791  (unsigned long long)(val),
792  (unsigned long long)(low),
793  (unsigned long long)(high));
794  }
795  return result;
796 }

§ Between() [2/2]

static bool leveldb::Between ( uint64_t  val,
uint64_t  low,
uint64_t  high 
)
static

Definition at line 1064 of file db_test.cc.

1064  {
1065  bool result = (val >= low) && (val <= high);
1066  if (!result) {
1067  fprintf(stderr, "Value %llu is not in range [%llu, %llu]\n",
1068  (unsigned long long)(val),
1069  (unsigned long long)(low),
1070  (unsigned long long)(high));
1071  }
1072  return result;
1073 }
Here is the caller graph for this function:

§ BM_LogAndApply()

void leveldb::BM_LogAndApply ( int  iters,
int  num_base_files 
)

Definition at line 2094 of file db_test.cc.

2094  {
2095  std::string dbname = test::TmpDir() + "/leveldb_test_benchmark";
2096  DestroyDB(dbname, Options());
2097 
2098  DB* db = NULL;
2099  Options opts;
2100  opts.create_if_missing = true;
2101  Status s = DB::Open(opts, dbname, &db);
2102  ASSERT_OK(s);
2103  ASSERT_TRUE(db != NULL);
2104 
2105  delete db;
2106  db = NULL;
2107 
2108  Env* env = Env::Default();
2109 
2110  port::Mutex mu;
2111  MutexLock l(&mu);
2112 
2113  InternalKeyComparator cmp(BytewiseComparator());
2114  Options options;
2115  VersionSet vset(dbname, &options, NULL, &cmp);
2116  bool save_manifest;
2117  ASSERT_OK(vset.Recover(&save_manifest));
2118  VersionEdit vbase;
2119  uint64_t fnum = 1;
2120  for (int i = 0; i < num_base_files; i++) {
2121  InternalKey start(MakeKey(2*fnum), 1, kTypeValue);
2122  InternalKey limit(MakeKey(2*fnum+1), 1, kTypeDeletion);
2123  vbase.AddFile(2, fnum++, 1 /* file size */, start, limit);
2124  }
2125  ASSERT_OK(vset.LogAndApply(&vbase, &mu));
2126 
2127  uint64_t start_micros = env->NowMicros();
2128 
2129  for (int i = 0; i < iters; i++) {
2130  VersionEdit vedit;
2131  vedit.DeleteFile(2, fnum);
2132  InternalKey start(MakeKey(2*fnum), 1, kTypeValue);
2133  InternalKey limit(MakeKey(2*fnum+1), 1, kTypeDeletion);
2134  vedit.AddFile(2, fnum++, 1 /* file size */, start, limit);
2135  vset.LogAndApply(&vedit, &mu);
2136  }
2137  uint64_t stop_micros = env->NowMicros();
2138  unsigned int us = stop_micros - start_micros;
2139  char buf[16];
2140  snprintf(buf, sizeof(buf), "%d", num_base_files);
2141  fprintf(stderr,
2142  "BM_LogAndApply/%-6s %8d iters : %9u us (%7.0f us / iter)\n",
2143  buf, iters, us, ((float)us) / iters);
2144 }
std::string TmpDir()
Definition: testharness.cc:60
std::string MakeKey(unsigned int num)
Definition: db_test.cc:2088
#define ASSERT_OK(s)
Definition: testharness.h:106
Status DestroyDB(const std::string &dbname, const Options &options)
Definition: db_impl.cc:1537
static char dbname[200]
Definition: c_test.c:15
#define ASSERT_TRUE(c)
Definition: testharness.h:105
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:
Here is the caller graph for this function:

§ BuildTable()

Status leveldb::BuildTable ( const std::string &  dbname,
Env env,
const Options options,
TableCache table_cache,
Iterator iter,
FileMetaData meta 
)

Definition at line 17 of file builder.cc.

22  {
23  Status s;
24  meta->file_size = 0;
25  iter->SeekToFirst();
26 
27  std::string fname = TableFileName(dbname, meta->number);
28  if (iter->Valid()) {
29  WritableFile* file;
30  s = env->NewWritableFile(fname, &file);
31  if (!s.ok()) {
32  return s;
33  }
34 
35  TableBuilder* builder = new TableBuilder(options, file);
36  meta->smallest.DecodeFrom(iter->key());
37  for (; iter->Valid(); iter->Next()) {
38  Slice key = iter->key();
39  meta->largest.DecodeFrom(key);
40  builder->Add(key, iter->value());
41  }
42 
43  // Finish and check for builder errors
44  if (s.ok()) {
45  s = builder->Finish();
46  if (s.ok()) {
47  meta->file_size = builder->FileSize();
48  assert(meta->file_size > 0);
49  }
50  } else {
51  builder->Abandon();
52  }
53  delete builder;
54 
55  // Finish and check for file errors
56  if (s.ok()) {
57  s = file->Sync();
58  }
59  if (s.ok()) {
60  s = file->Close();
61  }
62  delete file;
63  file = NULL;
64 
65  if (s.ok()) {
66  // Verify that the table is usable
67  Iterator* it = table_cache->NewIterator(ReadOptions(),
68  meta->number,
69  meta->file_size);
70  s = it->status();
71  delete it;
72  }
73  }
74 
75  // Check for input iterator errors
76  if (!iter->status().ok()) {
77  s = iter->status();
78  }
79 
80  if (s.ok() && meta->file_size > 0) {
81  // Keep it
82  } else {
83  env->DeleteFile(fname);
84  }
85  return s;
86 }
std::string TableFileName(const std::string &name, uint64_t number)
Definition: filename.cc:32
static char dbname[200]
Definition: c_test.c:15
Here is the call graph for this function:
Here is the caller graph for this function:

§ BytewiseComparator()

const Comparator * leveldb::BytewiseComparator ( )

Definition at line 76 of file comparator.cc.

76  {
77  port::InitOnce(&once, InitModule);
78  return bytewise;
79 }
static port::OnceType once
Definition: comparator.cc:69
static const Comparator * bytewise
Definition: comparator.cc:70
static void InitModule()
Definition: comparator.cc:72
Here is the call graph for this function:
Here is the caller graph for this function:

§ ClipToRange()

template<class T , class V >
static void leveldb::ClipToRange ( T *  ptr,
minvalue,
maxvalue 
)
static

Definition at line 86 of file db_impl.cc.

86  {
87  if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
88  if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
89 }
Here is the caller graph for this function:

§ CompareIterators()

static bool leveldb::CompareIterators ( int  step,
DB model,
DB db,
const Snapshot model_snap,
const Snapshot db_snap 
)
static

Definition at line 1969 of file db_test.cc.

1973  {
1974  ReadOptions options;
1975  options.snapshot = model_snap;
1976  Iterator* miter = model->NewIterator(options);
1977  options.snapshot = db_snap;
1978  Iterator* dbiter = db->NewIterator(options);
1979  bool ok = true;
1980  int count = 0;
1981  for (miter->SeekToFirst(), dbiter->SeekToFirst();
1982  ok && miter->Valid() && dbiter->Valid();
1983  miter->Next(), dbiter->Next()) {
1984  count++;
1985  if (miter->key().compare(dbiter->key()) != 0) {
1986  fprintf(stderr, "step %d: Key mismatch: '%s' vs. '%s'\n",
1987  step,
1988  EscapeString(miter->key()).c_str(),
1989  EscapeString(dbiter->key()).c_str());
1990  ok = false;
1991  break;
1992  }
1993 
1994  if (miter->value().compare(dbiter->value()) != 0) {
1995  fprintf(stderr, "step %d: Value mismatch for key '%s': '%s' vs. '%s'\n",
1996  step,
1997  EscapeString(miter->key()).c_str(),
1998  EscapeString(miter->value()).c_str(),
1999  EscapeString(miter->value()).c_str());
2000  ok = false;
2001  }
2002  }
2003 
2004  if (ok) {
2005  if (miter->Valid() != dbiter->Valid()) {
2006  fprintf(stderr, "step %d: Mismatch at end of iterators: %d vs. %d\n",
2007  step, miter->Valid(), dbiter->Valid());
2008  ok = false;
2009  }
2010  }
2011  fprintf(stderr, "%d entries compared: ok=%d\n", count, ok);
2012  delete miter;
2013  delete dbiter;
2014  return ok;
2015 }
std::string EscapeString(const Slice &value)
Definition: logging.cc:42
Here is the call graph for this function:
Here is the caller graph for this function:

§ ConcurrentReader()

static void leveldb::ConcurrentReader ( void *  arg)
static

Definition at line 336 of file skiplist_test.cc.

336  {
337  TestState* state = reinterpret_cast<TestState*>(arg);
338  Random rnd(state->seed_);
339  int64_t reads = 0;
340  state->Change(TestState::RUNNING);
341  while (!state->quit_flag_.Acquire_Load()) {
342  state->t_.ReadStep(&rnd);
343  ++reads;
344  }
345  state->Change(TestState::DONE);
346 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ ConsumeDecimalNumber()

bool leveldb::ConsumeDecimalNumber ( Slice in,
uint64_t *  val 
)

Definition at line 48 of file logging.cc.

48  {
49  uint64_t v = 0;
50  int digits = 0;
51  while (!in->empty()) {
52  char c = (*in)[0];
53  if (c >= '0' && c <= '9') {
54  ++digits;
55  const int delta = (c - '0');
56  static const uint64_t kMaxUint64 = ~static_cast<uint64_t>(0);
57  if (v > kMaxUint64/10 ||
58  (v == kMaxUint64/10 && delta > kMaxUint64%10)) {
59  // Overflow
60  return false;
61  }
62  v = (v * 10) + delta;
63  in->remove_prefix(1);
64  } else {
65  break;
66  }
67  }
68  *val = v;
69  return (digits > 0);
70 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ CurrentFileName()

std::string leveldb::CurrentFileName ( const std::string &  dbname)

Definition at line 50 of file filename.cc.

50  {
51  return dbname + "/CURRENT";
52 }
static char dbname[200]
Definition: c_test.c:15
Here is the caller graph for this function:

§ DecodeEntry()

static const char* leveldb::DecodeEntry ( const char *  p,
const char *  limit,
uint32_t *  shared,
uint32_t *  non_shared,
uint32_t *  value_length 
)
inlinestatic

Definition at line 53 of file block.cc.

56  {
57  if (limit - p < 3) return NULL;
58  *shared = reinterpret_cast<const unsigned char*>(p)[0];
59  *non_shared = reinterpret_cast<const unsigned char*>(p)[1];
60  *value_length = reinterpret_cast<const unsigned char*>(p)[2];
61  if ((*shared | *non_shared | *value_length) < 128) {
62  // Fast path: all three values are encoded in one byte each
63  p += 3;
64  } else {
65  if ((p = GetVarint32Ptr(p, limit, shared)) == NULL) return NULL;
66  if ((p = GetVarint32Ptr(p, limit, non_shared)) == NULL) return NULL;
67  if ((p = GetVarint32Ptr(p, limit, value_length)) == NULL) return NULL;
68  }
69 
70  if (static_cast<uint32_t>(limit - p) < (*non_shared + *value_length)) {
71  return NULL;
72  }
73  return p;
74 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

§ DecodeFixed32()

uint32_t leveldb::DecodeFixed32 ( const char *  ptr)
inline

Definition at line 58 of file coding.h.

58  {
59  if (port::kLittleEndian) {
60  // Load the raw bytes
61  uint32_t result;
62  memcpy(&result, ptr, sizeof(result)); // gcc optimizes this to a plain load
63  return result;
64  } else {
65  return ((static_cast<uint32_t>(static_cast<unsigned char>(ptr[0])))
66  | (static_cast<uint32_t>(static_cast<unsigned char>(ptr[1])) << 8)
67  | (static_cast<uint32_t>(static_cast<unsigned char>(ptr[2])) << 16)
68  | (static_cast<uint32_t>(static_cast<unsigned char>(ptr[3])) << 24));
69  }
70 }
Here is the caller graph for this function:

§ DecodeFixed64()

uint64_t leveldb::DecodeFixed64 ( const char *  ptr)
inline

Definition at line 72 of file coding.h.

72  {
73  if (port::kLittleEndian) {
74  // Load the raw bytes
75  uint64_t result;
76  memcpy(&result, ptr, sizeof(result)); // gcc optimizes this to a plain load
77  return result;
78  } else {
79  uint64_t lo = DecodeFixed32(ptr);
80  uint64_t hi = DecodeFixed32(ptr + 4);
81  return (hi << 32) | lo;
82  }
83 }
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

§ DecodeKey()

static int leveldb::DecodeKey ( const Slice k)
static

Definition at line 19 of file cache_test.cc.

19  {
20  assert(k.size() == 4);
21  return DecodeFixed32(k.data());
22 }
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

§ DecodeValue()

static int leveldb::DecodeValue ( void *  v)
static

Definition at line 24 of file cache_test.cc.

24 { return reinterpret_cast<uintptr_t>(v); }
Here is the caller graph for this function:

§ DeleteBlock()

static void leveldb::DeleteBlock ( void *  arg,
void *  ignored 
)
static

Definition at line 147 of file table.cc.

147  {
148  delete reinterpret_cast<Block*>(arg);
149 }
Here is the caller graph for this function:

§ DeleteCachedBlock()

static void leveldb::DeleteCachedBlock ( const Slice key,
void *  value 
)
static

Definition at line 151 of file table.cc.

151  {
152  Block* block = reinterpret_cast<Block*>(value);
153  delete block;
154 }
Here is the caller graph for this function:

§ DeleteEntry()

static void leveldb::DeleteEntry ( const Slice key,
void *  value 
)
static

Definition at line 19 of file table_cache.cc.

19  {
20  TableAndFile* tf = reinterpret_cast<TableAndFile*>(value);
21  delete tf->table;
22  delete tf->file;
23  delete tf;
24 }
Here is the caller graph for this function:

§ DescriptorFileName()

std::string leveldb::DescriptorFileName ( const std::string &  dbname,
uint64_t  number 
)

Definition at line 42 of file filename.cc.

42  {
43  assert(number > 0);
44  char buf[100];
45  snprintf(buf, sizeof(buf), "/MANIFEST-%06llu",
46  static_cast<unsigned long long>(number));
47  return dbname + buf;
48 }
static char dbname[200]
Definition: c_test.c:15
Here is the caller graph for this function:

§ DestroyDB()

Status leveldb::DestroyDB ( const std::string &  dbname,
const Options options 
)

Definition at line 1537 of file db_impl.cc.

1537  {
1538  Env* env = options.env;
1539  std::vector<std::string> filenames;
1540  // Ignore error in case directory does not exist
1541  env->GetChildren(dbname, &filenames);
1542  if (filenames.empty()) {
1543  return Status::OK();
1544  }
1545 
1546  FileLock* lock;
1547  const std::string lockname = LockFileName(dbname);
1548  Status result = env->LockFile(lockname, &lock);
1549  if (result.ok()) {
1550  uint64_t number;
1551  FileType type;
1552  for (size_t i = 0; i < filenames.size(); i++) {
1553  if (ParseFileName(filenames[i], &number, &type) &&
1554  type != kDBLockFile) { // Lock file will be deleted at end
1555  Status del = env->DeleteFile(dbname + "/" + filenames[i]);
1556  if (result.ok() && !del.ok()) {
1557  result = del;
1558  }
1559  }
1560  }
1561  env->UnlockFile(lock); // Ignore error since state is already gone
1562  env->DeleteFile(lockname);
1563  env->DeleteDir(dbname); // Ignore error in case dir contains other files
1564  }
1565  return result;
1566 }
bool ParseFileName(const std::string &fname, uint64_t *number, FileType *type)
Definition: filename.cc:80
static char dbname[200]
Definition: c_test.c:15
FileType
Definition: filename.h:20
std::string LockFileName(const std::string &dbname)
Definition: filename.cc:54
Here is the call graph for this function:
Here is the caller graph for this function:

§ DoWriteStringToFile()

static Status leveldb::DoWriteStringToFile ( Env env,
const Slice data,
const std::string &  fname,
bool  should_sync 
)
static

Definition at line 40 of file env.cc.

42  {
43  WritableFile* file;
44  Status s = env->NewWritableFile(fname, &file);
45  if (!s.ok()) {
46  return s;
47  }
48  s = file->Append(data);
49  if (s.ok() && should_sync) {
50  s = file->Sync();
51  }
52  if (s.ok()) {
53  s = file->Close();
54  }
55  delete file; // Will auto-close if we did not close above
56  if (!s.ok()) {
57  env->DeleteFile(fname);
58  }
59  return s;
60 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ DumpFile()

Status leveldb::DumpFile ( Env env,
const std::string &  fname,
WritableFile dst 
)

Definition at line 210 of file dumpfile.cc.

210  {
211  FileType ftype;
212  if (!GuessType(fname, &ftype)) {
213  return Status::InvalidArgument(fname + ": unknown file type");
214  }
215  switch (ftype) {
216  case kLogFile: return DumpLog(env, fname, dst);
217  case kDescriptorFile: return DumpDescriptor(env, fname, dst);
218  case kTableFile: return DumpTable(env, fname, dst);
219  default:
220  break;
221  }
222  return Status::InvalidArgument(fname + ": not a dump-able file type");
223 }
Status DumpLog(Env *env, const std::string &fname, WritableFile *dst)
Definition: dumpfile.cc:118
bool GuessType(const std::string &fname, FileType *type)
Definition: dumpfile.cc:23
Status DumpTable(Env *env, const std::string &fname, WritableFile *dst)
Definition: dumpfile.cc:143
FileType
Definition: filename.h:20
Status DumpDescriptor(Env *env, const std::string &fname, WritableFile *dst)
Definition: dumpfile.cc:139
Here is the call graph for this function:
Here is the caller graph for this function:

§ EncodeFixed32()

void leveldb::EncodeFixed32 ( char *  buf,
uint32_t  value 
)

Definition at line 9 of file coding.cc.

9  {
10  if (port::kLittleEndian) {
11  memcpy(buf, &value, sizeof(value));
12  } else {
13  buf[0] = value & 0xff;
14  buf[1] = (value >> 8) & 0xff;
15  buf[2] = (value >> 16) & 0xff;
16  buf[3] = (value >> 24) & 0xff;
17  }
18 }
Here is the caller graph for this function:

§ EncodeFixed64()

void leveldb::EncodeFixed64 ( char *  buf,
uint64_t  value 
)

Definition at line 20 of file coding.cc.

20  {
21  if (port::kLittleEndian) {
22  memcpy(buf, &value, sizeof(value));
23  } else {
24  buf[0] = value & 0xff;
25  buf[1] = (value >> 8) & 0xff;
26  buf[2] = (value >> 16) & 0xff;
27  buf[3] = (value >> 24) & 0xff;
28  buf[4] = (value >> 32) & 0xff;
29  buf[5] = (value >> 40) & 0xff;
30  buf[6] = (value >> 48) & 0xff;
31  buf[7] = (value >> 56) & 0xff;
32  }
33 }
Here is the caller graph for this function:

§ EncodeKey() [1/2]

static std::string leveldb::EncodeKey ( int  k)
static

Definition at line 14 of file cache_test.cc.

14  {
15  std::string result;
16  PutFixed32(&result, k);
17  return result;
18 }
void PutFixed32(std::string *dst, uint32_t value)
Definition: coding.cc:35
Here is the call graph for this function:

§ EncodeKey() [2/2]

static const char* leveldb::EncodeKey ( std::string *  scratch,
const Slice target 
)
static

Definition at line 44 of file memtable.cc.

44  {
45  scratch->clear();
46  PutVarint32(scratch, target.size());
47  scratch->append(target.data(), target.size());
48  return scratch->data();
49 }
void PutVarint32(std::string *dst, uint32_t v)
Definition: coding.cc:75
Here is the call graph for this function:
Here is the caller graph for this function:

§ EncodeValue()

static void* leveldb::EncodeValue ( uintptr_t  v)
static

Definition at line 23 of file cache_test.cc.

23 { return reinterpret_cast<void*>(v); }
Here is the caller graph for this function:

§ EncodeVarint32()

char * leveldb::EncodeVarint32 ( char *  dst,
uint32_t  v 
)

Definition at line 47 of file coding.cc.

47  {
48  // Operate on characters as unsigneds
49  unsigned char* ptr = reinterpret_cast<unsigned char*>(dst);
50  static const int B = 128;
51  if (v < (1<<7)) {
52  *(ptr++) = v;
53  } else if (v < (1<<14)) {
54  *(ptr++) = v | B;
55  *(ptr++) = v>>7;
56  } else if (v < (1<<21)) {
57  *(ptr++) = v | B;
58  *(ptr++) = (v>>7) | B;
59  *(ptr++) = v>>14;
60  } else if (v < (1<<28)) {
61  *(ptr++) = v | B;
62  *(ptr++) = (v>>7) | B;
63  *(ptr++) = (v>>14) | B;
64  *(ptr++) = v>>21;
65  } else {
66  *(ptr++) = v | B;
67  *(ptr++) = (v>>7) | B;
68  *(ptr++) = (v>>14) | B;
69  *(ptr++) = (v>>21) | B;
70  *(ptr++) = v>>28;
71  }
72  return reinterpret_cast<char*>(ptr);
73 }
Here is the caller graph for this function:

§ EncodeVarint64()

char * leveldb::EncodeVarint64 ( char *  dst,
uint64_t  v 
)

Definition at line 81 of file coding.cc.

81  {
82  static const int B = 128;
83  unsigned char* ptr = reinterpret_cast<unsigned char*>(dst);
84  while (v >= B) {
85  *(ptr++) = (v & (B-1)) | B;
86  v >>= 7;
87  }
88  *(ptr++) = static_cast<unsigned char>(v);
89  return reinterpret_cast<char*>(ptr);
90 }
Here is the caller graph for this function:

§ EscapeString()

std::string leveldb::EscapeString ( const Slice value)

Definition at line 42 of file logging.cc.

42  {
43  std::string r;
44  AppendEscapedStringTo(&r, value);
45  return r;
46 }
void AppendEscapedStringTo(std::string *str, const Slice &value)
Definition: logging.cc:22
Here is the call graph for this function:
Here is the caller graph for this function:

§ ExpandedCompactionByteSizeLimit()

static int64_t leveldb::ExpandedCompactionByteSizeLimit ( const Options options)
static

Definition at line 36 of file version_set.cc.

36  {
37  return 25 * TargetFileSize(options);
38 }
static int TargetFileSize(const Options *options)
Definition: version_set.cc:23
Here is the call graph for this function:
Here is the caller graph for this function:

§ ExtractUserKey()

Slice leveldb::ExtractUserKey ( const Slice internal_key)
inline

Definition at line 98 of file dbformat.h.

98  {
99  assert(internal_key.size() >= 8);
100  return Slice(internal_key.data(), internal_key.size() - 8);
101 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ ExtractValueType()

ValueType leveldb::ExtractValueType ( const Slice internal_key)
inline

Definition at line 103 of file dbformat.h.

103  {
104  assert(internal_key.size() >= 8);
105  const size_t n = internal_key.size();
106  uint64_t num = DecodeFixed64(internal_key.data() + n - 8);
107  unsigned char c = num & 0xff;
108  return static_cast<ValueType>(c);
109 }
uint64_t DecodeFixed64(const char *ptr)
Definition: coding.h:72
ValueType
Definition: dbformat.h:51
Here is the call graph for this function:

§ FindFile()

int leveldb::FindFile ( const InternalKeyComparator icmp,
const std::vector< FileMetaData *> &  files,
const Slice key 
)

Definition at line 86 of file version_set.cc.

88  {
89  uint32_t left = 0;
90  uint32_t right = files.size();
91  while (left < right) {
92  uint32_t mid = (left + right) / 2;
93  const FileMetaData* f = files[mid];
94  if (icmp.InternalKeyComparator::Compare(f->largest.Encode(), key) < 0) {
95  // Key at "mid.largest" is < "target". Therefore all
96  // files at or before "mid" are uninteresting.
97  left = mid + 1;
98  } else {
99  // Key at "mid.largest" is >= "target". Therefore all files
100  // after "mid" are uninteresting.
101  right = mid;
102  }
103  }
104  return right;
105 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetFileIterator()

static Iterator* leveldb::GetFileIterator ( void *  arg,
const ReadOptions options,
const Slice file_value 
)
static

Definition at line 213 of file version_set.cc.

215  {
216  TableCache* cache = reinterpret_cast<TableCache*>(arg);
217  if (file_value.size() != 16) {
218  return NewErrorIterator(
219  Status::Corruption("FileReader invoked with unexpected value"));
220  } else {
221  return cache->NewIterator(options,
222  DecodeFixed64(file_value.data()),
223  DecodeFixed64(file_value.data() + 8));
224  }
225 }
uint64_t DecodeFixed64(const char *ptr)
Definition: coding.h:72
Iterator * NewErrorIterator(const Status &status)
Definition: iterator.cc:63
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetInternalKey()

static bool leveldb::GetInternalKey ( Slice input,
InternalKey dst 
)
static

Definition at line 88 of file version_edit.cc.

88  {
89  Slice str;
90  if (GetLengthPrefixedSlice(input, &str)) {
91  dst->DecodeFrom(str);
92  return true;
93  } else {
94  return false;
95  }
96 }
static Slice GetLengthPrefixedSlice(const char *data)
Definition: memtable.cc:14
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetLengthPrefixedSlice() [1/3]

static Slice leveldb::GetLengthPrefixedSlice ( const char *  data)
static

Definition at line 14 of file memtable.cc.

14  {
15  uint32_t len;
16  const char* p = data;
17  p = GetVarint32Ptr(p, p + 5, &len); // +5: we assume "p" is not corrupted
18  return Slice(p, len);
19 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetLengthPrefixedSlice() [2/3]

const char* leveldb::GetLengthPrefixedSlice ( const char *  p,
const char *  limit,
Slice result 
)

Definition at line 172 of file coding.cc.

173  {
174  uint32_t len;
175  p = GetVarint32Ptr(p, limit, &len);
176  if (p == NULL) return NULL;
177  if (p + len > limit) return NULL;
178  *result = Slice(p, len);
179  return p + len;
180 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
Here is the call graph for this function:

§ GetLengthPrefixedSlice() [3/3]

bool leveldb::GetLengthPrefixedSlice ( Slice input,
Slice result 
)

Definition at line 182 of file coding.cc.

182  {
183  uint32_t len;
184  if (GetVarint32(input, &len) &&
185  input->size() >= len) {
186  *result = Slice(input->data(), len);
187  input->remove_prefix(len);
188  return true;
189  } else {
190  return false;
191  }
192 }
bool GetVarint32(Slice *input, uint32_t *value)
Definition: coding.cc:131
Here is the call graph for this function:

§ GetLevel()

static bool leveldb::GetLevel ( Slice input,
int *  level 
)
static

Definition at line 98 of file version_edit.cc.

98  {
99  uint32_t v;
100  if (GetVarint32(input, &v) &&
101  v < config::kNumLevels) {
102  *level = v;
103  return true;
104  } else {
105  return false;
106  }
107 }
static const int kNumLevels
Definition: dbformat.h:22
bool GetVarint32(Slice *input, uint32_t *value)
Definition: coding.cc:131
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetVarint32()

bool leveldb::GetVarint32 ( Slice input,
uint32_t *  value 
)

Definition at line 131 of file coding.cc.

131  {
132  const char* p = input->data();
133  const char* limit = p + input->size();
134  const char* q = GetVarint32Ptr(p, limit, value);
135  if (q == NULL) {
136  return false;
137  } else {
138  *input = Slice(q, limit - q);
139  return true;
140  }
141 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetVarint32Ptr()

const char * leveldb::GetVarint32Ptr ( const char *  p,
const char *  limit,
uint32_t *  v 
)
inline

Definition at line 89 of file coding.h.

91  {
92  if (p < limit) {
93  uint32_t result = *(reinterpret_cast<const unsigned char*>(p));
94  if ((result & 128) == 0) {
95  *value = result;
96  return p + 1;
97  }
98  }
99  return GetVarint32PtrFallback(p, limit, value);
100 }
const char * GetVarint32PtrFallback(const char *p, const char *limit, uint32_t *value)
Definition: coding.cc:112
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetVarint32PtrFallback()

const char * leveldb::GetVarint32PtrFallback ( const char *  p,
const char *  limit,
uint32_t *  value 
)

Definition at line 112 of file coding.cc.

114  {
115  uint32_t result = 0;
116  for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
117  uint32_t byte = *(reinterpret_cast<const unsigned char*>(p));
118  p++;
119  if (byte & 128) {
120  // More bytes are present
121  result |= ((byte & 127) << shift);
122  } else {
123  result |= (byte << shift);
124  *value = result;
125  return reinterpret_cast<const char*>(p);
126  }
127  }
128  return NULL;
129 }
Here is the caller graph for this function:

§ GetVarint64()

bool leveldb::GetVarint64 ( Slice input,
uint64_t *  value 
)

Definition at line 160 of file coding.cc.

160  {
161  const char* p = input->data();
162  const char* limit = p + input->size();
163  const char* q = GetVarint64Ptr(p, limit, value);
164  if (q == NULL) {
165  return false;
166  } else {
167  *input = Slice(q, limit - q);
168  return true;
169  }
170 }
const char * GetVarint64Ptr(const char *p, const char *limit, uint64_t *value)
Definition: coding.cc:143
Here is the call graph for this function:
Here is the caller graph for this function:

§ GetVarint64Ptr()

const char * leveldb::GetVarint64Ptr ( const char *  p,
const char *  limit,
uint64_t *  value 
)

Definition at line 143 of file coding.cc.

143  {
144  uint64_t result = 0;
145  for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
146  uint64_t byte = *(reinterpret_cast<const unsigned char*>(p));
147  p++;
148  if (byte & 128) {
149  // More bytes are present
150  result |= ((byte & 127) << shift);
151  } else {
152  result |= (byte << shift);
153  *value = result;
154  return reinterpret_cast<const char*>(p);
155  }
156  }
157  return NULL;
158 }
Here is the caller graph for this function:

§ Hash()

uint32_t leveldb::Hash ( const char *  data,
size_t  n,
uint32_t  seed 
)

Definition at line 18 of file hash.cc.

18  {
19  // Similar to murmur hash
20  const uint32_t m = 0xc6a4a793;
21  const uint32_t r = 24;
22  const char* limit = data + n;
23  uint32_t h = seed ^ (n * m);
24 
25  // Pick up four bytes at a time
26  while (data + 4 <= limit) {
27  uint32_t w = DecodeFixed32(data);
28  data += 4;
29  h += w;
30  h *= m;
31  h ^= (h >> 16);
32  }
33 
34  // Pick up remaining bytes
35  switch (limit - data) {
36  case 3:
37  h += static_cast<unsigned char>(data[2]) << 16;
39  case 2:
40  h += static_cast<unsigned char>(data[1]) << 8;
42  case 1:
43  h += static_cast<unsigned char>(data[0]);
44  h *= m;
45  h ^= (h >> r);
46  break;
47  }
48  return h;
49 }
#define FALLTHROUGH_INTENDED
Definition: hash.cc:13
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

§ IKey()

static std::string leveldb::IKey ( const std::string &  user_key,
uint64_t  seq,
ValueType  vt 
)
static

Definition at line 11 of file dbformat_test.cc.

13  {
14  std::string encoded;
15  AppendInternalKey(&encoded, ParsedInternalKey(user_key, seq, vt));
16  return encoded;
17 }
void AppendInternalKey(std::string *result, const ParsedInternalKey &key)
Definition: dbformat.cc:18
Here is the call graph for this function:
Here is the caller graph for this function:

§ Increment()

static void leveldb::Increment ( const Comparator cmp,
std::string *  key 
)
static

Definition at line 66 of file table_test.cc.

66  {
67  if (cmp == BytewiseComparator()) {
68  key->push_back('\0');
69  } else {
70  assert(cmp == &reverse_key_comparator);
71  std::string rev = Reverse(*key);
72  rev.push_back('\0');
73  *key = Reverse(rev);
74  }
75 }
static ReverseKeyComparator reverse_key_comparator
Definition: table_test.cc:64
static std::string Reverse(const Slice &key)
Definition: table_test.cc:27
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:
Here is the caller graph for this function:

§ InfoLogFileName()

std::string leveldb::InfoLogFileName ( const std::string &  dbname)

Definition at line 63 of file filename.cc.

63  {
64  return dbname + "/LOG";
65 }
static char dbname[200]
Definition: c_test.c:15
Here is the caller graph for this function:

§ InitDefaultEnv()

static void leveldb::InitDefaultEnv ( )
static

Definition at line 611 of file env_posix.cc.

611 { default_env = new PosixEnv; }
static Env * default_env
Definition: env_posix.cc:610
Here is the call graph for this function:
Here is the caller graph for this function:

§ InitModule()

static void leveldb::InitModule ( )
static

Definition at line 72 of file comparator.cc.

72  {
73  bytewise = new BytewiseComparatorImpl;
74 }
static const Comparator * bytewise
Definition: comparator.cc:70
Here is the caller graph for this function:

§ InternalKeyEncodingLength()

size_t leveldb::InternalKeyEncodingLength ( const ParsedInternalKey key)
inline

Definition at line 82 of file dbformat.h.

82  {
83  return key.user_key.size() + 8;
84 }
Here is the call graph for this function:

§ Key() [1/2]

static Slice leveldb::Key ( int  i,
char *  buffer 
)
static

Definition at line 16 of file bloom_test.cc.

16  {
17  EncodeFixed32(buffer, i);
18  return Slice(buffer, sizeof(uint32_t));
19 }
void EncodeFixed32(char *buf, uint32_t value)
Definition: coding.cc:9
Here is the call graph for this function:

§ Key() [2/2]

static std::string leveldb::Key ( int  i)
static

Definition at line 924 of file db_test.cc.

924  {
925  char buf[100];
926  snprintf(buf, sizeof(buf), "key%06d", i);
927  return std::string(buf);
928 }

§ LockFileName()

std::string leveldb::LockFileName ( const std::string &  dbname)

Definition at line 54 of file filename.cc.

54  {
55  return dbname + "/LOCK";
56 }
static char dbname[200]
Definition: c_test.c:15
Here is the caller graph for this function:

§ Log()

void leveldb::Log ( Logger info_log,
const char *  format,
  ... 
)

Definition at line 31 of file env.cc.

31  {
32  if (info_log != NULL) {
33  va_list ap;
34  va_start(ap, format);
35  info_log->Logv(format, ap);
36  va_end(ap);
37  }
38 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ LogFileName()

std::string leveldb::LogFileName ( const std::string &  name,
uint64_t  number 
)

Definition at line 27 of file filename.cc.

27  {
28  assert(number > 0);
29  return MakeFileName(name, number, "log");
30 }
static std::string MakeFileName(const std::string &name, uint64_t number, const char *suffix)
Definition: filename.cc:18
Here is the call graph for this function:
Here is the caller graph for this function:

§ MakeFileName()

static std::string leveldb::MakeFileName ( const std::string &  name,
uint64_t  number,
const char *  suffix 
)
static

Definition at line 18 of file filename.cc.

19  {
20  char buf[100];
21  snprintf(buf, sizeof(buf), "/%06llu.%s",
22  static_cast<unsigned long long>(number),
23  suffix);
24  return name + buf;
25 }
Here is the caller graph for this function:

§ MakeKey()

std::string leveldb::MakeKey ( unsigned int  num)

Definition at line 2088 of file db_test.cc.

2088  {
2089  char buf[30];
2090  snprintf(buf, sizeof(buf), "%016u", num);
2091  return std::string(buf);
2092 }
Here is the caller graph for this function:

§ MaxBytesForLevel()

static double leveldb::MaxBytesForLevel ( const Options options,
int  level 
)
static

Definition at line 40 of file version_set.cc.

40  {
41  // Note: the result for level zero is not really used since we set
42  // the level-0 compaction threshold based on number of files.
43 
44  // Result for both level-0 and level-1
45  double result = 10. * 1048576.0;
46  while (level > 1) {
47  result *= 10;
48  level--;
49  }
50  return result;
51 }
Here is the caller graph for this function:

§ MaxFileSizeForLevel()

static uint64_t leveldb::MaxFileSizeForLevel ( const Options options,
int  level 
)
static

Definition at line 53 of file version_set.cc.

53  {
54  // We could vary per level to reduce number of files?
55  return TargetFileSize(options);
56 }
static int TargetFileSize(const Options *options)
Definition: version_set.cc:23
Here is the call graph for this function:
Here is the caller graph for this function:

§ MaxGrandParentOverlapBytes()

static int64_t leveldb::MaxGrandParentOverlapBytes ( const Options options)
static

Definition at line 29 of file version_set.cc.

29  {
30  return 10 * TargetFileSize(options);
31 }
static int TargetFileSize(const Options *options)
Definition: version_set.cc:23
Here is the call graph for this function:
Here is the caller graph for this function:

§ NewBloomFilterPolicy()

const FilterPolicy * leveldb::NewBloomFilterPolicy ( int  bits_per_key)

Definition at line 91 of file bloom.cc.

91  {
92  return new BloomFilterPolicy(bits_per_key);
93 }
Here is the caller graph for this function:

§ NewDBIterator()

Iterator * leveldb::NewDBIterator ( DBImpl db,
const Comparator user_key_comparator,
Iterator internal_iter,
SequenceNumber  sequence,
uint32_t  seed 
)

Definition at line 308 of file db_iter.cc.

313  {
314  return new DBIter(db, user_key_comparator, internal_iter, sequence, seed);
315 }
Here is the caller graph for this function:

§ NewEmptyIterator()

Iterator * leveldb::NewEmptyIterator ( )

Definition at line 59 of file iterator.cc.

59  {
60  return new EmptyIterator(Status::OK());
61 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ NewErrorIterator()

Iterator * leveldb::NewErrorIterator ( const Status status)

Definition at line 63 of file iterator.cc.

63  {
64  return new EmptyIterator(status);
65 }
Here is the caller graph for this function:

§ NewestFirst()

static bool leveldb::NewestFirst ( FileMetaData a,
FileMetaData b 
)
static

Definition at line 283 of file version_set.cc.

283  {
284  return a->number > b->number;
285 }
Here is the caller graph for this function:

§ NewLRUCache()

Cache * leveldb::NewLRUCache ( size_t  capacity)

Definition at line 401 of file cache.cc.

401  {
402  return new ShardedLRUCache(capacity);
403 }
Here is the caller graph for this function:

§ NewMemEnv()

Env * leveldb::NewMemEnv ( Env base_env)

Definition at line 394 of file memenv.cc.

394  {
395  return new InMemoryEnv(base_env);
396 }

§ NewMergingIterator()

Iterator * leveldb::NewMergingIterator ( const Comparator cmp,
Iterator **  list,
int  n 
)

Definition at line 186 of file merger.cc.

186  {
187  assert(n >= 0);
188  if (n == 0) {
189  return NewEmptyIterator();
190  } else if (n == 1) {
191  return list[0];
192  } else {
193  return new MergingIterator(cmp, list, n);
194  }
195 }
Iterator * NewEmptyIterator()
Definition: iterator.cc:59
Here is the call graph for this function:
Here is the caller graph for this function:

§ NewTwoLevelIterator() [1/2]

Iterator* leveldb::NewTwoLevelIterator ( Iterator index_iter,
Iterator *(*)(void *arg, const ReadOptions &options, const Slice &index_value)  block_function,
void *  arg,
const ReadOptions options 
)

§ NewTwoLevelIterator() [2/2]

Iterator* leveldb::NewTwoLevelIterator ( Iterator index_iter,
BlockFunction  block_function,
void *  arg,
const ReadOptions options 
)

Definition at line 174 of file two_level_iterator.cc.

178  {
179  return new TwoLevelIterator(index_iter, block_function, arg, options);
180 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ NextLength()

static int leveldb::NextLength ( int  length)
static

Definition at line 103 of file bloom_test.cc.

103  {
104  if (length < 10) {
105  length += 1;
106  } else if (length < 100) {
107  length += 10;
108  } else if (length < 1000) {
109  length += 100;
110  } else {
111  length += 1000;
112  }
113  return length;
114 }
Here is the caller graph for this function:

§ NumberToString()

std::string leveldb::NumberToString ( uint64_t  num)

Definition at line 36 of file logging.cc.

36  {
37  std::string r;
38  AppendNumberTo(&r, num);
39  return r;
40 }
void AppendNumberTo(std::string *str, uint64_t num)
Definition: logging.cc:16
Here is the call graph for this function:
Here is the caller graph for this function:

§ OldInfoLogFileName()

std::string leveldb::OldInfoLogFileName ( const std::string &  dbname)

Definition at line 68 of file filename.cc.

68  {
69  return dbname + "/LOG.old";
70 }
static char dbname[200]
Definition: c_test.c:15
Here is the caller graph for this function:

§ operator!=()

bool leveldb::operator!= ( const Slice x,
const Slice y 
)
inline

Definition at line 92 of file slice.h.

92  {
93  return !(x == y);
94 }

§ operator==()

bool leveldb::operator== ( const Slice x,
const Slice y 
)
inline

Definition at line 87 of file slice.h.

87  {
88  return ((x.size() == y.size()) &&
89  (memcmp(x.data(), y.data(), x.size()) == 0));
90 }
Here is the call graph for this function:

§ PackSequenceAndType()

static uint64_t leveldb::PackSequenceAndType ( uint64_t  seq,
ValueType  t 
)
static

Definition at line 12 of file dbformat.cc.

12  {
13  assert(seq <= kMaxSequenceNumber);
14  assert(t <= kValueTypeForSeek);
15  return (seq << 8) | t;
16 }
static const SequenceNumber kMaxSequenceNumber
Definition: dbformat.h:67
static const ValueType kValueTypeForSeek
Definition: dbformat.h:61
Here is the caller graph for this function:

§ ParseFileName()

bool leveldb::ParseFileName ( const std::string &  fname,
uint64_t *  number,
FileType type 
)

Definition at line 80 of file filename.cc.

82  {
83  Slice rest(fname);
84  if (rest == "CURRENT") {
85  *number = 0;
86  *type = kCurrentFile;
87  } else if (rest == "LOCK") {
88  *number = 0;
89  *type = kDBLockFile;
90  } else if (rest == "LOG" || rest == "LOG.old") {
91  *number = 0;
92  *type = kInfoLogFile;
93  } else if (rest.starts_with("MANIFEST-")) {
94  rest.remove_prefix(strlen("MANIFEST-"));
95  uint64_t num;
96  if (!ConsumeDecimalNumber(&rest, &num)) {
97  return false;
98  }
99  if (!rest.empty()) {
100  return false;
101  }
102  *type = kDescriptorFile;
103  *number = num;
104  } else {
105  // Avoid strtoull() to keep filename format independent of the
106  // current locale
107  uint64_t num;
108  if (!ConsumeDecimalNumber(&rest, &num)) {
109  return false;
110  }
111  Slice suffix = rest;
112  if (suffix == Slice(".log")) {
113  *type = kLogFile;
114  } else if (suffix == Slice(".sst") || suffix == Slice(".ldb")) {
115  *type = kTableFile;
116  } else if (suffix == Slice(".dbtmp")) {
117  *type = kTempFile;
118  } else {
119  return false;
120  }
121  *number = num;
122  }
123  return true;
124 }
bool ConsumeDecimalNumber(Slice *in, uint64_t *val)
Definition: logging.cc:48
Here is the call graph for this function:
Here is the caller graph for this function:

§ ParseInternalKey()

bool leveldb::ParseInternalKey ( const Slice internal_key,
ParsedInternalKey result 
)
inline

Definition at line 176 of file dbformat.h.

177  {
178  const size_t n = internal_key.size();
179  if (n < 8) return false;
180  uint64_t num = DecodeFixed64(internal_key.data() + n - 8);
181  unsigned char c = num & 0xff;
182  result->sequence = num >> 8;
183  result->type = static_cast<ValueType>(c);
184  result->user_key = Slice(internal_key.data(), n - 8);
185  return (c <= static_cast<unsigned char>(kTypeValue));
186 }
uint64_t DecodeFixed64(const char *ptr)
Definition: coding.h:72
ValueType
Definition: dbformat.h:51
Here is the call graph for this function:
Here is the caller graph for this function:

§ PrintContents()

static std::string leveldb::PrintContents ( WriteBatch b)
static

Definition at line 15 of file write_batch_test.cc.

15  {
16  InternalKeyComparator cmp(BytewiseComparator());
17  MemTable* mem = new MemTable(cmp);
18  mem->Ref();
19  std::string state;
20  Status s = WriteBatchInternal::InsertInto(b, mem);
21  int count = 0;
22  Iterator* iter = mem->NewIterator();
23  for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
24  ParsedInternalKey ikey;
25  ASSERT_TRUE(ParseInternalKey(iter->key(), &ikey));
26  switch (ikey.type) {
27  case kTypeValue:
28  state.append("Put(");
29  state.append(ikey.user_key.ToString());
30  state.append(", ");
31  state.append(iter->value().ToString());
32  state.append(")");
33  count++;
34  break;
35  case kTypeDeletion:
36  state.append("Delete(");
37  state.append(ikey.user_key.ToString());
38  state.append(")");
39  count++;
40  break;
41  }
42  state.append("@");
43  state.append(NumberToString(ikey.sequence));
44  }
45  delete iter;
46  if (!s.ok()) {
47  state.append("ParseError()");
48  } else if (count != WriteBatchInternal::Count(b)) {
49  state.append("CountMismatch()");
50  }
51  mem->Unref();
52  return state;
53 }
bool ParseInternalKey(const Slice &internal_key, ParsedInternalKey *result)
Definition: dbformat.h:176
#define ASSERT_TRUE(c)
Definition: testharness.h:105
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
std::string NumberToString(uint64_t num)
Definition: logging.cc:36
Here is the call graph for this function:
Here is the caller graph for this function:

§ PutFixed32()

void leveldb::PutFixed32 ( std::string *  dst,
uint32_t  value 
)

Definition at line 35 of file coding.cc.

35  {
36  char buf[sizeof(value)];
37  EncodeFixed32(buf, value);
38  dst->append(buf, sizeof(buf));
39 }
void EncodeFixed32(char *buf, uint32_t value)
Definition: coding.cc:9
Here is the call graph for this function:
Here is the caller graph for this function:

§ PutFixed64()

void leveldb::PutFixed64 ( std::string *  dst,
uint64_t  value 
)

Definition at line 41 of file coding.cc.

41  {
42  char buf[sizeof(value)];
43  EncodeFixed64(buf, value);
44  dst->append(buf, sizeof(buf));
45 }
void EncodeFixed64(char *buf, uint64_t value)
Definition: coding.cc:20
Here is the call graph for this function:
Here is the caller graph for this function:

§ PutLengthPrefixedSlice()

void leveldb::PutLengthPrefixedSlice ( std::string *  dst,
const Slice value 
)

Definition at line 98 of file coding.cc.

98  {
99  PutVarint32(dst, value.size());
100  dst->append(value.data(), value.size());
101 }
void PutVarint32(std::string *dst, uint32_t v)
Definition: coding.cc:75
Here is the call graph for this function:
Here is the caller graph for this function:

§ PutVarint32()

void leveldb::PutVarint32 ( std::string *  dst,
uint32_t  v 
)

Definition at line 75 of file coding.cc.

75  {
76  char buf[5];
77  char* ptr = EncodeVarint32(buf, v);
78  dst->append(buf, ptr - buf);
79 }
char * EncodeVarint32(char *dst, uint32_t v)
Definition: coding.cc:47
Here is the call graph for this function:
Here is the caller graph for this function:

§ PutVarint64()

void leveldb::PutVarint64 ( std::string *  dst,
uint64_t  v 
)

Definition at line 92 of file coding.cc.

92  {
93  char buf[10];
94  char* ptr = EncodeVarint64(buf, v);
95  dst->append(buf, ptr - buf);
96 }
char * EncodeVarint64(char *dst, uint64_t v)
Definition: coding.cc:81
Here is the call graph for this function:
Here is the caller graph for this function:

§ RandomKey()

static std::string leveldb::RandomKey ( Random rnd)
static

Definition at line 1962 of file db_test.cc.

1962  {
1963  int len = (rnd->OneIn(3)
1964  ? 1 // Short sometimes to encourage collisions
1965  : (rnd->OneIn(100) ? rnd->Skewed(10) : rnd->Uniform(10)));
1966  return test::RandomKey(rnd, len);
1967 }
static std::string RandomKey(Random *rnd)
Definition: db_test.cc:1962
Here is the call graph for this function:
Here is the caller graph for this function:

§ RandomString()

static std::string leveldb::RandomString ( Random rnd,
int  len 
)
static

Definition at line 22 of file db_test.cc.

22  {
23  std::string r;
24  test::RandomString(rnd, len, &r);
25  return r;
26 }
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
Here is the call graph for this function:
Here is the caller graph for this function:

§ ReadBlock()

Status leveldb::ReadBlock ( RandomAccessFile file,
const ReadOptions options,
const BlockHandle handle,
BlockContents result 
)

Definition at line 65 of file format.cc.

68  {
69  result->data = Slice();
70  result->cachable = false;
71  result->heap_allocated = false;
72 
73  // Read the block contents as well as the type/crc footer.
74  // See table_builder.cc for the code that built this structure.
75  size_t n = static_cast<size_t>(handle.size());
76  char* buf = new char[n + kBlockTrailerSize];
77  Slice contents;
78  Status s = file->Read(handle.offset(), n + kBlockTrailerSize, &contents, buf);
79  if (!s.ok()) {
80  delete[] buf;
81  return s;
82  }
83  if (contents.size() != n + kBlockTrailerSize) {
84  delete[] buf;
85  return Status::Corruption("truncated block read");
86  }
87 
88  // Check the crc of the type and the block contents
89  const char* data = contents.data(); // Pointer to where Read put the data
90  if (options.verify_checksums) {
91  const uint32_t crc = crc32c::Unmask(DecodeFixed32(data + n + 1));
92  const uint32_t actual = crc32c::Value(data, n + 1);
93  if (actual != crc) {
94  delete[] buf;
95  s = Status::Corruption("block checksum mismatch");
96  return s;
97  }
98  }
99 
100  switch (data[n]) {
101  case kNoCompression:
102  if (data != buf) {
103  // File implementation gave us pointer to some other data.
104  // Use it directly under the assumption that it will be live
105  // while the file is open.
106  delete[] buf;
107  result->data = Slice(data, n);
108  result->heap_allocated = false;
109  result->cachable = false; // Do not double-cache
110  } else {
111  result->data = Slice(buf, n);
112  result->heap_allocated = true;
113  result->cachable = true;
114  }
115 
116  // Ok
117  break;
118  case kSnappyCompression: {
119  size_t ulength = 0;
120  if (!port::Snappy_GetUncompressedLength(data, n, &ulength)) {
121  delete[] buf;
122  return Status::Corruption("corrupted compressed block contents");
123  }
124  char* ubuf = new char[ulength];
125  if (!port::Snappy_Uncompress(data, n, ubuf)) {
126  delete[] buf;
127  delete[] ubuf;
128  return Status::Corruption("corrupted compressed block contents");
129  }
130  delete[] buf;
131  result->data = Slice(ubuf, ulength);
132  result->heap_allocated = true;
133  result->cachable = true;
134  break;
135  }
136  default:
137  delete[] buf;
138  return Status::Corruption("bad block type");
139  }
140 
141  return Status::OK();
142 }
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
uint32_t Unmask(uint32_t masked_crc)
Definition: crc32c.h:37
uint32_t Value(const char *data, size_t n)
Definition: crc32c.h:20
static const size_t kBlockTrailerSize
Definition: format.h:84
Here is the call graph for this function:
Here is the caller graph for this function:

§ ReadFileToString()

Status leveldb::ReadFileToString ( Env env,
const std::string &  fname,
std::string *  data 
)

Definition at line 72 of file env.cc.

72  {
73  data->clear();
74  SequentialFile* file;
75  Status s = env->NewSequentialFile(fname, &file);
76  if (!s.ok()) {
77  return s;
78  }
79  static const int kBufferSize = 8192;
80  char* space = new char[kBufferSize];
81  while (true) {
82  Slice fragment;
83  s = file->Read(kBufferSize, &fragment, space);
84  if (!s.ok()) {
85  break;
86  }
87  data->append(fragment.data(), fragment.size());
88  if (fragment.empty()) {
89  break;
90  }
91  }
92  delete[] space;
93  delete file;
94  return s;
95 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ ReleaseBlock()

static void leveldb::ReleaseBlock ( void *  arg,
void *  h 
)
static

Definition at line 156 of file table.cc.

156  {
157  Cache* cache = reinterpret_cast<Cache*>(arg);
158  Cache::Handle* handle = reinterpret_cast<Cache::Handle*>(h);
159  cache->Release(handle);
160 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ RepairDB()

Status leveldb::RepairDB ( const std::string &  dbname,
const Options options 
)

Definition at line 456 of file repair.cc.

456  {
457  Repairer repairer(dbname, options);
458  return repairer.Run();
459 }
static char dbname[200]
Definition: c_test.c:15
Here is the caller graph for this function:

§ Reverse()

static std::string leveldb::Reverse ( const Slice key)
static

Definition at line 27 of file table_test.cc.

27  {
28  std::string str(key.ToString());
29  std::string rev("");
30  for (std::string::reverse_iterator rit = str.rbegin();
31  rit != str.rend(); ++rit) {
32  rev.push_back(*rit);
33  }
34  return rev;
35 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ RunConcurrent()

static void leveldb::RunConcurrent ( int  run)
static

Definition at line 348 of file skiplist_test.cc.

348  {
349  const int seed = test::RandomSeed() + (run * 100);
350  Random rnd(seed);
351  const int N = 1000;
352  const int kSize = 1000;
353  for (int i = 0; i < N; i++) {
354  if ((i % 100) == 0) {
355  fprintf(stderr, "Run %d of %d\n", i, N);
356  }
357  TestState state(seed + 1);
358  Env::Default()->Schedule(ConcurrentReader, &state);
359  state.Wait(TestState::RUNNING);
360  for (int i = 0; i < kSize; i++) {
361  state.t_.WriteStep(&rnd);
362  }
363  state.quit_flag_.Release_Store(&state); // Any non-NULL arg will do
364  state.Wait(TestState::DONE);
365  }
366 }
int RandomSeed()
Definition: testharness.cc:67
static void ConcurrentReader(void *arg)
Here is the call graph for this function:
Here is the caller graph for this function:

§ SanitizeOptions()

Options leveldb::SanitizeOptions ( const std::string &  dbname,
const InternalKeyComparator icmp,
const InternalFilterPolicy ipolicy,
const Options src 
)

Definition at line 90 of file db_impl.cc.

93  {
94  Options result = src;
95  result.comparator = icmp;
96  result.filter_policy = (src.filter_policy != NULL) ? ipolicy : NULL;
97  ClipToRange(&result.max_open_files, 64 + kNumNonTableCacheFiles, 50000);
98  ClipToRange(&result.write_buffer_size, 64<<10, 1<<30);
99  ClipToRange(&result.max_file_size, 1<<20, 1<<30);
100  ClipToRange(&result.block_size, 1<<10, 4<<20);
101  if (result.info_log == NULL) {
102  // Open a log file in the same directory as the db
103  src.env->CreateDir(dbname); // In case it does not exist
104  src.env->RenameFile(InfoLogFileName(dbname), OldInfoLogFileName(dbname));
105  Status s = src.env->NewLogger(InfoLogFileName(dbname), &result.info_log);
106  if (!s.ok()) {
107  // No place suitable for logging
108  result.info_log = NULL;
109  }
110  }
111  if (result.block_cache == NULL) {
112  result.block_cache = NewLRUCache(8 << 20);
113  }
114  return result;
115 }
const int kNumNonTableCacheFiles
Definition: db_impl.cc:38
static void ClipToRange(T *ptr, V minvalue, V maxvalue)
Definition: db_impl.cc:86
std::string OldInfoLogFileName(const std::string &dbname)
Definition: filename.cc:68
std::string InfoLogFileName(const std::string &dbname)
Definition: filename.cc:63
static char dbname[200]
Definition: c_test.c:15
Cache * NewLRUCache(size_t capacity)
Definition: cache.cc:401
Here is the call graph for this function:
Here is the caller graph for this function:

§ SaveValue()

static void leveldb::SaveValue ( void *  arg,
const Slice ikey,
const Slice v 
)
static

Definition at line 268 of file version_set.cc.

268  {
269  Saver* s = reinterpret_cast<Saver*>(arg);
270  ParsedInternalKey parsed_key;
271  if (!ParseInternalKey(ikey, &parsed_key)) {
272  s->state = kCorrupt;
273  } else {
274  if (s->ucmp->Compare(parsed_key.user_key, s->user_key) == 0) {
275  s->state = (parsed_key.type == kTypeValue) ? kFound : kDeleted;
276  if (s->state == kFound) {
277  s->value->assign(v.data(), v.size());
278  }
279  }
280  }
281 }
bool ParseInternalKey(const Slice &internal_key, ParsedInternalKey *result)
Definition: dbformat.h:176
Here is the call graph for this function:
Here is the caller graph for this function:

§ SetBool()

static void leveldb::SetBool ( void *  ptr)
static

Definition at line 24 of file env_test.cc.

24  {
25  reinterpret_cast<port::AtomicPointer*>(ptr)->NoBarrier_Store(ptr);
26 }
Here is the caller graph for this function:

§ SetCurrentFile()

Status leveldb::SetCurrentFile ( Env env,
const std::string &  dbname,
uint64_t  descriptor_number 
)

Definition at line 126 of file filename.cc.

127  {
128  // Remove leading "dbname/" and add newline to manifest file name
129  std::string manifest = DescriptorFileName(dbname, descriptor_number);
130  Slice contents = manifest;
131  assert(contents.starts_with(dbname + "/"));
132  contents.remove_prefix(dbname.size() + 1);
133  std::string tmp = TempFileName(dbname, descriptor_number);
134  Status s = WriteStringToFileSync(env, contents.ToString() + "\n", tmp);
135  if (s.ok()) {
136  s = env->RenameFile(tmp, CurrentFileName(dbname));
137  }
138  if (!s.ok()) {
139  env->DeleteFile(tmp);
140  }
141  return s;
142 }
Status WriteStringToFileSync(Env *env, const Slice &data, const std::string &fname)
Definition: env.cc:67
std::string TempFileName(const std::string &dbname, uint64_t number)
Definition: filename.cc:58
std::string DescriptorFileName(const std::string &dbname, uint64_t number)
Definition: filename.cc:42
static char dbname[200]
Definition: c_test.c:15
std::string CurrentFileName(const std::string &dbname)
Definition: filename.cc:50
Here is the call graph for this function:
Here is the caller graph for this function:

§ Shorten()

static std::string leveldb::Shorten ( const std::string &  s,
const std::string &  l 
)
static

Definition at line 19 of file dbformat_test.cc.

19  {
20  std::string result = s;
21  InternalKeyComparator(BytewiseComparator()).FindShortestSeparator(&result, l);
22  return result;
23 }
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:
Here is the caller graph for this function:

§ ShortSuccessor()

static std::string leveldb::ShortSuccessor ( const std::string &  s)
static

Definition at line 25 of file dbformat_test.cc.

25  {
26  std::string result = s;
27  InternalKeyComparator(BytewiseComparator()).FindShortSuccessor(&result);
28  return result;
29 }
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:
Here is the caller graph for this function:

§ SnappyCompressionSupported()

static bool leveldb::SnappyCompressionSupported ( )
static

Definition at line 830 of file table_test.cc.

830  {
831  std::string out;
832  Slice in = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
833  return port::Snappy_Compress(in.data(), in.size(), &out);
834 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ SomeFileOverlapsRange()

bool leveldb::SomeFileOverlapsRange ( const InternalKeyComparator icmp,
bool  disjoint_sorted_files,
const std::vector< FileMetaData *> &  files,
const Slice smallest_user_key,
const Slice largest_user_key 
)

Definition at line 121 of file version_set.cc.

126  {
127  const Comparator* ucmp = icmp.user_comparator();
128  if (!disjoint_sorted_files) {
129  // Need to check against all files
130  for (size_t i = 0; i < files.size(); i++) {
131  const FileMetaData* f = files[i];
132  if (AfterFile(ucmp, smallest_user_key, f) ||
133  BeforeFile(ucmp, largest_user_key, f)) {
134  // No overlap
135  } else {
136  return true; // Overlap
137  }
138  }
139  return false;
140  }
141 
142  // Binary search over file list
143  uint32_t index = 0;
144  if (smallest_user_key != NULL) {
145  // Find the earliest possible internal key for smallest_user_key
146  InternalKey small(*smallest_user_key, kMaxSequenceNumber,kValueTypeForSeek);
147  index = FindFile(icmp, files, small.Encode());
148  }
149 
150  if (index >= files.size()) {
151  // beginning of range is after all files, so no overlap.
152  return false;
153  }
154 
155  return !BeforeFile(ucmp, largest_user_key, files[index]);
156 }
static const SequenceNumber kMaxSequenceNumber
Definition: dbformat.h:67
int FindFile(const InternalKeyComparator &icmp, const std::vector< FileMetaData *> &files, const Slice &key)
Definition: version_set.cc:86
static const ValueType kValueTypeForSeek
Definition: dbformat.h:61
static bool BeforeFile(const Comparator *ucmp, const Slice *user_key, const FileMetaData *f)
Definition: version_set.cc:114
static bool AfterFile(const Comparator *ucmp, const Slice *user_key, const FileMetaData *f)
Definition: version_set.cc:107
Here is the call graph for this function:
Here is the caller graph for this function:

§ SSTTableFileName()

std::string leveldb::SSTTableFileName ( const std::string &  name,
uint64_t  number 
)

Definition at line 37 of file filename.cc.

37  {
38  assert(number > 0);
39  return MakeFileName(name, number, "sst");
40 }
static std::string MakeFileName(const std::string &name, uint64_t number, const char *suffix)
Definition: filename.cc:18
Here is the call graph for this function:
Here is the caller graph for this function:

§ TableFileName()

std::string leveldb::TableFileName ( const std::string &  name,
uint64_t  number 
)

Definition at line 32 of file filename.cc.

32  {
33  assert(number > 0);
34  return MakeFileName(name, number, "ldb");
35 }
static std::string MakeFileName(const std::string &name, uint64_t number, const char *suffix)
Definition: filename.cc:18
Here is the call graph for this function:
Here is the caller graph for this function:

§ TargetFileSize()

static int leveldb::TargetFileSize ( const Options options)
static

Definition at line 23 of file version_set.cc.

23  {
24  return options->max_file_size;
25 }
Here is the caller graph for this function:

§ TempFileName()

std::string leveldb::TempFileName ( const std::string &  dbname,
uint64_t  number 
)

Definition at line 58 of file filename.cc.

58  {
59  assert(number > 0);
60  return MakeFileName(dbname, number, "dbtmp");
61 }
static char dbname[200]
Definition: c_test.c:15
static std::string MakeFileName(const std::string &name, uint64_t number, const char *suffix)
Definition: filename.cc:18
Here is the call graph for this function:
Here is the caller graph for this function:

§ TEST() [1/142]

leveldb::TEST ( HASH  ,
SignedUnsignedIssue   
)

Definition at line 12 of file hash_test.cc.

12  {
13  const unsigned char data1[1] = {0x62};
14  const unsigned char data2[2] = {0xc3, 0x97};
15  const unsigned char data3[3] = {0xe2, 0x99, 0xa5};
16  const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32};
17  const unsigned char data5[48] = {
18  0x01, 0xc0, 0x00, 0x00,
19  0x00, 0x00, 0x00, 0x00,
20  0x00, 0x00, 0x00, 0x00,
21  0x00, 0x00, 0x00, 0x00,
22  0x14, 0x00, 0x00, 0x00,
23  0x00, 0x00, 0x04, 0x00,
24  0x00, 0x00, 0x00, 0x14,
25  0x00, 0x00, 0x00, 0x18,
26  0x28, 0x00, 0x00, 0x00,
27  0x00, 0x00, 0x00, 0x00,
28  0x02, 0x00, 0x00, 0x00,
29  0x00, 0x00, 0x00, 0x00,
30  };
31 
32  ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34);
33  ASSERT_EQ(
34  Hash(reinterpret_cast<const char*>(data1), sizeof(data1), 0xbc9f1d34),
35  0xef1345c4);
36  ASSERT_EQ(
37  Hash(reinterpret_cast<const char*>(data2), sizeof(data2), 0xbc9f1d34),
38  0x5b663814);
39  ASSERT_EQ(
40  Hash(reinterpret_cast<const char*>(data3), sizeof(data3), 0xbc9f1d34),
41  0x323c078f);
42  ASSERT_EQ(
43  Hash(reinterpret_cast<const char*>(data4), sizeof(data4), 0xbc9f1d34),
44  0xed21633a);
45  ASSERT_EQ(
46  Hash(reinterpret_cast<const char*>(data5), sizeof(data5), 0x12345678),
47  0xf333dabb);
48 }
uint32_t Hash(const char *data, size_t n, uint32_t seed)
Definition: hash.cc:18
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [2/142]

leveldb::TEST ( Coding  ,
Fixed32   
)

Definition at line 13 of file coding_test.cc.

13  {
14  std::string s;
15  for (uint32_t v = 0; v < 100000; v++) {
16  PutFixed32(&s, v);
17  }
18 
19  const char* p = s.data();
20  for (uint32_t v = 0; v < 100000; v++) {
21  uint32_t actual = DecodeFixed32(p);
22  ASSERT_EQ(v, actual);
23  p += sizeof(uint32_t);
24  }
25 }
void PutFixed32(std::string *dst, uint32_t value)
Definition: coding.cc:35
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [3/142]

leveldb::TEST ( ArenaTest  ,
Empty   
)

Definition at line 14 of file arena_test.cc.

14  {
15  Arena arena;
16 }

§ TEST() [4/142]

leveldb::TEST ( FileNameTest  ,
Parse   
)

Definition at line 16 of file filename_test.cc.

16  {
17  Slice db;
18  FileType type;
19  uint64_t number;
20 
21  // Successful parses
22  static struct {
23  const char* fname;
24  uint64_t number;
25  FileType type;
26  } cases[] = {
27  { "100.log", 100, kLogFile },
28  { "0.log", 0, kLogFile },
29  { "0.sst", 0, kTableFile },
30  { "0.ldb", 0, kTableFile },
31  { "CURRENT", 0, kCurrentFile },
32  { "LOCK", 0, kDBLockFile },
33  { "MANIFEST-2", 2, kDescriptorFile },
34  { "MANIFEST-7", 7, kDescriptorFile },
35  { "LOG", 0, kInfoLogFile },
36  { "LOG.old", 0, kInfoLogFile },
37  { "18446744073709551615.log", 18446744073709551615ull, kLogFile },
38  };
39  for (int i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
40  std::string f = cases[i].fname;
41  ASSERT_TRUE(ParseFileName(f, &number, &type)) << f;
42  ASSERT_EQ(cases[i].type, type) << f;
43  ASSERT_EQ(cases[i].number, number) << f;
44  }
45 
46  // Errors
47  static const char* errors[] = {
48  "",
49  "foo",
50  "foo-dx-100.log",
51  ".log",
52  "",
53  "manifest",
54  "CURREN",
55  "CURRENTX",
56  "MANIFES",
57  "MANIFEST",
58  "MANIFEST-",
59  "XMANIFEST-3",
60  "MANIFEST-3x",
61  "LOC",
62  "LOCKx",
63  "LO",
64  "LOGx",
65  "18446744073709551616.log",
66  "184467440737095516150.log",
67  "100",
68  "100.",
69  "100.lop"
70  };
71  for (int i = 0; i < sizeof(errors) / sizeof(errors[0]); i++) {
72  std::string f = errors[i];
73  ASSERT_TRUE(!ParseFileName(f, &number, &type)) << f;
74  }
75 }
bool ParseFileName(const std::string &fname, uint64_t *number, FileType *type)
Definition: filename.cc:80
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
FileType
Definition: filename.h:20
Here is the call graph for this function:

§ TEST() [5/142]

leveldb::TEST ( ArenaTest  ,
Simple   
)

Definition at line 18 of file arena_test.cc.

18  {
19  std::vector<std::pair<size_t, char*> > allocated;
20  Arena arena;
21  const int N = 100000;
22  size_t bytes = 0;
23  Random rnd(301);
24  for (int i = 0; i < N; i++) {
25  size_t s;
26  if (i % (N / 10) == 0) {
27  s = i;
28  } else {
29  s = rnd.OneIn(4000) ? rnd.Uniform(6000) :
30  (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20));
31  }
32  if (s == 0) {
33  // Our arena disallows size 0 allocations.
34  s = 1;
35  }
36  char* r;
37  if (rnd.OneIn(10)) {
38  r = arena.AllocateAligned(s);
39  } else {
40  r = arena.Allocate(s);
41  }
42 
43  for (size_t b = 0; b < s; b++) {
44  // Fill the "i"th allocation with a known bit pattern
45  r[b] = i % 256;
46  }
47  bytes += s;
48  allocated.push_back(std::make_pair(s, r));
49  ASSERT_GE(arena.MemoryUsage(), bytes);
50  if (i > N/10) {
51  ASSERT_LE(arena.MemoryUsage(), bytes * 1.10);
52  }
53  }
54  for (size_t i = 0; i < allocated.size(); i++) {
55  size_t num_bytes = allocated[i].first;
56  const char* p = allocated[i].second;
57  for (size_t b = 0; b < num_bytes; b++) {
58  // Check the "i"th allocation for the known bit pattern
59  ASSERT_EQ(int(p[b]) & 0xff, i % 256);
60  }
61  }
62 }
#define ASSERT_LE(a, b)
Definition: testharness.h:111
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_GE(a, b)
Definition: testharness.h:109
Here is the call graph for this function:

§ TEST() [6/142]

leveldb::TEST ( VersionEditTest  ,
EncodeDecode   
)

Definition at line 22 of file version_edit_test.cc.

22  {
23  static const uint64_t kBig = 1ull << 50;
24 
25  VersionEdit edit;
26  for (int i = 0; i < 4; i++) {
27  TestEncodeDecode(edit);
28  edit.AddFile(3, kBig + 300 + i, kBig + 400 + i,
29  InternalKey("foo", kBig + 500 + i, kTypeValue),
30  InternalKey("zoo", kBig + 600 + i, kTypeDeletion));
31  edit.DeleteFile(4, kBig + 700 + i);
32  edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue));
33  }
34 
35  edit.SetComparatorName("foo");
36  edit.SetLogNumber(kBig + 100);
37  edit.SetNextFile(kBig + 200);
38  edit.SetLastSequence(kBig + 1000);
39  TestEncodeDecode(edit);
40 }
static void TestEncodeDecode(const VersionEdit &edit)
Here is the call graph for this function:

§ TEST() [7/142]

leveldb::TEST ( Coding  ,
Fixed64   
)

Definition at line 27 of file coding_test.cc.

27  {
28  std::string s;
29  for (int power = 0; power <= 63; power++) {
30  uint64_t v = static_cast<uint64_t>(1) << power;
31  PutFixed64(&s, v - 1);
32  PutFixed64(&s, v + 0);
33  PutFixed64(&s, v + 1);
34  }
35 
36  const char* p = s.data();
37  for (int power = 0; power <= 63; power++) {
38  uint64_t v = static_cast<uint64_t>(1) << power;
39  uint64_t actual;
40  actual = DecodeFixed64(p);
41  ASSERT_EQ(v-1, actual);
42  p += sizeof(uint64_t);
43 
44  actual = DecodeFixed64(p);
45  ASSERT_EQ(v+0, actual);
46  p += sizeof(uint64_t);
47 
48  actual = DecodeFixed64(p);
49  ASSERT_EQ(v+1, actual);
50  p += sizeof(uint64_t);
51  }
52 }
uint64_t DecodeFixed64(const char *ptr)
Definition: coding.h:72
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
void PutFixed64(std::string *dst, uint64_t value)
Definition: coding.cc:41
Here is the call graph for this function:

§ TEST() [8/142]

leveldb::TEST ( MemEnvTest  ,
Basics   
)

Definition at line 28 of file memenv_test.cc.

28  {
29  uint64_t file_size;
30  WritableFile* writable_file;
31  std::vector<std::string> children;
32 
33  ASSERT_OK(env_->CreateDir("/dir"));
34 
35  // Check that the directory is empty.
36  ASSERT_TRUE(!env_->FileExists("/dir/non_existent"));
37  ASSERT_TRUE(!env_->GetFileSize("/dir/non_existent", &file_size).ok());
38  ASSERT_OK(env_->GetChildren("/dir", &children));
39  ASSERT_EQ(0, children.size());
40 
41  // Create a file.
42  ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
43  ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
44  ASSERT_EQ(0, file_size);
45  delete writable_file;
46 
47  // Check that the file exists.
48  ASSERT_TRUE(env_->FileExists("/dir/f"));
49  ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
50  ASSERT_EQ(0, file_size);
51  ASSERT_OK(env_->GetChildren("/dir", &children));
52  ASSERT_EQ(1, children.size());
53  ASSERT_EQ("f", children[0]);
54 
55  // Write to the file.
56  ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
57  ASSERT_OK(writable_file->Append("abc"));
58  delete writable_file;
59 
60  // Check that append works.
61  ASSERT_OK(env_->NewAppendableFile("/dir/f", &writable_file));
62  ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
63  ASSERT_EQ(3, file_size);
64  ASSERT_OK(writable_file->Append("hello"));
65  delete writable_file;
66 
67  // Check for expected size.
68  ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
69  ASSERT_EQ(8, file_size);
70 
71  // Check that renaming works.
72  ASSERT_TRUE(!env_->RenameFile("/dir/non_existent", "/dir/g").ok());
73  ASSERT_OK(env_->RenameFile("/dir/f", "/dir/g"));
74  ASSERT_TRUE(!env_->FileExists("/dir/f"));
75  ASSERT_TRUE(env_->FileExists("/dir/g"));
76  ASSERT_OK(env_->GetFileSize("/dir/g", &file_size));
77  ASSERT_EQ(8, file_size);
78 
79  // Check that opening non-existent file fails.
80  SequentialFile* seq_file;
81  RandomAccessFile* rand_file;
82  ASSERT_TRUE(!env_->NewSequentialFile("/dir/non_existent", &seq_file).ok());
83  ASSERT_TRUE(!seq_file);
84  ASSERT_TRUE(!env_->NewRandomAccessFile("/dir/non_existent", &rand_file).ok());
85  ASSERT_TRUE(!rand_file);
86 
87  // Check that deleting works.
88  ASSERT_TRUE(!env_->DeleteFile("/dir/non_existent").ok());
89  ASSERT_OK(env_->DeleteFile("/dir/g"));
90  ASSERT_TRUE(!env_->FileExists("/dir/g"));
91  ASSERT_OK(env_->GetChildren("/dir", &children));
92  ASSERT_EQ(0, children.size());
93  ASSERT_OK(env_->DeleteDir("/dir"));
94 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [9/142]

leveldb::TEST ( EnvPosixTest  ,
RunImmediately   
)

Definition at line 28 of file env_test.cc.

28  {
29  port::AtomicPointer called (NULL);
30  env_->Schedule(&SetBool, &called);
31  Env::Default()->SleepForMicroseconds(kDelayMicros);
32  ASSERT_TRUE(called.NoBarrier_Load() != NULL);
33 }
static void SetBool(void *ptr)
Definition: env_test.cc:24
static const int kDelayMicros
Definition: env_test.cc:12
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [10/142]

leveldb::TEST ( SkipTest  ,
Empty   
)

Definition at line 31 of file skiplist_test.cc.

31  {
32  Arena arena;
33  Comparator cmp;
34  SkipList<Key, Comparator> list(cmp, &arena);
35  ASSERT_TRUE(!list.Contains(10));
36 
37  SkipList<Key, Comparator>::Iterator iter(&list);
38  ASSERT_TRUE(!iter.Valid());
39  iter.SeekToFirst();
40  ASSERT_TRUE(!iter.Valid());
41  iter.Seek(100);
42  ASSERT_TRUE(!iter.Valid());
43  iter.SeekToLast();
44  ASSERT_TRUE(!iter.Valid());
45 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [11/142]

leveldb::TEST ( EnvPosixTest  ,
RunMany   
)

Definition at line 35 of file env_test.cc.

35  {
36  port::AtomicPointer last_id (NULL);
37 
38  struct CB {
39  port::AtomicPointer* last_id_ptr; // Pointer to shared slot
40  uintptr_t id; // Order# for the execution of this callback
41 
42  CB(port::AtomicPointer* p, int i) : last_id_ptr(p), id(i) { }
43 
44  static void Run(void* v) {
45  CB* cb = reinterpret_cast<CB*>(v);
46  void* cur = cb->last_id_ptr->NoBarrier_Load();
47  ASSERT_EQ(cb->id-1, reinterpret_cast<uintptr_t>(cur));
48  cb->last_id_ptr->Release_Store(reinterpret_cast<void*>(cb->id));
49  }
50  };
51 
52  // Schedule in different order than start time
53  CB cb1(&last_id, 1);
54  CB cb2(&last_id, 2);
55  CB cb3(&last_id, 3);
56  CB cb4(&last_id, 4);
57  env_->Schedule(&CB::Run, &cb1);
58  env_->Schedule(&CB::Run, &cb2);
59  env_->Schedule(&CB::Run, &cb3);
60  env_->Schedule(&CB::Run, &cb4);
61 
62  Env::Default()->SleepForMicroseconds(kDelayMicros);
63  void* cur = last_id.Acquire_Load();
64  ASSERT_EQ(4, reinterpret_cast<uintptr_t>(cur));
65 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kDelayMicros
Definition: env_test.cc:12
Here is the call graph for this function:

§ TEST() [12/142]

leveldb::TEST ( FilterBlockTest  ,
EmptyBuilder   
)

Definition at line 46 of file filter_block_test.cc.

46  {
47  FilterBlockBuilder builder(&policy_);
48  Slice block = builder.Finish();
49  ASSERT_EQ("\\x00\\x00\\x00\\x00\\x0b", EscapeString(block));
50  FilterBlockReader reader(&policy_, block);
51  ASSERT_TRUE(reader.KeyMayMatch(0, "foo"));
52  ASSERT_TRUE(reader.KeyMayMatch(100000, "foo"));
53 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
std::string EscapeString(const Slice &value)
Definition: logging.cc:42
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [13/142]

leveldb::TEST ( SkipTest  ,
InsertAndLookup   
)

Definition at line 47 of file skiplist_test.cc.

47  {
48  const int N = 2000;
49  const int R = 5000;
50  Random rnd(1000);
51  std::set<Key> keys;
52  Arena arena;
53  Comparator cmp;
54  SkipList<Key, Comparator> list(cmp, &arena);
55  for (int i = 0; i < N; i++) {
56  Key key = rnd.Next() % R;
57  if (keys.insert(key).second) {
58  list.Insert(key);
59  }
60  }
61 
62  for (int i = 0; i < R; i++) {
63  if (list.Contains(i)) {
64  ASSERT_EQ(keys.count(i), 1);
65  } else {
66  ASSERT_EQ(keys.count(i), 0);
67  }
68  }
69 
70  // Simple iterator tests
71  {
72  SkipList<Key, Comparator>::Iterator iter(&list);
73  ASSERT_TRUE(!iter.Valid());
74 
75  iter.Seek(0);
76  ASSERT_TRUE(iter.Valid());
77  ASSERT_EQ(*(keys.begin()), iter.key());
78 
79  iter.SeekToFirst();
80  ASSERT_TRUE(iter.Valid());
81  ASSERT_EQ(*(keys.begin()), iter.key());
82 
83  iter.SeekToLast();
84  ASSERT_TRUE(iter.Valid());
85  ASSERT_EQ(*(keys.rbegin()), iter.key());
86  }
87 
88  // Forward iteration test
89  for (int i = 0; i < R; i++) {
90  SkipList<Key, Comparator>::Iterator iter(&list);
91  iter.Seek(i);
92 
93  // Compare against model iterator
94  std::set<Key>::iterator model_iter = keys.lower_bound(i);
95  for (int j = 0; j < 3; j++) {
96  if (model_iter == keys.end()) {
97  ASSERT_TRUE(!iter.Valid());
98  break;
99  } else {
100  ASSERT_TRUE(iter.Valid());
101  ASSERT_EQ(*model_iter, iter.key());
102  ++model_iter;
103  iter.Next();
104  }
105  }
106  }
107 
108  // Backward iteration test
109  {
110  SkipList<Key, Comparator>::Iterator iter(&list);
111  iter.SeekToLast();
112 
113  // Compare against model iterator
114  for (std::set<Key>::reverse_iterator model_iter = keys.rbegin();
115  model_iter != keys.rend();
116  ++model_iter) {
117  ASSERT_TRUE(iter.Valid());
118  ASSERT_EQ(*model_iter, iter.key());
119  iter.Prev();
120  }
121  ASSERT_TRUE(!iter.Valid());
122  }
123 }
uint64_t Key
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [14/142]

leveldb::TEST ( FormatTest  ,
InternalKey_EncodeDecode   
)

Definition at line 49 of file dbformat_test.cc.

49  {
50  const char* keys[] = { "", "k", "hello", "longggggggggggggggggggggg" };
51  const uint64_t seq[] = {
52  1, 2, 3,
53  (1ull << 8) - 1, 1ull << 8, (1ull << 8) + 1,
54  (1ull << 16) - 1, 1ull << 16, (1ull << 16) + 1,
55  (1ull << 32) - 1, 1ull << 32, (1ull << 32) + 1
56  };
57  for (int k = 0; k < sizeof(keys) / sizeof(keys[0]); k++) {
58  for (int s = 0; s < sizeof(seq) / sizeof(seq[0]); s++) {
59  TestKey(keys[k], seq[s], kTypeValue);
60  TestKey("hello", 1, kTypeDeletion);
61  }
62  }
63 }
static void TestKey(const std::string &key, uint64_t seq, ValueType vt)
Here is the call graph for this function:

§ TEST() [15/142]

leveldb::TEST ( FindFileTest  ,
Empty   
)

Definition at line 51 of file version_set_test.cc.

51  {
52  ASSERT_EQ(0, Find("foo"));
53  ASSERT_TRUE(! Overlaps("a", "z"));
54  ASSERT_TRUE(! Overlaps(NULL, "z"));
55  ASSERT_TRUE(! Overlaps("a", NULL));
56  ASSERT_TRUE(! Overlaps(NULL, NULL));
57 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [16/142]

leveldb::TEST ( FilterBlockTest  ,
SingleChunk   
)

Definition at line 55 of file filter_block_test.cc.

55  {
56  FilterBlockBuilder builder(&policy_);
57  builder.StartBlock(100);
58  builder.AddKey("foo");
59  builder.AddKey("bar");
60  builder.AddKey("box");
61  builder.StartBlock(200);
62  builder.AddKey("box");
63  builder.StartBlock(300);
64  builder.AddKey("hello");
65  Slice block = builder.Finish();
66  FilterBlockReader reader(&policy_, block);
67  ASSERT_TRUE(reader.KeyMayMatch(100, "foo"));
68  ASSERT_TRUE(reader.KeyMayMatch(100, "bar"));
69  ASSERT_TRUE(reader.KeyMayMatch(100, "box"));
70  ASSERT_TRUE(reader.KeyMayMatch(100, "hello"));
71  ASSERT_TRUE(reader.KeyMayMatch(100, "foo"));
72  ASSERT_TRUE(! reader.KeyMayMatch(100, "missing"));
73  ASSERT_TRUE(! reader.KeyMayMatch(100, "other"));
74 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [17/142]

leveldb::TEST ( Coding  ,
EncodingOutput   
)

Definition at line 55 of file coding_test.cc.

55  {
56  std::string dst;
57  PutFixed32(&dst, 0x04030201);
58  ASSERT_EQ(4, dst.size());
59  ASSERT_EQ(0x01, static_cast<int>(dst[0]));
60  ASSERT_EQ(0x02, static_cast<int>(dst[1]));
61  ASSERT_EQ(0x03, static_cast<int>(dst[2]));
62  ASSERT_EQ(0x04, static_cast<int>(dst[3]));
63 
64  dst.clear();
65  PutFixed64(&dst, 0x0807060504030201ull);
66  ASSERT_EQ(8, dst.size());
67  ASSERT_EQ(0x01, static_cast<int>(dst[0]));
68  ASSERT_EQ(0x02, static_cast<int>(dst[1]));
69  ASSERT_EQ(0x03, static_cast<int>(dst[2]));
70  ASSERT_EQ(0x04, static_cast<int>(dst[3]));
71  ASSERT_EQ(0x05, static_cast<int>(dst[4]));
72  ASSERT_EQ(0x06, static_cast<int>(dst[5]));
73  ASSERT_EQ(0x07, static_cast<int>(dst[6]));
74  ASSERT_EQ(0x08, static_cast<int>(dst[7]));
75 }
void PutFixed32(std::string *dst, uint32_t value)
Definition: coding.cc:35
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
void PutFixed64(std::string *dst, uint64_t value)
Definition: coding.cc:41
Here is the call graph for this function:

§ TEST() [18/142]

leveldb::TEST ( WriteBatchTest  ,
Empty   
)

Definition at line 57 of file write_batch_test.cc.

57  {
58  WriteBatch batch;
59  ASSERT_EQ("", PrintContents(&batch));
60  ASSERT_EQ(0, WriteBatchInternal::Count(&batch));
61 }
static std::string PrintContents(WriteBatch *b)
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [19/142]

leveldb::TEST ( FindFileTest  ,
Single   
)

Definition at line 59 of file version_set_test.cc.

59  {
60  Add("p", "q");
61  ASSERT_EQ(0, Find("a"));
62  ASSERT_EQ(0, Find("p"));
63  ASSERT_EQ(0, Find("p1"));
64  ASSERT_EQ(0, Find("q"));
65  ASSERT_EQ(1, Find("q1"));
66  ASSERT_EQ(1, Find("z"));
67 
68  ASSERT_TRUE(! Overlaps("a", "b"));
69  ASSERT_TRUE(! Overlaps("z1", "z2"));
70  ASSERT_TRUE(Overlaps("a", "p"));
71  ASSERT_TRUE(Overlaps("a", "q"));
72  ASSERT_TRUE(Overlaps("a", "z"));
73  ASSERT_TRUE(Overlaps("p", "p1"));
74  ASSERT_TRUE(Overlaps("p", "q"));
75  ASSERT_TRUE(Overlaps("p", "z"));
76  ASSERT_TRUE(Overlaps("p1", "p2"));
77  ASSERT_TRUE(Overlaps("p1", "z"));
78  ASSERT_TRUE(Overlaps("q", "q"));
79  ASSERT_TRUE(Overlaps("q", "q1"));
80 
81  ASSERT_TRUE(! Overlaps(NULL, "j"));
82  ASSERT_TRUE(! Overlaps("r", NULL));
83  ASSERT_TRUE(Overlaps(NULL, "p"));
84  ASSERT_TRUE(Overlaps(NULL, "p1"));
85  ASSERT_TRUE(Overlaps("q", NULL));
86  ASSERT_TRUE(Overlaps(NULL, NULL));
87 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [20/142]

leveldb::TEST ( WriteBatchTest  ,
Multiple   
)

Definition at line 63 of file write_batch_test.cc.

63  {
64  WriteBatch batch;
65  batch.Put(Slice("foo"), Slice("bar"));
66  batch.Delete(Slice("box"));
67  batch.Put(Slice("baz"), Slice("boo"));
68  WriteBatchInternal::SetSequence(&batch, 100);
69  ASSERT_EQ(100, WriteBatchInternal::Sequence(&batch));
70  ASSERT_EQ(3, WriteBatchInternal::Count(&batch));
71  ASSERT_EQ("Put(baz, boo)@102"
72  "Delete(box)@101"
73  "Put(foo, bar)@100",
74  PrintContents(&batch));
75 }
static std::string PrintContents(WriteBatch *b)
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [21/142]

leveldb::TEST ( FormatTest  ,
InternalKeyShortSeparator   
)

Definition at line 65 of file dbformat_test.cc.

65  {
66  // When user keys are same
67  ASSERT_EQ(IKey("foo", 100, kTypeValue),
68  Shorten(IKey("foo", 100, kTypeValue),
69  IKey("foo", 99, kTypeValue)));
70  ASSERT_EQ(IKey("foo", 100, kTypeValue),
71  Shorten(IKey("foo", 100, kTypeValue),
72  IKey("foo", 101, kTypeValue)));
73  ASSERT_EQ(IKey("foo", 100, kTypeValue),
74  Shorten(IKey("foo", 100, kTypeValue),
75  IKey("foo", 100, kTypeValue)));
76  ASSERT_EQ(IKey("foo", 100, kTypeValue),
77  Shorten(IKey("foo", 100, kTypeValue),
78  IKey("foo", 100, kTypeDeletion)));
79 
80  // When user keys are misordered
81  ASSERT_EQ(IKey("foo", 100, kTypeValue),
82  Shorten(IKey("foo", 100, kTypeValue),
83  IKey("bar", 99, kTypeValue)));
84 
85  // When user keys are different, but correctly ordered
87  Shorten(IKey("foo", 100, kTypeValue),
88  IKey("hello", 200, kTypeValue)));
89 
90  // When start user key is prefix of limit user key
91  ASSERT_EQ(IKey("foo", 100, kTypeValue),
92  Shorten(IKey("foo", 100, kTypeValue),
93  IKey("foobar", 200, kTypeValue)));
94 
95  // When limit user key is prefix of start user key
96  ASSERT_EQ(IKey("foobar", 100, kTypeValue),
97  Shorten(IKey("foobar", 100, kTypeValue),
98  IKey("foo", 200, kTypeValue)));
99 }
static const SequenceNumber kMaxSequenceNumber
Definition: dbformat.h:67
static std::string Shorten(const std::string &s, const std::string &l)
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const ValueType kValueTypeForSeek
Definition: dbformat.h:61
static std::string IKey(const std::string &user_key, uint64_t seq, ValueType vt)
Here is the call graph for this function:

§ TEST() [22/142]

leveldb::TEST ( CacheTest  ,
HitAndMiss   
)

Definition at line 73 of file cache_test.cc.

73  {
74  ASSERT_EQ(-1, Lookup(100));
75 
76  Insert(100, 101);
77  ASSERT_EQ(101, Lookup(100));
78  ASSERT_EQ(-1, Lookup(200));
79  ASSERT_EQ(-1, Lookup(300));
80 
81  Insert(200, 201);
82  ASSERT_EQ(101, Lookup(100));
83  ASSERT_EQ(201, Lookup(200));
84  ASSERT_EQ(-1, Lookup(300));
85 
86  Insert(100, 102);
87  ASSERT_EQ(102, Lookup(100));
88  ASSERT_EQ(201, Lookup(200));
89  ASSERT_EQ(-1, Lookup(300));
90 
91  ASSERT_EQ(1, deleted_keys_.size());
92  ASSERT_EQ(100, deleted_keys_[0]);
93  ASSERT_EQ(101, deleted_values_[0]);
94 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [23/142]

leveldb::TEST ( FilterBlockTest  ,
MultiChunk   
)

Definition at line 76 of file filter_block_test.cc.

76  {
77  FilterBlockBuilder builder(&policy_);
78 
79  // First filter
80  builder.StartBlock(0);
81  builder.AddKey("foo");
82  builder.StartBlock(2000);
83  builder.AddKey("bar");
84 
85  // Second filter
86  builder.StartBlock(3100);
87  builder.AddKey("box");
88 
89  // Third filter is empty
90 
91  // Last filter
92  builder.StartBlock(9000);
93  builder.AddKey("box");
94  builder.AddKey("hello");
95 
96  Slice block = builder.Finish();
97  FilterBlockReader reader(&policy_, block);
98 
99  // Check first filter
100  ASSERT_TRUE(reader.KeyMayMatch(0, "foo"));
101  ASSERT_TRUE(reader.KeyMayMatch(2000, "bar"));
102  ASSERT_TRUE(! reader.KeyMayMatch(0, "box"));
103  ASSERT_TRUE(! reader.KeyMayMatch(0, "hello"));
104 
105  // Check second filter
106  ASSERT_TRUE(reader.KeyMayMatch(3100, "box"));
107  ASSERT_TRUE(! reader.KeyMayMatch(3100, "foo"));
108  ASSERT_TRUE(! reader.KeyMayMatch(3100, "bar"));
109  ASSERT_TRUE(! reader.KeyMayMatch(3100, "hello"));
110 
111  // Check third filter (empty)
112  ASSERT_TRUE(! reader.KeyMayMatch(4100, "foo"));
113  ASSERT_TRUE(! reader.KeyMayMatch(4100, "bar"));
114  ASSERT_TRUE(! reader.KeyMayMatch(4100, "box"));
115  ASSERT_TRUE(! reader.KeyMayMatch(4100, "hello"));
116 
117  // Check last filter
118  ASSERT_TRUE(reader.KeyMayMatch(9000, "box"));
119  ASSERT_TRUE(reader.KeyMayMatch(9000, "hello"));
120  ASSERT_TRUE(! reader.KeyMayMatch(9000, "foo"));
121  ASSERT_TRUE(! reader.KeyMayMatch(9000, "bar"));
122 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [24/142]

leveldb::TEST ( WriteBatchTest  ,
Corruption   
)

Definition at line 77 of file write_batch_test.cc.

77  {
78  WriteBatch batch;
79  batch.Put(Slice("foo"), Slice("bar"));
80  batch.Delete(Slice("box"));
81  WriteBatchInternal::SetSequence(&batch, 200);
82  Slice contents = WriteBatchInternal::Contents(&batch);
83  WriteBatchInternal::SetContents(&batch,
84  Slice(contents.data(),contents.size()-1));
85  ASSERT_EQ("Put(foo, bar)@200"
86  "ParseError()",
87  PrintContents(&batch));
88 }
static std::string PrintContents(WriteBatch *b)
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [25/142]

leveldb::TEST ( FileNameTest  ,
Construction   
)

Definition at line 77 of file filename_test.cc.

77  {
78  uint64_t number;
79  FileType type;
80  std::string fname;
81 
82  fname = CurrentFileName("foo");
83  ASSERT_EQ("foo/", std::string(fname.data(), 4));
84  ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));
85  ASSERT_EQ(0, number);
86  ASSERT_EQ(kCurrentFile, type);
87 
88  fname = LockFileName("foo");
89  ASSERT_EQ("foo/", std::string(fname.data(), 4));
90  ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));
91  ASSERT_EQ(0, number);
92  ASSERT_EQ(kDBLockFile, type);
93 
94  fname = LogFileName("foo", 192);
95  ASSERT_EQ("foo/", std::string(fname.data(), 4));
96  ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));
97  ASSERT_EQ(192, number);
98  ASSERT_EQ(kLogFile, type);
99 
100  fname = TableFileName("bar", 200);
101  ASSERT_EQ("bar/", std::string(fname.data(), 4));
102  ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));
103  ASSERT_EQ(200, number);
104  ASSERT_EQ(kTableFile, type);
105 
106  fname = DescriptorFileName("bar", 100);
107  ASSERT_EQ("bar/", std::string(fname.data(), 4));
108  ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));
109  ASSERT_EQ(100, number);
110  ASSERT_EQ(kDescriptorFile, type);
111 
112  fname = TempFileName("tmp", 999);
113  ASSERT_EQ("tmp/", std::string(fname.data(), 4));
114  ASSERT_TRUE(ParseFileName(fname.c_str() + 4, &number, &type));
115  ASSERT_EQ(999, number);
116  ASSERT_EQ(kTempFile, type);
117 }
bool ParseFileName(const std::string &fname, uint64_t *number, FileType *type)
Definition: filename.cc:80
std::string TempFileName(const std::string &dbname, uint64_t number)
Definition: filename.cc:58
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
std::string TableFileName(const std::string &name, uint64_t number)
Definition: filename.cc:32
std::string DescriptorFileName(const std::string &dbname, uint64_t number)
Definition: filename.cc:42
std::string CurrentFileName(const std::string &dbname)
Definition: filename.cc:50
#define ASSERT_TRUE(c)
Definition: testharness.h:105
std::string LogFileName(const std::string &name, uint64_t number)
Definition: filename.cc:27
FileType
Definition: filename.h:20
std::string LockFileName(const std::string &dbname)
Definition: filename.cc:54
Here is the call graph for this function:

§ TEST() [26/142]

leveldb::TEST ( Coding  ,
Varint32   
)

Definition at line 77 of file coding_test.cc.

77  {
78  std::string s;
79  for (uint32_t i = 0; i < (32 * 32); i++) {
80  uint32_t v = (i / 32) << (i % 32);
81  PutVarint32(&s, v);
82  }
83 
84  const char* p = s.data();
85  const char* limit = p + s.size();
86  for (uint32_t i = 0; i < (32 * 32); i++) {
87  uint32_t expected = (i / 32) << (i % 32);
88  uint32_t actual;
89  const char* start = p;
90  p = GetVarint32Ptr(p, limit, &actual);
91  ASSERT_TRUE(p != NULL);
92  ASSERT_EQ(expected, actual);
93  ASSERT_EQ(VarintLength(actual), p - start);
94  }
95  ASSERT_EQ(p, s.data() + s.size());
96 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
int VarintLength(uint64_t v)
Definition: coding.cc:103
void PutVarint32(std::string *dst, uint32_t v)
Definition: coding.cc:75
Here is the call graph for this function:

§ TEST() [27/142]

leveldb::TEST ( EnvPosixTest  ,
StartThread   
)

Definition at line 81 of file env_test.cc.

81  {
82  State state;
83  state.val = 0;
84  state.num_running = 3;
85  for (int i = 0; i < 3; i++) {
86  env_->StartThread(&ThreadBody, &state);
87  }
88  while (true) {
89  state.mu.Lock();
90  int num = state.num_running;
91  state.mu.Unlock();
92  if (num == 0) {
93  break;
94  }
95  Env::Default()->SleepForMicroseconds(kDelayMicros);
96  }
97  ASSERT_EQ(state.val, 3);
98 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kDelayMicros
Definition: env_test.cc:12
static void ThreadBody(void *arg)
Definition: env_test.cc:73
Here is the call graph for this function:

§ TEST() [28/142]

leveldb::TEST ( BloomTest  ,
EmptyFilter   
)

Definition at line 89 of file bloom_test.cc.

89  {
90  ASSERT_TRUE(! Matches("hello"));
91  ASSERT_TRUE(! Matches("world"));
92 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [29/142]

leveldb::TEST ( FindFileTest  ,
Multiple   
)

Definition at line 90 of file version_set_test.cc.

90  {
91  Add("150", "200");
92  Add("200", "250");
93  Add("300", "350");
94  Add("400", "450");
95  ASSERT_EQ(0, Find("100"));
96  ASSERT_EQ(0, Find("150"));
97  ASSERT_EQ(0, Find("151"));
98  ASSERT_EQ(0, Find("199"));
99  ASSERT_EQ(0, Find("200"));
100  ASSERT_EQ(1, Find("201"));
101  ASSERT_EQ(1, Find("249"));
102  ASSERT_EQ(1, Find("250"));
103  ASSERT_EQ(2, Find("251"));
104  ASSERT_EQ(2, Find("299"));
105  ASSERT_EQ(2, Find("300"));
106  ASSERT_EQ(2, Find("349"));
107  ASSERT_EQ(2, Find("350"));
108  ASSERT_EQ(3, Find("351"));
109  ASSERT_EQ(3, Find("400"));
110  ASSERT_EQ(3, Find("450"));
111  ASSERT_EQ(4, Find("451"));
112 
113  ASSERT_TRUE(! Overlaps("100", "149"));
114  ASSERT_TRUE(! Overlaps("251", "299"));
115  ASSERT_TRUE(! Overlaps("451", "500"));
116  ASSERT_TRUE(! Overlaps("351", "399"));
117 
118  ASSERT_TRUE(Overlaps("100", "150"));
119  ASSERT_TRUE(Overlaps("100", "200"));
120  ASSERT_TRUE(Overlaps("100", "300"));
121  ASSERT_TRUE(Overlaps("100", "400"));
122  ASSERT_TRUE(Overlaps("100", "500"));
123  ASSERT_TRUE(Overlaps("375", "400"));
124  ASSERT_TRUE(Overlaps("450", "450"));
125  ASSERT_TRUE(Overlaps("450", "500"));
126 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [30/142]

leveldb::TEST ( WriteBatchTest  ,
Append   
)

Definition at line 90 of file write_batch_test.cc.

90  {
91  WriteBatch b1, b2;
92  WriteBatchInternal::SetSequence(&b1, 200);
93  WriteBatchInternal::SetSequence(&b2, 300);
94  WriteBatchInternal::Append(&b1, &b2);
95  ASSERT_EQ("",
96  PrintContents(&b1));
97  b2.Put("a", "va");
98  WriteBatchInternal::Append(&b1, &b2);
99  ASSERT_EQ("Put(a, va)@200",
100  PrintContents(&b1));
101  b2.Clear();
102  b2.Put("b", "vb");
103  WriteBatchInternal::Append(&b1, &b2);
104  ASSERT_EQ("Put(a, va)@200"
105  "Put(b, vb)@201",
106  PrintContents(&b1));
107  b2.Delete("foo");
108  WriteBatchInternal::Append(&b1, &b2);
109  ASSERT_EQ("Put(a, va)@200"
110  "Put(b, vb)@202"
111  "Put(b, vb)@201"
112  "Delete(foo)@203",
113  PrintContents(&b1));
114 }
static std::string PrintContents(WriteBatch *b)
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [31/142]

leveldb::TEST ( BloomTest  ,
Small   
)

Definition at line 94 of file bloom_test.cc.

94  {
95  Add("hello");
96  Add("world");
97  ASSERT_TRUE(Matches("hello"));
98  ASSERT_TRUE(Matches("world"));
99  ASSERT_TRUE(! Matches("x"));
100  ASSERT_TRUE(! Matches("foo"));
101 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [32/142]

leveldb::TEST ( MemEnvTest  ,
ReadWrite   
)

Definition at line 96 of file memenv_test.cc.

96  {
97  WritableFile* writable_file;
98  SequentialFile* seq_file;
99  RandomAccessFile* rand_file;
100  Slice result;
101  char scratch[100];
102 
103  ASSERT_OK(env_->CreateDir("/dir"));
104 
105  ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
106  ASSERT_OK(writable_file->Append("hello "));
107  ASSERT_OK(writable_file->Append("world"));
108  delete writable_file;
109 
110  // Read sequentially.
111  ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
112  ASSERT_OK(seq_file->Read(5, &result, scratch)); // Read "hello".
113  ASSERT_EQ(0, result.compare("hello"));
114  ASSERT_OK(seq_file->Skip(1));
115  ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Read "world".
116  ASSERT_EQ(0, result.compare("world"));
117  ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Try reading past EOF.
118  ASSERT_EQ(0, result.size());
119  ASSERT_OK(seq_file->Skip(100)); // Try to skip past end of file.
120  ASSERT_OK(seq_file->Read(1000, &result, scratch));
121  ASSERT_EQ(0, result.size());
122  delete seq_file;
123 
124  // Random reads.
125  ASSERT_OK(env_->NewRandomAccessFile("/dir/f", &rand_file));
126  ASSERT_OK(rand_file->Read(6, 5, &result, scratch)); // Read "world".
127  ASSERT_EQ(0, result.compare("world"));
128  ASSERT_OK(rand_file->Read(0, 5, &result, scratch)); // Read "hello".
129  ASSERT_EQ(0, result.compare("hello"));
130  ASSERT_OK(rand_file->Read(10, 100, &result, scratch)); // Read "d".
131  ASSERT_EQ(0, result.compare("d"));
132 
133  // Too high offset.
134  ASSERT_TRUE(!rand_file->Read(1000, 5, &result, scratch).ok());
135  delete rand_file;
136 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [33/142]

leveldb::TEST ( CacheTest  ,
Erase   
)

Definition at line 96 of file cache_test.cc.

96  {
97  Erase(200);
98  ASSERT_EQ(0, deleted_keys_.size());
99 
100  Insert(100, 101);
101  Insert(200, 201);
102  Erase(100);
103  ASSERT_EQ(-1, Lookup(100));
104  ASSERT_EQ(201, Lookup(200));
105  ASSERT_EQ(1, deleted_keys_.size());
106  ASSERT_EQ(100, deleted_keys_[0]);
107  ASSERT_EQ(101, deleted_values_[0]);
108 
109  Erase(100);
110  ASSERT_EQ(-1, Lookup(100));
111  ASSERT_EQ(201, Lookup(200));
112  ASSERT_EQ(1, deleted_keys_.size());
113 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [34/142]

leveldb::TEST ( Coding  ,
Varint64   
)

Definition at line 98 of file coding_test.cc.

98  {
99  // Construct the list of values to check
100  std::vector<uint64_t> values;
101  // Some special values
102  values.push_back(0);
103  values.push_back(100);
104  values.push_back(~static_cast<uint64_t>(0));
105  values.push_back(~static_cast<uint64_t>(0) - 1);
106  for (uint32_t k = 0; k < 64; k++) {
107  // Test values near powers of two
108  const uint64_t power = 1ull << k;
109  values.push_back(power);
110  values.push_back(power-1);
111  values.push_back(power+1);
112  }
113 
114  std::string s;
115  for (size_t i = 0; i < values.size(); i++) {
116  PutVarint64(&s, values[i]);
117  }
118 
119  const char* p = s.data();
120  const char* limit = p + s.size();
121  for (size_t i = 0; i < values.size(); i++) {
122  ASSERT_TRUE(p < limit);
123  uint64_t actual;
124  const char* start = p;
125  p = GetVarint64Ptr(p, limit, &actual);
126  ASSERT_TRUE(p != NULL);
127  ASSERT_EQ(values[i], actual);
128  ASSERT_EQ(VarintLength(actual), p - start);
129  }
130  ASSERT_EQ(p, limit);
131 
132 }
void PutVarint64(std::string *dst, uint64_t v)
Definition: coding.cc:92
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
const char * GetVarint64Ptr(const char *p, const char *limit, uint64_t *value)
Definition: coding.cc:143
#define ASSERT_TRUE(c)
Definition: testharness.h:105
int VarintLength(uint64_t v)
Definition: coding.cc:103
Here is the call graph for this function:

§ TEST() [35/142]

leveldb::TEST ( FormatTest  ,
InternalKeyShortestSuccessor   
)

Definition at line 101 of file dbformat_test.cc.

101  {
103  ShortSuccessor(IKey("foo", 100, kTypeValue)));
104  ASSERT_EQ(IKey("\xff\xff", 100, kTypeValue),
105  ShortSuccessor(IKey("\xff\xff", 100, kTypeValue)));
106 }
static const SequenceNumber kMaxSequenceNumber
Definition: dbformat.h:67
static std::string ShortSuccessor(const std::string &s)
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const ValueType kValueTypeForSeek
Definition: dbformat.h:61
static std::string IKey(const std::string &user_key, uint64_t seq, ValueType vt)
Here is the call graph for this function:

§ TEST() [36/142]

leveldb::TEST ( AutoCompactTest  ,
ReadAll   
)

Definition at line 106 of file autocompact_test.cc.

106  {
107  DoReads(kCount);
108 }
static const int kCount
Here is the call graph for this function:

§ TEST() [37/142]

leveldb::TEST ( AutoCompactTest  ,
ReadHalf   
)

Definition at line 110 of file autocompact_test.cc.

110  {
111  DoReads(kCount/2);
112 }
static const int kCount
Here is the call graph for this function:

§ TEST() [38/142]

leveldb::TEST ( CacheTest  ,
EntriesArePinned   
)

Definition at line 115 of file cache_test.cc.

115  {
116  Insert(100, 101);
117  Cache::Handle* h1 = cache_->Lookup(EncodeKey(100));
118  ASSERT_EQ(101, DecodeValue(cache_->Value(h1)));
119 
120  Insert(100, 102);
121  Cache::Handle* h2 = cache_->Lookup(EncodeKey(100));
122  ASSERT_EQ(102, DecodeValue(cache_->Value(h2)));
123  ASSERT_EQ(0, deleted_keys_.size());
124 
125  cache_->Release(h1);
126  ASSERT_EQ(1, deleted_keys_.size());
127  ASSERT_EQ(100, deleted_keys_[0]);
128  ASSERT_EQ(101, deleted_values_[0]);
129 
130  Erase(100);
131  ASSERT_EQ(-1, Lookup(100));
132  ASSERT_EQ(1, deleted_keys_.size());
133 
134  cache_->Release(h2);
135  ASSERT_EQ(2, deleted_keys_.size());
136  ASSERT_EQ(100, deleted_keys_[1]);
137  ASSERT_EQ(102, deleted_values_[1]);
138 }
static int DecodeValue(void *v)
Definition: cache_test.cc:24
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static std::string EncodeKey(int k)
Definition: cache_test.cc:14
Here is the call graph for this function:

§ TEST() [39/142]

leveldb::TEST ( BloomTest  ,
VaryingLengths   
)

Definition at line 116 of file bloom_test.cc.

116  {
117  char buffer[sizeof(int)];
118 
119  // Count number of filters that significantly exceed the false positive rate
120  int mediocre_filters = 0;
121  int good_filters = 0;
122 
123  for (int length = 1; length <= 10000; length = NextLength(length)) {
124  Reset();
125  for (int i = 0; i < length; i++) {
126  Add(Key(i, buffer));
127  }
128  Build();
129 
130  ASSERT_LE(FilterSize(), static_cast<size_t>((length * 10 / 8) + 40))
131  << length;
132 
133  // All added keys must match
134  for (int i = 0; i < length; i++) {
135  ASSERT_TRUE(Matches(Key(i, buffer)))
136  << "Length " << length << "; key " << i;
137  }
138 
139  // Check false positive rate
140  double rate = FalsePositiveRate();
141  if (kVerbose >= 1) {
142  fprintf(stderr, "False positives: %5.2f%% @ length = %6d ; bytes = %6d\n",
143  rate*100.0, length, static_cast<int>(FilterSize()));
144  }
145  ASSERT_LE(rate, 0.02); // Must not be over 2%
146  if (rate > 0.0125) mediocre_filters++; // Allowed, but not too often
147  else good_filters++;
148  }
149  if (kVerbose >= 1) {
150  fprintf(stderr, "Filters: %d good, %d mediocre\n",
151  good_filters, mediocre_filters);
152  }
153  ASSERT_LE(mediocre_filters, good_filters/5);
154 }
#define ASSERT_LE(a, b)
Definition: testharness.h:111
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static Slice Key(int i, char *buffer)
Definition: bloom_test.cc:16
static int NextLength(int length)
Definition: bloom_test.cc:103
static const int kVerbose
Definition: bloom_test.cc:14
Here is the call graph for this function:

§ TEST() [40/142]

leveldb::TEST ( FindFileTest  ,
MultipleNullBoundaries   
)

Definition at line 128 of file version_set_test.cc.

128  {
129  Add("150", "200");
130  Add("200", "250");
131  Add("300", "350");
132  Add("400", "450");
133  ASSERT_TRUE(! Overlaps(NULL, "149"));
134  ASSERT_TRUE(! Overlaps("451", NULL));
135  ASSERT_TRUE(Overlaps(NULL, NULL));
136  ASSERT_TRUE(Overlaps(NULL, "150"));
137  ASSERT_TRUE(Overlaps(NULL, "199"));
138  ASSERT_TRUE(Overlaps(NULL, "200"));
139  ASSERT_TRUE(Overlaps(NULL, "201"));
140  ASSERT_TRUE(Overlaps(NULL, "400"));
141  ASSERT_TRUE(Overlaps(NULL, "800"));
142  ASSERT_TRUE(Overlaps("100", NULL));
143  ASSERT_TRUE(Overlaps("200", NULL));
144  ASSERT_TRUE(Overlaps("449", NULL));
145  ASSERT_TRUE(Overlaps("450", NULL));
146 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [41/142]

leveldb::TEST ( Coding  ,
Varint32Overflow   
)

Definition at line 134 of file coding_test.cc.

134  {
135  uint32_t result;
136  std::string input("\x81\x82\x83\x84\x85\x11");
137  ASSERT_TRUE(GetVarint32Ptr(input.data(), input.data() + input.size(), &result)
138  == NULL);
139 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [42/142]

leveldb::TEST ( MemEnvTest  ,
Locks   
)

Definition at line 138 of file memenv_test.cc.

138  {
139  FileLock* lock;
140 
141  // These are no-ops, but we test they return success.
142  ASSERT_OK(env_->LockFile("some file", &lock));
143  ASSERT_OK(env_->UnlockFile(lock));
144 }
#define ASSERT_OK(s)
Definition: testharness.h:106
Here is the call graph for this function:

§ TEST() [43/142]

leveldb::TEST ( CacheTest  ,
EvictionPolicy   
)

Definition at line 140 of file cache_test.cc.

140  {
141  Insert(100, 101);
142  Insert(200, 201);
143  Insert(300, 301);
144  Cache::Handle* h = cache_->Lookup(EncodeKey(300));
145 
146  // Frequently used entry must be kept around,
147  // as must things that are still in use.
148  for (int i = 0; i < kCacheSize + 100; i++) {
149  Insert(1000+i, 2000+i);
150  ASSERT_EQ(2000+i, Lookup(1000+i));
151  ASSERT_EQ(101, Lookup(100));
152  }
153  ASSERT_EQ(101, Lookup(100));
154  ASSERT_EQ(-1, Lookup(200));
155  ASSERT_EQ(301, Lookup(300));
156  cache_->Release(h);
157 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static std::string EncodeKey(int k)
Definition: cache_test.cc:14
Here is the call graph for this function:

§ TEST() [44/142]

leveldb::TEST ( Coding  ,
Varint32Truncation   
)

Definition at line 141 of file coding_test.cc.

141  {
142  uint32_t large_value = (1u << 31) + 100;
143  std::string s;
144  PutVarint32(&s, large_value);
145  uint32_t result;
146  for (size_t len = 0; len < s.size() - 1; len++) {
147  ASSERT_TRUE(GetVarint32Ptr(s.data(), s.data() + len, &result) == NULL);
148  }
149  ASSERT_TRUE(GetVarint32Ptr(s.data(), s.data() + s.size(), &result) != NULL);
150  ASSERT_EQ(large_value, result);
151 }
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
Definition: coding.h:89
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
void PutVarint32(std::string *dst, uint32_t v)
Definition: coding.cc:75
Here is the call graph for this function:

§ TEST() [45/142]

leveldb::TEST ( MemEnvTest  ,
Misc   
)

Definition at line 146 of file memenv_test.cc.

146  {
147  std::string test_dir;
148  ASSERT_OK(env_->GetTestDirectory(&test_dir));
149  ASSERT_TRUE(!test_dir.empty());
150 
151  WritableFile* writable_file;
152  ASSERT_OK(env_->NewWritableFile("/a/b", &writable_file));
153 
154  // These are no-ops, but we test they return success.
155  ASSERT_OK(writable_file->Sync());
156  ASSERT_OK(writable_file->Flush());
157  ASSERT_OK(writable_file->Close());
158  delete writable_file;
159 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [46/142]

leveldb::TEST ( FindFileTest  ,
OverlapSequenceChecks   
)

Definition at line 148 of file version_set_test.cc.

148  {
149  Add("200", "200", 5000, 3000);
150  ASSERT_TRUE(! Overlaps("199", "199"));
151  ASSERT_TRUE(! Overlaps("201", "300"));
152  ASSERT_TRUE(Overlaps("200", "200"));
153  ASSERT_TRUE(Overlaps("190", "200"));
154  ASSERT_TRUE(Overlaps("200", "210"));
155 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [47/142]

leveldb::TEST ( Coding  ,
Varint64Overflow   
)

Definition at line 153 of file coding_test.cc.

153  {
154  uint64_t result;
155  std::string input("\x81\x82\x83\x84\x85\x81\x82\x83\x84\x85\x11");
156  ASSERT_TRUE(GetVarint64Ptr(input.data(), input.data() + input.size(), &result)
157  == NULL);
158 }
const char * GetVarint64Ptr(const char *p, const char *limit, uint64_t *value)
Definition: coding.cc:143
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [48/142]

leveldb::TEST ( FindFileTest  ,
OverlappingFiles   
)

Definition at line 157 of file version_set_test.cc.

157  {
158  Add("150", "600");
159  Add("400", "500");
160  disjoint_sorted_files_ = false;
161  ASSERT_TRUE(! Overlaps("100", "149"));
162  ASSERT_TRUE(! Overlaps("601", "700"));
163  ASSERT_TRUE(Overlaps("100", "150"));
164  ASSERT_TRUE(Overlaps("100", "200"));
165  ASSERT_TRUE(Overlaps("100", "300"));
166  ASSERT_TRUE(Overlaps("100", "400"));
167  ASSERT_TRUE(Overlaps("100", "500"));
168  ASSERT_TRUE(Overlaps("375", "400"));
169  ASSERT_TRUE(Overlaps("450", "450"));
170  ASSERT_TRUE(Overlaps("450", "500"));
171  ASSERT_TRUE(Overlaps("450", "700"));
172  ASSERT_TRUE(Overlaps("600", "700"));
173 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [49/142]

leveldb::TEST ( CacheTest  ,
UseExceedsCacheSize   
)

Definition at line 159 of file cache_test.cc.

159  {
160  // Overfill the cache, keeping handles on all inserted entries.
161  std::vector<Cache::Handle*> h;
162  for (int i = 0; i < kCacheSize + 100; i++) {
163  h.push_back(InsertAndReturnHandle(1000+i, 2000+i));
164  }
165 
166  // Check that all the entries can be found in the cache.
167  for (int i = 0; i < h.size(); i++) {
168  ASSERT_EQ(2000+i, Lookup(1000+i));
169  }
170 
171  for (int i = 0; i < h.size(); i++) {
172  cache_->Release(h[i]);
173  }
174 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [50/142]

leveldb::TEST ( RecoveryTest  ,
ManifestReused   
)

Definition at line 159 of file recovery_test.cc.

159  {
160  if (!CanAppend()) {
161  fprintf(stderr, "skipping test because env does not support appending\n");
162  return;
163  }
164  ASSERT_OK(Put("foo", "bar"));
165  Close();
166  std::string old_manifest = ManifestFileName();
167  Open();
168  ASSERT_EQ(old_manifest, ManifestFileName());
169  ASSERT_EQ("bar", Get("foo"));
170  Open();
171  ASSERT_EQ(old_manifest, ManifestFileName());
172  ASSERT_EQ("bar", Get("foo"));
173 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [51/142]

leveldb::TEST ( Coding  ,
Varint64Truncation   
)

Definition at line 160 of file coding_test.cc.

160  {
161  uint64_t large_value = (1ull << 63) + 100ull;
162  std::string s;
163  PutVarint64(&s, large_value);
164  uint64_t result;
165  for (size_t len = 0; len < s.size() - 1; len++) {
166  ASSERT_TRUE(GetVarint64Ptr(s.data(), s.data() + len, &result) == NULL);
167  }
168  ASSERT_TRUE(GetVarint64Ptr(s.data(), s.data() + s.size(), &result) != NULL);
169  ASSERT_EQ(large_value, result);
170 }
void PutVarint64(std::string *dst, uint64_t v)
Definition: coding.cc:92
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
const char * GetVarint64Ptr(const char *p, const char *limit, uint64_t *value)
Definition: coding.cc:143
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [52/142]

leveldb::TEST ( MemEnvTest  ,
LargeWrite   
)

Definition at line 161 of file memenv_test.cc.

161  {
162  const size_t kWriteSize = 300 * 1024;
163  char* scratch = new char[kWriteSize * 2];
164 
165  std::string write_data;
166  for (size_t i = 0; i < kWriteSize; ++i) {
167  write_data.append(1, static_cast<char>(i));
168  }
169 
170  WritableFile* writable_file;
171  ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
172  ASSERT_OK(writable_file->Append("foo"));
173  ASSERT_OK(writable_file->Append(write_data));
174  delete writable_file;
175 
176  SequentialFile* seq_file;
177  Slice result;
178  ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
179  ASSERT_OK(seq_file->Read(3, &result, scratch)); // Read "foo".
180  ASSERT_EQ(0, result.compare("foo"));
181 
182  size_t read = 0;
183  std::string read_data;
184  while (read < kWriteSize) {
185  ASSERT_OK(seq_file->Read(kWriteSize - read, &result, scratch));
186  read_data.append(result.data(), result.size());
187  read += result.size();
188  }
189  ASSERT_TRUE(write_data == read_data);
190  delete seq_file;
191  delete [] scratch;
192 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [53/142]

leveldb::TEST ( Coding  ,
Strings   
)

Definition at line 172 of file coding_test.cc.

172  {
173  std::string s;
174  PutLengthPrefixedSlice(&s, Slice(""));
175  PutLengthPrefixedSlice(&s, Slice("foo"));
176  PutLengthPrefixedSlice(&s, Slice("bar"));
177  PutLengthPrefixedSlice(&s, Slice(std::string(200, 'x')));
178 
179  Slice input(s);
180  Slice v;
181  ASSERT_TRUE(GetLengthPrefixedSlice(&input, &v));
182  ASSERT_EQ("", v.ToString());
183  ASSERT_TRUE(GetLengthPrefixedSlice(&input, &v));
184  ASSERT_EQ("foo", v.ToString());
185  ASSERT_TRUE(GetLengthPrefixedSlice(&input, &v));
186  ASSERT_EQ("bar", v.ToString());
187  ASSERT_TRUE(GetLengthPrefixedSlice(&input, &v));
188  ASSERT_EQ(std::string(200, 'x'), v.ToString());
189  ASSERT_EQ("", input.ToString());
190 }
static Slice GetLengthPrefixedSlice(const char *data)
Definition: memtable.cc:14
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
void PutLengthPrefixedSlice(std::string *dst, const Slice &value)
Definition: coding.cc:98
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [54/142]

leveldb::TEST ( RecoveryTest  ,
LargeManifestCompacted   
)

Definition at line 175 of file recovery_test.cc.

175  {
176  if (!CanAppend()) {
177  fprintf(stderr, "skipping test because env does not support appending\n");
178  return;
179  }
180  ASSERT_OK(Put("foo", "bar"));
181  Close();
182  std::string old_manifest = ManifestFileName();
183 
184  // Pad with zeroes to make manifest file very big.
185  {
186  uint64_t len = FileSize(old_manifest);
187  WritableFile* file;
188  ASSERT_OK(env()->NewAppendableFile(old_manifest, &file));
189  std::string zeroes(3*1048576 - static_cast<size_t>(len), 0);
190  ASSERT_OK(file->Append(zeroes));
191  ASSERT_OK(file->Flush());
192  delete file;
193  }
194 
195  Open();
196  std::string new_manifest = ManifestFileName();
197  ASSERT_NE(old_manifest, new_manifest);
198  ASSERT_GT(10000, FileSize(new_manifest));
199  ASSERT_EQ("bar", Get("foo"));
200 
201  Open();
202  ASSERT_EQ(new_manifest, ManifestFileName());
203  ASSERT_EQ("bar", Get("foo"));
204 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_NE(a, b)
Definition: testharness.h:108
Here is the call graph for this function:

§ TEST() [55/142]

leveldb::TEST ( CacheTest  ,
HeavyEntries   
)

Definition at line 176 of file cache_test.cc.

176  {
177  // Add a bunch of light and heavy entries and then count the combined
178  // size of items still in the cache, which must be approximately the
179  // same as the total capacity.
180  const int kLight = 1;
181  const int kHeavy = 10;
182  int added = 0;
183  int index = 0;
184  while (added < 2*kCacheSize) {
185  const int weight = (index & 1) ? kLight : kHeavy;
186  Insert(index, 1000+index, weight);
187  added += weight;
188  index++;
189  }
190 
191  int cached_weight = 0;
192  for (int i = 0; i < index; i++) {
193  const int weight = (i & 1 ? kLight : kHeavy);
194  int r = Lookup(i);
195  if (r >= 0) {
196  cached_weight += weight;
197  ASSERT_EQ(1000+i, r);
198  }
199  }
200  ASSERT_LE(cached_weight, kCacheSize + kCacheSize/10);
201 }
#define ASSERT_LE(a, b)
Definition: testharness.h:111
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [56/142]

leveldb::TEST ( MemEnvTest  ,
DBTest   
)

Definition at line 194 of file memenv_test.cc.

194  {
195  Options options;
196  options.create_if_missing = true;
197  options.env = env_;
198  DB* db;
199 
200  const Slice keys[] = {Slice("aaa"), Slice("bbb"), Slice("ccc")};
201  const Slice vals[] = {Slice("foo"), Slice("bar"), Slice("baz")};
202 
203  ASSERT_OK(DB::Open(options, "/dir/db", &db));
204  for (size_t i = 0; i < 3; ++i) {
205  ASSERT_OK(db->Put(WriteOptions(), keys[i], vals[i]));
206  }
207 
208  for (size_t i = 0; i < 3; ++i) {
209  std::string res;
210  ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
211  ASSERT_TRUE(res == vals[i]);
212  }
213 
214  Iterator* iterator = db->NewIterator(ReadOptions());
215  iterator->SeekToFirst();
216  for (size_t i = 0; i < 3; ++i) {
217  ASSERT_TRUE(iterator->Valid());
218  ASSERT_TRUE(keys[i] == iterator->key());
219  ASSERT_TRUE(vals[i] == iterator->value());
220  iterator->Next();
221  }
222  ASSERT_TRUE(!iterator->Valid());
223  delete iterator;
224 
225  DBImpl* dbi = reinterpret_cast<DBImpl*>(db);
226  ASSERT_OK(dbi->TEST_CompactMemTable());
227 
228  for (size_t i = 0; i < 3; ++i) {
229  std::string res;
230  ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
231  ASSERT_TRUE(res == vals[i]);
232  }
233 
234  delete db;
235 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [57/142]

leveldb::TEST ( CorruptionTest  ,
Recovery   
)

Definition at line 202 of file corruption_test.cc.

202  {
203  Build(100);
204  Check(100, 100);
205  Corrupt(kLogFile, 19, 1); // WriteBatch tag for first record
206  Corrupt(kLogFile, log::kBlockSize + 1000, 1); // Somewhere in second block
207  Reopen();
208 
209  // The 64 records in the first two log blocks are completely lost.
210  Check(36, 36);
211 }
static const int kBlockSize
Definition: log_format.h:27
Here is the call graph for this function:

§ TEST() [58/142]

leveldb::TEST ( CacheTest  ,
NewId   
)

Definition at line 203 of file cache_test.cc.

203  {
204  uint64_t a = cache_->NewId();
205  uint64_t b = cache_->NewId();
206  ASSERT_NE(a, b);
207 }
#define ASSERT_NE(a, b)
Definition: testharness.h:108
Here is the call graph for this function:

§ TEST() [59/142]

leveldb::TEST ( RecoveryTest  ,
NoLogFiles   
)

Definition at line 206 of file recovery_test.cc.

206  {
207  ASSERT_OK(Put("foo", "bar"));
208  ASSERT_EQ(1, DeleteLogFiles());
209  Open();
210  ASSERT_EQ("NOT_FOUND", Get("foo"));
211  Open();
212  ASSERT_EQ("NOT_FOUND", Get("foo"));
213 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [60/142]

leveldb::TEST ( CacheTest  ,
Prune   
)

Definition at line 209 of file cache_test.cc.

209  {
210  Insert(1, 100);
211  Insert(2, 200);
212 
213  Cache::Handle* handle = cache_->Lookup(EncodeKey(1));
214  ASSERT_TRUE(handle);
215  cache_->Prune();
216  cache_->Release(handle);
217 
218  ASSERT_EQ(100, Lookup(1));
219  ASSERT_EQ(-1, Lookup(2));
220 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static std::string EncodeKey(int k)
Definition: cache_test.cc:14
Here is the call graph for this function:

§ TEST() [61/142]

leveldb::TEST ( CorruptionTest  ,
RecoverWriteError   
)

Definition at line 213 of file corruption_test.cc.

213  {
214  env_.writable_file_error_ = true;
215  Status s = TryReopen();
216  ASSERT_TRUE(!s.ok());
217 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [62/142]

leveldb::TEST ( RecoveryTest  ,
LogFileReuse   
)

Definition at line 215 of file recovery_test.cc.

215  {
216  if (!CanAppend()) {
217  fprintf(stderr, "skipping test because env does not support appending\n");
218  return;
219  }
220  for (int i = 0; i < 2; i++) {
221  ASSERT_OK(Put("foo", "bar"));
222  if (i == 0) {
223  // Compact to ensure current log is empty
224  CompactMemTable();
225  }
226  Close();
227  ASSERT_EQ(1, NumLogs());
228  uint64_t number = FirstLogFile();
229  if (i == 0) {
230  ASSERT_EQ(0, FileSize(LogName(number)));
231  } else {
232  ASSERT_LT(0, FileSize(LogName(number)));
233  }
234  Open();
235  ASSERT_EQ(1, NumLogs());
236  ASSERT_EQ(number, FirstLogFile()) << "did not reuse log file";
237  ASSERT_EQ("bar", Get("foo"));
238  Open();
239  ASSERT_EQ(1, NumLogs());
240  ASSERT_EQ(number, FirstLogFile()) << "did not reuse log file";
241  ASSERT_EQ("bar", Get("foo"));
242  }
243 }
#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
Here is the call graph for this function:

§ TEST() [63/142]

leveldb::TEST ( CorruptionTest  ,
NewFileErrorDuringWrite   
)

Definition at line 219 of file corruption_test.cc.

219  {
220  // Do enough writing to force minor compaction
221  env_.writable_file_error_ = true;
222  const int num = 3 + (Options().write_buffer_size / kValueSize);
223  std::string value_storage;
224  Status s;
225  for (int i = 0; s.ok() && i < num; i++) {
226  WriteBatch batch;
227  batch.Put("a", Value(100, &value_storage));
228  s = db_->Write(WriteOptions(), &batch);
229  }
230  ASSERT_TRUE(!s.ok());
231  ASSERT_GE(env_.num_writable_file_errors_, 1);
232  env_.writable_file_error_ = false;
233  Reopen();
234 }
static const int kValueSize
#define ASSERT_TRUE(c)
Definition: testharness.h:105
#define ASSERT_GE(a, b)
Definition: testharness.h:109
uint32_t Value(const char *data, size_t n)
Definition: crc32c.h:20
Here is the call graph for this function:

§ TEST() [64/142]

leveldb::TEST ( CorruptionTest  ,
TableFile   
)

Definition at line 236 of file corruption_test.cc.

236  {
237  Build(100);
238  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
239  dbi->TEST_CompactMemTable();
240  dbi->TEST_CompactRange(0, NULL, NULL);
241  dbi->TEST_CompactRange(1, NULL, NULL);
242 
243  Corrupt(kTableFile, 100, 1);
244  Check(90, 99);
245 }
Here is the call graph for this function:

§ TEST() [65/142]

leveldb::TEST ( RecoveryTest  ,
MultipleMemTables   
)

Definition at line 245 of file recovery_test.cc.

245  {
246  // Make a large log.
247  const int kNum = 1000;
248  for (int i = 0; i < kNum; i++) {
249  char buf[100];
250  snprintf(buf, sizeof(buf), "%050d", i);
251  ASSERT_OK(Put(buf, buf));
252  }
253  ASSERT_EQ(0, NumTables());
254  Close();
255  ASSERT_EQ(0, NumTables());
256  ASSERT_EQ(1, NumLogs());
257  uint64_t old_log_file = FirstLogFile();
258 
259  // Force creation of multiple memtables by reducing the write buffer size.
260  Options opt;
261  opt.reuse_logs = true;
262  opt.write_buffer_size = (kNum*100) / 2;
263  Open(&opt);
264  ASSERT_LE(2, NumTables());
265  ASSERT_EQ(1, NumLogs());
266  ASSERT_NE(old_log_file, FirstLogFile()) << "must not reuse log";
267  for (int i = 0; i < kNum; i++) {
268  char buf[100];
269  snprintf(buf, sizeof(buf), "%050d", i);
270  ASSERT_EQ(buf, Get(buf));
271  }
272 }
#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_NE(a, b)
Definition: testharness.h:108
Here is the call graph for this function:

§ TEST() [66/142]

leveldb::TEST ( CorruptionTest  ,
TableFileRepair   
)

Definition at line 247 of file corruption_test.cc.

247  {
248  options_.block_size = 2 * kValueSize; // Limit scope of corruption
249  options_.paranoid_checks = true;
250  Reopen();
251  Build(100);
252  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
253  dbi->TEST_CompactMemTable();
254  dbi->TEST_CompactRange(0, NULL, NULL);
255  dbi->TEST_CompactRange(1, NULL, NULL);
256 
257  Corrupt(kTableFile, 100, 1);
258  RepairDB();
259  Reopen();
260  Check(95, 99);
261 }
static const int kValueSize
Status RepairDB(const std::string &dbname, const Options &options)
Definition: repair.cc:456
Here is the call graph for this function:

§ TEST() [67/142]

leveldb::TEST ( CorruptionTest  ,
TableFileIndexData   
)

Definition at line 263 of file corruption_test.cc.

263  {
264  Build(10000); // Enough to build multiple Tables
265  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
266  dbi->TEST_CompactMemTable();
267 
268  Corrupt(kTableFile, -2000, 500);
269  Reopen();
270  Check(5000, 9999);
271 }
Here is the call graph for this function:

§ TEST() [68/142]

leveldb::TEST ( CorruptionTest  ,
MissingDescriptor   
)

Definition at line 273 of file corruption_test.cc.

273  {
274  Build(1000);
275  RepairDB();
276  Reopen();
277  Check(1000, 1000);
278 }
Status RepairDB(const std::string &dbname, const Options &options)
Definition: repair.cc:456
Here is the call graph for this function:

§ TEST() [69/142]

leveldb::TEST ( RecoveryTest  ,
MultipleLogFiles   
)

Definition at line 274 of file recovery_test.cc.

274  {
275  ASSERT_OK(Put("foo", "bar"));
276  Close();
277  ASSERT_EQ(1, NumLogs());
278 
279  // Make a bunch of uncompacted log files.
280  uint64_t old_log = FirstLogFile();
281  MakeLogFile(old_log+1, 1000, "hello", "world");
282  MakeLogFile(old_log+2, 1001, "hi", "there");
283  MakeLogFile(old_log+3, 1002, "foo", "bar2");
284 
285  // Recover and check that all log files were processed.
286  Open();
287  ASSERT_LE(1, NumTables());
288  ASSERT_EQ(1, NumLogs());
289  uint64_t new_log = FirstLogFile();
290  ASSERT_LE(old_log+3, new_log);
291  ASSERT_EQ("bar2", Get("foo"));
292  ASSERT_EQ("world", Get("hello"));
293  ASSERT_EQ("there", Get("hi"));
294 
295  // Test that previous recovery produced recoverable state.
296  Open();
297  ASSERT_LE(1, NumTables());
298  ASSERT_EQ(1, NumLogs());
299  if (CanAppend()) {
300  ASSERT_EQ(new_log, FirstLogFile());
301  }
302  ASSERT_EQ("bar2", Get("foo"));
303  ASSERT_EQ("world", Get("hello"));
304  ASSERT_EQ("there", Get("hi"));
305 
306  // Check that introducing an older log file does not cause it to be re-read.
307  Close();
308  MakeLogFile(old_log+1, 2000, "hello", "stale write");
309  Open();
310  ASSERT_LE(1, NumTables());
311  ASSERT_EQ(1, NumLogs());
312  if (CanAppend()) {
313  ASSERT_EQ(new_log, FirstLogFile());
314  }
315  ASSERT_EQ("bar2", Get("foo"));
316  ASSERT_EQ("world", Get("hello"));
317  ASSERT_EQ("there", Get("hi"));
318 }
#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
Here is the call graph for this function:

§ TEST() [70/142]

leveldb::TEST ( CorruptionTest  ,
SequenceNumberRecovery   
)

Definition at line 280 of file corruption_test.cc.

280  {
281  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v1"));
282  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v2"));
283  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v3"));
284  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v4"));
285  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v5"));
286  RepairDB();
287  Reopen();
288  std::string v;
289  ASSERT_OK(db_->Get(ReadOptions(), "foo", &v));
290  ASSERT_EQ("v5", v);
291  // Write something. If sequence number was not recovered properly,
292  // it will be hidden by an earlier write.
293  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v6"));
294  ASSERT_OK(db_->Get(ReadOptions(), "foo", &v));
295  ASSERT_EQ("v6", v);
296  Reopen();
297  ASSERT_OK(db_->Get(ReadOptions(), "foo", &v));
298  ASSERT_EQ("v6", v);
299 }
#define ASSERT_OK(s)
Definition: testharness.h:106
Status RepairDB(const std::string &dbname, const Options &options)
Definition: repair.cc:456
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [71/142]

leveldb::TEST ( SkipTest  ,
ConcurrentWithoutThreads   
)

Definition at line 288 of file skiplist_test.cc.

288  {
289  ConcurrentTest test;
290  Random rnd(test::RandomSeed());
291  for (int i = 0; i < 10000; i++) {
292  test.ReadStep(&rnd);
293  test.WriteStep(&rnd);
294  }
295 }
int RandomSeed()
Definition: testharness.cc:67
Here is the call graph for this function:

§ TEST() [72/142]

leveldb::TEST ( CorruptionTest  ,
CorruptedDescriptor   
)

Definition at line 301 of file corruption_test.cc.

301  {
302  ASSERT_OK(db_->Put(WriteOptions(), "foo", "hello"));
303  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
304  dbi->TEST_CompactMemTable();
305  dbi->TEST_CompactRange(0, NULL, NULL);
306 
307  Corrupt(kDescriptorFile, 0, 1000);
308  Status s = TryReopen();
309  ASSERT_TRUE(!s.ok());
310 
311  RepairDB();
312  Reopen();
313  std::string v;
314  ASSERT_OK(db_->Get(ReadOptions(), "foo", &v));
315  ASSERT_EQ("hello", v);
316 }
#define ASSERT_OK(s)
Definition: testharness.h:106
Status RepairDB(const std::string &dbname, const Options &options)
Definition: repair.cc:456
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [73/142]

leveldb::TEST ( CorruptionTest  ,
CompactionInputError   
)

Definition at line 318 of file corruption_test.cc.

318  {
319  Build(10);
320  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
321  dbi->TEST_CompactMemTable();
322  const int last = config::kMaxMemCompactLevel;
323  ASSERT_EQ(1, Property("leveldb.num-files-at-level" + NumberToString(last)));
324 
325  Corrupt(kTableFile, 100, 1);
326  Check(5, 9);
327 
328  // Force compactions by writing lots of values
329  Build(10000);
330  Check(10000, 10000);
331 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kMaxMemCompactLevel
Definition: dbformat.h:39
std::string NumberToString(uint64_t num)
Definition: logging.cc:36
Here is the call graph for this function:

§ TEST() [74/142]

leveldb::TEST ( CorruptionTest  ,
CompactionInputErrorParanoid   
)

Definition at line 333 of file corruption_test.cc.

333  {
334  options_.paranoid_checks = true;
335  options_.write_buffer_size = 512 << 10;
336  Reopen();
337  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
338 
339  // Make multiple inputs so we need to compact.
340  for (int i = 0; i < 2; i++) {
341  Build(10);
342  dbi->TEST_CompactMemTable();
343  Corrupt(kTableFile, 100, 1);
344  env_.SleepForMicroseconds(100000);
345  }
346  dbi->CompactRange(NULL, NULL);
347 
348  // Write must fail because of corrupted table
349  std::string tmp1, tmp2;
350  Status s = db_->Put(WriteOptions(), Key(5, &tmp1), Value(5, &tmp2));
351  ASSERT_TRUE(!s.ok()) << "write did not fail in corrupted paranoid db";
352 }
uint64_t Key
#define ASSERT_TRUE(c)
Definition: testharness.h:105
uint32_t Value(const char *data, size_t n)
Definition: crc32c.h:20
Here is the call graph for this function:

§ TEST() [75/142]

leveldb::TEST ( CorruptionTest  ,
UnrelatedKeys   
)

Definition at line 354 of file corruption_test.cc.

354  {
355  Build(10);
356  DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
357  dbi->TEST_CompactMemTable();
358  Corrupt(kTableFile, 100, 1);
359 
360  std::string tmp1, tmp2;
361  ASSERT_OK(db_->Put(WriteOptions(), Key(1000, &tmp1), Value(1000, &tmp2)));
362  std::string v;
363  ASSERT_OK(db_->Get(ReadOptions(), Key(1000, &tmp1), &v));
364  ASSERT_EQ(Value(1000, &tmp2).ToString(), v);
365  dbi->TEST_CompactMemTable();
366  ASSERT_OK(db_->Get(ReadOptions(), Key(1000, &tmp1), &v));
367  ASSERT_EQ(Value(1000, &tmp2).ToString(), v);
368 }
uint64_t Key
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
uint32_t Value(const char *data, size_t n)
Definition: crc32c.h:20
Here is the call graph for this function:

§ TEST() [76/142]

leveldb::TEST ( SkipTest  ,
Concurrent1   
)

Definition at line 368 of file skiplist_test.cc.

368 { RunConcurrent(1); }
static void RunConcurrent(int run)
Here is the call graph for this function:

§ TEST() [77/142]

leveldb::TEST ( SkipTest  ,
Concurrent2   
)

Definition at line 369 of file skiplist_test.cc.

369 { RunConcurrent(2); }
static void RunConcurrent(int run)
Here is the call graph for this function:

§ TEST() [78/142]

leveldb::TEST ( SkipTest  ,
Concurrent3   
)

Definition at line 370 of file skiplist_test.cc.

370 { RunConcurrent(3); }
static void RunConcurrent(int run)
Here is the call graph for this function:

§ TEST() [79/142]

leveldb::TEST ( SkipTest  ,
Concurrent4   
)

Definition at line 371 of file skiplist_test.cc.

371 { RunConcurrent(4); }
static void RunConcurrent(int run)
Here is the call graph for this function:

§ TEST() [80/142]

leveldb::TEST ( SkipTest  ,
Concurrent5   
)

Definition at line 372 of file skiplist_test.cc.

372 { RunConcurrent(5); }
static void RunConcurrent(int run)
Here is the call graph for this function:

§ TEST() [81/142]

leveldb::TEST ( DBTest  ,
Empty   
)

Definition at line 511 of file db_test.cc.

511  {
512  do {
513  ASSERT_TRUE(db_ != NULL);
514  ASSERT_EQ("NOT_FOUND", Get("foo"));
515  } while (ChangeOptions());
516 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105

§ TEST() [82/142]

leveldb::TEST ( DBTest  ,
ReadWrite   
)

Definition at line 518 of file db_test.cc.

518  {
519  do {
520  ASSERT_OK(Put("foo", "v1"));
521  ASSERT_EQ("v1", Get("foo"));
522  ASSERT_OK(Put("bar", "v2"));
523  ASSERT_OK(Put("foo", "v3"));
524  ASSERT_EQ("v3", Get("foo"));
525  ASSERT_EQ("v2", Get("bar"));
526  } while (ChangeOptions());
527 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [83/142]

leveldb::TEST ( DBTest  ,
PutDeleteGet   
)

Definition at line 529 of file db_test.cc.

529  {
530  do {
531  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v1"));
532  ASSERT_EQ("v1", Get("foo"));
533  ASSERT_OK(db_->Put(WriteOptions(), "foo", "v2"));
534  ASSERT_EQ("v2", Get("foo"));
535  ASSERT_OK(db_->Delete(WriteOptions(), "foo"));
536  ASSERT_EQ("NOT_FOUND", Get("foo"));
537  } while (ChangeOptions());
538 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [84/142]

leveldb::TEST ( DBTest  ,
GetFromImmutableLayer   
)

Definition at line 540 of file db_test.cc.

540  {
541  do {
542  Options options = CurrentOptions();
543  options.env = env_;
544  options.write_buffer_size = 100000; // Small write buffer
545  Reopen(&options);
546 
547  ASSERT_OK(Put("foo", "v1"));
548  ASSERT_EQ("v1", Get("foo"));
549 
550  env_->delay_data_sync_.Release_Store(env_); // Block sync calls
551  Put("k1", std::string(100000, 'x')); // Fill memtable
552  Put("k2", std::string(100000, 'y')); // Trigger compaction
553  ASSERT_EQ("v1", Get("foo"));
554  env_->delay_data_sync_.Release_Store(NULL); // Release sync calls
555  } while (ChangeOptions());
556 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [85/142]

leveldb::TEST ( FaultInjectionTest  ,
FaultTestNoLogReuse   
)

Definition at line 540 of file fault_injection_test.cc.

540  {
541  ReuseLogs(false);
542  DoTest();
543 }

§ TEST() [86/142]

leveldb::TEST ( FaultInjectionTest  ,
FaultTestWithLogReuse   
)

Definition at line 545 of file fault_injection_test.cc.

545  {
546  ReuseLogs(true);
547  DoTest();
548 }

§ TEST() [87/142]

leveldb::TEST ( DBTest  ,
GetFromVersions   
)

Definition at line 558 of file db_test.cc.

558  {
559  do {
560  ASSERT_OK(Put("foo", "v1"));
561  dbfull()->TEST_CompactMemTable();
562  ASSERT_EQ("v1", Get("foo"));
563  } while (ChangeOptions());
564 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [88/142]

leveldb::TEST ( DBTest  ,
GetMemUsage   
)

Definition at line 566 of file db_test.cc.

566  {
567  do {
568  ASSERT_OK(Put("foo", "v1"));
569  std::string val;
570  ASSERT_TRUE(db_->GetProperty("leveldb.approximate-memory-usage", &val));
571  int mem_usage = atoi(val.c_str());
572  ASSERT_GT(mem_usage, 0);
573  ASSERT_LT(mem_usage, 5*1024*1024);
574  } while (ChangeOptions());
575 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_LT(a, b)
Definition: testharness.h:112
#define ASSERT_TRUE(c)
Definition: testharness.h:105

§ TEST() [89/142]

leveldb::TEST ( DBTest  ,
GetSnapshot   
)

Definition at line 577 of file db_test.cc.

577  {
578  do {
579  // Try with both a short key and a long key
580  for (int i = 0; i < 2; i++) {
581  std::string key = (i == 0) ? std::string("foo") : std::string(200, 'x');
582  ASSERT_OK(Put(key, "v1"));
583  const Snapshot* s1 = db_->GetSnapshot();
584  ASSERT_OK(Put(key, "v2"));
585  ASSERT_EQ("v2", Get(key));
586  ASSERT_EQ("v1", Get(key, s1));
587  dbfull()->TEST_CompactMemTable();
588  ASSERT_EQ("v2", Get(key));
589  ASSERT_EQ("v1", Get(key, s1));
590  db_->ReleaseSnapshot(s1);
591  }
592  } while (ChangeOptions());
593 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [90/142]

leveldb::TEST ( DBTest  ,
GetLevel0Ordering   
)

Definition at line 595 of file db_test.cc.

595  {
596  do {
597  // Check that we process level-0 files in correct order. The code
598  // below generates two level-0 files where the earlier one comes
599  // before the later one in the level-0 file list since the earlier
600  // one has a smaller "smallest" key.
601  ASSERT_OK(Put("bar", "b"));
602  ASSERT_OK(Put("foo", "v1"));
603  dbfull()->TEST_CompactMemTable();
604  ASSERT_OK(Put("foo", "v2"));
605  dbfull()->TEST_CompactMemTable();
606  ASSERT_EQ("v2", Get("foo"));
607  } while (ChangeOptions());
608 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [91/142]

leveldb::TEST ( DBTest  ,
GetOrderedByLevels   
)

Definition at line 610 of file db_test.cc.

610  {
611  do {
612  ASSERT_OK(Put("foo", "v1"));
613  Compact("a", "z");
614  ASSERT_EQ("v1", Get("foo"));
615  ASSERT_OK(Put("foo", "v2"));
616  ASSERT_EQ("v2", Get("foo"));
617  dbfull()->TEST_CompactMemTable();
618  ASSERT_EQ("v2", Get("foo"));
619  } while (ChangeOptions());
620 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [92/142]

leveldb::TEST ( DBTest  ,
GetPicksCorrectFile   
)

Definition at line 622 of file db_test.cc.

622  {
623  do {
624  // Arrange to have multiple files in a non-level-0 level.
625  ASSERT_OK(Put("a", "va"));
626  Compact("a", "b");
627  ASSERT_OK(Put("x", "vx"));
628  Compact("x", "y");
629  ASSERT_OK(Put("f", "vf"));
630  Compact("f", "g");
631  ASSERT_EQ("va", Get("a"));
632  ASSERT_EQ("vf", Get("f"));
633  ASSERT_EQ("vx", Get("x"));
634  } while (ChangeOptions());
635 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [93/142]

leveldb::TEST ( DBTest  ,
GetEncountersEmptyLevel   
)

Definition at line 637 of file db_test.cc.

637  {
638  do {
639  // Arrange for the following to happen:
640  // * sstable A in level 0
641  // * nothing in level 1
642  // * sstable B in level 2
643  // Then do enough Get() calls to arrange for an automatic compaction
644  // of sstable A. A bug would cause the compaction to be marked as
645  // occurring at level 1 (instead of the correct level 0).
646 
647  // Step 1: First place sstables in levels 0 and 2
648  int compaction_count = 0;
649  while (NumTableFilesAtLevel(0) == 0 ||
650  NumTableFilesAtLevel(2) == 0) {
651  ASSERT_LE(compaction_count, 100) << "could not fill levels 0 and 2";
652  compaction_count++;
653  Put("a", "begin");
654  Put("z", "end");
655  dbfull()->TEST_CompactMemTable();
656  }
657 
658  // Step 2: clear level 1 if necessary.
659  dbfull()->TEST_CompactRange(1, NULL, NULL);
660  ASSERT_EQ(NumTableFilesAtLevel(0), 1);
661  ASSERT_EQ(NumTableFilesAtLevel(1), 0);
662  ASSERT_EQ(NumTableFilesAtLevel(2), 1);
663 
664  // Step 3: read a bunch of times
665  for (int i = 0; i < 1000; i++) {
666  ASSERT_EQ("NOT_FOUND", Get("missing"));
667  }
668 
669  // Step 4: Wait for compaction to finish
670  DelayMilliseconds(1000);
671 
672  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
673  } while (ChangeOptions());
674 }
#define ASSERT_LE(a, b)
Definition: testharness.h:111
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [94/142]

leveldb::TEST ( Harness  ,
Empty   
)

Definition at line 648 of file table_test.cc.

648  {
649  for (int i = 0; i < kNumTestArgs; i++) {
650  Init(kTestArgList[i]);
651  Random rnd(test::RandomSeed() + 1);
652  Test(&rnd);
653  }
654 }
int RandomSeed()
Definition: testharness.cc:67
static const TestArgs kTestArgList[]
Definition: table_test.cc:412
static const int kNumTestArgs
Definition: table_test.cc:435
Here is the call graph for this function:

§ TEST() [95/142]

leveldb::TEST ( Harness  ,
ZeroRestartPointsInBlock   
)

Definition at line 659 of file table_test.cc.

659  {
660  char data[sizeof(uint32_t)];
661  memset(data, 0, sizeof(data));
662  BlockContents contents;
663  contents.data = Slice(data, sizeof(data));
664  contents.cachable = false;
665  contents.heap_allocated = false;
666  Block block(contents);
667  Iterator* iter = block.NewIterator(BytewiseComparator());
668  iter->SeekToFirst();
669  ASSERT_TRUE(!iter->Valid());
670  iter->SeekToLast();
671  ASSERT_TRUE(!iter->Valid());
672  iter->Seek("foo");
673  ASSERT_TRUE(!iter->Valid());
674  delete iter;
675 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:

§ TEST() [96/142]

leveldb::TEST ( DBTest  ,
IterEmpty   
)

Definition at line 676 of file db_test.cc.

676  {
677  Iterator* iter = db_->NewIterator(ReadOptions());
678 
679  iter->SeekToFirst();
680  ASSERT_EQ(IterStatus(iter), "(invalid)");
681 
682  iter->SeekToLast();
683  ASSERT_EQ(IterStatus(iter), "(invalid)");
684 
685  iter->Seek("foo");
686  ASSERT_EQ(IterStatus(iter), "(invalid)");
687 
688  delete iter;
689 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [97/142]

leveldb::TEST ( Harness  ,
SimpleEmptyKey   
)

Definition at line 678 of file table_test.cc.

678  {
679  for (int i = 0; i < kNumTestArgs; i++) {
680  Init(kTestArgList[i]);
681  Random rnd(test::RandomSeed() + 1);
682  Add("", "v");
683  Test(&rnd);
684  }
685 }
int RandomSeed()
Definition: testharness.cc:67
static const TestArgs kTestArgList[]
Definition: table_test.cc:412
static const int kNumTestArgs
Definition: table_test.cc:435
Here is the call graph for this function:

§ TEST() [98/142]

leveldb::TEST ( Harness  ,
SimpleSingle   
)

Definition at line 687 of file table_test.cc.

687  {
688  for (int i = 0; i < kNumTestArgs; i++) {
689  Init(kTestArgList[i]);
690  Random rnd(test::RandomSeed() + 2);
691  Add("abc", "v");
692  Test(&rnd);
693  }
694 }
int RandomSeed()
Definition: testharness.cc:67
static const TestArgs kTestArgList[]
Definition: table_test.cc:412
static const int kNumTestArgs
Definition: table_test.cc:435
Here is the call graph for this function:

§ TEST() [99/142]

leveldb::TEST ( DBTest  ,
IterSingle   
)

Definition at line 691 of file db_test.cc.

691  {
692  ASSERT_OK(Put("a", "va"));
693  Iterator* iter = db_->NewIterator(ReadOptions());
694 
695  iter->SeekToFirst();
696  ASSERT_EQ(IterStatus(iter), "a->va");
697  iter->Next();
698  ASSERT_EQ(IterStatus(iter), "(invalid)");
699  iter->SeekToFirst();
700  ASSERT_EQ(IterStatus(iter), "a->va");
701  iter->Prev();
702  ASSERT_EQ(IterStatus(iter), "(invalid)");
703 
704  iter->SeekToLast();
705  ASSERT_EQ(IterStatus(iter), "a->va");
706  iter->Next();
707  ASSERT_EQ(IterStatus(iter), "(invalid)");
708  iter->SeekToLast();
709  ASSERT_EQ(IterStatus(iter), "a->va");
710  iter->Prev();
711  ASSERT_EQ(IterStatus(iter), "(invalid)");
712 
713  iter->Seek("");
714  ASSERT_EQ(IterStatus(iter), "a->va");
715  iter->Next();
716  ASSERT_EQ(IterStatus(iter), "(invalid)");
717 
718  iter->Seek("a");
719  ASSERT_EQ(IterStatus(iter), "a->va");
720  iter->Next();
721  ASSERT_EQ(IterStatus(iter), "(invalid)");
722 
723  iter->Seek("b");
724  ASSERT_EQ(IterStatus(iter), "(invalid)");
725 
726  delete iter;
727 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [100/142]

leveldb::TEST ( Harness  ,
SimpleMulti   
)

Definition at line 696 of file table_test.cc.

696  {
697  for (int i = 0; i < kNumTestArgs; i++) {
698  Init(kTestArgList[i]);
699  Random rnd(test::RandomSeed() + 3);
700  Add("abc", "v");
701  Add("abcd", "v");
702  Add("ac", "v2");
703  Test(&rnd);
704  }
705 }
int RandomSeed()
Definition: testharness.cc:67
static const TestArgs kTestArgList[]
Definition: table_test.cc:412
static const int kNumTestArgs
Definition: table_test.cc:435
Here is the call graph for this function:

§ TEST() [101/142]

leveldb::TEST ( Harness  ,
SimpleSpecialKey   
)

Definition at line 707 of file table_test.cc.

707  {
708  for (int i = 0; i < kNumTestArgs; i++) {
709  Init(kTestArgList[i]);
710  Random rnd(test::RandomSeed() + 4);
711  Add("\xff\xff", "v3");
712  Test(&rnd);
713  }
714 }
int RandomSeed()
Definition: testharness.cc:67
static const TestArgs kTestArgList[]
Definition: table_test.cc:412
static const int kNumTestArgs
Definition: table_test.cc:435
Here is the call graph for this function:

§ TEST() [102/142]

leveldb::TEST ( Harness  ,
Randomized   
)

Definition at line 716 of file table_test.cc.

716  {
717  for (int i = 0; i < kNumTestArgs; i++) {
718  Init(kTestArgList[i]);
719  Random rnd(test::RandomSeed() + 5);
720  for (int num_entries = 0; num_entries < 2000;
721  num_entries += (num_entries < 50 ? 1 : 200)) {
722  if ((num_entries % 10) == 0) {
723  fprintf(stderr, "case %d of %d: num_entries = %d\n",
724  (i + 1), int(kNumTestArgs), num_entries);
725  }
726  for (int e = 0; e < num_entries; e++) {
727  std::string v;
728  Add(test::RandomKey(&rnd, rnd.Skewed(4)),
729  test::RandomString(&rnd, rnd.Skewed(5), &v).ToString());
730  }
731  Test(&rnd);
732  }
733  }
734 }
int RandomSeed()
Definition: testharness.cc:67
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
static const TestArgs kTestArgList[]
Definition: table_test.cc:412
static const int kNumTestArgs
Definition: table_test.cc:435
static std::string RandomKey(Random *rnd)
Definition: db_test.cc:1962
Here is the call graph for this function:

§ TEST() [103/142]

leveldb::TEST ( DBTest  ,
IterMulti   
)

Definition at line 729 of file db_test.cc.

729  {
730  ASSERT_OK(Put("a", "va"));
731  ASSERT_OK(Put("b", "vb"));
732  ASSERT_OK(Put("c", "vc"));
733  Iterator* iter = db_->NewIterator(ReadOptions());
734 
735  iter->SeekToFirst();
736  ASSERT_EQ(IterStatus(iter), "a->va");
737  iter->Next();
738  ASSERT_EQ(IterStatus(iter), "b->vb");
739  iter->Next();
740  ASSERT_EQ(IterStatus(iter), "c->vc");
741  iter->Next();
742  ASSERT_EQ(IterStatus(iter), "(invalid)");
743  iter->SeekToFirst();
744  ASSERT_EQ(IterStatus(iter), "a->va");
745  iter->Prev();
746  ASSERT_EQ(IterStatus(iter), "(invalid)");
747 
748  iter->SeekToLast();
749  ASSERT_EQ(IterStatus(iter), "c->vc");
750  iter->Prev();
751  ASSERT_EQ(IterStatus(iter), "b->vb");
752  iter->Prev();
753  ASSERT_EQ(IterStatus(iter), "a->va");
754  iter->Prev();
755  ASSERT_EQ(IterStatus(iter), "(invalid)");
756  iter->SeekToLast();
757  ASSERT_EQ(IterStatus(iter), "c->vc");
758  iter->Next();
759  ASSERT_EQ(IterStatus(iter), "(invalid)");
760 
761  iter->Seek("");
762  ASSERT_EQ(IterStatus(iter), "a->va");
763  iter->Seek("a");
764  ASSERT_EQ(IterStatus(iter), "a->va");
765  iter->Seek("ax");
766  ASSERT_EQ(IterStatus(iter), "b->vb");
767  iter->Seek("b");
768  ASSERT_EQ(IterStatus(iter), "b->vb");
769  iter->Seek("z");
770  ASSERT_EQ(IterStatus(iter), "(invalid)");
771 
772  // Switch from reverse to forward
773  iter->SeekToLast();
774  iter->Prev();
775  iter->Prev();
776  iter->Next();
777  ASSERT_EQ(IterStatus(iter), "b->vb");
778 
779  // Switch from forward to reverse
780  iter->SeekToFirst();
781  iter->Next();
782  iter->Next();
783  iter->Prev();
784  ASSERT_EQ(IterStatus(iter), "b->vb");
785 
786  // Make sure iter stays at snapshot
787  ASSERT_OK(Put("a", "va2"));
788  ASSERT_OK(Put("a2", "va3"));
789  ASSERT_OK(Put("b", "vb2"));
790  ASSERT_OK(Put("c", "vc2"));
791  ASSERT_OK(Delete("b"));
792  iter->SeekToFirst();
793  ASSERT_EQ(IterStatus(iter), "a->va");
794  iter->Next();
795  ASSERT_EQ(IterStatus(iter), "b->vb");
796  iter->Next();
797  ASSERT_EQ(IterStatus(iter), "c->vc");
798  iter->Next();
799  ASSERT_EQ(IterStatus(iter), "(invalid)");
800  iter->SeekToLast();
801  ASSERT_EQ(IterStatus(iter), "c->vc");
802  iter->Prev();
803  ASSERT_EQ(IterStatus(iter), "b->vb");
804  iter->Prev();
805  ASSERT_EQ(IterStatus(iter), "a->va");
806  iter->Prev();
807  ASSERT_EQ(IterStatus(iter), "(invalid)");
808 
809  delete iter;
810 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [104/142]

leveldb::TEST ( Harness  ,
RandomizedLongDB   
)

Definition at line 736 of file table_test.cc.

736  {
737  Random rnd(test::RandomSeed());
738  TestArgs args = { DB_TEST, false, 16 };
739  Init(args);
740  int num_entries = 100000;
741  for (int e = 0; e < num_entries; e++) {
742  std::string v;
743  Add(test::RandomKey(&rnd, rnd.Skewed(4)),
744  test::RandomString(&rnd, rnd.Skewed(5), &v).ToString());
745  }
746  Test(&rnd);
747 
748  // We must have created enough data to force merging
749  int files = 0;
750  for (int level = 0; level < config::kNumLevels; level++) {
751  std::string value;
752  char name[100];
753  snprintf(name, sizeof(name), "leveldb.num-files-at-level%d", level);
754  ASSERT_TRUE(db()->GetProperty(name, &value));
755  files += atoi(value.c_str());
756  }
757  ASSERT_GT(files, 0);
758 }
static const int kNumLevels
Definition: dbformat.h:22
int RandomSeed()
Definition: testharness.cc:67
#define ASSERT_GT(a, b)
Definition: testharness.h:110
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
static std::string RandomKey(Random *rnd)
Definition: db_test.cc:1962
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [105/142]

leveldb::TEST ( MemTableTest  ,
Simple   
)

Definition at line 762 of file table_test.cc.

762  {
763  InternalKeyComparator cmp(BytewiseComparator());
764  MemTable* memtable = new MemTable(cmp);
765  memtable->Ref();
766  WriteBatch batch;
767  WriteBatchInternal::SetSequence(&batch, 100);
768  batch.Put(std::string("k1"), std::string("v1"));
769  batch.Put(std::string("k2"), std::string("v2"));
770  batch.Put(std::string("k3"), std::string("v3"));
771  batch.Put(std::string("largekey"), std::string("vlarge"));
772  ASSERT_TRUE(WriteBatchInternal::InsertInto(&batch, memtable).ok());
773 
774  Iterator* iter = memtable->NewIterator();
775  iter->SeekToFirst();
776  while (iter->Valid()) {
777  fprintf(stderr, "key: '%s' -> '%s'\n",
778  iter->key().ToString().c_str(),
779  iter->value().ToString().c_str());
780  iter->Next();
781  }
782 
783  delete iter;
784  memtable->Unref();
785 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:

§ TEST() [106/142]

leveldb::TEST ( TableTest  ,
ApproximateOffsetOfPlain   
)

Definition at line 800 of file table_test.cc.

800  {
801  TableConstructor c(BytewiseComparator());
802  c.Add("k01", "hello");
803  c.Add("k02", "hello2");
804  c.Add("k03", std::string(10000, 'x'));
805  c.Add("k04", std::string(200000, 'x'));
806  c.Add("k05", std::string(300000, 'x'));
807  c.Add("k06", "hello3");
808  c.Add("k07", std::string(100000, 'x'));
809  std::vector<std::string> keys;
810  KVMap kvmap;
811  Options options;
812  options.block_size = 1024;
813  options.compression = kNoCompression;
814  c.Finish(options, &keys, &kvmap);
815 
816  ASSERT_TRUE(Between(c.ApproximateOffsetOf("abc"), 0, 0));
817  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k01"), 0, 0));
818  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k01a"), 0, 0));
819  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k02"), 0, 0));
820  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k03"), 0, 0));
821  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k04"), 10000, 11000));
822  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k04a"), 210000, 211000));
823  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k05"), 210000, 211000));
824  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k06"), 510000, 511000));
825  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k07"), 510000, 511000));
826  ASSERT_TRUE(Between(c.ApproximateOffsetOf("xyz"), 610000, 612000));
827 
828 }
static bool Between(uint64_t val, uint64_t low, uint64_t high)
Definition: table_test.cc:787
std::map< std::string, std::string, STLLessThan > KVMap
Definition: table_test.cc:137
#define ASSERT_TRUE(c)
Definition: testharness.h:105
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
Here is the call graph for this function:

§ TEST() [107/142]

leveldb::TEST ( DBTest  ,
IterSmallAndLargeMix   
)

Definition at line 812 of file db_test.cc.

812  {
813  ASSERT_OK(Put("a", "va"));
814  ASSERT_OK(Put("b", std::string(100000, 'b')));
815  ASSERT_OK(Put("c", "vc"));
816  ASSERT_OK(Put("d", std::string(100000, 'd')));
817  ASSERT_OK(Put("e", std::string(100000, 'e')));
818 
819  Iterator* iter = db_->NewIterator(ReadOptions());
820 
821  iter->SeekToFirst();
822  ASSERT_EQ(IterStatus(iter), "a->va");
823  iter->Next();
824  ASSERT_EQ(IterStatus(iter), "b->" + std::string(100000, 'b'));
825  iter->Next();
826  ASSERT_EQ(IterStatus(iter), "c->vc");
827  iter->Next();
828  ASSERT_EQ(IterStatus(iter), "d->" + std::string(100000, 'd'));
829  iter->Next();
830  ASSERT_EQ(IterStatus(iter), "e->" + std::string(100000, 'e'));
831  iter->Next();
832  ASSERT_EQ(IterStatus(iter), "(invalid)");
833 
834  iter->SeekToLast();
835  ASSERT_EQ(IterStatus(iter), "e->" + std::string(100000, 'e'));
836  iter->Prev();
837  ASSERT_EQ(IterStatus(iter), "d->" + std::string(100000, 'd'));
838  iter->Prev();
839  ASSERT_EQ(IterStatus(iter), "c->vc");
840  iter->Prev();
841  ASSERT_EQ(IterStatus(iter), "b->" + std::string(100000, 'b'));
842  iter->Prev();
843  ASSERT_EQ(IterStatus(iter), "a->va");
844  iter->Prev();
845  ASSERT_EQ(IterStatus(iter), "(invalid)");
846 
847  delete iter;
848 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [108/142]

leveldb::TEST ( TableTest  ,
ApproximateOffsetOfCompressed   
)

Definition at line 836 of file table_test.cc.

836  {
838  fprintf(stderr, "skipping compression tests\n");
839  return;
840  }
841 
842  Random rnd(301);
843  TableConstructor c(BytewiseComparator());
844  std::string tmp;
845  c.Add("k01", "hello");
846  c.Add("k02", test::CompressibleString(&rnd, 0.25, 10000, &tmp));
847  c.Add("k03", "hello3");
848  c.Add("k04", test::CompressibleString(&rnd, 0.25, 10000, &tmp));
849  std::vector<std::string> keys;
850  KVMap kvmap;
851  Options options;
852  options.block_size = 1024;
853  options.compression = kSnappyCompression;
854  c.Finish(options, &keys, &kvmap);
855 
856  // Expected upper and lower bounds of space used by compressible strings.
857  static const int kSlop = 1000; // Compressor effectiveness varies.
858  const int expected = 2500; // 10000 * compression ratio (0.25)
859  const int min_z = expected - kSlop;
860  const int max_z = expected + kSlop;
861 
862  ASSERT_TRUE(Between(c.ApproximateOffsetOf("abc"), 0, kSlop));
863  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k01"), 0, kSlop));
864  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k02"), 0, kSlop));
865  // Have now emitted a large compressible string, so adjust expected offset.
866  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k03"), min_z, max_z));
867  ASSERT_TRUE(Between(c.ApproximateOffsetOf("k04"), min_z, max_z));
868  // Have now emitted two large compressible strings, so adjust expected offset.
869  ASSERT_TRUE(Between(c.ApproximateOffsetOf("xyz"), 2 * min_z, 2 * max_z));
870 }
static bool Between(uint64_t val, uint64_t low, uint64_t high)
Definition: table_test.cc:787
std::map< std::string, std::string, STLLessThan > KVMap
Definition: table_test.cc:137
Slice CompressibleString(Random *rnd, double compressed_fraction, size_t len, std::string *dst)
Definition: testutil.cc:34
#define ASSERT_TRUE(c)
Definition: testharness.h:105
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
static bool SnappyCompressionSupported()
Definition: table_test.cc:830
Here is the call graph for this function:

§ TEST() [109/142]

leveldb::TEST ( DBTest  ,
IterMultiWithDelete   
)

Definition at line 850 of file db_test.cc.

850  {
851  do {
852  ASSERT_OK(Put("a", "va"));
853  ASSERT_OK(Put("b", "vb"));
854  ASSERT_OK(Put("c", "vc"));
855  ASSERT_OK(Delete("b"));
856  ASSERT_EQ("NOT_FOUND", Get("b"));
857 
858  Iterator* iter = db_->NewIterator(ReadOptions());
859  iter->Seek("c");
860  ASSERT_EQ(IterStatus(iter), "c->vc");
861  iter->Prev();
862  ASSERT_EQ(IterStatus(iter), "a->va");
863  delete iter;
864  } while (ChangeOptions());
865 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [110/142]

leveldb::TEST ( DBTest  ,
Recover   
)

Definition at line 867 of file db_test.cc.

867  {
868  do {
869  ASSERT_OK(Put("foo", "v1"));
870  ASSERT_OK(Put("baz", "v5"));
871 
872  Reopen();
873  ASSERT_EQ("v1", Get("foo"));
874 
875  ASSERT_EQ("v1", Get("foo"));
876  ASSERT_EQ("v5", Get("baz"));
877  ASSERT_OK(Put("bar", "v2"));
878  ASSERT_OK(Put("foo", "v3"));
879 
880  Reopen();
881  ASSERT_EQ("v3", Get("foo"));
882  ASSERT_OK(Put("foo", "v4"));
883  ASSERT_EQ("v4", Get("foo"));
884  ASSERT_EQ("v2", Get("bar"));
885  ASSERT_EQ("v5", Get("baz"));
886  } while (ChangeOptions());
887 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [111/142]

leveldb::TEST ( DBTest  ,
RecoveryWithEmptyLog   
)

Definition at line 889 of file db_test.cc.

889  {
890  do {
891  ASSERT_OK(Put("foo", "v1"));
892  ASSERT_OK(Put("foo", "v2"));
893  Reopen();
894  Reopen();
895  ASSERT_OK(Put("foo", "v3"));
896  Reopen();
897  ASSERT_EQ("v3", Get("foo"));
898  } while (ChangeOptions());
899 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [112/142]

leveldb::TEST ( DBTest  ,
RecoverDuringMemtableCompaction   
)

Definition at line 903 of file db_test.cc.

903  {
904  do {
905  Options options = CurrentOptions();
906  options.env = env_;
907  options.write_buffer_size = 1000000;
908  Reopen(&options);
909 
910  // Trigger a long memtable compaction and reopen the database during it
911  ASSERT_OK(Put("foo", "v1")); // Goes to 1st log file
912  ASSERT_OK(Put("big1", std::string(10000000, 'x'))); // Fills memtable
913  ASSERT_OK(Put("big2", std::string(1000, 'y'))); // Triggers compaction
914  ASSERT_OK(Put("bar", "v2")); // Goes to new log file
915 
916  Reopen(&options);
917  ASSERT_EQ("v1", Get("foo"));
918  ASSERT_EQ("v2", Get("bar"));
919  ASSERT_EQ(std::string(10000000, 'x'), Get("big1"));
920  ASSERT_EQ(std::string(1000, 'y'), Get("big2"));
921  } while (ChangeOptions());
922 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [113/142]

leveldb::TEST ( DBTest  ,
MinorCompactionsHappen   
)

Definition at line 930 of file db_test.cc.

930  {
931  Options options = CurrentOptions();
932  options.write_buffer_size = 10000;
933  Reopen(&options);
934 
935  const int N = 500;
936 
937  int starting_num_tables = TotalTableFiles();
938  for (int i = 0; i < N; i++) {
939  ASSERT_OK(Put(Key(i), Key(i) + std::string(1000, 'v')));
940  }
941  int ending_num_tables = TotalTableFiles();
942  ASSERT_GT(ending_num_tables, starting_num_tables);
943 
944  for (int i = 0; i < N; i++) {
945  ASSERT_EQ(Key(i) + std::string(1000, 'v'), Get(Key(i)));
946  }
947 
948  Reopen();
949 
950  for (int i = 0; i < N; i++) {
951  ASSERT_EQ(Key(i) + std::string(1000, 'v'), Get(Key(i)));
952  }
953 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static std::string Key(int i)
Definition: db_test.cc:924

§ TEST() [114/142]

leveldb::TEST ( DBTest  ,
RecoverWithLargeLog   
)

Definition at line 955 of file db_test.cc.

955  {
956  {
957  Options options = CurrentOptions();
958  Reopen(&options);
959  ASSERT_OK(Put("big1", std::string(200000, '1')));
960  ASSERT_OK(Put("big2", std::string(200000, '2')));
961  ASSERT_OK(Put("small3", std::string(10, '3')));
962  ASSERT_OK(Put("small4", std::string(10, '4')));
963  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
964  }
965 
966  // Make sure that if we re-open with a small write buffer size that
967  // we flush table files in the middle of a large log file.
968  Options options = CurrentOptions();
969  options.write_buffer_size = 100000;
970  Reopen(&options);
971  ASSERT_EQ(NumTableFilesAtLevel(0), 3);
972  ASSERT_EQ(std::string(200000, '1'), Get("big1"));
973  ASSERT_EQ(std::string(200000, '2'), Get("big2"));
974  ASSERT_EQ(std::string(10, '3'), Get("small3"));
975  ASSERT_EQ(std::string(10, '4'), Get("small4"));
976  ASSERT_GT(NumTableFilesAtLevel(0), 1);
977 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [115/142]

leveldb::TEST ( DBTest  ,
CompactionsGenerateMultipleFiles   
)

Definition at line 979 of file db_test.cc.

979  {
980  Options options = CurrentOptions();
981  options.write_buffer_size = 100000000; // Large write buffer
982  Reopen(&options);
983 
984  Random rnd(301);
985 
986  // Write 8MB (80 values, each 100K)
987  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
988  std::vector<std::string> values;
989  for (int i = 0; i < 80; i++) {
990  values.push_back(RandomString(&rnd, 100000));
991  ASSERT_OK(Put(Key(i), values[i]));
992  }
993 
994  // Reopening moves updates to level-0
995  Reopen(&options);
996  dbfull()->TEST_CompactRange(0, NULL, NULL);
997 
998  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
999  ASSERT_GT(NumTableFilesAtLevel(1), 1);
1000  for (int i = 0; i < 80; i++) {
1001  ASSERT_EQ(Get(Key(i)), values[i]);
1002  }
1003 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static std::string Key(int i)
Definition: db_test.cc:924
Here is the call graph for this function:

§ TEST() [116/142]

leveldb::TEST ( DBTest  ,
RepeatedWritesToSameKey   
)

Definition at line 1005 of file db_test.cc.

1005  {
1006  Options options = CurrentOptions();
1007  options.env = env_;
1008  options.write_buffer_size = 100000; // Small write buffer
1009  Reopen(&options);
1010 
1011  // We must have at most one file per level except for level-0,
1012  // which may have up to kL0_StopWritesTrigger files.
1013  const int kMaxFiles = config::kNumLevels + config::kL0_StopWritesTrigger;
1014 
1015  Random rnd(301);
1016  std::string value = RandomString(&rnd, 2 * options.write_buffer_size);
1017  for (int i = 0; i < 5 * kMaxFiles; i++) {
1018  Put("key", value);
1019  ASSERT_LE(TotalTableFiles(), kMaxFiles);
1020  fprintf(stderr, "after %d: %d files\n", int(i+1), TotalTableFiles());
1021  }
1022 }
static const int kL0_StopWritesTrigger
Definition: dbformat.h:31
static const int kNumLevels
Definition: dbformat.h:22
#define ASSERT_LE(a, b)
Definition: testharness.h:111
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
Here is the call graph for this function:

§ TEST() [117/142]

leveldb::TEST ( DBTest  ,
SparseMerge   
)

Definition at line 1024 of file db_test.cc.

1024  {
1025  Options options = CurrentOptions();
1026  options.compression = kNoCompression;
1027  Reopen(&options);
1028 
1029  FillLevels("A", "Z");
1030 
1031  // Suppose there is:
1032  // small amount of data with prefix A
1033  // large amount of data with prefix B
1034  // small amount of data with prefix C
1035  // and that recent updates have made small changes to all three prefixes.
1036  // Check that we do not do a compaction that merges all of B in one shot.
1037  const std::string value(1000, 'x');
1038  Put("A", "va");
1039  // Write approximately 100MB of "B" values
1040  for (int i = 0; i < 100000; i++) {
1041  char key[100];
1042  snprintf(key, sizeof(key), "B%010d", i);
1043  Put(key, value);
1044  }
1045  Put("C", "vc");
1046  dbfull()->TEST_CompactMemTable();
1047  dbfull()->TEST_CompactRange(0, NULL, NULL);
1048 
1049  // Make sparse update
1050  Put("A", "va2");
1051  Put("B100", "bvalue2");
1052  Put("C", "vc2");
1053  dbfull()->TEST_CompactMemTable();
1054 
1055  // Compactions should not cause us to create a situation where
1056  // a file overlaps too much data at the next level.
1057  ASSERT_LE(dbfull()->TEST_MaxNextLevelOverlappingBytes(), 20*1048576);
1058  dbfull()->TEST_CompactRange(0, NULL, NULL);
1059  ASSERT_LE(dbfull()->TEST_MaxNextLevelOverlappingBytes(), 20*1048576);
1060  dbfull()->TEST_CompactRange(1, NULL, NULL);
1061  ASSERT_LE(dbfull()->TEST_MaxNextLevelOverlappingBytes(), 20*1048576);
1062 }
#define ASSERT_LE(a, b)
Definition: testharness.h:111

§ TEST() [118/142]

leveldb::TEST ( DBTest  ,
ApproximateSizes   
)

Definition at line 1075 of file db_test.cc.

1075  {
1076  do {
1077  Options options = CurrentOptions();
1078  options.write_buffer_size = 100000000; // Large write buffer
1079  options.compression = kNoCompression;
1080  DestroyAndReopen();
1081 
1082  ASSERT_TRUE(Between(Size("", "xyz"), 0, 0));
1083  Reopen(&options);
1084  ASSERT_TRUE(Between(Size("", "xyz"), 0, 0));
1085 
1086  // Write 8MB (80 values, each 100K)
1087  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
1088  const int N = 80;
1089  static const int S1 = 100000;
1090  static const int S2 = 105000; // Allow some expansion from metadata
1091  Random rnd(301);
1092  for (int i = 0; i < N; i++) {
1093  ASSERT_OK(Put(Key(i), RandomString(&rnd, S1)));
1094  }
1095 
1096  // 0 because GetApproximateSizes() does not account for memtable space
1097  ASSERT_TRUE(Between(Size("", Key(50)), 0, 0));
1098 
1099  if (options.reuse_logs) {
1100  // Recovery will reuse memtable, and GetApproximateSizes() does not
1101  // account for memtable usage;
1102  Reopen(&options);
1103  ASSERT_TRUE(Between(Size("", Key(50)), 0, 0));
1104  continue;
1105  }
1106 
1107  // Check sizes across recovery by reopening a few times
1108  for (int run = 0; run < 3; run++) {
1109  Reopen(&options);
1110 
1111  for (int compact_start = 0; compact_start < N; compact_start += 10) {
1112  for (int i = 0; i < N; i += 10) {
1113  ASSERT_TRUE(Between(Size("", Key(i)), S1*i, S2*i));
1114  ASSERT_TRUE(Between(Size("", Key(i)+".suffix"), S1*(i+1), S2*(i+1)));
1115  ASSERT_TRUE(Between(Size(Key(i), Key(i+10)), S1*10, S2*10));
1116  }
1117  ASSERT_TRUE(Between(Size("", Key(50)), S1*50, S2*50));
1118  ASSERT_TRUE(Between(Size("", Key(50)+".suffix"), S1*50, S2*50));
1119 
1120  std::string cstart_str = Key(compact_start);
1121  std::string cend_str = Key(compact_start + 9);
1122  Slice cstart = cstart_str;
1123  Slice cend = cend_str;
1124  dbfull()->TEST_CompactRange(0, &cstart, &cend);
1125  }
1126 
1127  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
1128  ASSERT_GT(NumTableFilesAtLevel(1), 0);
1129  }
1130  } while (ChangeOptions());
1131 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
static bool Between(uint64_t val, uint64_t low, uint64_t high)
Definition: db_test.cc:1064
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static std::string Key(int i)
Definition: db_test.cc:924
Here is the call graph for this function:

§ TEST() [119/142]

leveldb::TEST ( DBTest  ,
ApproximateSizes_MixOfSmallAndLarge   
)

Definition at line 1133 of file db_test.cc.

1133  {
1134  do {
1135  Options options = CurrentOptions();
1136  options.compression = kNoCompression;
1137  Reopen();
1138 
1139  Random rnd(301);
1140  std::string big1 = RandomString(&rnd, 100000);
1141  ASSERT_OK(Put(Key(0), RandomString(&rnd, 10000)));
1142  ASSERT_OK(Put(Key(1), RandomString(&rnd, 10000)));
1143  ASSERT_OK(Put(Key(2), big1));
1144  ASSERT_OK(Put(Key(3), RandomString(&rnd, 10000)));
1145  ASSERT_OK(Put(Key(4), big1));
1146  ASSERT_OK(Put(Key(5), RandomString(&rnd, 10000)));
1147  ASSERT_OK(Put(Key(6), RandomString(&rnd, 300000)));
1148  ASSERT_OK(Put(Key(7), RandomString(&rnd, 10000)));
1149 
1150  if (options.reuse_logs) {
1151  // Need to force a memtable compaction since recovery does not do so.
1152  ASSERT_OK(dbfull()->TEST_CompactMemTable());
1153  }
1154 
1155  // Check sizes across recovery by reopening a few times
1156  for (int run = 0; run < 3; run++) {
1157  Reopen(&options);
1158 
1159  ASSERT_TRUE(Between(Size("", Key(0)), 0, 0));
1160  ASSERT_TRUE(Between(Size("", Key(1)), 10000, 11000));
1161  ASSERT_TRUE(Between(Size("", Key(2)), 20000, 21000));
1162  ASSERT_TRUE(Between(Size("", Key(3)), 120000, 121000));
1163  ASSERT_TRUE(Between(Size("", Key(4)), 130000, 131000));
1164  ASSERT_TRUE(Between(Size("", Key(5)), 230000, 231000));
1165  ASSERT_TRUE(Between(Size("", Key(6)), 240000, 241000));
1166  ASSERT_TRUE(Between(Size("", Key(7)), 540000, 541000));
1167  ASSERT_TRUE(Between(Size("", Key(8)), 550000, 560000));
1168 
1169  ASSERT_TRUE(Between(Size(Key(3), Key(5)), 110000, 111000));
1170 
1171  dbfull()->TEST_CompactRange(0, NULL, NULL);
1172  }
1173  } while (ChangeOptions());
1174 }
#define ASSERT_OK(s)
Definition: testharness.h:106
static bool Between(uint64_t val, uint64_t low, uint64_t high)
Definition: db_test.cc:1064
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static std::string Key(int i)
Definition: db_test.cc:924
Here is the call graph for this function:

§ TEST() [120/142]

leveldb::TEST ( DBTest  ,
IteratorPinsRef   
)

Definition at line 1176 of file db_test.cc.

1176  {
1177  Put("foo", "hello");
1178 
1179  // Get iterator that will yield the current contents of the DB.
1180  Iterator* iter = db_->NewIterator(ReadOptions());
1181 
1182  // Write to force compactions
1183  Put("foo", "newvalue1");
1184  for (int i = 0; i < 100; i++) {
1185  ASSERT_OK(Put(Key(i), Key(i) + std::string(100000, 'v'))); // 100K values
1186  }
1187  Put("foo", "newvalue2");
1188 
1189  iter->SeekToFirst();
1190  ASSERT_TRUE(iter->Valid());
1191  ASSERT_EQ("foo", iter->key().ToString());
1192  ASSERT_EQ("hello", iter->value().ToString());
1193  iter->Next();
1194  ASSERT_TRUE(!iter->Valid());
1195  delete iter;
1196 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static std::string Key(int i)
Definition: db_test.cc:924
Here is the call graph for this function:

§ TEST() [121/142]

leveldb::TEST ( DBTest  ,
Snapshot   
)

Definition at line 1198 of file db_test.cc.

1198  {
1199  do {
1200  Put("foo", "v1");
1201  const Snapshot* s1 = db_->GetSnapshot();
1202  Put("foo", "v2");
1203  const Snapshot* s2 = db_->GetSnapshot();
1204  Put("foo", "v3");
1205  const Snapshot* s3 = db_->GetSnapshot();
1206 
1207  Put("foo", "v4");
1208  ASSERT_EQ("v1", Get("foo", s1));
1209  ASSERT_EQ("v2", Get("foo", s2));
1210  ASSERT_EQ("v3", Get("foo", s3));
1211  ASSERT_EQ("v4", Get("foo"));
1212 
1213  db_->ReleaseSnapshot(s3);
1214  ASSERT_EQ("v1", Get("foo", s1));
1215  ASSERT_EQ("v2", Get("foo", s2));
1216  ASSERT_EQ("v4", Get("foo"));
1217 
1218  db_->ReleaseSnapshot(s1);
1219  ASSERT_EQ("v2", Get("foo", s2));
1220  ASSERT_EQ("v4", Get("foo"));
1221 
1222  db_->ReleaseSnapshot(s2);
1223  ASSERT_EQ("v4", Get("foo"));
1224  } while (ChangeOptions());
1225 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [122/142]

leveldb::TEST ( DBTest  ,
HiddenValuesAreRemoved   
)

Definition at line 1227 of file db_test.cc.

1227  {
1228  do {
1229  Random rnd(301);
1230  FillLevels("a", "z");
1231 
1232  std::string big = RandomString(&rnd, 50000);
1233  Put("foo", big);
1234  Put("pastfoo", "v");
1235  const Snapshot* snapshot = db_->GetSnapshot();
1236  Put("foo", "tiny");
1237  Put("pastfoo2", "v2"); // Advance sequence number one more
1238 
1239  ASSERT_OK(dbfull()->TEST_CompactMemTable());
1240  ASSERT_GT(NumTableFilesAtLevel(0), 0);
1241 
1242  ASSERT_EQ(big, Get("foo", snapshot));
1243  ASSERT_TRUE(Between(Size("", "pastfoo"), 50000, 60000));
1244  db_->ReleaseSnapshot(snapshot);
1245  ASSERT_EQ(AllEntriesFor("foo"), "[ tiny, " + big + " ]");
1246  Slice x("x");
1247  dbfull()->TEST_CompactRange(0, NULL, &x);
1248  ASSERT_EQ(AllEntriesFor("foo"), "[ tiny ]");
1249  ASSERT_EQ(NumTableFilesAtLevel(0), 0);
1250  ASSERT_GE(NumTableFilesAtLevel(1), 1);
1251  dbfull()->TEST_CompactRange(1, NULL, &x);
1252  ASSERT_EQ(AllEntriesFor("foo"), "[ tiny ]");
1253 
1254  ASSERT_TRUE(Between(Size("", "pastfoo"), 0, 1000));
1255  } while (ChangeOptions());
1256 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
static bool Between(uint64_t val, uint64_t low, uint64_t high)
Definition: db_test.cc:1064
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
#define ASSERT_GE(a, b)
Definition: testharness.h:109
Here is the call graph for this function:

§ TEST() [123/142]

leveldb::TEST ( DBTest  ,
DeletionMarkers1   
)

Definition at line 1258 of file db_test.cc.

1258  {
1259  Put("foo", "v1");
1260  ASSERT_OK(dbfull()->TEST_CompactMemTable());
1261  const int last = config::kMaxMemCompactLevel;
1262  ASSERT_EQ(NumTableFilesAtLevel(last), 1); // foo => v1 is now in last level
1263 
1264  // Place a table at level last-1 to prevent merging with preceding mutation
1265  Put("a", "begin");
1266  Put("z", "end");
1267  dbfull()->TEST_CompactMemTable();
1268  ASSERT_EQ(NumTableFilesAtLevel(last), 1);
1269  ASSERT_EQ(NumTableFilesAtLevel(last-1), 1);
1270 
1271  Delete("foo");
1272  Put("foo", "v2");
1273  ASSERT_EQ(AllEntriesFor("foo"), "[ v2, DEL, v1 ]");
1274  ASSERT_OK(dbfull()->TEST_CompactMemTable()); // Moves to level last-2
1275  ASSERT_EQ(AllEntriesFor("foo"), "[ v2, DEL, v1 ]");
1276  Slice z("z");
1277  dbfull()->TEST_CompactRange(last-2, NULL, &z);
1278  // DEL eliminated, but v1 remains because we aren't compacting that level
1279  // (DEL can be eliminated because v2 hides v1).
1280  ASSERT_EQ(AllEntriesFor("foo"), "[ v2, v1 ]");
1281  dbfull()->TEST_CompactRange(last-1, NULL, NULL);
1282  // Merging last-1 w/ last, so we are the base level for "foo", so
1283  // DEL is removed. (as is v1).
1284  ASSERT_EQ(AllEntriesFor("foo"), "[ v2 ]");
1285 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kMaxMemCompactLevel
Definition: dbformat.h:39

§ TEST() [124/142]

leveldb::TEST ( DBTest  ,
DeletionMarkers2   
)

Definition at line 1287 of file db_test.cc.

1287  {
1288  Put("foo", "v1");
1289  ASSERT_OK(dbfull()->TEST_CompactMemTable());
1290  const int last = config::kMaxMemCompactLevel;
1291  ASSERT_EQ(NumTableFilesAtLevel(last), 1); // foo => v1 is now in last level
1292 
1293  // Place a table at level last-1 to prevent merging with preceding mutation
1294  Put("a", "begin");
1295  Put("z", "end");
1296  dbfull()->TEST_CompactMemTable();
1297  ASSERT_EQ(NumTableFilesAtLevel(last), 1);
1298  ASSERT_EQ(NumTableFilesAtLevel(last-1), 1);
1299 
1300  Delete("foo");
1301  ASSERT_EQ(AllEntriesFor("foo"), "[ DEL, v1 ]");
1302  ASSERT_OK(dbfull()->TEST_CompactMemTable()); // Moves to level last-2
1303  ASSERT_EQ(AllEntriesFor("foo"), "[ DEL, v1 ]");
1304  dbfull()->TEST_CompactRange(last-2, NULL, NULL);
1305  // DEL kept: "last" file overlaps
1306  ASSERT_EQ(AllEntriesFor("foo"), "[ DEL, v1 ]");
1307  dbfull()->TEST_CompactRange(last-1, NULL, NULL);
1308  // Merging last-1 w/ last, so we are the base level for "foo", so
1309  // DEL is removed. (as is v1).
1310  ASSERT_EQ(AllEntriesFor("foo"), "[ ]");
1311 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kMaxMemCompactLevel
Definition: dbformat.h:39

§ TEST() [125/142]

leveldb::TEST ( DBTest  ,
OverlapInLevel0   
)

Definition at line 1313 of file db_test.cc.

1313  {
1314  do {
1315  ASSERT_EQ(config::kMaxMemCompactLevel, 2) << "Fix test to match config";
1316 
1317  // Fill levels 1 and 2 to disable the pushing of new memtables to levels > 0.
1318  ASSERT_OK(Put("100", "v100"));
1319  ASSERT_OK(Put("999", "v999"));
1320  dbfull()->TEST_CompactMemTable();
1321  ASSERT_OK(Delete("100"));
1322  ASSERT_OK(Delete("999"));
1323  dbfull()->TEST_CompactMemTable();
1324  ASSERT_EQ("0,1,1", FilesPerLevel());
1325 
1326  // Make files spanning the following ranges in level-0:
1327  // files[0] 200 .. 900
1328  // files[1] 300 .. 500
1329  // Note that files are sorted by smallest key.
1330  ASSERT_OK(Put("300", "v300"));
1331  ASSERT_OK(Put("500", "v500"));
1332  dbfull()->TEST_CompactMemTable();
1333  ASSERT_OK(Put("200", "v200"));
1334  ASSERT_OK(Put("600", "v600"));
1335  ASSERT_OK(Put("900", "v900"));
1336  dbfull()->TEST_CompactMemTable();
1337  ASSERT_EQ("2,1,1", FilesPerLevel());
1338 
1339  // Compact away the placeholder files we created initially
1340  dbfull()->TEST_CompactRange(1, NULL, NULL);
1341  dbfull()->TEST_CompactRange(2, NULL, NULL);
1342  ASSERT_EQ("2", FilesPerLevel());
1343 
1344  // Do a memtable compaction. Before bug-fix, the compaction would
1345  // not detect the overlap with level-0 files and would incorrectly place
1346  // the deletion in a deeper level.
1347  ASSERT_OK(Delete("600"));
1348  dbfull()->TEST_CompactMemTable();
1349  ASSERT_EQ("3", FilesPerLevel());
1350  ASSERT_EQ("NOT_FOUND", Get("600"));
1351  } while (ChangeOptions());
1352 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kMaxMemCompactLevel
Definition: dbformat.h:39

§ TEST() [126/142]

leveldb::TEST ( DBTest  ,
L0_CompactionBug_Issue44_a   
)

Definition at line 1354 of file db_test.cc.

1354  {
1355  Reopen();
1356  ASSERT_OK(Put("b", "v"));
1357  Reopen();
1358  ASSERT_OK(Delete("b"));
1359  ASSERT_OK(Delete("a"));
1360  Reopen();
1361  ASSERT_OK(Delete("a"));
1362  Reopen();
1363  ASSERT_OK(Put("a", "v"));
1364  Reopen();
1365  Reopen();
1366  ASSERT_EQ("(a->v)", Contents());
1367  DelayMilliseconds(1000); // Wait for compaction to finish
1368  ASSERT_EQ("(a->v)", Contents());
1369 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [127/142]

leveldb::TEST ( DBTest  ,
L0_CompactionBug_Issue44_b   
)

Definition at line 1371 of file db_test.cc.

1371  {
1372  Reopen();
1373  Put("","");
1374  Reopen();
1375  Delete("e");
1376  Put("","");
1377  Reopen();
1378  Put("c", "cv");
1379  Reopen();
1380  Put("","");
1381  Reopen();
1382  Put("","");
1383  DelayMilliseconds(1000); // Wait for compaction to finish
1384  Reopen();
1385  Put("d","dv");
1386  Reopen();
1387  Put("","");
1388  Reopen();
1389  Delete("d");
1390  Delete("b");
1391  Reopen();
1392  ASSERT_EQ("(->)(c->cv)", Contents());
1393  DelayMilliseconds(1000); // Wait for compaction to finish
1394  ASSERT_EQ("(->)(c->cv)", Contents());
1395 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
Here is the call graph for this function:

§ TEST() [128/142]

leveldb::TEST ( DBTest  ,
ComparatorCheck   
)

Definition at line 1397 of file db_test.cc.

1397  {
1398  class NewComparator : public Comparator {
1399  public:
1400  virtual const char* Name() const { return "leveldb.NewComparator"; }
1401  virtual int Compare(const Slice& a, const Slice& b) const {
1402  return BytewiseComparator()->Compare(a, b);
1403  }
1404  virtual void FindShortestSeparator(std::string* s, const Slice& l) const {
1406  }
1407  virtual void FindShortSuccessor(std::string* key) const {
1409  }
1410  };
1411  NewComparator cmp;
1412  Options new_options = CurrentOptions();
1413  new_options.comparator = &cmp;
1414  Status s = TryReopen(&new_options);
1415  ASSERT_TRUE(!s.ok());
1416  ASSERT_TRUE(s.ToString().find("comparator") != std::string::npos)
1417  << s.ToString();
1418 }
virtual void FindShortestSeparator(std::string *start, const Slice &limit) const =0
#define ASSERT_TRUE(c)
Definition: testharness.h:105
virtual void FindShortSuccessor(std::string *key) const =0
const Comparator * BytewiseComparator()
Definition: comparator.cc:76
virtual int Compare(const Slice &a, const Slice &b) const =0
Here is the call graph for this function:

§ TEST() [129/142]

leveldb::TEST ( DBTest  ,
CustomComparator   
)

Definition at line 1420 of file db_test.cc.

1420  {
1421  class NumberComparator : public Comparator {
1422  public:
1423  virtual const char* Name() const { return "test.NumberComparator"; }
1424  virtual int Compare(const Slice& a, const Slice& b) const {
1425  return ToNumber(a) - ToNumber(b);
1426  }
1427  virtual void FindShortestSeparator(std::string* s, const Slice& l) const {
1428  ToNumber(*s); // Check format
1429  ToNumber(l); // Check format
1430  }
1431  virtual void FindShortSuccessor(std::string* key) const {
1432  ToNumber(*key); // Check format
1433  }
1434  private:
1435  static int ToNumber(const Slice& x) {
1436  // Check that there are no extra characters.
1437  ASSERT_TRUE(x.size() >= 2 && x[0] == '[' && x[x.size()-1] == ']')
1438  << EscapeString(x);
1439  int val;
1440  char ignored;
1441  ASSERT_TRUE(sscanf(x.ToString().c_str(), "[%i]%c", &val, &ignored) == 1)
1442  << EscapeString(x);
1443  return val;
1444  }
1445  };
1446  NumberComparator cmp;
1447  Options new_options = CurrentOptions();
1448  new_options.create_if_missing = true;
1449  new_options.comparator = &cmp;
1450  new_options.filter_policy = NULL; // Cannot use bloom filters
1451  new_options.write_buffer_size = 1000; // Compact more often
1452  DestroyAndReopen(&new_options);
1453  ASSERT_OK(Put("[10]", "ten"));
1454  ASSERT_OK(Put("[0x14]", "twenty"));
1455  for (int i = 0; i < 2; i++) {
1456  ASSERT_EQ("ten", Get("[10]"));
1457  ASSERT_EQ("ten", Get("[0xa]"));
1458  ASSERT_EQ("twenty", Get("[20]"));
1459  ASSERT_EQ("twenty", Get("[0x14]"));
1460  ASSERT_EQ("NOT_FOUND", Get("[15]"));
1461  ASSERT_EQ("NOT_FOUND", Get("[0xf]"));
1462  Compact("[0]", "[9999]");
1463  }
1464 
1465  for (int run = 0; run < 2; run++) {
1466  for (int i = 0; i < 1000; i++) {
1467  char buf[100];
1468  snprintf(buf, sizeof(buf), "[%d]", i*10);
1469  ASSERT_OK(Put(buf, buf));
1470  }
1471  Compact("[0]", "[1000000]");
1472  }
1473 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
std::string EscapeString(const Slice &value)
Definition: logging.cc:42
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [130/142]

leveldb::TEST ( DBTest  ,
ManualCompaction   
)

Definition at line 1475 of file db_test.cc.

1475  {
1477  << "Need to update this test to match kMaxMemCompactLevel";
1478 
1479  MakeTables(3, "p", "q");
1480  ASSERT_EQ("1,1,1", FilesPerLevel());
1481 
1482  // Compaction range falls before files
1483  Compact("", "c");
1484  ASSERT_EQ("1,1,1", FilesPerLevel());
1485 
1486  // Compaction range falls after files
1487  Compact("r", "z");
1488  ASSERT_EQ("1,1,1", FilesPerLevel());
1489 
1490  // Compaction range overlaps files
1491  Compact("p1", "p9");
1492  ASSERT_EQ("0,0,1", FilesPerLevel());
1493 
1494  // Populate a different range
1495  MakeTables(3, "c", "e");
1496  ASSERT_EQ("1,1,2", FilesPerLevel());
1497 
1498  // Compact just the new range
1499  Compact("b", "f");
1500  ASSERT_EQ("0,0,2", FilesPerLevel());
1501 
1502  // Compact all
1503  MakeTables(1, "a", "z");
1504  ASSERT_EQ("0,1,2", FilesPerLevel());
1505  db_->CompactRange(NULL, NULL);
1506  ASSERT_EQ("0,0,1", FilesPerLevel());
1507 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kMaxMemCompactLevel
Definition: dbformat.h:39

§ TEST() [131/142]

leveldb::TEST ( DBTest  ,
DBOpen_Options   
)

Definition at line 1509 of file db_test.cc.

1509  {
1510  std::string dbname = test::TmpDir() + "/db_options_test";
1511  DestroyDB(dbname, Options());
1512 
1513  // Does not exist, and create_if_missing == false: error
1514  DB* db = NULL;
1515  Options opts;
1516  opts.create_if_missing = false;
1517  Status s = DB::Open(opts, dbname, &db);
1518  ASSERT_TRUE(strstr(s.ToString().c_str(), "does not exist") != NULL);
1519  ASSERT_TRUE(db == NULL);
1520 
1521  // Does not exist, and create_if_missing == true: OK
1522  opts.create_if_missing = true;
1523  s = DB::Open(opts, dbname, &db);
1524  ASSERT_OK(s);
1525  ASSERT_TRUE(db != NULL);
1526 
1527  delete db;
1528  db = NULL;
1529 
1530  // Does exist, and error_if_exists == true: error
1531  opts.create_if_missing = false;
1532  opts.error_if_exists = true;
1533  s = DB::Open(opts, dbname, &db);
1534  ASSERT_TRUE(strstr(s.ToString().c_str(), "exists") != NULL);
1535  ASSERT_TRUE(db == NULL);
1536 
1537  // Does exist, and error_if_exists == false: OK
1538  opts.create_if_missing = true;
1539  opts.error_if_exists = false;
1540  s = DB::Open(opts, dbname, &db);
1541  ASSERT_OK(s);
1542  ASSERT_TRUE(db != NULL);
1543 
1544  delete db;
1545  db = NULL;
1546 }
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 char dbname[200]
Definition: c_test.c:15
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [132/142]

leveldb::TEST ( DBTest  ,
Locking   
)

Definition at line 1548 of file db_test.cc.

1548  {
1549  DB* db2 = NULL;
1550  Status s = DB::Open(CurrentOptions(), dbname_, &db2);
1551  ASSERT_TRUE(!s.ok()) << "Locking did not prevent re-opening db";
1552 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [133/142]

leveldb::TEST ( DBTest  ,
NoSpace   
)

Definition at line 1555 of file db_test.cc.

1555  {
1556  Options options = CurrentOptions();
1557  options.env = env_;
1558  Reopen(&options);
1559 
1560  ASSERT_OK(Put("foo", "v1"));
1561  ASSERT_EQ("v1", Get("foo"));
1562  Compact("a", "z");
1563  const int num_files = CountFiles();
1564  env_->no_space_.Release_Store(env_); // Force out-of-space errors
1565  for (int i = 0; i < 10; i++) {
1566  for (int level = 0; level < config::kNumLevels-1; level++) {
1567  dbfull()->TEST_CompactRange(level, NULL, NULL);
1568  }
1569  }
1570  env_->no_space_.Release_Store(NULL);
1571  ASSERT_LT(CountFiles(), num_files + 3);
1572 }
static const int kNumLevels
Definition: dbformat.h:22
#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

§ TEST() [134/142]

leveldb::TEST ( DBTest  ,
NonWritableFileSystem   
)

Definition at line 1574 of file db_test.cc.

1574  {
1575  Options options = CurrentOptions();
1576  options.write_buffer_size = 1000;
1577  options.env = env_;
1578  Reopen(&options);
1579  ASSERT_OK(Put("foo", "v1"));
1580  env_->non_writable_.Release_Store(env_); // Force errors for new files
1581  std::string big(100000, 'x');
1582  int errors = 0;
1583  for (int i = 0; i < 20; i++) {
1584  fprintf(stderr, "iter %d; errors %d\n", i, errors);
1585  if (!Put("foo", big).ok()) {
1586  errors++;
1587  DelayMilliseconds(100);
1588  }
1589  }
1590  ASSERT_GT(errors, 0);
1591  env_->non_writable_.Release_Store(NULL);
1592 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
Here is the call graph for this function:

§ TEST() [135/142]

leveldb::TEST ( DBTest  ,
WriteSyncError   
)

Definition at line 1594 of file db_test.cc.

1594  {
1595  // Check that log sync errors cause the DB to disallow future writes.
1596 
1597  // (a) Cause log sync calls to fail
1598  Options options = CurrentOptions();
1599  options.env = env_;
1600  Reopen(&options);
1601  env_->data_sync_error_.Release_Store(env_);
1602 
1603  // (b) Normal write should succeed
1604  WriteOptions w;
1605  ASSERT_OK(db_->Put(w, "k1", "v1"));
1606  ASSERT_EQ("v1", Get("k1"));
1607 
1608  // (c) Do a sync write; should fail
1609  w.sync = true;
1610  ASSERT_TRUE(!db_->Put(w, "k2", "v2").ok());
1611  ASSERT_EQ("v1", Get("k1"));
1612  ASSERT_EQ("NOT_FOUND", Get("k2"));
1613 
1614  // (d) make sync behave normally
1615  env_->data_sync_error_.Release_Store(NULL);
1616 
1617  // (e) Do a non-sync write; should fail
1618  w.sync = false;
1619  ASSERT_TRUE(!db_->Put(w, "k3", "v3").ok());
1620  ASSERT_EQ("v1", Get("k1"));
1621  ASSERT_EQ("NOT_FOUND", Get("k2"));
1622  ASSERT_EQ("NOT_FOUND", Get("k3"));
1623 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105

§ TEST() [136/142]

leveldb::TEST ( DBTest  ,
ManifestWriteError   
)

Definition at line 1625 of file db_test.cc.

1625  {
1626  // Test for the following problem:
1627  // (a) Compaction produces file F
1628  // (b) Log record containing F is written to MANIFEST file, but Sync() fails
1629  // (c) GC deletes F
1630  // (d) After reopening DB, reads fail since deleted F is named in log record
1631 
1632  // We iterate twice. In the second iteration, everything is the
1633  // same except the log record never makes it to the MANIFEST file.
1634  for (int iter = 0; iter < 2; iter++) {
1635  port::AtomicPointer* error_type = (iter == 0)
1636  ? &env_->manifest_sync_error_
1637  : &env_->manifest_write_error_;
1638 
1639  // Insert foo=>bar mapping
1640  Options options = CurrentOptions();
1641  options.env = env_;
1642  options.create_if_missing = true;
1643  options.error_if_exists = false;
1644  DestroyAndReopen(&options);
1645  ASSERT_OK(Put("foo", "bar"));
1646  ASSERT_EQ("bar", Get("foo"));
1647 
1648  // Memtable compaction (will succeed)
1649  dbfull()->TEST_CompactMemTable();
1650  ASSERT_EQ("bar", Get("foo"));
1651  const int last = config::kMaxMemCompactLevel;
1652  ASSERT_EQ(NumTableFilesAtLevel(last), 1); // foo=>bar is now in last level
1653 
1654  // Merging compaction (will fail)
1655  error_type->Release_Store(env_);
1656  dbfull()->TEST_CompactRange(last, NULL, NULL); // Should fail
1657  ASSERT_EQ("bar", Get("foo"));
1658 
1659  // Recovery: should not lose data
1660  error_type->Release_Store(NULL);
1661  Reopen(&options);
1662  ASSERT_EQ("bar", Get("foo"));
1663  }
1664 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static const int kMaxMemCompactLevel
Definition: dbformat.h:39

§ TEST() [137/142]

leveldb::TEST ( DBTest  ,
MissingSSTFile   
)

Definition at line 1666 of file db_test.cc.

1666  {
1667  ASSERT_OK(Put("foo", "bar"));
1668  ASSERT_EQ("bar", Get("foo"));
1669 
1670  // Dump the memtable to disk.
1671  dbfull()->TEST_CompactMemTable();
1672  ASSERT_EQ("bar", Get("foo"));
1673 
1674  Close();
1675  ASSERT_TRUE(DeleteAnSSTFile());
1676  Options options = CurrentOptions();
1677  options.paranoid_checks = true;
1678  Status s = TryReopen(&options);
1679  ASSERT_TRUE(!s.ok());
1680  ASSERT_TRUE(s.ToString().find("issing") != std::string::npos)
1681  << s.ToString();
1682 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [138/142]

leveldb::TEST ( DBTest  ,
StillReadSST   
)

Definition at line 1684 of file db_test.cc.

1684  {
1685  ASSERT_OK(Put("foo", "bar"));
1686  ASSERT_EQ("bar", Get("foo"));
1687 
1688  // Dump the memtable to disk.
1689  dbfull()->TEST_CompactMemTable();
1690  ASSERT_EQ("bar", Get("foo"));
1691  Close();
1692  ASSERT_GT(RenameLDBToSST(), 0);
1693  Options options = CurrentOptions();
1694  options.paranoid_checks = true;
1695  Status s = TryReopen(&options);
1696  ASSERT_TRUE(s.ok());
1697  ASSERT_EQ("bar", Get("foo"));
1698 }
#define ASSERT_GT(a, b)
Definition: testharness.h:110
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TEST() [139/142]

leveldb::TEST ( DBTest  ,
FilesDeletedAfterCompaction   
)

Definition at line 1700 of file db_test.cc.

1700  {
1701  ASSERT_OK(Put("foo", "v2"));
1702  Compact("a", "z");
1703  const int num_files = CountFiles();
1704  for (int i = 0; i < 10; i++) {
1705  ASSERT_OK(Put("foo", "v2"));
1706  Compact("a", "z");
1707  }
1708  ASSERT_EQ(CountFiles(), num_files);
1709 }
#define ASSERT_OK(s)
Definition: testharness.h:106
#define ASSERT_EQ(a, b)
Definition: testharness.h:107

§ TEST() [140/142]

leveldb::TEST ( DBTest  ,
BloomFilter   
)

Definition at line 1711 of file db_test.cc.

1711  {
1712  env_->count_random_reads_ = true;
1713  Options options = CurrentOptions();
1714  options.env = env_;
1715  options.block_cache = NewLRUCache(0); // Prevent cache hits
1716  options.filter_policy = NewBloomFilterPolicy(10);
1717  Reopen(&options);
1718 
1719  // Populate multiple layers
1720  const int N = 10000;
1721  for (int i = 0; i < N; i++) {
1722  ASSERT_OK(Put(Key(i), Key(i)));
1723  }
1724  Compact("a", "z");
1725  for (int i = 0; i < N; i += 100) {
1726  ASSERT_OK(Put(Key(i), Key(i)));
1727  }
1728  dbfull()->TEST_CompactMemTable();
1729 
1730  // Prevent auto compactions triggered by seeks
1731  env_->delay_data_sync_.Release_Store(env_);
1732 
1733  // Lookup present keys. Should rarely read from small sstable.
1734  env_->random_read_counter_.Reset();
1735  for (int i = 0; i < N; i++) {
1736  ASSERT_EQ(Key(i), Get(Key(i)));
1737  }
1738  int reads = env_->random_read_counter_.Read();
1739  fprintf(stderr, "%d present => %d reads\n", N, reads);
1740  ASSERT_GE(reads, N);
1741  ASSERT_LE(reads, N + 2*N/100);
1742 
1743  // Lookup present keys. Should rarely read from either sstable.
1744  env_->random_read_counter_.Reset();
1745  for (int i = 0; i < N; i++) {
1746  ASSERT_EQ("NOT_FOUND", Get(Key(i) + ".missing"));
1747  }
1748  reads = env_->random_read_counter_.Read();
1749  fprintf(stderr, "%d missing => %d reads\n", N, reads);
1750  ASSERT_LE(reads, 3*N/100);
1751 
1752  env_->delay_data_sync_.Release_Store(NULL);
1753  Close();
1754  delete options.block_cache;
1755  delete options.filter_policy;
1756 }
#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
const FilterPolicy * NewBloomFilterPolicy(int bits_per_key)
Definition: bloom.cc:91
#define ASSERT_GE(a, b)
Definition: testharness.h:109
static std::string Key(int i)
Definition: db_test.cc:924
Cache * NewLRUCache(size_t capacity)
Definition: cache.cc:401
Here is the call graph for this function:

§ TEST() [141/142]

leveldb::TEST ( DBTest  ,
MultiThreaded   
)

Definition at line 1824 of file db_test.cc.

1824  {
1825  do {
1826  // Initialize state
1827  MTState mt;
1828  mt.test = this;
1829  mt.stop.Release_Store(0);
1830  for (int id = 0; id < kNumThreads; id++) {
1831  mt.counter[id].Release_Store(0);
1832  mt.thread_done[id].Release_Store(0);
1833  }
1834 
1835  // Start threads
1836  MTThread thread[kNumThreads];
1837  for (int id = 0; id < kNumThreads; id++) {
1838  thread[id].state = &mt;
1839  thread[id].id = id;
1840  env_->StartThread(MTThreadBody, &thread[id]);
1841  }
1842 
1843  // Let them run for a while
1845 
1846  // Stop the threads and wait for them to finish
1847  mt.stop.Release_Store(&mt);
1848  for (int id = 0; id < kNumThreads; id++) {
1849  while (mt.thread_done[id].Acquire_Load() == NULL) {
1850  DelayMilliseconds(100);
1851  }
1852  }
1853  } while (ChangeOptions());
1854 }
static void MTThreadBody(void *arg)
Definition: db_test.cc:1777
Here is the call graph for this function:

§ TEST() [142/142]

leveldb::TEST ( DBTest  ,
Randomized   
)

Definition at line 2017 of file db_test.cc.

2017  {
2018  Random rnd(test::RandomSeed());
2019  do {
2020  ModelDB model(CurrentOptions());
2021  const int N = 10000;
2022  const Snapshot* model_snap = NULL;
2023  const Snapshot* db_snap = NULL;
2024  std::string k, v;
2025  for (int step = 0; step < N; step++) {
2026  if (step % 100 == 0) {
2027  fprintf(stderr, "Step %d of %d\n", step, N);
2028  }
2029  // TODO(sanjay): Test Get() works
2030  int p = rnd.Uniform(100);
2031  if (p < 45) { // Put
2032  k = RandomKey(&rnd);
2033  v = RandomString(&rnd,
2034  rnd.OneIn(20)
2035  ? 100 + rnd.Uniform(100)
2036  : rnd.Uniform(8));
2037  ASSERT_OK(model.Put(WriteOptions(), k, v));
2038  ASSERT_OK(db_->Put(WriteOptions(), k, v));
2039 
2040  } else if (p < 90) { // Delete
2041  k = RandomKey(&rnd);
2042  ASSERT_OK(model.Delete(WriteOptions(), k));
2043  ASSERT_OK(db_->Delete(WriteOptions(), k));
2044 
2045 
2046  } else { // Multi-element batch
2047  WriteBatch b;
2048  const int num = rnd.Uniform(8);
2049  for (int i = 0; i < num; i++) {
2050  if (i == 0 || !rnd.OneIn(10)) {
2051  k = RandomKey(&rnd);
2052  } else {
2053  // Periodically re-use the same key from the previous iter, so
2054  // we have multiple entries in the write batch for the same key
2055  }
2056  if (rnd.OneIn(2)) {
2057  v = RandomString(&rnd, rnd.Uniform(10));
2058  b.Put(k, v);
2059  } else {
2060  b.Delete(k);
2061  }
2062  }
2063  ASSERT_OK(model.Write(WriteOptions(), &b));
2064  ASSERT_OK(db_->Write(WriteOptions(), &b));
2065  }
2066 
2067  if ((step % 100) == 0) {
2068  ASSERT_TRUE(CompareIterators(step, &model, db_, NULL, NULL));
2069  ASSERT_TRUE(CompareIterators(step, &model, db_, model_snap, db_snap));
2070  // Save a snapshot from each DB this time that we'll use next
2071  // time we compare things, to make sure the current state is
2072  // preserved with the snapshot
2073  if (model_snap != NULL) model.ReleaseSnapshot(model_snap);
2074  if (db_snap != NULL) db_->ReleaseSnapshot(db_snap);
2075 
2076  Reopen();
2077  ASSERT_TRUE(CompareIterators(step, &model, db_, NULL, NULL));
2078 
2079  model_snap = model.GetSnapshot();
2080  db_snap = db_->GetSnapshot();
2081  }
2082  }
2083  if (model_snap != NULL) model.ReleaseSnapshot(model_snap);
2084  if (db_snap != NULL) db_->ReleaseSnapshot(db_snap);
2085  } while (ChangeOptions());
2086 }
static bool CompareIterators(int step, DB *model, DB *db, const Snapshot *model_snap, const Snapshot *db_snap)
Definition: db_test.cc:1969
int RandomSeed()
Definition: testharness.cc:67
#define ASSERT_OK(s)
Definition: testharness.h:106
static std::string RandomString(Random *rnd, int len)
Definition: db_test.cc:22
static std::string RandomKey(Random *rnd)
Definition: db_test.cc:1962
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TestEncodeDecode()

static void leveldb::TestEncodeDecode ( const VersionEdit edit)
static

Definition at line 10 of file version_edit_test.cc.

10  {
11  std::string encoded, encoded2;
12  edit.EncodeTo(&encoded);
13  VersionEdit parsed;
14  Status s = parsed.DecodeFrom(encoded);
15  ASSERT_TRUE(s.ok()) << s.ToString();
16  parsed.EncodeTo(&encoded2);
17  ASSERT_EQ(encoded, encoded2);
18 }
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:
Here is the caller graph for this function:

§ TestKey()

static void leveldb::TestKey ( const std::string &  key,
uint64_t  seq,
ValueType  vt 
)
static

Definition at line 31 of file dbformat_test.cc.

33  {
34  std::string encoded = IKey(key, seq, vt);
35 
36  Slice in(encoded);
37  ParsedInternalKey decoded("", 0, kTypeValue);
38 
39  ASSERT_TRUE(ParseInternalKey(in, &decoded));
40  ASSERT_EQ(key, decoded.user_key.ToString());
41  ASSERT_EQ(seq, decoded.sequence);
42  ASSERT_EQ(vt, decoded.type);
43 
44  ASSERT_TRUE(!ParseInternalKey(Slice("bar"), &decoded));
45 }
bool ParseInternalKey(const Slice &internal_key, ParsedInternalKey *result)
Definition: dbformat.h:176
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static std::string IKey(const std::string &user_key, uint64_t seq, ValueType vt)
Here is the call graph for this function:
Here is the caller graph for this function:

§ ThreadBody()

static void leveldb::ThreadBody ( void *  arg)
static

Definition at line 73 of file env_test.cc.

73  {
74  State* s = reinterpret_cast<State*>(arg);
75  s->mu.Lock();
76  s->val += 1;
77  s->num_running -= 1;
78  s->mu.Unlock();
79 }
Here is the caller graph for this function:

§ TotalFileSize()

static int64_t leveldb::TotalFileSize ( const std::vector< FileMetaData *> &  files)
static

Definition at line 58 of file version_set.cc.

58  {
59  int64_t sum = 0;
60  for (size_t i = 0; i < files.size(); i++) {
61  sum += files[i]->file_size;
62  }
63  return sum;
64 }
Here is the caller graph for this function:

§ UnrefEntry()

static void leveldb::UnrefEntry ( void *  arg1,
void *  arg2 
)
static

Definition at line 26 of file table_cache.cc.

26  {
27  Cache* cache = reinterpret_cast<Cache*>(arg1);
28  Cache::Handle* h = reinterpret_cast<Cache::Handle*>(arg2);
29  cache->Release(h);
30 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ VarintLength()

int leveldb::VarintLength ( uint64_t  v)

Definition at line 103 of file coding.cc.

103  {
104  int len = 1;
105  while (v >= 128) {
106  v >>= 7;
107  len++;
108  }
109  return len;
110 }
Here is the caller graph for this function:

§ WriteStringToFile()

Status leveldb::WriteStringToFile ( Env env,
const Slice data,
const std::string &  fname 
)

Definition at line 62 of file env.cc.

63  {
64  return DoWriteStringToFile(env, data, fname, false);
65 }
static Status DoWriteStringToFile(Env *env, const Slice &data, const std::string &fname, bool should_sync)
Definition: env.cc:40
Here is the call graph for this function:
Here is the caller graph for this function:

§ WriteStringToFileSync()

Status leveldb::WriteStringToFileSync ( Env env,
const Slice data,
const std::string &  fname 
)

Definition at line 67 of file env.cc.

68  {
69  return DoWriteStringToFile(env, data, fname, true);
70 }
static Status DoWriteStringToFile(Env *env, const Slice &data, const std::string &fname, bool should_sync)
Definition: env.cc:40
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

§ bytewise

const Comparator* leveldb::bytewise
static

Definition at line 70 of file comparator.cc.

§ default_env

Env* leveldb::default_env
static

Definition at line 610 of file env_posix.cc.

§ kBlockSize

const int leveldb::kBlockSize = 4096
static

Definition at line 10 of file arena.cc.

§ kBlockTrailerSize

const size_t leveldb::kBlockTrailerSize = 5
static

Definition at line 84 of file format.h.

§ kCount

const int leveldb::kCount = kTotalSize / kValueSize
static

Definition at line 54 of file autocompact_test.cc.

§ kDelayMicros

const int leveldb::kDelayMicros = 100000
static

Definition at line 12 of file env_test.cc.

§ kFilterBase

const size_t leveldb::kFilterBase = 1 << kFilterBaseLg
static

Definition at line 16 of file filter_block.cc.

§ kFilterBaseLg

const size_t leveldb::kFilterBaseLg = 11
static

Definition at line 15 of file filter_block.cc.

§ kHeader

const size_t leveldb::kHeader = 12
static

Definition at line 27 of file write_batch.cc.

§ kMajorVersion

const int leveldb::kMajorVersion = 1
static

Definition at line 16 of file db.h.

§ kMaxNumValues

const int leveldb::kMaxNumValues = 2000
static

Definition at line 29 of file fault_injection_test.cc.

§ kMaxSequenceNumber

const SequenceNumber leveldb::kMaxSequenceNumber
static
Initial value:
=
((0x1ull << 56) - 1)

Definition at line 67 of file dbformat.h.

§ kMinorVersion

const int leveldb::kMinorVersion = 19
static

Definition at line 17 of file db.h.

§ kNumIterations

const size_t leveldb::kNumIterations = 3
static

Definition at line 30 of file fault_injection_test.cc.

§ kNumNonTableCacheFiles

const int leveldb::kNumNonTableCacheFiles = 10

Definition at line 38 of file db_impl.cc.

§ kNumTestArgs

const int leveldb::kNumTestArgs = sizeof(kTestArgList) / sizeof(kTestArgList[0])
static

Definition at line 435 of file table_test.cc.

§ kTableMagicNumber

const uint64_t leveldb::kTableMagicNumber = 0xdb4775248b80fb57ull
static

Definition at line 81 of file format.h.

§ kTestArgList

const TestArgs leveldb::kTestArgList[]
static
Initial value:
= {
{ TABLE_TEST, false, 16 },
{ TABLE_TEST, false, 1 },
{ TABLE_TEST, false, 1024 },
{ TABLE_TEST, true, 16 },
{ TABLE_TEST, true, 1 },
{ TABLE_TEST, true, 1024 },
{ BLOCK_TEST, false, 16 },
{ BLOCK_TEST, false, 1 },
{ BLOCK_TEST, false, 1024 },
{ BLOCK_TEST, true, 16 },
{ BLOCK_TEST, true, 1 },
{ BLOCK_TEST, true, 1024 },
{ MEMTABLE_TEST, false, 16 },
{ MEMTABLE_TEST, true, 16 },
{ DB_TEST, false, 16 },
{ DB_TEST, true, 16 },
}

Definition at line 412 of file table_test.cc.

§ kTotalSize

const int leveldb::kTotalSize = 100 * 1024 * 1024
static

Definition at line 53 of file autocompact_test.cc.

§ kValueSize [1/3]

const int leveldb::kValueSize = 1000
static

Definition at line 25 of file corruption_test.cc.

§ kValueSize [2/3]

const int leveldb::kValueSize = 1000
static

Definition at line 28 of file fault_injection_test.cc.

§ kValueSize [3/3]

const int leveldb::kValueSize = 200 * 1024
static

Definition at line 52 of file autocompact_test.cc.

§ kValueTypeForSeek

const ValueType leveldb::kValueTypeForSeek = kTypeValue
static

Definition at line 61 of file dbformat.h.

§ kVerbose

const int leveldb::kVerbose = 1
static

Definition at line 14 of file bloom_test.cc.

§ once [1/2]

port::OnceType leveldb::once = LEVELDB_ONCE_INIT
static

Definition at line 69 of file comparator.cc.

§ once [2/2]

pthread_once_t leveldb::once = PTHREAD_ONCE_INIT
static

Definition at line 609 of file env_posix.cc.

§ reverse_key_comparator

ReverseKeyComparator leveldb::reverse_key_comparator
static

Definition at line 64 of file table_test.cc.