aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-02-17 14:11:18 +0800
committerKunoiSayami <[email protected]>2022-02-17 14:11:18 +0800
commit74c563f94e4b02779465ead2b2dbce0db59e352a (patch)
tree64e747bfa7b46274a34b6c7787a7233ceafba846
parente98fc6bf301bb3bf38aab4ccce51edc16953024b (diff)
merge: Merge remote-tracking branch google/[email protected]
Signed-off-by: KunoiSayami <[email protected]>
-rw-r--r--CMakeLists.txt104
-rw-r--r--CONTRIBUTING.md49
-rw-r--r--README.md10
-rw-r--r--benchmarks/db_bench_log.cc92
-rw-r--r--db/autocompact_test.cc5
-rw-r--r--db/corruption_test.cc5
-rw-r--r--db/db_test.cc69
-rw-r--r--db/dbformat_test.cc5
-rw-r--r--db/fault_injection_test.cc5
-rw-r--r--db/filename_test.cc5
-rw-r--r--db/log_reader.h2
-rw-r--r--db/log_test.cc5
-rw-r--r--db/memtable.cc1
-rw-r--r--db/memtable.h5
-rw-r--r--db/recovery_test.cc5
-rw-r--r--db/skiplist.cuh2
-rw-r--r--db/skiplist.h4
-rw-r--r--db/snapshot.h2
-rw-r--r--db/table_cache.h4
-rw-r--r--db/version_edit.cc1
-rw-r--r--db/version_edit_test.cc5
-rw-r--r--db/version_set.cc5
-rw-r--r--db/version_set.h6
-rw-r--r--db/version_set_test.cc5
-rw-r--r--db/write_batch_test.cc5
-rw-r--r--doc/benchmark.html6
-rw-r--r--doc/index.md11
-rw-r--r--helpers/memenv/memenv_test.cc5
-rw-r--r--include/leveldb/cache.h8
-rw-r--r--issues/issue178_test.cc5
-rw-r--r--issues/issue200_test.cc5
-rw-r--r--issues/issue320_test.cc5
-rw-r--r--port/port_example.h2
-rw-r--r--table/filter_block_test.cc5
-rw-r--r--table/table_test.cc5
-rw-r--r--util/arena.cc2
-rw-r--r--util/arena_test.cc7
-rw-r--r--util/bloom_test.cc5
-rw-r--r--util/cache.cc2
-rw-r--r--util/cache_test.cc5
-rw-r--r--util/coding.cc10
-rw-r--r--util/coding_test.cc5
-rw-r--r--util/crc32c_test.cc5
-rw-r--r--util/env_posix.cc44
-rw-r--r--util/env_posix_test.cc6
-rw-r--r--util/env_test.cc7
-rw-r--r--util/env_windows.cc32
-rw-r--r--util/hash_test.cc5
-rw-r--r--util/logging_test.cc5
-rw-r--r--util/no_destructor_test.cc5
-rw-r--r--util/random.h2
-rw-r--r--util/status_test.cc5
52 files changed, 278 insertions, 337 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f807626..0890b9f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,7 +148,7 @@ target_sources(leveldb
"db/memtable.h"
"db/repair.cc"
"db/skiplist.h"
- "db/skiplist.cuh"
+ "db/skiplist.cuh"
"db/skiplist.cu"
"db/snapshot.h"
"db/table_cache.cc"
@@ -315,11 +315,6 @@ if(LEVELDB_BUILD_TESTS)
# This project is tested using GoogleTest.
add_subdirectory("third_party/googletest")
- # This project uses Google benchmark for benchmarking.
- set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
- set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
- add_subdirectory("third_party/benchmark")
-
# GoogleTest triggers a missing field initializers warning.
if(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
set_property(TARGET gtest
@@ -328,6 +323,60 @@ if(LEVELDB_BUILD_TESTS)
APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
endif(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
+ add_executable(leveldb_tests "")
+ target_sources(leveldb_tests
+ PRIVATE
+ # "db/fault_injection_test.cc"
+ # "issues/issue178_test.cc"
+ # "issues/issue200_test.cc"
+ # "issues/issue320_test.cc"
+ "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
+ # "util/env_test.cc"
+ "util/status_test.cc"
+ "util/no_destructor_test.cc"
+ "util/testutil.cc"
+ "util/testutil.h"
+ )
+ if(NOT BUILD_SHARED_LIBS)
+ target_sources(leveldb_tests
+ PRIVATE
+ "db/autocompact_test.cc"
+ "db/corruption_test.cc"
+ "db/db_test.cc"
+ "db/dbformat_test.cc"
+ "db/filename_test.cc"
+ "db/log_test.cc"
+ "db/recovery_test.cc"
+ "db/skiplist_test.cc"
+ "db/version_edit_test.cc"
+ "db/version_set_test.cc"
+ "db/write_batch_test.cc"
+ "helpers/memenv/memenv_test.cc"
+ "table/filter_block_test.cc"
+ "table/table_test.cc"
+ "util/arena_test.cc"
+ "util/bloom_test.cc"
+ "util/cache_test.cc"
+ "util/coding_test.cc"
+ "util/crc32c_test.cc"
+ "util/hash_test.cc"
+ "util/logging_test.cc"
+ )
+ endif(NOT BUILD_SHARED_LIBS)
+ target_link_libraries(leveldb_tests leveldb gmock gtest gtest_main)
+ target_compile_definitions(leveldb_tests
+ PRIVATE
+ ${LEVELDB_PLATFORM_NAME}=1
+ )
+ if (NOT HAVE_CXX17_HAS_INCLUDE)
+ target_compile_definitions(leveldb_tests
+ PRIVATE
+ LEVELDB_HAS_PORT_CONFIG_H=1
+ )
+ endif(NOT HAVE_CXX17_HAS_INCLUDE)
+
+ add_test(NAME "leveldb_tests" COMMAND "leveldb_tests")
+
function(leveldb_test test_file)
get_filename_component(test_target_name "${test_file}" NAME_WE)
@@ -340,7 +389,7 @@ if(LEVELDB_BUILD_TESTS)
"${test_file}"
)
- target_link_libraries("${test_target_name}" leveldb gmock gtest benchmark)
+ target_link_libraries("${test_target_name}" leveldb gmock gtest)
target_compile_definitions("${test_target_name}"
PRIVATE
${LEVELDB_PLATFORM_NAME}=1
@@ -358,42 +407,8 @@ if(LEVELDB_BUILD_TESTS)
endfunction(leveldb_test)
leveldb_test("db/c_test.c")
- leveldb_test("db/fault_injection_test.cc")
-
- leveldb_test("issues/issue178_test.cc")
- leveldb_test("issues/issue200_test.cc")
- leveldb_test("issues/issue320_test.cc")
-
- leveldb_test("util/env_test.cc")
- leveldb_test("util/status_test.cc")
- leveldb_test("util/no_destructor_test.cc")
if(NOT BUILD_SHARED_LIBS)
- leveldb_test("db/autocompact_test.cc")
- leveldb_test("db/corruption_test.cc")
- leveldb_test("db/db_test.cc")
- leveldb_test("db/dbformat_test.cc")
- leveldb_test("db/filename_test.cc")
- leveldb_test("db/log_test.cc")
- leveldb_test("db/recovery_test.cc")
- leveldb_test("db/skiplist_test.cu")
- leveldb_test("db/version_edit_test.cc")
- leveldb_test("db/version_set_test.cc")
- leveldb_test("db/write_batch_test.cc")
-
- leveldb_test("helpers/memenv/memenv_test.cc")
-
- leveldb_test("table/filter_block_test.cc")
- leveldb_test("table/table_test.cc")
-
- leveldb_test("util/arena_test.cc")
- leveldb_test("util/bloom_test.cc")
- leveldb_test("util/cache_test.cc")
- leveldb_test("util/coding_test.cc")
- leveldb_test("util/crc32c_test.cc")
- leveldb_test("util/hash_test.cc")
- leveldb_test("util/logging_test.cc")
-
# TODO(costan): This test also uses
# "util/env_{posix|windows}_test_helper.h"
if (WIN32)
@@ -405,6 +420,11 @@ if(LEVELDB_BUILD_TESTS)
endif(LEVELDB_BUILD_TESTS)
if(LEVELDB_BUILD_BENCHMARKS)
+ # This project uses Google benchmark for benchmarking.
+ set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
+ set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
+ add_subdirectory("third_party/benchmark")
+
function(leveldb_benchmark bench_file)
get_filename_component(bench_target_name "${bench_file}" NAME_WE)
@@ -419,7 +439,7 @@ if(LEVELDB_BUILD_BENCHMARKS)
"${bench_file}"
)
- target_link_libraries("${bench_target_name}" leveldb gmock gtest)
+ target_link_libraries("${bench_target_name}" leveldb gmock gtest benchmark)
target_compile_definitions("${bench_target_name}"
PRIVATE
${LEVELDB_PLATFORM_NAME}=1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7ede021..9d8a7d7 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,36 +1,31 @@
-# Contributing
+# How to Contribute
-We'd love to accept your code patches! However, before we can take them, we
-have to jump a couple of legal hurdles.
+We'd love to accept your patches and contributions to this project. There are
+just a few small guidelines you need to follow.
-## Contributor License Agreements
+## Contributor License Agreement
-Please fill out either the individual or corporate Contributor License
-Agreement as appropriate.
+Contributions to this project must be accompanied by a Contributor License
+Agreement. You (or your employer) retain the copyright to your contribution;
+this simply gives us permission to use and redistribute your contributions as
+part of the project. Head over to <https://cla.developers.google.com/> to see
+your current agreements on file or to sign a new one.
-* If you are an individual writing original source code and you're sure you
-own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual).
-* If you work for a company that wants to allow you to contribute your work,
-then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate).
+You generally only need to submit a CLA once, so if you've already submitted one
+(even if it was for a different project), you probably don't need to do it
+again.
-Follow either of the two links above to access the appropriate CLA and
-instructions for how to sign and return it.
+## Code Reviews
-## Submitting a Patch
+All submissions, including submissions by project members, require review. We
+use GitHub pull requests for this purpose. Consult
+[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
+information on using pull requests.
-1. Sign the contributors license agreement above.
-2. Decide which code you want to submit. A submission should be a set of changes
-that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues).
-Please don't mix more than one logical change per submission, because it makes
-the history hard to follow. If you want to make a change
-(e.g. add a sample or feature) that doesn't have a corresponding issue in the
-issue tracker, please create one.
-3. **Submitting**: When you are ready to submit, send us a Pull Request. Be
-sure to include the issue number you fixed and the name you used to sign
-the CLA.
+See [the README](README.md#contributing-to-the-leveldb-project) for areas
+where we are likely to accept external contributions.
-## Writing Code ##
+## Community Guidelines
-If your contribution contains code, please make sure that it follows
-[the style guide](https://google.github.io/styleguide/cppguide.html).
-Otherwise we will have to ask you to make changes, and that's no fun for anyone.
+This project follows [Google's Open Source Community
+Guidelines](https://opensource.google/conduct/).
diff --git a/README.md b/README.md
index 3c4d14d..3a24477 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Authors: Sanjay Ghemawat ([email protected]) and Jeff Dean ([email protected])
# Documentation
- [LevelDB library documentation](https://github.com/google/leveldb/blob/master/doc/index.md) is online and bundled with the source code.
+ [LevelDB library documentation](https://github.com/google/leveldb/blob/main/doc/index.md) is online and bundled with the source code.
# Limitations
@@ -99,6 +99,12 @@ Contribution requirements:
clang-format -i --style=file <file>
```
+We are unlikely to accept contributions to the build configuration files, such
+as `CMakeLists.txt`. We are focused on maintaining a build configuration that
+allows us to test that the project works in a few supported configurations
+inside Google. We are not currently interested in supporting other requirements,
+such as different operating systems, compilers, or build systems.
+
## Submitting a Pull Request
Before any pull request will be accepted the author must first sign a
@@ -107,7 +113,7 @@ Contributor License Agreement (CLA) at https://cla.developers.google.com/.
In order to keep the commit timeline linear
[squash](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Squashing-Commits)
your changes down to a single commit and [rebase](https://git-scm.com/docs/git-rebase)
-on google/leveldb/master. This keeps the commit timeline linear and more easily sync'ed
+on google/leveldb/main. This keeps the commit timeline linear and more easily sync'ed
with the internal repository at Google. More information at GitHub's
[About Git rebase](https://help.github.com/articles/about-git-rebase/) page.
diff --git a/benchmarks/db_bench_log.cc b/benchmarks/db_bench_log.cc
new file mode 100644
index 0000000..a1845bf
--- /dev/null
+++ b/benchmarks/db_bench_log.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2019 The LevelDB Authors. All rights reserved.
+// 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 <cinttypes>
+#include <cstdio>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "benchmark/benchmark.h"
+#include "db/version_set.h"
+#include "leveldb/comparator.h"
+#include "leveldb/db.h"
+#include "leveldb/env.h"
+#include "leveldb/options.h"
+#include "port/port.h"
+#include "util/mutexlock.h"
+#include "util/testutil.h"
+
+namespace leveldb {
+
+namespace {
+
+std::string MakeKey(unsigned int num) {
+ char buf[30];
+ std::snprintf(buf, sizeof(buf), "%016u", num);
+ return std::string(buf);
+}
+
+void BM_LogAndApply(benchmark::State& state) {
+ const int num_base_files = state.range(0);
+
+ std::string dbname = testing::TempDir() + "leveldb_test_benchmark";
+ DestroyDB(dbname, Options());
+
+ DB* db = nullptr;
+ Options opts;
+ opts.create_if_missing = true;
+ Status s = DB::Open(opts, dbname, &db);
+ ASSERT_LEVELDB_OK(s);
+ ASSERT_TRUE(db != nullptr);
+
+ delete db;
+ db = nullptr;
+
+ Env* env = Env::Default();
+
+ port::Mutex mu;
+ MutexLock l(&mu);
+
+ InternalKeyComparator cmp(BytewiseComparator());
+ Options options;
+ VersionSet vset(dbname, &options, nullptr, &cmp);
+ bool save_manifest;
+ ASSERT_LEVELDB_OK(vset.Recover(&save_manifest));
+ VersionEdit vbase;
+ uint64_t fnum = 1;
+ for (int i = 0; i < num_base_files; i++) {
+ InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
+ InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
+ vbase.AddFile(2, fnum++, 1 /* file size */, start, limit);
+ }
+ ASSERT_LEVELDB_OK(vset.LogAndApply(&vbase, &mu));
+
+ uint64_t start_micros = env->NowMicros();
+
+ for (auto st : state) {
+ VersionEdit vedit;
+ vedit.RemoveFile(2, fnum);
+ InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
+ InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
+ vedit.AddFile(2, fnum++, 1 /* file size */, start, limit);
+ vset.LogAndApply(&vedit, &mu);
+ }
+
+ uint64_t stop_micros = env->NowMicros();
+ unsigned int us = stop_micros - start_micros;
+ char buf[16];
+ std::snprintf(buf, sizeof(buf), "%d", num_base_files);
+ std::fprintf(stderr,
+ "BM_LogAndApply/%-6s %8" PRIu64
+ " iters : %9u us (%7.0f us / iter)\n",
+ buf, state.iterations(), us, ((float)us) / state.iterations());
+}
+
+BENCHMARK(BM_LogAndApply)->Arg(1)->Arg(100)->Arg(10000)->Arg(100000);
+
+} // namespace
+
+} // namespace leveldb
+
+BENCHMARK_MAIN();
diff --git a/db/autocompact_test.cc b/db/autocompact_test.cc
index 3b7241b..69341e3 100644
--- a/db/autocompact_test.cc
+++ b/db/autocompact_test.cc
@@ -108,8 +108,3 @@ TEST_F(AutoCompactTest, ReadAll) { DoReads(kCount); }
TEST_F(AutoCompactTest, ReadHalf) { DoReads(kCount / 2); }
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/corruption_test.cc b/db/corruption_test.cc
index a31f448..dc7da76 100644
--- a/db/corruption_test.cc
+++ b/db/corruption_test.cc
@@ -360,8 +360,3 @@ TEST_F(CorruptionTest, UnrelatedKeys) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/db_test.cc b/db/db_test.cc
index 908b41d..9bd6e14 100644
--- a/db/db_test.cc
+++ b/db/db_test.cc
@@ -9,7 +9,6 @@
#include <string>
#include "gtest/gtest.h"
-#include "benchmark/benchmark.h"
#include "db/db_impl.h"
#include "db/filename.h"
#include "db/version_set.h"
@@ -2295,72 +2294,4 @@ TEST_F(DBTest, Randomized) {
} while (ChangeOptions());
}
-std::string MakeKey(unsigned int num) {
- char buf[30];
- std::snprintf(buf, sizeof(buf), "%016u", num);
- return std::string(buf);
-}
-
-static void BM_LogAndApply(benchmark::State& state) {
- const int num_base_files = state.range(0);
-
- std::string dbname = testing::TempDir() + "leveldb_test_benchmark";
- DestroyDB(dbname, Options());
-
- DB* db = nullptr;
- Options opts;
- opts.create_if_missing = true;
- Status s = DB::Open(opts, dbname, &db);
- ASSERT_LEVELDB_OK(s);
- ASSERT_TRUE(db != nullptr);
-
- delete db;
- db = nullptr;
-
- Env* env = Env::Default();
-
- port::Mutex mu;
- MutexLock l(&mu);
-
- InternalKeyComparator cmp(BytewiseComparator());
- Options options;
- VersionSet vset(dbname, &options, nullptr, &cmp);
- bool save_manifest;
- ASSERT_LEVELDB_OK(vset.Recover(&save_manifest));
- VersionEdit vbase;
- uint64_t fnum = 1;
- for (int i = 0; i < num_base_files; i++) {
- InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
- InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
- vbase.AddFile(2, fnum++, 1 /* file size */, start, limit);
- }
- ASSERT_LEVELDB_OK(vset.LogAndApply(&vbase, &mu));
-
- uint64_t start_micros = env->NowMicros();
-
- for (auto st : state) {
- VersionEdit vedit;
- vedit.RemoveFile(2, fnum);
- InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
- InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
- vedit.AddFile(2, fnum++, 1 /* file size */, start, limit);
- vset.LogAndApply(&vedit, &mu);
- }
- uint64_t stop_micros = env->NowMicros();
- unsigned int us = stop_micros - start_micros;
- char buf[16];
- std::snprintf(buf, sizeof(buf), "%d", num_base_files);
- std::fprintf(stderr,
- "BM_LogAndApply/%-6s %8" PRIu64
- " iters : %9u us (%7.0f us / iter)\n",
- buf, state.iterations(), us, ((float)us) / state.iterations());
-}
-
-BENCHMARK(BM_LogAndApply)->Arg(1)->Arg(100)->Arg(10000)->Arg(100000);
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- benchmark::RunSpecifiedBenchmarks();
- return RUN_ALL_TESTS();
-}
diff --git a/db/dbformat_test.cc b/db/dbformat_test.cc
index 4a11c4a..7f3f81a 100644
--- a/db/dbformat_test.cc
+++ b/db/dbformat_test.cc
@@ -126,8 +126,3 @@ TEST(FormatTest, InternalKeyDebugString) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc
index 6eebafa..ef864a4 100644
--- a/db/fault_injection_test.cc
+++ b/db/fault_injection_test.cc
@@ -548,8 +548,3 @@ TEST_F(FaultInjectionTest, FaultTestWithLogReuse) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/filename_test.cc b/db/filename_test.cc
index f291d72..9ac0111 100644
--- a/db/filename_test.cc
+++ b/db/filename_test.cc
@@ -125,8 +125,3 @@ TEST(FileNameTest, Construction) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/log_reader.h b/db/log_reader.h
index 75d53f7..ba711f8 100644
--- a/db/log_reader.h
+++ b/db/log_reader.h
@@ -24,7 +24,7 @@ class Reader {
public:
virtual ~Reporter();
- // Some corruption was detected. "size" is the approximate number
+ // Some corruption was detected. "bytes" is the approximate number
// of bytes dropped due to the corruption.
virtual void Corruption(size_t bytes, const Status& status) = 0;
};
diff --git a/db/log_test.cc b/db/log_test.cc
index 346b19c..d55d4dd 100644
--- a/db/log_test.cc
+++ b/db/log_test.cc
@@ -556,8 +556,3 @@ TEST_F(LogTest, ReadPastEnd) { CheckOffsetPastEndReturnsNoRecords(5); }
} // namespace log
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/memtable.cc b/db/memtable.cc
index f42774d..4f09340 100644
--- a/db/memtable.cc
+++ b/db/memtable.cc
@@ -78,6 +78,7 @@ void MemTable::Add(SequenceNumber s, ValueType type, const Slice& key,
// Format of an entry is concatenation of:
// key_size : varint32 of internal_key.size()
// key bytes : char[internal_key.size()]
+ // tag : uint64((sequence << 8) | type)
// value_size : varint32 of value.size()
// value bytes : char[value.size()]
size_t key_size = key.size();
diff --git a/db/memtable.h b/db/memtable.h
index 1099504..9d986b1 100644
--- a/db/memtable.h
+++ b/db/memtable.h
@@ -5,12 +5,11 @@
#ifndef STORAGE_LEVELDB_DB_MEMTABLE_H_
#define STORAGE_LEVELDB_DB_MEMTABLE_H_
-#include "db/dbformat.h"
-#include "db/skiplist.h"
#include <string>
+#include "db/dbformat.h"
+#include "db/skiplist.h"
#include "leveldb/db.h"
-
#include "util/arena.h"
namespace leveldb {
diff --git a/db/recovery_test.cc b/db/recovery_test.cc
index 6c5d42e..1d9f621 100644
--- a/db/recovery_test.cc
+++ b/db/recovery_test.cc
@@ -332,8 +332,3 @@ TEST_F(RecoveryTest, ManifestMissing) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/skiplist.cuh b/db/skiplist.cuh
index 2501af8..6f0cc6c 100644
--- a/db/skiplist.cuh
+++ b/db/skiplist.cuh
@@ -327,7 +327,7 @@ __device__ int SkipList<Key, Comparator>::RandomHeight() {
// Increase height with probability 1 in kBranching
static const unsigned int kBranching = 4;
int height = 1;
- while (height < kMaxHeight && ((rnd_.Next() % kBranching) == 0)) {
+ while (height < kMaxHeight && rnd_.OneIn(kBranching)) {
height++;
}
assert(height > 0);
diff --git a/db/skiplist.h b/db/skiplist.h
index a59b45b..1140e59 100644
--- a/db/skiplist.h
+++ b/db/skiplist.h
@@ -36,8 +36,6 @@
namespace leveldb {
-class Arena;
-
template <typename Key, class Comparator>
class SkipList {
private:
@@ -243,7 +241,7 @@ int SkipList<Key, Comparator>::RandomHeight() {
// Increase height with probability 1 in kBranching
static const unsigned int kBranching = 4;
int height = 1;
- while (height < kMaxHeight && ((rnd_.Next() % kBranching) == 0)) {
+ while (height < kMaxHeight && rnd_.OneIn(kBranching)) {
height++;
}
assert(height > 0);
diff --git a/db/snapshot.h b/db/snapshot.h
index 9f1d664..817bb7b 100644
--- a/db/snapshot.h
+++ b/db/snapshot.h
@@ -25,7 +25,7 @@ class SnapshotImpl : public Snapshot {
friend class SnapshotList;
// SnapshotImpl is kept in a doubly-linked circular list. The SnapshotList
- // implementation operates on the next/previous fields direcly.
+ // implementation operates on the next/previous fields directly.
SnapshotImpl* prev_;
SnapshotImpl* next_;
diff --git a/db/table_cache.h b/db/table_cache.h
index aac9bfc..db8a123 100644
--- a/db/table_cache.h
+++ b/db/table_cache.h
@@ -22,6 +22,10 @@ class Env;
class TableCache {
public:
TableCache(const std::string& dbname, const Options& options, int entries);
+
+ TableCache(const TableCache&) = delete;
+ TableCache& operator=(const TableCache&) = delete;
+
~TableCache();
// Return an iterator for the specified file number (the corresponding
diff --git a/db/version_edit.cc b/db/version_edit.cc
index 3e9012f..356ce88 100644
--- a/db/version_edit.cc
+++ b/db/version_edit.cc
@@ -34,6 +34,7 @@ void VersionEdit::Clear() {
has_prev_log_number_ = false;
has_next_file_number_ = false;
has_last_sequence_ = false;
+ compact_pointers_.clear();
deleted_files_.clear();
new_files_.clear();
}
diff --git a/db/version_edit_test.cc b/db/version_edit_test.cc
index acafab0..a108c15 100644
--- a/db/version_edit_test.cc
+++ b/db/version_edit_test.cc
@@ -39,8 +39,3 @@ TEST(VersionEditTest, EncodeDecode) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/version_set.cc b/db/version_set.cc
index 8d85fce..4e37bf9 100644
--- a/db/version_set.cc
+++ b/db/version_set.cc
@@ -626,7 +626,7 @@ class VersionSet::Builder {
}
// Apply all of the edits in *edit to the current state.
- void Apply(VersionEdit* edit) {
+ void Apply(const VersionEdit* edit) {
// Update compaction pointers
for (size_t i = 0; i < edit->compact_pointers_.size(); i++) {
const int level = edit->compact_pointers_[i].first;
@@ -806,7 +806,6 @@ Status VersionSet::LogAndApply(VersionEdit* edit, port::Mutex* mu) {
// first call to LogAndApply (when opening the database).
assert(descriptor_file_ == nullptr);
new_manifest_file = DescriptorFileName(dbname_, manifest_file_number_);
- edit->SetNextFile(next_file_number_);
s = env_->NewWritableFile(new_manifest_file, &descriptor_file_);
if (s.ok()) {
descriptor_log_ = new log::Writer(descriptor_file_);
@@ -1304,7 +1303,7 @@ Compaction* VersionSet::PickCompaction() {
return c;
}
-// Finds the largest key in a vector of files. Returns true if files it not
+// Finds the largest key in a vector of files. Returns true if files is not
// empty.
bool FindLargestKey(const InternalKeyComparator& icmp,
const std::vector<FileMetaData*>& files,
diff --git a/db/version_set.h b/db/version_set.h
index 69f3d70..ea0c925 100644
--- a/db/version_set.h
+++ b/db/version_set.h
@@ -59,9 +59,6 @@ bool SomeFileOverlapsRange(const InternalKeyComparator& icmp,
class Version {
public:
- // Lookup the value for key. If found, store it in *val and
- // return OK. Else return a non-OK status. Fills *stats.
- // REQUIRES: lock is not held
struct GetStats {
FileMetaData* seek_file;
int seek_file_level;
@@ -72,6 +69,9 @@ class Version {
// REQUIRES: This version has been saved (see VersionSet::SaveTo)
void AddIterators(const ReadOptions&, std::vector<Iterator*>* iters);
+ // Lookup the value for key. If found, store it in *val and
+ // return OK. Else return a non-OK status. Fills *stats.
+ // REQUIRES: lock is not held
Status Get(const ReadOptions&, const LookupKey& key, std::string* val,
GetStats* stats);
diff --git a/db/version_set_test.cc b/db/version_set_test.cc
index dee6b4c..64bb983 100644
--- a/db/version_set_test.cc
+++ b/db/version_set_test.cc
@@ -329,8 +329,3 @@ TEST_F(AddBoundaryInputsTest, TestDisjoinFilePointers) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/write_batch_test.cc b/db/write_batch_test.cc
index 64df9b8..1a3ea8f 100644
--- a/db/write_batch_test.cc
+++ b/db/write_batch_test.cc
@@ -130,8 +130,3 @@ TEST(WriteBatchTest, ApproximateSize) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/doc/benchmark.html b/doc/benchmark.html
index 1e0b4ef..80e6c2a 100644
--- a/doc/benchmark.html
+++ b/doc/benchmark.html
@@ -90,9 +90,9 @@ div.bsql {
<h4>Benchmark Source Code</h4>
<p>We wrote benchmark tools for SQLite and Kyoto TreeDB based on LevelDB's <span class="code">db_bench</span>. The code for each of the benchmarks resides here:</p>
<ul>
- <li> <b>LevelDB:</b> <a href="https://github.com/google/leveldb/blob/master/benchmarks/db_bench.cc">benchmarks/db_bench.cc</a>.</li>
- <li> <b>SQLite:</b> <a href="https://github.com/google/leveldb/blob/master/benchmarks/db_bench_sqlite3.cc">benchmarks/db_bench_sqlite3.cc</a>.</li>
- <li> <b>Kyoto TreeDB:</b> <a href="https://github.com/google/leveldb/blob/master/benchmarks/db_bench_tree_db.cc">benchmarks/db_bench_tree_db.cc</a>.</li>
+ <li> <b>LevelDB:</b> <a href="https://github.com/google/leveldb/blob/main/benchmarks/db_bench.cc">benchmarks/db_bench.cc</a>.</li>
+ <li> <b>SQLite:</b> <a href="https://github.com/google/leveldb/blob/main/benchmarks/db_bench_sqlite3.cc">benchmarks/db_bench_sqlite3.cc</a>.</li>
+ <li> <b>Kyoto TreeDB:</b> <a href="https://github.com/google/leveldb/blob/main/benchmarks/db_bench_tree_db.cc">benchmarks/db_bench_tree_db.cc</a>.</li>
</ul>
<h4>Custom Build Specifications</h4>
diff --git a/doc/index.md b/doc/index.md
index 01693ad..0f6d649 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -369,6 +369,7 @@ leveldb::Iterator* it = db->NewIterator(options);
for (it->SeekToFirst(); it->Valid(); it->Next()) {
...
}
+delete it;
```
### Key Layout
@@ -424,21 +425,21 @@ spaces. For example:
```c++
class CustomFilterPolicy : public leveldb::FilterPolicy {
private:
- FilterPolicy* builtin_policy_;
+ leveldb::FilterPolicy* builtin_policy_;
public:
- CustomFilterPolicy() : builtin_policy_(NewBloomFilterPolicy(10)) {}
+ CustomFilterPolicy() : builtin_policy_(leveldb::NewBloomFilterPolicy(10)) {}
~CustomFilterPolicy() { delete builtin_policy_; }
const char* Name() const { return "IgnoreTrailingSpacesFilter"; }
- void CreateFilter(const Slice* keys, int n, std::string* dst) const {
+ void CreateFilter(const leveldb::Slice* keys, int n, std::string* dst) const {
// Use builtin bloom filter code after removing trailing spaces
- std::vector<Slice> trimmed(n);
+ std::vector<leveldb::Slice> trimmed(n);
for (int i = 0; i < n; i++) {
trimmed[i] = RemoveTrailingSpaces(keys[i]);
}
- return builtin_policy_->CreateFilter(trimmed.data(), n, dst);
+ builtin_policy_->CreateFilter(trimmed.data(), n, dst);
}
};
```
diff --git a/helpers/memenv/memenv_test.cc b/helpers/memenv/memenv_test.cc
index 3f03cb6..909a0ca 100644
--- a/helpers/memenv/memenv_test.cc
+++ b/helpers/memenv/memenv_test.cc
@@ -257,8 +257,3 @@ TEST_F(MemEnvTest, DBTest) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/include/leveldb/cache.h b/include/leveldb/cache.h
index 98c95ac..a94c683 100644
--- a/include/leveldb/cache.h
+++ b/include/leveldb/cache.h
@@ -96,14 +96,6 @@ class LEVELDB_EXPORT Cache {
// Return an estimate of the combined charges of all elements stored in the
// cache.
virtual size_t TotalCharge() const = 0;
-
- private:
- void LRU_Remove(Handle* e);
- void LRU_Append(Handle* e);
- void Unref(Handle* e);
-
- struct Rep;
- Rep* rep_;
};
} // namespace leveldb
diff --git a/issues/issue178_test.cc b/issues/issue178_test.cc
index 8fa5bb9..5cd5862 100644
--- a/issues/issue178_test.cc
+++ b/issues/issue178_test.cc
@@ -83,8 +83,3 @@ TEST(Issue178, Test) {
}
} // anonymous namespace
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/issues/issue200_test.cc b/issues/issue200_test.cc
index 4eba23a..959b371 100644
--- a/issues/issue200_test.cc
+++ b/issues/issue200_test.cc
@@ -52,8 +52,3 @@ TEST(Issue200, Test) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/issues/issue320_test.cc b/issues/issue320_test.cc
index c08296a..9d7fa7b 100644
--- a/issues/issue320_test.cc
+++ b/issues/issue320_test.cc
@@ -124,8 +124,3 @@ TEST(Issue320, Test) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/port/port_example.h b/port/port_example.h
index a665910..704aa24 100644
--- a/port/port_example.h
+++ b/port/port_example.h
@@ -55,7 +55,7 @@ class CondVar {
void Signal();
// Wake up all waiting threads.
- void SignallAll();
+ void SignalAll();
};
// ------------------ Compression -------------------
diff --git a/table/filter_block_test.cc b/table/filter_block_test.cc
index 91a6be2..3ee41cf 100644
--- a/table/filter_block_test.cc
+++ b/table/filter_block_test.cc
@@ -120,8 +120,3 @@ TEST_F(FilterBlockTest, MultiChunk) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/table/table_test.cc b/table/table_test.cc
index 190dd0f..7f0f998 100644
--- a/table/table_test.cc
+++ b/table/table_test.cc
@@ -827,8 +827,3 @@ TEST(TableTest, ApproximateOffsetOfCompressed) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/arena.cc b/util/arena.cc
index 41c6a0d..d3ec2be 100644
--- a/util/arena.cc
+++ b/util/arena.cc
@@ -14,7 +14,7 @@ Arena::Arena()
Arena::~Arena() {
for (size_t i = 0; i < blocks_.size(); i++) {
//cudaFree(blocks_[i]);
- delete [] blocks_[i];
+ delete[] blocks_[i];
}
}
diff --git a/util/arena_test.cc b/util/arena_test.cc
index d2ead39..3e2011e 100644
--- a/util/arena_test.cc
+++ b/util/arena_test.cc
@@ -3,9 +3,9 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "util/arena.h"
-#include "util/random.h"
#include "gtest/gtest.h"
+#include "util/random.h"
namespace leveldb {
@@ -59,8 +59,3 @@ TEST(ArenaTest, Simple) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/bloom_test.cc b/util/bloom_test.cc
index 520473e..9f11108 100644
--- a/util/bloom_test.cc
+++ b/util/bloom_test.cc
@@ -152,8 +152,3 @@ TEST_F(BloomTest, VaryingLengths) {
// Different bits-per-byte
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/cache.cc b/util/cache.cc
index ad1e9a2..fc3d154 100644
--- a/util/cache.cc
+++ b/util/cache.cc
@@ -54,7 +54,7 @@ struct LRUHandle {
char key_data[1]; // Beginning of key
Slice key() const {
- // next_ is only equal to this if the LRU handle is the list head of an
+ // next is only equal to this if the LRU handle is the list head of an
// empty list. List heads never have meaningful keys.
assert(next != this);
diff --git a/util/cache_test.cc b/util/cache_test.cc
index 79cfc27..e68da34 100644
--- a/util/cache_test.cc
+++ b/util/cache_test.cc
@@ -222,8 +222,3 @@ TEST_F(CacheTest, ZeroSizeCache) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/coding.cc b/util/coding.cc
index df3fa10..a8f8af8 100644
--- a/util/coding.cc
+++ b/util/coding.cc
@@ -142,16 +142,6 @@ bool GetVarint64(Slice* input, uint64_t* value) {
}
}
-const char* GetLengthPrefixedSlice(const char* p, const char* limit,
- Slice* result) {
- uint32_t len;
- p = GetVarint32Ptr(p, limit, &len);
- if (p == nullptr) return nullptr;
- if (p + len > limit) return nullptr;
- *result = Slice(p, len);
- return p + len;
-}
-
bool GetLengthPrefixedSlice(Slice* input, Slice* result) {
uint32_t len;
if (GetVarint32(input, &len) && input->size() >= len) {
diff --git a/util/coding_test.cc b/util/coding_test.cc
index aa6c748..cceda14 100644
--- a/util/coding_test.cc
+++ b/util/coding_test.cc
@@ -191,8 +191,3 @@ TEST(Coding, Strings) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/crc32c_test.cc b/util/crc32c_test.cc
index 647e561..2fe1c41 100644
--- a/util/crc32c_test.cc
+++ b/util/crc32c_test.cc
@@ -54,8 +54,3 @@ TEST(CRC, Mask) {
} // namespace crc32c
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/env_posix.cc b/util/env_posix.cc
index 24b1c4c..ffd06c4 100644
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -4,7 +4,6 @@
#include <dirent.h>
#include <fcntl.h>
-#include <pthread.h>
#include <sys/mman.h>
#ifndef __Fuchsia__
#include <sys/resource.h>
@@ -74,7 +73,14 @@ Status PosixError(const std::string& context, int error_number) {
class Limiter {
public:
// Limit maximum number of resources to |max_acquires|.
- Limiter(int max_acquires) : acquires_allowed_(max_acquires) {}
+ Limiter(int max_acquires)
+ :
+#if !defined(NDEBUG)
+ max_acquires_(max_acquires),
+#endif // !defined(NDEBUG)
+ acquires_allowed_(max_acquires) {
+ assert(max_acquires >= 0);
+ }
Limiter(const Limiter&) = delete;
Limiter operator=(const Limiter&) = delete;
@@ -87,15 +93,35 @@ class Limiter {
if (old_acquires_allowed > 0) return true;
- acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+ int pre_increment_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)pre_increment_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(pre_increment_acquires_allowed < max_acquires_);
+
return false;
}
// Release a resource acquired by a previous call to Acquire() that returned
// true.
- void Release() { acquires_allowed_.fetch_add(1, std::memory_order_relaxed); }
+ void Release() {
+ int old_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)old_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(old_acquires_allowed < max_acquires_);
+ }
private:
+#if !defined(NDEBUG)
+ // Catches an excessive number of Release() calls.
+ const int max_acquires_;
+#endif // !defined(NDEBUG)
+
// The number of available resources.
//
// This is a counter and is not tied to the invariants of any other class, so
@@ -110,7 +136,7 @@ class Limiter {
class PosixSequentialFile final : public SequentialFile {
public:
PosixSequentialFile(std::string filename, int fd)
- : fd_(fd), filename_(filename) {}
+ : fd_(fd), filename_(std::move(filename)) {}
~PosixSequentialFile() override { close(fd_); }
Status Read(size_t n, Slice* result, char* scratch) override {
@@ -216,7 +242,7 @@ class PosixMmapReadableFile final : public RandomAccessFile {
// over the ownership of the region.
//
// |mmap_limiter| must outlive this instance. The caller must have already
- // aquired the right to use one mmap region, which will be released when this
+ // acquired the right to use one mmap region, which will be released when this
// instance is destroyed.
PosixMmapReadableFile(std::string filename, char* mmap_base, size_t length,
Limiter* mmap_limiter)
@@ -730,7 +756,7 @@ class PosixEnv : public Env {
// Instances are constructed on the thread calling Schedule() and used on the
// background thread.
//
- // This structure is thread-safe beacuse it is immutable.
+ // This structure is thread-safe because it is immutable.
struct BackgroundWorkItem {
explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
: function(function), arg(arg) {}
@@ -844,7 +870,7 @@ class SingletonEnv {
public:
SingletonEnv() {
#if !defined(NDEBUG)
- env_initialized_.store(true, std::memory_order::memory_order_relaxed);
+ env_initialized_.store(true, std::memory_order_relaxed);
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
@@ -861,7 +887,7 @@ class SingletonEnv {
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
- assert(!env_initialized_.load(std::memory_order::memory_order_relaxed));
+ assert(!env_initialized_.load(std::memory_order_relaxed));
#endif // !defined(NDEBUG)
}
diff --git a/util/env_posix_test.cc b/util/env_posix_test.cc
index da264f0..34bda62 100644
--- a/util/env_posix_test.cc
+++ b/util/env_posix_test.cc
@@ -243,8 +243,8 @@ TEST_F(EnvPosixTest, TestCloseOnExecRandomAccessFile) {
// Exhaust the RandomAccessFile mmap limit. This way, the test
// RandomAccessFile instance below is backed by a file descriptor, not by an
// mmap region.
- leveldb::RandomAccessFile* mmapped_files[kReadOnlyFileLimit] = {nullptr};
- for (int i = 0; i < kReadOnlyFileLimit; i++) {
+ leveldb::RandomAccessFile* mmapped_files[kMMapLimit];
+ for (int i = 0; i < kMMapLimit; i++) {
ASSERT_LEVELDB_OK(env_->NewRandomAccessFile(file_path, &mmapped_files[i]));
}
@@ -253,7 +253,7 @@ TEST_F(EnvPosixTest, TestCloseOnExecRandomAccessFile) {
CheckCloseOnExecDoesNotLeakFDs(open_fds);
delete file;
- for (int i = 0; i < kReadOnlyFileLimit; i++) {
+ for (int i = 0; i < kMMapLimit; i++) {
delete mmapped_files[i];
}
ASSERT_LEVELDB_OK(env_->RemoveFile(file_path));
diff --git a/util/env_test.cc b/util/env_test.cc
index 491ef43..47174f5 100644
--- a/util/env_test.cc
+++ b/util/env_test.cc
@@ -14,8 +14,6 @@
namespace leveldb {
-static const int kDelayMicros = 100000;
-
class EnvTest : public testing::Test {
public:
EnvTest() : env_(Env::Default()) {}
@@ -233,8 +231,3 @@ TEST_F(EnvTest, ReopenAppendableFile) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/env_windows.cc b/util/env_windows.cc
index 449f564..1c74b02 100644
--- a/util/env_windows.cc
+++ b/util/env_windows.cc
@@ -114,7 +114,14 @@ class ScopedHandle {
class Limiter {
public:
// Limit maximum number of resources to |max_acquires|.
- Limiter(int max_acquires) : acquires_allowed_(max_acquires) {}
+ Limiter(int max_acquires)
+ :
+#if !defined(NDEBUG)
+ max_acquires_(max_acquires),
+#endif // !defined(NDEBUG)
+ acquires_allowed_(max_acquires) {
+ assert(max_acquires >= 0);
+ }
Limiter(const Limiter&) = delete;
Limiter operator=(const Limiter&) = delete;
@@ -133,9 +140,22 @@ class Limiter {
// Release a resource acquired by a previous call to Acquire() that returned
// true.
- void Release() { acquires_allowed_.fetch_add(1, std::memory_order_relaxed); }
+ void Release() {
+ int old_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)old_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(old_acquires_allowed < max_acquires_);
+ }
private:
+#if !defined(NDEBUG)
+ // Catches an excessive number of Release() calls.
+ const int max_acquires_;
+#endif // !defined(NDEBUG)
+
// The number of available resources.
//
// This is a counter and is not tied to the invariants of any other class, so
@@ -622,7 +642,7 @@ class WindowsEnv : public Env {
}
Status NewLogger(const std::string& filename, Logger** result) override {
- std::FILE* fp = std::fopen(filename.c_str(), "w");
+ std::FILE* fp = std::fopen(filename.c_str(), "wN");
if (fp == nullptr) {
*result = nullptr;
return WindowsError(filename, ::GetLastError());
@@ -661,7 +681,7 @@ class WindowsEnv : public Env {
// Instances are constructed on the thread calling Schedule() and used on the
// background thread.
//
- // This structure is thread-safe beacuse it is immutable.
+ // This structure is thread-safe because it is immutable.
struct BackgroundWorkItem {
explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
: function(function), arg(arg) {}
@@ -745,7 +765,7 @@ class SingletonEnv {
public:
SingletonEnv() {
#if !defined(NDEBUG)
- env_initialized_.store(true, std::memory_order::memory_order_relaxed);
+ env_initialized_.store(true, std::memory_order_relaxed);
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
@@ -762,7 +782,7 @@ class SingletonEnv {
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
- assert(!env_initialized_.load(std::memory_order::memory_order_relaxed));
+ assert(!env_initialized_.load(std::memory_order_relaxed));
#endif // !defined(NDEBUG)
}
diff --git a/util/hash_test.cc b/util/hash_test.cc
index 6d6771f..0ea5977 100644
--- a/util/hash_test.cc
+++ b/util/hash_test.cc
@@ -39,8 +39,3 @@ TEST(HASH, SignedUnsignedIssue) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/logging_test.cc b/util/logging_test.cc
index 24e1fe9..1746c57 100644
--- a/util/logging_test.cc
+++ b/util/logging_test.cc
@@ -138,8 +138,3 @@ TEST(Logging, ConsumeDecimalNumberNoDigits) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/no_destructor_test.cc b/util/no_destructor_test.cc
index 68fdfee..e3602cc 100644
--- a/util/no_destructor_test.cc
+++ b/util/no_destructor_test.cc
@@ -42,8 +42,3 @@ TEST(NoDestructorTest, StaticInstance) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/random.h b/util/random.h
index d7cbdd9..60ca9ed 100644
--- a/util/random.h
+++ b/util/random.h
@@ -57,8 +57,6 @@ class Random {
// range [0,2^max_log-1] with exponential bias towards smaller numbers.
uint32_t Skewed(int max_log) { return Uniform(1 << Uniform(max_log + 1)); }
};
-
-
} // namespace leveldb
#endif // STORAGE_LEVELDB_UTIL_RANDOM_H_
diff --git a/util/status_test.cc b/util/status_test.cc
index 914b386..dbf5faa 100644
--- a/util/status_test.cc
+++ b/util/status_test.cc
@@ -37,8 +37,3 @@ TEST(Status, MoveConstructor) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}