Skip to content

Commit

Permalink
logdb: upgraded leveldb to v1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
lni committed Jun 16, 2019
1 parent 84bfd6c commit 530b9bb
Show file tree
Hide file tree
Showing 131 changed files with 4,010 additions and 2,994 deletions.
50 changes: 37 additions & 13 deletions internal/logdb/kv/leveldb/levigo/deps/leveldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# found in the LICENSE file. See the AUTHORS file for names of contributors.

cmake_minimum_required(VERSION 3.9)
project(leveldb VERSION 1.21.0 LANGUAGES C CXX)
# Keep the version below in sync with the one in db.h
project(leveldb VERSION 1.22.0 LANGUAGES C CXX)

# This project can use C11, but will gracefully decay down to C89.
set(CMAKE_C_STANDARD 11)
Expand All @@ -15,6 +16,14 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (WIN32)
set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_WINDOWS)
# TODO(cmumford): Make UNICODE configurable for Windows.
add_definitions(-D_UNICODE -DUNICODE)
else (WIN32)
set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_POSIX)
endif (WIN32)

option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)
option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON)
option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)
Expand Down Expand Up @@ -119,7 +128,6 @@ target_sources(leveldb
"${PROJECT_SOURCE_DIR}/db/version_set.h"
"${PROJECT_SOURCE_DIR}/db/write_batch_internal.h"
"${PROJECT_SOURCE_DIR}/db/write_batch.cc"
"${PROJECT_SOURCE_DIR}/port/atomic_pointer.h"
"${PROJECT_SOURCE_DIR}/port/port_stdcxx.h"
"${PROJECT_SOURCE_DIR}/port/port.h"
"${PROJECT_SOURCE_DIR}/port/thread_annotations.h"
Expand Down Expand Up @@ -179,12 +187,19 @@ target_sources(leveldb
"${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h"
)

# POSIX code is specified separately so we can leave it out in the future.
target_sources(leveldb
PRIVATE
"${PROJECT_SOURCE_DIR}/util/env_posix.cc"
"${PROJECT_SOURCE_DIR}/util/posix_logger.h"
)
if (WIN32)
target_sources(leveldb
PRIVATE
"${PROJECT_SOURCE_DIR}/util/env_windows.cc"
"${PROJECT_SOURCE_DIR}/util/windows_logger.h"
)
else (WIN32)
target_sources(leveldb
PRIVATE
"${PROJECT_SOURCE_DIR}/util/env_posix.cc"
"${PROJECT_SOURCE_DIR}/util/posix_logger.h"
)
endif (WIN32)

# MemEnv is not part of the interface and could be pulled to a separate library.
target_sources(leveldb
Expand All @@ -198,12 +213,16 @@ target_include_directories(leveldb
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set_target_properties(leveldb
PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

target_compile_definitions(leveldb
PRIVATE
# Used by include/export.h when building shared libraries.
LEVELDB_COMPILE_LIBRARY
# Used by port/port.h.
LEVELDB_PLATFORM_POSIX=1
${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions(leveldb
Expand Down Expand Up @@ -265,7 +284,7 @@ if(LEVELDB_BUILD_TESTS)
target_link_libraries("${test_target_name}" leveldb)
target_compile_definitions("${test_target_name}"
PRIVATE
LEVELDB_PLATFORM_POSIX=1
${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions("${test_target_name}"
Expand All @@ -282,6 +301,7 @@ if(LEVELDB_BUILD_TESTS)

leveldb_test("${PROJECT_SOURCE_DIR}/issues/issue178_test.cc")
leveldb_test("${PROJECT_SOURCE_DIR}/issues/issue200_test.cc")
leveldb_test("${PROJECT_SOURCE_DIR}/issues/issue320_test.cc")

leveldb_test("${PROJECT_SOURCE_DIR}/util/env_test.cc")
leveldb_test("${PROJECT_SOURCE_DIR}/util/status_test.cc")
Expand Down Expand Up @@ -314,8 +334,12 @@ if(LEVELDB_BUILD_TESTS)
leveldb_test("${PROJECT_SOURCE_DIR}/util/logging_test.cc")

# TODO(costan): This test also uses
# "${PROJECT_SOURCE_DIR}/util/env_posix_test_helper.h"
leveldb_test("${PROJECT_SOURCE_DIR}/util/env_posix_test.cc")
# "${PROJECT_SOURCE_DIR}/util/env_{posix|windows}_test_helper.h"
if (WIN32)
leveldb_test("${PROJECT_SOURCE_DIR}/util/env_windows_test.cc")
else (WIN32)
leveldb_test("${PROJECT_SOURCE_DIR}/util/env_posix_test.cc")
endif (WIN32)
endif(NOT BUILD_SHARED_LIBS)
endif(LEVELDB_BUILD_TESTS)

Expand All @@ -339,7 +363,7 @@ if(LEVELDB_BUILD_BENCHMARKS)
target_link_libraries("${bench_target_name}" leveldb)
target_compile_definitions("${bench_target_name}"
PRIVATE
LEVELDB_PLATFORM_POSIX=1
${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions("${bench_target_name}"
Expand Down
42 changes: 38 additions & 4 deletions internal/logdb/kv/leveldb/levigo/deps/leveldb/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.**

[![Build Status](https://travis-ci.org/google/leveldb.svg?branch=master)](https://travis-ci.org/google/leveldb)
[![Build status](https://ci.appveyor.com/api/projects/status/g2j5j4rfkda6eyw5/branch/master?svg=true)](https://ci.appveyor.com/project/pwnall/leveldb)

Authors: Sanjay Ghemawat ([email protected]) and Jeff Dean ([email protected])

Expand Down Expand Up @@ -30,13 +31,38 @@ Authors: Sanjay Ghemawat ([email protected]) and Jeff Dean ([email protected])

This project supports [CMake](https://cmake.org/) out of the box.

### Build for POSIX

Quick start:

```bash
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
```

### Building for Windows

First generate the Visual Studio 2017 project/solution files:

```cmd
mkdir build
cd build
cmake -G "Visual Studio 15" ..
```
The default default will build for x86. For 64-bit run:

```cmd
cmake -G "Visual Studio 15 Win64" ..
```

To compile the Windows solution from the command-line:

```cmd
devenv /build Debug leveldb.sln
```

or open leveldb.sln in Visual Studio and build from within.

Please see the CMake documentation and `CMakeLists.txt` for more advanced usage.

# Contributing to the leveldb Project
Expand All @@ -48,10 +74,10 @@ will be considered.

Contribution requirements:

1. **POSIX only**. We _generally_ will only accept changes that are both
compiled, and tested on a POSIX platform - usually Linux. Very small
changes will sometimes be accepted, but consider that more of an
exception than the rule.
1. **Tested platforms only**. We _generally_ will only accept changes for
platforms that are compiled and tested. This means POSIX (for Linux and
macOS) or Windows. Very small changes will sometimes be accepted, but
consider that more of an exception than the rule.

2. **Stable API**. We strive very hard to maintain a stable API. Changes that
require changes for projects using leveldb _might_ be rejected without
Expand All @@ -60,6 +86,14 @@ Contribution requirements:
3. **Tests**: All changes must be accompanied by a new (or changed) test, or
a sufficient explanation as to why a new (or changed) test is not required.

4. **Consistent Style**: This project conforms to the
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
To ensure your changes are properly formatted please run:

```
clang-format -i --style=file <file>
```

## Submitting a Pull Request

Before any pull request will be accepted the author must first sign a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "leveldb/db.h"
#include "db/db_impl.h"
#include "leveldb/cache.h"
#include "leveldb/db.h"
#include "util/testharness.h"
#include "util/testutil.h"

namespace leveldb {

class AutoCompactTest {
public:
std::string dbname_;
Cache* tiny_cache_;
Options options_;
DB* db_;

AutoCompactTest() {
dbname_ = test::TmpDir() + "/autocompact_test";
tiny_cache_ = NewLRUCache(100);
Expand Down Expand Up @@ -47,6 +42,12 @@ class AutoCompactTest {
}

void DoReads(int n);

private:
std::string dbname_;
Cache* tiny_cache_;
Options options_;
DB* db_;
};

static const int kValueSize = 200 * 1024;
Expand Down Expand Up @@ -81,17 +82,16 @@ void AutoCompactTest::DoReads(int n) {
ASSERT_LT(read, 100) << "Taking too long to compact";
Iterator* iter = db_->NewIterator(ReadOptions());
for (iter->SeekToFirst();
iter->Valid() && iter->key().ToString() < limit_key;
iter->Next()) {
iter->Valid() && iter->key().ToString() < limit_key; iter->Next()) {
// Drop data
}
delete iter;
// Wait a little bit to allow any triggered compactions to complete.
Env::Default()->SleepForMicroseconds(1000000);
uint64_t size = Size(Key(0), Key(n));
fprintf(stderr, "iter %3d => %7.3f MB [other %7.3f MB]\n",
read+1, size/1048576.0, Size(Key(n), Key(kCount))/1048576.0);
if (size <= initial_size/10) {
fprintf(stderr, "iter %3d => %7.3f MB [other %7.3f MB]\n", read + 1,
size / 1048576.0, Size(Key(n), Key(kCount)) / 1048576.0);
if (size <= initial_size / 10) {
break;
}
}
Expand All @@ -100,19 +100,13 @@ void AutoCompactTest::DoReads(int n) {
// is pretty much unchanged.
const int64_t final_other_size = Size(Key(n), Key(kCount));
ASSERT_LE(final_other_size, initial_other_size + 1048576);
ASSERT_GE(final_other_size, initial_other_size/5 - 1048576);
ASSERT_GE(final_other_size, initial_other_size / 5 - 1048576);
}

TEST(AutoCompactTest, ReadAll) {
DoReads(kCount);
}
TEST(AutoCompactTest, ReadAll) { DoReads(kCount); }

TEST(AutoCompactTest, ReadHalf) {
DoReads(kCount/2);
}
TEST(AutoCompactTest, ReadHalf) { DoReads(kCount / 2); }

} // namespace leveldb

int main(int argc, char** argv) {
return leveldb::test::RunAllTests();
}
int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
13 changes: 4 additions & 9 deletions internal/logdb/kv/leveldb/levigo/deps/leveldb/db/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "db/builder.h"

#include "db/filename.h"
#include "db/dbformat.h"
#include "db/filename.h"
#include "db/table_cache.h"
#include "db/version_edit.h"
#include "leveldb/db.h"
Expand All @@ -14,12 +14,8 @@

namespace leveldb {

Status BuildTable(const std::string& dbname,
Env* env,
const Options& options,
TableCache* table_cache,
Iterator* iter,
FileMetaData* meta) {
Status BuildTable(const std::string& dbname, Env* env, const Options& options,
TableCache* table_cache, Iterator* iter, FileMetaData* meta) {
Status s;
meta->file_size = 0;
iter->SeekToFirst();
Expand Down Expand Up @@ -60,8 +56,7 @@ Status BuildTable(const std::string& dbname,

if (s.ok()) {
// Verify that the table is usable
Iterator* it = table_cache->NewIterator(ReadOptions(),
meta->number,
Iterator* it = table_cache->NewIterator(ReadOptions(), meta->number,
meta->file_size);
s = it->status();
delete it;
Expand Down
8 changes: 2 additions & 6 deletions internal/logdb/kv/leveldb/levigo/deps/leveldb/db/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ class VersionEdit;
// *meta will be filled with metadata about the generated table.
// If no data is present in *iter, meta->file_size will be set to
// zero, and no Table file will be produced.
Status BuildTable(const std::string& dbname,
Env* env,
const Options& options,
TableCache* table_cache,
Iterator* iter,
FileMetaData* meta);
Status BuildTable(const std::string& dbname, Env* env, const Options& options,
TableCache* table_cache, Iterator* iter, FileMetaData* meta);

} // namespace leveldb

Expand Down
Loading

0 comments on commit 530b9bb

Please sign in to comment.