mirror of
https://github.com/facebook/rocksdb.git
synced 2026-11-06 19:12:36 -05:00
Compare commits
35
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9ed290bfa | ||
|
|
9cc25190e1 | ||
|
|
50d6969816 | ||
|
|
83a4dd1a67 | ||
|
|
8efb5cfb6f | ||
|
|
9f21d08660 | ||
|
|
5b2bbacb6f | ||
|
|
1092f19d95 | ||
|
|
d739318ba7 | ||
|
|
096beb787e | ||
|
|
dea4063b13 | ||
|
|
25a0d0ca30 | ||
|
|
d76eed4839 | ||
|
|
88b4210701 | ||
|
|
a607f3efaa | ||
|
|
f4583f7480 | ||
|
|
552fd765b3 | ||
|
|
d6b7b7712f | ||
|
|
569b87e8c7 | ||
|
|
775dc623ad | ||
|
|
312f23c92d | ||
|
|
223b57eeb8 | ||
|
|
94d04529de | ||
|
|
742b452863 | ||
|
|
b7bab48099 | ||
|
|
9bfd46d0d8 | ||
|
|
aa8f1331af | ||
|
|
88db97b06d | ||
|
|
9c24a5cb4d | ||
|
|
f7613e2a9e | ||
|
|
15d9f28da5 | ||
|
|
bacd6edcbe | ||
|
|
7e2ac0c3a0 | ||
|
|
d63f86e506 | ||
|
|
9810f40075 |
No files matched your search
+18
-1
@@ -53,7 +53,21 @@ jobs:
|
||||
resource_class: 2xlarge
|
||||
steps:
|
||||
- checkout # check out the code in the project directory
|
||||
- run: USE_CLANG=1 make all -j32
|
||||
- run: sudo apt-get update -y
|
||||
- run: sudo apt-get install -y clang
|
||||
- run: CC=clang CXX=clang++ USE_CLANG=1 PORTABLE=1 make all -j32
|
||||
|
||||
build-linux-clang10-no-test:
|
||||
machine:
|
||||
image: ubuntu-1604:201903-01
|
||||
resource_class: 2xlarge
|
||||
steps:
|
||||
- checkout # check out the code in the project directory
|
||||
- run: sudo sh -c 'echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main" >> /etc/apt/sources.list'
|
||||
- run: sudo sh -c 'echo "deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main" >> /etc/apt/sources.list'
|
||||
- run: sudo apt-get update -y
|
||||
- run: sudo apt-get install -y clang-10
|
||||
- run: CC=clang-10 CXX=clang++-10 ROCKSDB_DISABLE_ALIGNED_NEW=1 USE_CLANG=1 make all -j32 # aligned new doesn't work for reason we haven't figured out
|
||||
|
||||
build-linux-cmake:
|
||||
machine:
|
||||
@@ -123,6 +137,9 @@ workflows:
|
||||
build-linux-clang-no-test:
|
||||
jobs:
|
||||
- build-linux-clang-no-test
|
||||
build-linux-clang10-no-test:
|
||||
jobs:
|
||||
- build-linux-clang10-no-test
|
||||
build-linux-cmake:
|
||||
jobs:
|
||||
- build-linux-cmake
|
||||
|
||||
+17
-4
@@ -95,7 +95,7 @@ if(MSVC)
|
||||
option(WITH_XPRESS "build with windows built in compression" OFF)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty.inc)
|
||||
else()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
|
||||
# FreeBSD has jemalloc as default malloc
|
||||
# but it does not have all the jemalloc files in include/...
|
||||
set(WITH_JEMALLOC ON)
|
||||
@@ -448,6 +448,8 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
add_definitions(-DOS_LINUX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
|
||||
add_definitions(-DOS_SOLARIS)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
|
||||
add_definitions(-DOS_GNU_KFREEBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
add_definitions(-DOS_FREEBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
|
||||
@@ -974,12 +976,19 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
|
||||
)
|
||||
endif()
|
||||
|
||||
option(WITH_ALL_TESTS "Build all test, rather than a small subset" ON)
|
||||
|
||||
if(WITH_TESTS)
|
||||
add_subdirectory(third-party/gtest-1.8.1/fused-src/gtest)
|
||||
add_library(testharness STATIC
|
||||
test_util/testharness.cc)
|
||||
target_link_libraries(testharness gtest)
|
||||
set(TESTS
|
||||
db/db_basic_test.cc
|
||||
env/env_basic_test.cc
|
||||
)
|
||||
if(WITH_ALL_TESTS)
|
||||
list(APPEND TESTS
|
||||
cache/cache_test.cc
|
||||
cache/lru_cache_test.cc
|
||||
db/blob/blob_file_addition_test.cc
|
||||
@@ -994,7 +1003,6 @@ if(WITH_TESTS)
|
||||
db/comparator_db_test.cc
|
||||
db/corruption_test.cc
|
||||
db/cuckoo_table_db_test.cc
|
||||
db/db_basic_test.cc
|
||||
db/db_with_timestamp_basic_test.cc
|
||||
db/db_block_cache_test.cc
|
||||
db/db_bloom_filter_test.cc
|
||||
@@ -1057,7 +1065,6 @@ if(WITH_TESTS)
|
||||
db/write_batch_test.cc
|
||||
db/write_callback_test.cc
|
||||
db/write_controller_test.cc
|
||||
env/env_basic_test.cc
|
||||
env/env_test.cc
|
||||
env/io_posix_test.cc
|
||||
env/mock_env_test.cc
|
||||
@@ -1140,7 +1147,8 @@ if(WITH_TESTS)
|
||||
utilities/transactions/write_unprepared_transaction_test.cc
|
||||
utilities/ttl/ttl_test.cc
|
||||
utilities/write_batch_with_index/write_batch_with_index_test.cc
|
||||
)
|
||||
)
|
||||
endif()
|
||||
if(WITH_LIBRADOS)
|
||||
list(APPEND TESTS utilities/env_librados_test.cc)
|
||||
endif()
|
||||
@@ -1261,3 +1269,8 @@ if(WITH_TOOLS)
|
||||
add_custom_target(tools
|
||||
DEPENDS ${tool_deps})
|
||||
endif()
|
||||
|
||||
option(WITH_EXAMPLES "build with examples" OFF)
|
||||
if(WITH_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
+13
-26
@@ -1,37 +1,23 @@
|
||||
# Rocksdb Change Log
|
||||
## 6.11.7 (11/15/2020)
|
||||
### Bug Fixes
|
||||
* Fix a bug of encoding and parsing BlockBasedTableOptions::read_amp_bytes_per_bit as a 64-bit integer.
|
||||
* Fixed the logic of populating native data structure for `read_amp_bytes_per_bit` during OPTIONS file parsing on big-endian architecture. Without this fix, original code introduced in PR7659, when running on big-endian machine, can mistakenly store read_amp_bytes_per_bit (an uint32) in little endian format. Future access to `read_amp_bytes_per_bit` will give wrong values. Little endian architecture is not affected.
|
||||
## Unreleased
|
||||
### Public API Change
|
||||
* Encryption file classes now exposed for inheritance in env_encryption.h
|
||||
|
||||
## 6.11.6 (10/12/2020)
|
||||
### Bug Fixes
|
||||
* Fixed a bug in the following combination of features: indexes with user keys (`format_version >= 3`), indexes are partitioned (`index_type == kTwoLevelIndexSearch`), and some index partitions are pinned in memory (`BlockBasedTableOptions::pin_l0_filter_and_index_blocks_in_cache`). The bug could cause keys to be truncated when read from the index leading to wrong read results or other unexpected behavior.
|
||||
* Fixed a bug when indexes are partitioned (`index_type == kTwoLevelIndexSearch`), some index partitions are pinned in memory (`BlockBasedTableOptions::pin_l0_filter_and_index_blocks_in_cache`), and partitions reads could be mixed between block cache and directly from the file (e.g., with `enable_index_compression == 1` and `mmap_read == 1`, partitions that were stored uncompressed due to poor compression ratio would be read directly from the file via mmap, while partitions that were stored compressed would be read from block cache). The bug could cause index partitions to be mistakenly considered empty during reads leading to wrong read results.
|
||||
|
||||
## 6.11.5 (7/23/2020)
|
||||
### Bug Fixes
|
||||
* Memtable lookup should report unrecognized value_type as corruption (#7121).
|
||||
|
||||
## 6.11.4 (7/15/2020)
|
||||
### Bug Fixes
|
||||
* Make compaction report InternalKey corruption while iterating over the input.
|
||||
|
||||
## 6.11.3 (7/9/2020)
|
||||
### Bug Fixes
|
||||
* Fix a bug when index_type == kTwoLevelIndexSearch in PartitionedIndexBuilder to update FlushPolicy to point to internal key partitioner when it changes from user-key mode to internal-key mode in index partition.
|
||||
* Disable file deletion after MANIFEST write/sync failure until db re-open or Resume() so that subsequent re-open will not see MANIFEST referencing deleted SSTs.
|
||||
|
||||
## 6.11.1 (6/23/2020)
|
||||
### Bug Fixes
|
||||
### Behavior Changes
|
||||
* Best-efforts recovery ignores CURRENT file completely. If CURRENT file is missing during recovery, best-efforts recovery still proceeds with MANIFEST file(s).
|
||||
* In best-efforts recovery, an error that is not Corruption or IOError::kNotFound or IOError::kPathNotFound will be overwritten silently. Fix this by checking all non-ok cases and return early.
|
||||
* Compressed block cache was automatically disabled with read-only DBs by mistake. Now it is fixed: compressed block cache will be in effective with read-only DB too.
|
||||
* Fail recovery and report once hitting a physical log record checksum mismatch, while reading MANIFEST. RocksDB should not continue processing the MANIFEST any further.
|
||||
* Fix a bug of wrong iterator result if another thread finishes an update and a DB flush between two statement.
|
||||
|
||||
### Public API Change
|
||||
* `DB::OpenForReadOnly()` now returns `Status::NotFound` when the specified DB directory does not exist. Previously the error returned depended on the underlying `Env`.
|
||||
* `DB::GetDbSessionId(std::string& session_id)` is added. `session_id` stores a unique identifier that gets reset every time the DB is opened. This DB session ID should be unique among all open DB instances on all hosts, and should be unique among re-openings of the same or other DBs. This identifier is recorded in the LOG file on the line starting with "DB Session ID:".
|
||||
|
||||
### New Features
|
||||
* DB identity (`db_id`) and DB session identity (`db_session_id`) are added to table properties and stored in SST files. SST files generated from SstFileWriter and Repairer have DB identity “SST Writer” and “DB Repairer”, respectively. Their DB session IDs are generated in the same way as `DB::GetDbSessionId`. The session ID for SstFileWriter (resp., Repairer) resets every time `SstFileWriter::Open` (resp., `Repairer::Run`) is called.
|
||||
* Added experimental option BlockBasedTableOptions::optimize_filters_for_memory for reducing allocated memory size of Bloom filters (~10% savings with Jemalloc) while preserving the same general accuracy. To have an effect, the option requires format_version=5 and malloc_usable_size. Enabling this option is forward and backward compatible with existing format_version=5.
|
||||
|
||||
### Bug Fixes
|
||||
* Fail recovery and report once hitting a physical log record checksum mismatch, while reading MANIFEST. RocksDB should not continue processing the MANIFEST any further.
|
||||
|
||||
## 6.11 (6/12/2020)
|
||||
### Bug Fixes
|
||||
@@ -57,6 +43,7 @@
|
||||
* Disable delete triggered compaction (NewCompactOnDeletionCollectorFactory) in universal compaction mode and num_levels = 1 in order to avoid a corruption bug.
|
||||
* `pin_l0_filter_and_index_blocks_in_cache` no longer applies to L0 files larger than `1.5 * write_buffer_size` to give more predictable memory usage. Such L0 files may exist due to intra-L0 compaction, external file ingestion, or user dynamically changing `write_buffer_size` (note, however, that files that are already pinned will continue being pinned, even after such a dynamic change).
|
||||
* In point-in-time wal recovery mode, fail database recovery in case of IOError while reading the WAL to avoid data loss.
|
||||
* A new method `Env::LowerThreadPoolCPUPriority(Priority, CpuPriority)` is added to `Env` to be able to lower to a specific priority such as `CpuPriority::kIdle`.
|
||||
|
||||
### New Features
|
||||
* sst_dump to add a new --readahead_size argument. Users can specify read size when scanning the data. Sst_dump also tries to prefetch tail part of the SST files so usually some number of I/Os are saved there too.
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
BASH_EXISTS := $(shell which bash)
|
||||
SHELL := $(shell which bash)
|
||||
# Default to python3. Some distros like CentOS 8 do not have `python`.
|
||||
ifeq ($(origin PYTHON), undefined)
|
||||
PYTHON := $(shell which python3 || which python || echo python3)
|
||||
endif
|
||||
PYTHON?=$(shell which python3 || which python || echo python3)
|
||||
export PYTHON
|
||||
|
||||
CLEAN_FILES = # deliberately empty, so we can append below.
|
||||
@@ -642,6 +640,7 @@ TESTS = \
|
||||
timer_test \
|
||||
db_with_timestamp_compaction_test \
|
||||
testutil_test \
|
||||
io_tracer_test \
|
||||
|
||||
PARALLEL_TEST = \
|
||||
backupable_db_test \
|
||||
@@ -676,9 +675,9 @@ ifdef COMPILE_WITH_UBSAN
|
||||
TESTS := $(shell echo $(TESTS) | sed 's/\boptions_settable_test\b//g')
|
||||
endif
|
||||
ifdef ASSERT_STATUS_CHECKED
|
||||
# This is a new check for which we will add support incrementally. The
|
||||
# whitelist can be removed once support is fully added.
|
||||
TESTS_WHITELIST = \
|
||||
# This is a new check for which we will add support incrementally. This
|
||||
# list can be removed once support is fully added.
|
||||
TESTS_PASSING_ASC = \
|
||||
arena_test \
|
||||
autovector_test \
|
||||
blob_file_addition_test \
|
||||
@@ -724,8 +723,8 @@ ifdef ASSERT_STATUS_CHECKED
|
||||
work_queue_test \
|
||||
write_controller_test \
|
||||
|
||||
TESTS := $(filter $(TESTS_WHITELIST),$(TESTS))
|
||||
PARALLEL_TEST := $(filter $(TESTS_WHITELIST),$(PARALLEL_TEST))
|
||||
TESTS := $(filter $(TESTS_PASSING_ASC),$(TESTS))
|
||||
PARALLEL_TEST := $(filter $(TESTS_PASSING_ASC),$(PARALLEL_TEST))
|
||||
endif
|
||||
SUBSET := $(TESTS)
|
||||
ifdef ROCKSDBTESTS_START
|
||||
@@ -846,7 +845,8 @@ endif # PLATFORM_SHARED_EXT
|
||||
dbg rocksdbjavastatic rocksdbjava install install-static install-shared uninstall \
|
||||
analyze tools tools_lib \
|
||||
blackbox_crash_test_with_atomic_flush whitebox_crash_test_with_atomic_flush \
|
||||
blackbox_crash_test_with_txn whitebox_crash_test_with_txn
|
||||
blackbox_crash_test_with_txn whitebox_crash_test_with_txn \
|
||||
blackbox_crash_test_with_best_efforts_recovery
|
||||
|
||||
|
||||
all: $(LIBRARY) $(BENCHMARKS) tools tools_lib test_libs $(TESTS)
|
||||
@@ -978,7 +978,7 @@ J ?= 100%
|
||||
# Use this regexp to select the subset of tests whose names match.
|
||||
tests-regexp = .
|
||||
|
||||
ifeq ($(PRINT_PARALLEL_OUTPUTS), 1)
|
||||
ifeq ($(PRINT_PARALLEL_OUTPUTS), 1)
|
||||
parallel_com = '{}'
|
||||
else
|
||||
parallel_com = '{} >& t/log-{/}'
|
||||
@@ -1002,7 +1002,7 @@ check_0:
|
||||
awk '{ if ($$7 != 0 || $$8 != 0) { if ($$7 == "Exitval") { h = $$0; } else { if (!f) print h; print; f = 1 } } } END { if(f) exit 1; }' < LOG ; \
|
||||
if [ $$parallel_retcode -ne 0 ] ; then exit 1 ; fi
|
||||
|
||||
valgrind-blacklist-regexp = InlineSkipTest.ConcurrentInsert|TransactionStressTest.DeadlockStress|DBCompactionTest.SuggestCompactRangeNoTwoLevel0Compactions|BackupableDBTest.RateLimiting|DBTest.CloseSpeedup|DBTest.ThreadStatusFlush|DBTest.RateLimitingTest|DBTest.EncodeDecompressedBlockSizeTest|FaultInjectionTest.UninstalledCompaction|HarnessTest.Randomized|ExternalSSTFileTest.CompactDuringAddFileRandom|ExternalSSTFileTest.IngestFileWithGlobalSeqnoRandomized|MySQLStyleTransactionTest.TransactionStressTest
|
||||
valgrind-exclude-regexp = InlineSkipTest.ConcurrentInsert|TransactionStressTest.DeadlockStress|DBCompactionTest.SuggestCompactRangeNoTwoLevel0Compactions|BackupableDBTest.RateLimiting|DBTest.CloseSpeedup|DBTest.ThreadStatusFlush|DBTest.RateLimitingTest|DBTest.EncodeDecompressedBlockSizeTest|FaultInjectionTest.UninstalledCompaction|HarnessTest.Randomized|ExternalSSTFileTest.CompactDuringAddFileRandom|ExternalSSTFileTest.IngestFileWithGlobalSeqnoRandomized|MySQLStyleTransactionTest.TransactionStressTest
|
||||
|
||||
.PHONY: valgrind_check_0
|
||||
valgrind_check_0:
|
||||
@@ -1017,7 +1017,7 @@ valgrind_check_0:
|
||||
} \
|
||||
| $(prioritize_long_running_tests) \
|
||||
| grep -E '$(tests-regexp)' \
|
||||
| grep -E -v '$(valgrind-blacklist-regexp)' \
|
||||
| grep -E -v '$(valgrind-exclude-regexp)' \
|
||||
| build_tools/gnu_parallel -j$(J) --plain --joblog=LOG $$eta --gnu \
|
||||
'(if [[ "{}" == "./"* ]] ; then $(DRIVER) {}; else {}; fi) ' \
|
||||
'>& t/valgrind_log-{/}'
|
||||
@@ -1059,7 +1059,7 @@ ifndef ASSERT_STATUS_CHECKED # not yet working with these tests
|
||||
sh tools/rocksdb_dump_test.sh
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifndef SKIP_FORMAT_BUCK_CHECKS
|
||||
$(MAKE) check-format
|
||||
$(MAKE) check-buck-targets
|
||||
@@ -1079,6 +1079,8 @@ crash_test_with_atomic_flush: whitebox_crash_test_with_atomic_flush blackbox_cra
|
||||
|
||||
crash_test_with_txn: whitebox_crash_test_with_txn blackbox_crash_test_with_txn
|
||||
|
||||
crash_test_with_best_efforts_recovery: blackbox_crash_test_with_best_efforts_recovery
|
||||
|
||||
blackbox_crash_test: db_stress
|
||||
$(PYTHON) -u tools/db_crashtest.py --simple blackbox $(CRASH_TEST_EXT_ARGS)
|
||||
$(PYTHON) -u tools/db_crashtest.py blackbox $(CRASH_TEST_EXT_ARGS)
|
||||
@@ -1089,6 +1091,9 @@ blackbox_crash_test_with_atomic_flush: db_stress
|
||||
blackbox_crash_test_with_txn: db_stress
|
||||
$(PYTHON) -u tools/db_crashtest.py --txn blackbox $(CRASH_TEST_EXT_ARGS)
|
||||
|
||||
blackbox_crash_test_with_best_efforts_recovery: db_stress
|
||||
$(PYTHON) -u tools/db_crashtest.py --test_best_efforts_recovery blackbox $(CRASH_TEST_EXT_ARGS)
|
||||
|
||||
ifeq ($(CRASH_TEST_KILL_ODD),)
|
||||
CRASH_TEST_KILL_ODD=888887
|
||||
endif
|
||||
@@ -1127,6 +1132,11 @@ asan_crash_test_with_txn:
|
||||
COMPILE_WITH_ASAN=1 $(MAKE) crash_test_with_txn
|
||||
$(MAKE) clean
|
||||
|
||||
asan_crash_test_with_best_efforts_recovery:
|
||||
$(MAKE) clean
|
||||
COMPILE_WITH_ASAN=1 $(MAKE) crash_test_with_best_efforts_recovery
|
||||
$(MAKE) clean
|
||||
|
||||
ubsan_check:
|
||||
$(MAKE) clean
|
||||
COMPILE_WITH_UBSAN=1 $(MAKE) check -j32
|
||||
@@ -1147,6 +1157,11 @@ ubsan_crash_test_with_txn:
|
||||
COMPILE_WITH_UBSAN=1 $(MAKE) crash_test_with_txn
|
||||
$(MAKE) clean
|
||||
|
||||
ubsan_crash_test_with_best_efforts_recovery:
|
||||
$(MAKE) clean
|
||||
COMPILE_WITH_UBSAN=1 $(MAKE) crash_test_with_best_efforts_recovery
|
||||
$(MAKE) clean
|
||||
|
||||
valgrind_test:
|
||||
ROCKSDB_VALGRIND_RUN=1 DISABLE_JEMALLOC=1 $(MAKE) valgrind_check
|
||||
|
||||
@@ -1882,6 +1897,8 @@ timer_test: util/timer_test.o $(LIBOBJECTS) $(TESTHARNESS)
|
||||
|
||||
testutil_test: test_util/testutil_test.o $(LIBOBJECTS) $(TESTHARNESS)
|
||||
$(AM_LINK)
|
||||
io_tracer_test: trace_replay/io_tracer_test.o trace_replay/io_tracer.o $(LIBOBJECTS) $(TESTHARNESS)
|
||||
$(AM_LINK)
|
||||
|
||||
#-------------------------------------------------
|
||||
# make install related stuff
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
## RocksDB: A Persistent Key-Value Store for Flash and RAM Storage
|
||||
|
||||
[](https://travis-ci.org/facebook/rocksdb)
|
||||
[](https://ci.appveyor.com/project/Facebook/rocksdb/branch/master)
|
||||
[](https://circleci.com/gh/facebook/rocksdb)
|
||||
[](https://travis-ci.org/facebook/rocksdb)
|
||||
[](https://ci.appveyor.com/project/Facebook/rocksdb/branch/master)
|
||||
[](http://140.211.168.68:8080/job/Rocksdb)
|
||||
|
||||
RocksDB is developed and maintained by Facebook Database Engineering Team.
|
||||
|
||||
@@ -294,6 +294,7 @@ cpp_library(
|
||||
"tools/ldb_tool.cc",
|
||||
"tools/sst_dump_tool.cc",
|
||||
"trace_replay/block_cache_tracer.cc",
|
||||
"trace_replay/io_tracer.cc",
|
||||
"trace_replay/trace_replay.cc",
|
||||
"util/build_version.cc",
|
||||
"util/coding.cc",
|
||||
@@ -447,27 +448,6 @@ cpp_library(
|
||||
external_deps = ROCKSDB_EXTERNAL_DEPS,
|
||||
)
|
||||
|
||||
if not is_opt_mode:
|
||||
cpp_binary(
|
||||
name = "c_test_bin",
|
||||
srcs = ["db/c_test.c"],
|
||||
arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
|
||||
os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
|
||||
compiler_flags = ROCKSDB_COMPILER_FLAGS,
|
||||
preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
|
||||
deps = [":rocksdb_test_lib"],
|
||||
)
|
||||
|
||||
if not is_opt_mode:
|
||||
custom_unittest(
|
||||
"c_test",
|
||||
command = [
|
||||
native.package_name() + "/buckifier/rocks_test_runner.sh",
|
||||
"$(location :{})".format("c_test_bin"),
|
||||
],
|
||||
type = "simple",
|
||||
)
|
||||
|
||||
cpp_library(
|
||||
name = "env_basic_test_lib",
|
||||
srcs = ["env/env_basic_test.cc"],
|
||||
@@ -581,6 +561,13 @@ ROCKS_TESTS = [
|
||||
[],
|
||||
[],
|
||||
],
|
||||
[
|
||||
"c_test",
|
||||
"db/c_test.c",
|
||||
"serial",
|
||||
[],
|
||||
[],
|
||||
],
|
||||
[
|
||||
"cache_simulator_test",
|
||||
"utilities/simulator_cache/cache_simulator_test.cc",
|
||||
@@ -1169,6 +1156,13 @@ ROCKS_TESTS = [
|
||||
[],
|
||||
[],
|
||||
],
|
||||
[
|
||||
"io_tracer_test",
|
||||
"trace_replay/io_tracer_test.cc",
|
||||
"serial",
|
||||
[],
|
||||
[],
|
||||
],
|
||||
[
|
||||
"iostats_context_test",
|
||||
"monitoring/iostats_context_test.cc",
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ before_build:
|
||||
- md %APPVEYOR_BUILD_FOLDER%\build
|
||||
- cd %APPVEYOR_BUILD_FOLDER%\build
|
||||
- if DEFINED CMAKE_PLATEFORM_NAME (set "PLATEFORM_OPT=-A %CMAKE_PLATEFORM_NAME%")
|
||||
- cmake .. -G "%CMAKE_GENERATOR%" %PLATEFORM_OPT% %CMAKE_OPT% -DCMAKE_BUILD_TYPE=Debug -DOPTDBG=1 -DPORTABLE=1 -DSNAPPY=1 -DLZ4=1 -DZSTD=1 -DXPRESS=1 -DJNI=1
|
||||
- cmake .. -G "%CMAKE_GENERATOR%" %PLATEFORM_OPT% %CMAKE_OPT% -DCMAKE_BUILD_TYPE=Debug -DOPTDBG=1 -DPORTABLE=1 -DSNAPPY=1 -DLZ4=1 -DZSTD=1 -DXPRESS=1 -DJNI=1 -DWITH_ALL_TESTS=0
|
||||
- cd ..
|
||||
|
||||
build:
|
||||
@@ -79,7 +79,7 @@ build:
|
||||
test:
|
||||
|
||||
test_script:
|
||||
- ps: build_tools\run_ci_db_test.ps1 -SuiteRun db_basic_test,db_with_timestamp_basic_test,db_test2,db_test,env_basic_test,env_test,db_merge_operand_test -Concurrency 8
|
||||
- ps: build_tools\run_ci_db_test.ps1 -SuiteRun db_basic_test,env_basic_test -Concurrency 8
|
||||
|
||||
on_failure:
|
||||
- cmd: 7z a build-failed.zip %APPVEYOR_BUILD_FOLDER%\build\ && appveyor PushArtifact build-failed.zip
|
||||
|
||||
@@ -64,6 +64,8 @@ def get_cc_files(repo_path):
|
||||
continue
|
||||
for filename in fnmatch.filter(filenames, '*.cc'):
|
||||
cc_files.append(os.path.join(root, filename))
|
||||
for filename in fnmatch.filter(filenames, '*.c'):
|
||||
cc_files.append(os.path.join(root, filename))
|
||||
return cc_files
|
||||
|
||||
|
||||
@@ -176,18 +178,10 @@ def generate_targets(repo_path, deps_map):
|
||||
+ ["test_util/testutil.cc"])
|
||||
|
||||
print("Extra dependencies:\n{0}".format(json.dumps(deps_map)))
|
||||
|
||||
# c_test.c is added through TARGETS.add_c_test(). If there
|
||||
# are more than one .c test file, we need to extend
|
||||
# TARGETS.add_c_test() to include other C tests too.
|
||||
TARGETS.add_c_test()
|
||||
|
||||
# test for every .cc test we found in the Makefile
|
||||
# test for every test we found in the Makefile
|
||||
for target_alias, deps in deps_map.items():
|
||||
for test in sorted(tests):
|
||||
if test == 'c_test':
|
||||
continue
|
||||
match_src = [src for src in cc_files if ("/%s.cc" % test) in src]
|
||||
match_src = [src for src in cc_files if ("/%s.c" % test) in src]
|
||||
if len(match_src) == 0:
|
||||
print(ColorString.warning("Cannot find .cc file for %s" % test))
|
||||
continue
|
||||
|
||||
@@ -76,30 +76,6 @@ class TARGETSBuilder(object):
|
||||
pretty_list(deps)))
|
||||
self.total_bin = self.total_bin + 1
|
||||
|
||||
def add_c_test(self):
|
||||
self.targets_file.write("""
|
||||
if not is_opt_mode:
|
||||
cpp_binary(
|
||||
name = "c_test_bin",
|
||||
srcs = ["db/c_test.c"],
|
||||
arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
|
||||
os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
|
||||
compiler_flags = ROCKSDB_COMPILER_FLAGS,
|
||||
preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
|
||||
deps = [":rocksdb_test_lib"],
|
||||
)
|
||||
|
||||
if not is_opt_mode:
|
||||
custom_unittest(
|
||||
"c_test",
|
||||
command = [
|
||||
native.package_name() + "/buckifier/rocks_test_runner.sh",
|
||||
"$(location :{})".format("c_test_bin"),
|
||||
],
|
||||
type = "simple",
|
||||
)
|
||||
""")
|
||||
|
||||
def register_test(self,
|
||||
test_name,
|
||||
src,
|
||||
|
||||
@@ -192,6 +192,17 @@ EOF
|
||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread"
|
||||
# PORT_FILES=port/freebsd/freebsd_specific.cc
|
||||
;;
|
||||
GNU/kFreeBSD)
|
||||
PLATFORM=OS_GNU_KFREEBSD
|
||||
COMMON_FLAGS="$COMMON_FLAGS -DOS_GNU_KFREEBSD"
|
||||
if [ -z "$USE_CLANG" ]; then
|
||||
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp"
|
||||
else
|
||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -latomic"
|
||||
fi
|
||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread -lrt"
|
||||
# PORT_FILES=port/gnu_kfreebsd/gnu_kfreebsd_specific.cc
|
||||
;;
|
||||
NetBSD)
|
||||
PLATFORM=OS_NETBSD
|
||||
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp -D_REENTRANT -DOS_NETBSD"
|
||||
|
||||
+6
-4
@@ -51,7 +51,8 @@ TableBuilder* NewTableBuilder(
|
||||
uint64_t sample_for_compression, const CompressionOptions& compression_opts,
|
||||
int level, const bool skip_filters, const uint64_t creation_time,
|
||||
const uint64_t oldest_key_time, const uint64_t target_file_size,
|
||||
const uint64_t file_creation_time) {
|
||||
const uint64_t file_creation_time, const std::string& db_id,
|
||||
const std::string& db_session_id) {
|
||||
assert((column_family_id ==
|
||||
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily) ==
|
||||
column_family_name.empty());
|
||||
@@ -61,7 +62,7 @@ TableBuilder* NewTableBuilder(
|
||||
sample_for_compression, compression_opts,
|
||||
skip_filters, column_family_name, level,
|
||||
creation_time, oldest_key_time, target_file_size,
|
||||
file_creation_time),
|
||||
file_creation_time, db_id, db_session_id),
|
||||
column_family_id, file);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,8 @@ Status BuildTable(
|
||||
EventLogger* event_logger, int job_id, const Env::IOPriority io_priority,
|
||||
TableProperties* table_properties, int level, const uint64_t creation_time,
|
||||
const uint64_t oldest_key_time, Env::WriteLifeTimeHint write_hint,
|
||||
const uint64_t file_creation_time) {
|
||||
const uint64_t file_creation_time, const std::string& db_id,
|
||||
const std::string& db_session_id) {
|
||||
assert((column_family_id ==
|
||||
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily) ==
|
||||
column_family_name.empty());
|
||||
@@ -142,7 +144,7 @@ Status BuildTable(
|
||||
column_family_name, file_writer.get(), compression,
|
||||
sample_for_compression, compression_opts_for_flush, level,
|
||||
false /* skip_filters */, creation_time, oldest_key_time,
|
||||
0 /*target_file_size*/, file_creation_time);
|
||||
0 /*target_file_size*/, file_creation_time, db_id, db_session_id);
|
||||
}
|
||||
|
||||
MergeHelper merge(env, internal_comparator.user_comparator(),
|
||||
|
||||
+4
-2
@@ -51,7 +51,8 @@ TableBuilder* NewTableBuilder(
|
||||
const CompressionOptions& compression_opts, int level,
|
||||
const bool skip_filters = false, const uint64_t creation_time = 0,
|
||||
const uint64_t oldest_key_time = 0, const uint64_t target_file_size = 0,
|
||||
const uint64_t file_creation_time = 0);
|
||||
const uint64_t file_creation_time = 0, const std::string& db_id = "",
|
||||
const std::string& db_session_id = "");
|
||||
|
||||
// Build a Table file from the contents of *iter. The generated file
|
||||
// will be named according to number specified in meta. On success, the rest of
|
||||
@@ -83,6 +84,7 @@ extern Status BuildTable(
|
||||
TableProperties* table_properties = nullptr, int level = -1,
|
||||
const uint64_t creation_time = 0, const uint64_t oldest_key_time = 0,
|
||||
Env::WriteLifeTimeHint write_hint = Env::WLTH_NOT_SET,
|
||||
const uint64_t file_creation_time = 0);
|
||||
const uint64_t file_creation_time = 0, const std::string& db_id = "",
|
||||
const std::string& db_session_id = "");
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
@@ -246,7 +246,6 @@ void CompactionIterator::NextFromInput() {
|
||||
iter_stats_.num_input_records++;
|
||||
|
||||
if (!ParseInternalKey(key_, &ikey_)) {
|
||||
iter_stats_.num_input_corrupt_records++;
|
||||
// If `expect_valid_internal_key_` is false, return the corrupted key
|
||||
// and let the caller decide what to do with it.
|
||||
// TODO(noetzli): We should have a more elegant solution for this.
|
||||
@@ -259,6 +258,7 @@ void CompactionIterator::NextFromInput() {
|
||||
has_current_user_key_ = false;
|
||||
current_user_key_sequence_ = kMaxSequenceNumber;
|
||||
current_user_key_snapshot_ = 0;
|
||||
iter_stats_.num_input_corrupt_records++;
|
||||
valid_ = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -305,12 +305,15 @@ CompactionJob::CompactionJob(
|
||||
const SnapshotChecker* snapshot_checker, std::shared_ptr<Cache> table_cache,
|
||||
EventLogger* event_logger, bool paranoid_file_checks, bool measure_io_stats,
|
||||
const std::string& dbname, CompactionJobStats* compaction_job_stats,
|
||||
Env::Priority thread_pri, const std::atomic<bool>* manual_compaction_paused)
|
||||
Env::Priority thread_pri, const std::atomic<bool>* manual_compaction_paused,
|
||||
const std::string& db_id, const std::string& db_session_id)
|
||||
: job_id_(job_id),
|
||||
compact_(new CompactionState(compaction)),
|
||||
compaction_job_stats_(compaction_job_stats),
|
||||
compaction_stats_(compaction->compaction_reason(), 1),
|
||||
dbname_(dbname),
|
||||
db_id_(db_id),
|
||||
db_session_id_(db_session_id),
|
||||
db_options_(db_options),
|
||||
file_options_(file_options),
|
||||
env_(db_options.env),
|
||||
@@ -721,6 +724,7 @@ Status CompactionJob::Install(const MutableCFOptions& mutable_cf_options) {
|
||||
cfd->internal_stats()->AddCompactionStats(
|
||||
compact_->compaction->output_level(), thread_pri_, compaction_stats_);
|
||||
|
||||
versions_->SetIOStatusOK();
|
||||
if (status.ok()) {
|
||||
status = InstallCompactionResults(mutable_cf_options);
|
||||
}
|
||||
@@ -895,10 +899,9 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
|
||||
sub_compact->c_iter.reset(new CompactionIterator(
|
||||
input.get(), cfd->user_comparator(), &merge, versions_->LastSequence(),
|
||||
&existing_snapshots_, earliest_write_conflict_snapshot_,
|
||||
snapshot_checker_, env_, ShouldReportDetailedTime(env_, stats_),
|
||||
/*expect_valid_internal_key=*/true, &range_del_agg,
|
||||
sub_compact->compaction, compaction_filter, shutting_down_,
|
||||
preserve_deletes_seqnum_, manual_compaction_paused_,
|
||||
snapshot_checker_, env_, ShouldReportDetailedTime(env_, stats_), false,
|
||||
&range_del_agg, sub_compact->compaction, compaction_filter,
|
||||
shutting_down_, preserve_deletes_seqnum_, manual_compaction_paused_,
|
||||
db_options_.info_log));
|
||||
auto c_iter = sub_compact->c_iter.get();
|
||||
c_iter->SeekToFirst();
|
||||
@@ -1554,7 +1557,8 @@ Status CompactionJob::OpenCompactionOutputFile(
|
||||
sub_compact->compaction->output_compression_opts(),
|
||||
sub_compact->compaction->output_level(), skip_filters,
|
||||
oldest_ancester_time, 0 /* oldest_key_time */,
|
||||
sub_compact->compaction->max_output_file_size(), current_time));
|
||||
sub_compact->compaction->max_output_file_size(), current_time, db_id_,
|
||||
db_session_id_));
|
||||
LogFlush(db_options_.info_log);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,9 @@ class CompactionJob {
|
||||
const std::string& dbname,
|
||||
CompactionJobStats* compaction_job_stats,
|
||||
Env::Priority thread_pri,
|
||||
const std::atomic<bool>* manual_compaction_paused = nullptr);
|
||||
const std::atomic<bool>* manual_compaction_paused = nullptr,
|
||||
const std::string& db_id = "",
|
||||
const std::string& db_session_id = "");
|
||||
|
||||
~CompactionJob();
|
||||
|
||||
@@ -152,6 +154,8 @@ class CompactionJob {
|
||||
|
||||
// DBImpl state
|
||||
const std::string& dbname_;
|
||||
const std::string db_id_;
|
||||
const std::string db_session_id_;
|
||||
const ImmutableDBOptions& db_options_;
|
||||
const FileOptions file_options_;
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ TEST_F(CompactionJobTest, Simple) {
|
||||
RunCompaction({ files }, expected_results);
|
||||
}
|
||||
|
||||
TEST_F(CompactionJobTest, DISABLED_SimpleCorrupted) {
|
||||
TEST_F(CompactionJobTest, SimpleCorrupted) {
|
||||
NewDB();
|
||||
|
||||
auto expected_results = CreateTwoFiles(true);
|
||||
@@ -989,7 +989,7 @@ TEST_F(CompactionJobTest, MultiSingleDelete) {
|
||||
// single deletion and the (single) deletion gets removed while the corrupt key
|
||||
// gets written out. TODO(noetzli): We probably want a better way to treat
|
||||
// corrupt keys.
|
||||
TEST_F(CompactionJobTest, DISABLED_CorruptionAfterDeletion) {
|
||||
TEST_F(CompactionJobTest, CorruptionAfterDeletion) {
|
||||
NewDB();
|
||||
|
||||
auto file1 =
|
||||
|
||||
+50
-27
@@ -41,6 +41,56 @@ TEST_F(DBBasicTest, OpenWhenOpen) {
|
||||
delete db2;
|
||||
}
|
||||
|
||||
TEST_F(DBBasicTest, UniqueSession) {
|
||||
Options options = CurrentOptions();
|
||||
std::string sid1, sid2, sid3, sid4;
|
||||
|
||||
db_->GetDbSessionId(sid1);
|
||||
Reopen(options);
|
||||
db_->GetDbSessionId(sid2);
|
||||
ASSERT_OK(Put("foo", "v1"));
|
||||
db_->GetDbSessionId(sid4);
|
||||
Reopen(options);
|
||||
db_->GetDbSessionId(sid3);
|
||||
|
||||
ASSERT_NE(sid1, sid2);
|
||||
ASSERT_NE(sid1, sid3);
|
||||
ASSERT_NE(sid2, sid3);
|
||||
|
||||
ASSERT_EQ(sid2, sid4);
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
Close();
|
||||
ASSERT_OK(ReadOnlyReopen(options));
|
||||
db_->GetDbSessionId(sid1);
|
||||
// Test uniqueness between readonly open (sid1) and regular open (sid3)
|
||||
ASSERT_NE(sid1, sid3);
|
||||
Close();
|
||||
ASSERT_OK(ReadOnlyReopen(options));
|
||||
db_->GetDbSessionId(sid2);
|
||||
ASSERT_EQ("v1", Get("foo"));
|
||||
db_->GetDbSessionId(sid3);
|
||||
|
||||
ASSERT_NE(sid1, sid2);
|
||||
|
||||
ASSERT_EQ(sid2, sid3);
|
||||
#endif // ROCKSDB_LITE
|
||||
|
||||
CreateAndReopenWithCF({"goku"}, options);
|
||||
db_->GetDbSessionId(sid1);
|
||||
ASSERT_OK(Put("bar", "e1"));
|
||||
db_->GetDbSessionId(sid2);
|
||||
ASSERT_EQ("e1", Get("bar"));
|
||||
db_->GetDbSessionId(sid3);
|
||||
ReopenWithColumnFamilies({"default", "goku"}, options);
|
||||
db_->GetDbSessionId(sid4);
|
||||
|
||||
ASSERT_EQ(sid1, sid2);
|
||||
ASSERT_EQ(sid2, sid3);
|
||||
|
||||
ASSERT_NE(sid1, sid4);
|
||||
}
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
TEST_F(DBBasicTest, ReadOnlyDB) {
|
||||
ASSERT_OK(Put("foo", "v1"));
|
||||
@@ -3023,33 +3073,6 @@ TEST_F(DBBasicTestMultiGetDeadline, MultiGetDeadlineExceeded) {
|
||||
Close();
|
||||
}
|
||||
|
||||
TEST_F(DBBasicTest, ManifestWriteFailure) {
|
||||
Options options = GetDefaultOptions();
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.env = env_;
|
||||
DestroyAndReopen(options);
|
||||
ASSERT_OK(Put("foo", "bar"));
|
||||
ASSERT_OK(Flush());
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
SyncPoint::GetInstance()->SetCallBack(
|
||||
"VersionSet::ProcessManifestWrites:AfterSyncManifest", [&](void* arg) {
|
||||
ASSERT_NE(nullptr, arg);
|
||||
auto* s = reinterpret_cast<Status*>(arg);
|
||||
ASSERT_OK(*s);
|
||||
// Manually overwrite return status
|
||||
*s = Status::IOError();
|
||||
});
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
ASSERT_OK(Put("key", "value"));
|
||||
ASSERT_NOK(Flush());
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
Reopen(options);
|
||||
}
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
|
||||
#ifdef ROCKSDB_UNITTESTS_WITH_CUSTOM_OBJECTS_FROM_STATIC_LIBS
|
||||
|
||||
@@ -5183,7 +5183,6 @@ TEST_P(DBCompactionTestWithParam,
|
||||
// Put one key, to make biggest log sequence number in this memtable is bigger
|
||||
// than sst which would be ingested in next step.
|
||||
ASSERT_OK(Put(Key(2), "b"));
|
||||
ASSERT_EQ(10, NumTableFilesAtLevel(0));
|
||||
dbfull()->TEST_WaitForCompact();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
std::vector<std::vector<FileMetaData>> level_to_files;
|
||||
|
||||
@@ -23,6 +23,57 @@
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
Status DBImpl::DisableFileDeletions() {
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
++disable_delete_obsolete_files_;
|
||||
if (disable_delete_obsolete_files_ == 1) {
|
||||
ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Disabled");
|
||||
} else {
|
||||
ROCKS_LOG_WARN(immutable_db_options_.info_log,
|
||||
"File Deletions Disabled, but already disabled. Counter: %d",
|
||||
disable_delete_obsolete_files_);
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status DBImpl::EnableFileDeletions(bool force) {
|
||||
// Job id == 0 means that this is not our background process, but rather
|
||||
// user thread
|
||||
JobContext job_context(0);
|
||||
bool file_deletion_enabled = false;
|
||||
{
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
if (force) {
|
||||
// if force, we need to enable file deletions right away
|
||||
disable_delete_obsolete_files_ = 0;
|
||||
} else if (disable_delete_obsolete_files_ > 0) {
|
||||
--disable_delete_obsolete_files_;
|
||||
}
|
||||
if (disable_delete_obsolete_files_ == 0) {
|
||||
file_deletion_enabled = true;
|
||||
FindObsoleteFiles(&job_context, true);
|
||||
bg_cv_.SignalAll();
|
||||
}
|
||||
}
|
||||
if (file_deletion_enabled) {
|
||||
ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Enabled");
|
||||
if (job_context.HaveSomethingToDelete()) {
|
||||
PurgeObsoleteFiles(job_context);
|
||||
}
|
||||
} else {
|
||||
ROCKS_LOG_WARN(immutable_db_options_.info_log,
|
||||
"File Deletions Enable, but not really enabled. Counter: %d",
|
||||
disable_delete_obsolete_files_);
|
||||
}
|
||||
job_context.Clean();
|
||||
LogFlush(immutable_db_options_.info_log);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
int DBImpl::IsFileDeletionsEnabled() const {
|
||||
return !disable_delete_obsolete_files_;
|
||||
}
|
||||
|
||||
Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
|
||||
uint64_t* manifest_file_size,
|
||||
bool flush_memtable) {
|
||||
|
||||
+18
-45
@@ -249,7 +249,8 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname,
|
||||
new ColumnFamilyMemTablesImpl(versions_->GetColumnFamilySet()));
|
||||
|
||||
DumpRocksDBBuildVersion(immutable_db_options_.info_log.get());
|
||||
DumpDBFileSummary(immutable_db_options_, dbname_);
|
||||
SetDbSessionId();
|
||||
DumpDBFileSummary(immutable_db_options_, dbname_, db_session_id_);
|
||||
immutable_db_options_.Dump(immutable_db_options_.info_log.get());
|
||||
mutable_db_options_.Dump(immutable_db_options_.info_log.get());
|
||||
DumpSupportInfo(immutable_db_options_.info_log.get());
|
||||
@@ -312,36 +313,8 @@ Status DBImpl::ResumeImpl() {
|
||||
}
|
||||
|
||||
// Make sure the IO Status stored in version set is set to OK.
|
||||
bool file_deletion_disabled = !IsFileDeletionsEnabled();
|
||||
if (s.ok()) {
|
||||
IOStatus io_s = versions_->io_status();
|
||||
if (io_s.IsIOError()) {
|
||||
// If resuming from IOError resulted from MANIFEST write, then assert
|
||||
// that we must have already set the MANIFEST writer to nullptr during
|
||||
// clean-up phase MANIFEST writing. We must have also disabled file
|
||||
// deletions.
|
||||
assert(!versions_->descriptor_log_);
|
||||
assert(file_deletion_disabled);
|
||||
// Since we are trying to recover from MANIFEST write error, we need to
|
||||
// switch to a new MANIFEST anyway. The old MANIFEST can be corrupted.
|
||||
// Therefore, force writing a dummy version edit because we do not know
|
||||
// whether there are flush jobs with non-empty data to flush, triggering
|
||||
// appends to MANIFEST.
|
||||
VersionEdit edit;
|
||||
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(default_cf_handle_);
|
||||
assert(cfh);
|
||||
ColumnFamilyData* cfd = cfh->cfd();
|
||||
const MutableCFOptions& cf_opts = *cfd->GetLatestMutableCFOptions();
|
||||
s = versions_->LogAndApply(cfd, cf_opts, &edit, &mutex_,
|
||||
directories_.GetDbDir());
|
||||
if (!s.ok()) {
|
||||
io_s = versions_->io_status();
|
||||
if (!io_s.ok()) {
|
||||
s = error_handler_.SetBGError(io_s,
|
||||
BackgroundErrorReason::kManifestWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
versions_->SetIOStatusOK();
|
||||
}
|
||||
|
||||
// We cannot guarantee consistency of the WAL. So force flush Memtables of
|
||||
@@ -392,13 +365,6 @@ Status DBImpl::ResumeImpl() {
|
||||
job_context.Clean();
|
||||
|
||||
if (s.ok()) {
|
||||
assert(versions_->io_status().ok());
|
||||
// If we reach here, we should re-enable file deletions if it was disabled
|
||||
// during previous error handling.
|
||||
if (file_deletion_disabled) {
|
||||
// Always return ok
|
||||
EnableFileDeletions(/*force=*/true);
|
||||
}
|
||||
ROCKS_LOG_INFO(immutable_db_options_.info_log, "Successfully resumed DB");
|
||||
}
|
||||
mutex_.Lock();
|
||||
@@ -3656,6 +3622,21 @@ Status DBImpl::GetDbIdentityFromIdentityFile(std::string* identity) const {
|
||||
return s;
|
||||
}
|
||||
|
||||
Status DBImpl::GetDbSessionId(std::string& session_id) const {
|
||||
session_id.assign(db_session_id_);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void DBImpl::SetDbSessionId() {
|
||||
// GenerateUniqueId() generates an identifier
|
||||
// that has a negligible probability of being duplicated
|
||||
db_session_id_ = env_->GenerateUniqueId();
|
||||
// Remove the extra '\n' at the end if there is one
|
||||
if (!db_session_id_.empty() && db_session_id_.back() == '\n') {
|
||||
db_session_id_.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Default implementation -- returns not supported status
|
||||
Status DB::CreateColumnFamily(const ColumnFamilyOptions& /*cf_options*/,
|
||||
const std::string& /*column_family_name*/,
|
||||
@@ -4424,14 +4405,6 @@ Status DBImpl::IngestExternalFiles(
|
||||
#endif // !NDEBUG
|
||||
}
|
||||
}
|
||||
} else if (versions_->io_status().IsIOError()) {
|
||||
// Error while writing to MANIFEST.
|
||||
// In fact, versions_->io_status() can also be the result of renaming
|
||||
// CURRENT file. With current code, it's just difficult to tell. So just
|
||||
// be pessimistic and try write to a new MANIFEST.
|
||||
// TODO: distinguish between MANIFEST write and CURRENT renaming
|
||||
const IOStatus& io_s = versions_->io_status();
|
||||
error_handler_.SetBGError(io_s, BackgroundErrorReason::kManifestWrite);
|
||||
}
|
||||
|
||||
// Resume writes to the DB
|
||||
|
||||
+12
-8
@@ -350,18 +350,14 @@ class DBImpl : public DB {
|
||||
|
||||
virtual Status GetDbIdentityFromIdentityFile(std::string* identity) const;
|
||||
|
||||
virtual Status GetDbSessionId(std::string& session_id) const override;
|
||||
|
||||
ColumnFamilyHandle* DefaultColumnFamily() const override;
|
||||
|
||||
ColumnFamilyHandle* PersistentStatsColumnFamily() const;
|
||||
|
||||
virtual Status Close() override;
|
||||
|
||||
virtual Status DisableFileDeletions() override;
|
||||
|
||||
virtual Status EnableFileDeletions(bool force) override;
|
||||
|
||||
virtual bool IsFileDeletionsEnabled() const;
|
||||
|
||||
Status GetStatsHistory(
|
||||
uint64_t start_time, uint64_t end_time,
|
||||
std::unique_ptr<StatsHistoryIterator>* stats_iterator) override;
|
||||
@@ -369,6 +365,9 @@ class DBImpl : public DB {
|
||||
#ifndef ROCKSDB_LITE
|
||||
using DB::ResetStats;
|
||||
virtual Status ResetStats() override;
|
||||
virtual Status DisableFileDeletions() override;
|
||||
virtual Status EnableFileDeletions(bool force) override;
|
||||
virtual int IsFileDeletionsEnabled() const;
|
||||
// All the returned filenames start with "/"
|
||||
virtual Status GetLiveFiles(std::vector<std::string>&,
|
||||
uint64_t* manifest_file_size,
|
||||
@@ -984,6 +983,9 @@ class DBImpl : public DB {
|
||||
protected:
|
||||
const std::string dbname_;
|
||||
std::string db_id_;
|
||||
// db_session_id_ is an identifier that gets reset
|
||||
// every time the DB is opened
|
||||
std::string db_session_id_;
|
||||
std::unique_ptr<VersionSet> versions_;
|
||||
// Flag to check whether we allocated and own the info log file
|
||||
bool own_info_log_;
|
||||
@@ -1165,6 +1167,10 @@ class DBImpl : public DB {
|
||||
// bump up the version set's next_file_number_ to be 1 + largest_file_number.
|
||||
Status FinishBestEffortsRecovery();
|
||||
|
||||
// SetDbSessionId() should be called in the constuctor DBImpl()
|
||||
// to ensure that db_session_id_ gets updated every time the DB is opened
|
||||
void SetDbSessionId();
|
||||
|
||||
private:
|
||||
friend class DB;
|
||||
friend class ErrorHandler;
|
||||
@@ -1783,8 +1789,6 @@ class DBImpl : public DB {
|
||||
SuperVersion* sv, SequenceNumber snap_seqnum, ReadCallback* callback,
|
||||
bool* is_blob_index);
|
||||
|
||||
Status DisableFileDeletionsWithLock();
|
||||
|
||||
// table_cache_ provides its own synchronization
|
||||
std::shared_ptr<Cache> table_cache_;
|
||||
|
||||
|
||||
@@ -154,7 +154,8 @@ Status DBImpl::FlushMemTableToOutputFile(
|
||||
GetDataDir(cfd, 0U),
|
||||
GetCompressionFlush(*cfd->ioptions(), mutable_cf_options), stats_,
|
||||
&event_logger_, mutable_cf_options.report_bg_io_stats,
|
||||
true /* sync_output_directory */, true /* write_manifest */, thread_pri);
|
||||
true /* sync_output_directory */, true /* write_manifest */, thread_pri,
|
||||
db_id_, db_session_id_);
|
||||
FileMetaData file_meta;
|
||||
|
||||
TEST_SYNC_POINT("DBImpl::FlushMemTableToOutputFile:BeforePickMemtables");
|
||||
@@ -210,15 +211,7 @@ Status DBImpl::FlushMemTableToOutputFile(
|
||||
if (!s.ok() && !s.IsShutdownInProgress() && !s.IsColumnFamilyDropped()) {
|
||||
if (!io_s.ok() && !io_s.IsShutdownInProgress() &&
|
||||
!io_s.IsColumnFamilyDropped()) {
|
||||
// Error while writing to MANIFEST.
|
||||
// In fact, versions_->io_status() can also be the result of renaming
|
||||
// CURRENT file. With current code, it's just difficult to tell. So just
|
||||
// be pessimistic and try write to a new MANIFEST.
|
||||
// TODO: distinguish between MANIFEST write and CURRENT renaming
|
||||
auto err_reason = versions_->io_status().ok()
|
||||
? BackgroundErrorReason::kFlush
|
||||
: BackgroundErrorReason::kManifestWrite;
|
||||
error_handler_.SetBGError(io_s, err_reason);
|
||||
error_handler_.SetBGError(io_s, BackgroundErrorReason::kFlush);
|
||||
} else {
|
||||
Status new_bg_error = s;
|
||||
error_handler_.SetBGError(new_bg_error, BackgroundErrorReason::kFlush);
|
||||
@@ -353,7 +346,7 @@ Status DBImpl::AtomicFlushMemTablesToOutputFiles(
|
||||
data_dir, GetCompressionFlush(*cfd->ioptions(), mutable_cf_options),
|
||||
stats_, &event_logger_, mutable_cf_options.report_bg_io_stats,
|
||||
false /* sync_output_directory */, false /* write_manifest */,
|
||||
thread_pri));
|
||||
thread_pri, db_id_, db_session_id_));
|
||||
jobs.back()->PickMemTable();
|
||||
}
|
||||
|
||||
@@ -582,15 +575,7 @@ Status DBImpl::AtomicFlushMemTablesToOutputFiles(
|
||||
// it is not because of CF drop.
|
||||
if (!s.ok() && !s.IsColumnFamilyDropped()) {
|
||||
if (!io_s.ok() && !io_s.IsColumnFamilyDropped()) {
|
||||
// Error while writing to MANIFEST.
|
||||
// In fact, versions_->io_status() can also be the result of renaming
|
||||
// CURRENT file. With current code, it's just difficult to tell. So just
|
||||
// be pessimistic and try write to a new MANIFEST.
|
||||
// TODO: distinguish between MANIFEST write and CURRENT renaming
|
||||
auto err_reason = versions_->io_status().ok()
|
||||
? BackgroundErrorReason::kFlush
|
||||
: BackgroundErrorReason::kManifestWrite;
|
||||
error_handler_.SetBGError(io_s, err_reason);
|
||||
error_handler_.SetBGError(io_s, BackgroundErrorReason::kFlush);
|
||||
} else {
|
||||
Status new_bg_error = s;
|
||||
error_handler_.SetBGError(new_bg_error, BackgroundErrorReason::kFlush);
|
||||
@@ -1047,7 +1032,8 @@ Status DBImpl::CompactFilesImpl(
|
||||
snapshot_checker, table_cache_, &event_logger_,
|
||||
c->mutable_cf_options()->paranoid_file_checks,
|
||||
c->mutable_cf_options()->report_bg_io_stats, dbname_,
|
||||
&compaction_job_stats, Env::Priority::USER, &manual_compaction_paused_);
|
||||
&compaction_job_stats, Env::Priority::USER, &manual_compaction_paused_,
|
||||
db_id_, db_session_id_);
|
||||
|
||||
// Creating a compaction influences the compaction score because the score
|
||||
// takes running compactions into account (by skipping files that are already
|
||||
@@ -2703,6 +2689,7 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
for (const auto& f : *c->inputs(0)) {
|
||||
c->edit()->DeleteFile(c->level(), f->fd.GetNumber());
|
||||
}
|
||||
versions_->SetIOStatusOK();
|
||||
status = versions_->LogAndApply(c->column_family_data(),
|
||||
*c->mutable_cf_options(), c->edit(),
|
||||
&mutex_, directories_.GetDbDir());
|
||||
@@ -2760,6 +2747,7 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
}
|
||||
}
|
||||
|
||||
versions_->SetIOStatusOK();
|
||||
status = versions_->LogAndApply(c->column_family_data(),
|
||||
*c->mutable_cf_options(), c->edit(),
|
||||
&mutex_, directories_.GetDbDir());
|
||||
@@ -2836,7 +2824,8 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
&event_logger_, c->mutable_cf_options()->paranoid_file_checks,
|
||||
c->mutable_cf_options()->report_bg_io_stats, dbname_,
|
||||
&compaction_job_stats, thread_pri,
|
||||
is_manual ? &manual_compaction_paused_ : nullptr);
|
||||
is_manual ? &manual_compaction_paused_ : nullptr, db_id_,
|
||||
db_session_id_);
|
||||
compaction_job.Prepare();
|
||||
|
||||
NotifyOnCompactionBegin(c->column_family_data(), c.get(), status,
|
||||
@@ -2891,15 +2880,7 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
ROCKS_LOG_WARN(immutable_db_options_.info_log, "Compaction error: %s",
|
||||
status.ToString().c_str());
|
||||
if (!io_s.ok()) {
|
||||
// Error while writing to MANIFEST.
|
||||
// In fact, versions_->io_status() can also be the result of renaming
|
||||
// CURRENT file. With current code, it's just difficult to tell. So just
|
||||
// be pessimistic and try write to a new MANIFEST.
|
||||
// TODO: distinguish between MANIFEST write and CURRENT renaming
|
||||
auto err_reason = versions_->io_status().ok()
|
||||
? BackgroundErrorReason::kCompaction
|
||||
: BackgroundErrorReason::kManifestWrite;
|
||||
error_handler_.SetBGError(io_s, err_reason);
|
||||
error_handler_.SetBGError(io_s, BackgroundErrorReason::kCompaction);
|
||||
} else {
|
||||
error_handler_.SetBGError(status, BackgroundErrorReason::kCompaction);
|
||||
}
|
||||
|
||||
@@ -36,62 +36,6 @@ uint64_t DBImpl::MinObsoleteSstNumberToKeep() {
|
||||
return std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
|
||||
Status DBImpl::DisableFileDeletions() {
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
return DisableFileDeletionsWithLock();
|
||||
}
|
||||
|
||||
Status DBImpl::DisableFileDeletionsWithLock() {
|
||||
mutex_.AssertHeld();
|
||||
++disable_delete_obsolete_files_;
|
||||
if (disable_delete_obsolete_files_ == 1) {
|
||||
ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Disabled");
|
||||
} else {
|
||||
ROCKS_LOG_WARN(immutable_db_options_.info_log,
|
||||
"File Deletions Disabled, but already disabled. Counter: %d",
|
||||
disable_delete_obsolete_files_);
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status DBImpl::EnableFileDeletions(bool force) {
|
||||
// Job id == 0 means that this is not our background process, but rather
|
||||
// user thread
|
||||
JobContext job_context(0);
|
||||
bool file_deletion_enabled = false;
|
||||
{
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
if (force) {
|
||||
// if force, we need to enable file deletions right away
|
||||
disable_delete_obsolete_files_ = 0;
|
||||
} else if (disable_delete_obsolete_files_ > 0) {
|
||||
--disable_delete_obsolete_files_;
|
||||
}
|
||||
if (disable_delete_obsolete_files_ == 0) {
|
||||
file_deletion_enabled = true;
|
||||
FindObsoleteFiles(&job_context, true);
|
||||
bg_cv_.SignalAll();
|
||||
}
|
||||
}
|
||||
if (file_deletion_enabled) {
|
||||
ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Enabled");
|
||||
if (job_context.HaveSomethingToDelete()) {
|
||||
PurgeObsoleteFiles(job_context);
|
||||
}
|
||||
} else {
|
||||
ROCKS_LOG_WARN(immutable_db_options_.info_log,
|
||||
"File Deletions Enable, but not really enabled. Counter: %d",
|
||||
disable_delete_obsolete_files_);
|
||||
}
|
||||
job_context.Clean();
|
||||
LogFlush(immutable_db_options_.info_log);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
bool DBImpl::IsFileDeletionsEnabled() const {
|
||||
return 0 == disable_delete_obsolete_files_;
|
||||
}
|
||||
|
||||
// * Returns the list of live files in 'sst_live' and 'blob_live'.
|
||||
// If it's doing full scan:
|
||||
// * Returns the list of all files in the filesystem in
|
||||
|
||||
@@ -1289,7 +1289,8 @@ Status DBImpl::WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd,
|
||||
mutable_cf_options.compression_opts, paranoid_file_checks,
|
||||
cfd->internal_stats(), TableFileCreationReason::kRecovery, &io_s,
|
||||
&event_logger_, job_id, Env::IO_HIGH, nullptr /* table_properties */,
|
||||
-1 /* level */, current_time, write_hint);
|
||||
-1 /* level */, current_time, 0 /* oldest_key_time */, write_hint,
|
||||
0 /* file_creation_time */, db_id_, db_session_id_);
|
||||
LogFlush(immutable_db_options_.info_log);
|
||||
ROCKS_LOG_DEBUG(immutable_db_options_.info_log,
|
||||
"[%s] [WriteLevel0TableForRecovery]"
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
void DumpDBFileSummary(const ImmutableDBOptions& options,
|
||||
const std::string& dbname) {
|
||||
const std::string& dbname,
|
||||
const std::string& session_id) {
|
||||
if (options.info_log == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -32,6 +33,8 @@ void DumpDBFileSummary(const ImmutableDBOptions& options,
|
||||
std::string file_info, wal_info;
|
||||
|
||||
Header(options.info_log, "DB SUMMARY\n");
|
||||
Header(options.info_log, "DB Session ID: %s\n", session_id.c_str());
|
||||
|
||||
// Get files in dbname dir
|
||||
if (!env->GetChildren(dbname, &files).ok()) {
|
||||
Error(options.info_log,
|
||||
|
||||
+2
-1
@@ -10,5 +10,6 @@
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
void DumpDBFileSummary(const ImmutableDBOptions& options,
|
||||
const std::string& dbname);
|
||||
const std::string& dbname,
|
||||
const std::string& session_id = "");
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
@@ -97,7 +97,8 @@ struct StressTestIterator : public InternalIterator {
|
||||
|
||||
bool MaybeFail() {
|
||||
if (rnd->Next() >=
|
||||
std::numeric_limits<uint64_t>::max() * error_probability) {
|
||||
static_cast<double>(std::numeric_limits<uint64_t>::max()) *
|
||||
error_probability) {
|
||||
return false;
|
||||
}
|
||||
if (rnd->Next() % 2) {
|
||||
@@ -114,7 +115,8 @@ struct StressTestIterator : public InternalIterator {
|
||||
|
||||
void MaybeMutate() {
|
||||
if (rnd->Next() >=
|
||||
std::numeric_limits<uint64_t>::max() * mutation_probability) {
|
||||
static_cast<double>(std::numeric_limits<uint64_t>::max()) *
|
||||
mutation_probability) {
|
||||
return;
|
||||
}
|
||||
do {
|
||||
@@ -126,8 +128,9 @@ struct StressTestIterator : public InternalIterator {
|
||||
if (data->hidden.empty()) {
|
||||
hide_probability = 1;
|
||||
}
|
||||
bool do_hide =
|
||||
rnd->Next() < std::numeric_limits<uint64_t>::max() * hide_probability;
|
||||
bool do_hide = rnd->Next() <
|
||||
static_cast<double>(std::numeric_limits<uint64_t>::max()) *
|
||||
hide_probability;
|
||||
if (do_hide) {
|
||||
// Hide a random entry.
|
||||
size_t idx = rnd->Next() % data->entries.size();
|
||||
|
||||
@@ -303,14 +303,14 @@ TEST_F(DBMemTableTest, InsertWithHint) {
|
||||
ASSERT_EQ(hint_bar, rep->last_hint_in());
|
||||
ASSERT_EQ(hint_bar, rep->last_hint_out());
|
||||
ASSERT_EQ(5, rep->num_insert_with_hint());
|
||||
ASSERT_OK(Put("whitelisted", "vvv"));
|
||||
ASSERT_OK(Put("NotInPrefixDomain", "vvv"));
|
||||
ASSERT_EQ(5, rep->num_insert_with_hint());
|
||||
ASSERT_EQ("foo_v1", Get("foo_k1"));
|
||||
ASSERT_EQ("foo_v2", Get("foo_k2"));
|
||||
ASSERT_EQ("foo_v3", Get("foo_k3"));
|
||||
ASSERT_EQ("bar_v1", Get("bar_k1"));
|
||||
ASSERT_EQ("bar_v2", Get("bar_k2"));
|
||||
ASSERT_EQ("vvv", Get("whitelisted"));
|
||||
ASSERT_EQ("vvv", Get("NotInPrefixDomain"));
|
||||
}
|
||||
|
||||
TEST_F(DBMemTableTest, ColumnFamilyId) {
|
||||
|
||||
@@ -39,7 +39,7 @@ class DBOptionsTest : public DBTestBase {
|
||||
std::unordered_map<std::string, std::string> options_map;
|
||||
StringToMap(options_str, &options_map);
|
||||
std::unordered_map<std::string, std::string> mutable_map;
|
||||
for (const auto opt : db_options_type_info) {
|
||||
for (const auto& opt : db_options_type_info) {
|
||||
if (opt.second.IsMutable() && opt.second.ShouldSerialize()) {
|
||||
mutable_map[opt.first] = options_map[opt.first];
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class DBOptionsTest : public DBTestBase {
|
||||
std::unordered_map<std::string, std::string> options_map;
|
||||
StringToMap(options_str, &options_map);
|
||||
std::unordered_map<std::string, std::string> mutable_map;
|
||||
for (const auto opt : cf_options_type_info) {
|
||||
for (const auto& opt : cf_options_type_info) {
|
||||
if (opt.second.IsMutable() && opt.second.ShouldSerialize()) {
|
||||
mutable_map[opt.first] = options_map[opt.first];
|
||||
}
|
||||
|
||||
@@ -252,6 +252,26 @@ TEST_F(DBTablePropertiesTest, GetColumnFamilyNameProperty) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DBTablePropertiesTest, GetDbIdentifiersProperty) {
|
||||
CreateAndReopenWithCF({"goku"}, CurrentOptions());
|
||||
|
||||
for (uint32_t cf = 0; cf < 2; ++cf) {
|
||||
Put(cf, "key", "val");
|
||||
Put(cf, "foo", "bar");
|
||||
Flush(cf);
|
||||
|
||||
TablePropertiesCollection fname_to_props;
|
||||
ASSERT_OK(db_->GetPropertiesOfAllTables(handles_[cf], &fname_to_props));
|
||||
ASSERT_EQ(1U, fname_to_props.size());
|
||||
|
||||
std::string id, sid;
|
||||
db_->GetDbIdentity(id);
|
||||
db_->GetDbSessionId(sid);
|
||||
ASSERT_EQ(id, fname_to_props.begin()->second->db_id);
|
||||
ASSERT_EQ(sid, fname_to_props.begin()->second->db_session_id);
|
||||
}
|
||||
}
|
||||
|
||||
class DeletionTriggeredCompactionTestListener : public EventListener {
|
||||
public:
|
||||
void OnCompactionBegin(DB* , const CompactionJobInfo& ci) override {
|
||||
|
||||
+5
-2
@@ -2990,11 +2990,10 @@ class ModelDB : public DB {
|
||||
|
||||
Status SyncWAL() override { return Status::OK(); }
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
Status DisableFileDeletions() override { return Status::OK(); }
|
||||
|
||||
Status EnableFileDeletions(bool /*force*/) override { return Status::OK(); }
|
||||
#ifndef ROCKSDB_LITE
|
||||
|
||||
Status GetLiveFiles(std::vector<std::string>&, uint64_t* /*size*/,
|
||||
bool /*flush_memtable*/ = true) override {
|
||||
return Status::OK();
|
||||
@@ -3032,6 +3031,10 @@ class ModelDB : public DB {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status GetDbSessionId(std::string& /*session_id*/) const override {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
SequenceNumber GetLatestSequenceNumber() const override { return 0; }
|
||||
|
||||
bool SetPreserveDeletesSequenceNumber(SequenceNumber /*seqnum*/) override {
|
||||
|
||||
+7
-37
@@ -144,38 +144,6 @@ INSTANTIATE_TEST_CASE_P(TestReadOnlyWithCompressedCache,
|
||||
TestReadOnlyWithCompressedCache,
|
||||
::testing::Combine(::testing::Values(-1, 100),
|
||||
::testing::Bool()));
|
||||
|
||||
class PartitionedIndexTestListener : public EventListener {
|
||||
public:
|
||||
void OnFlushCompleted(DB* /*db*/, const FlushJobInfo& info) override {
|
||||
ASSERT_GT(info.table_properties.index_partitions, 1);
|
||||
ASSERT_EQ(info.table_properties.index_key_is_user_key, 0);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DBTest2, PartitionedIndexUserToInternalKey) {
|
||||
BlockBasedTableOptions table_options;
|
||||
Options options = CurrentOptions();
|
||||
table_options.index_type = BlockBasedTableOptions::kTwoLevelIndexSearch;
|
||||
PartitionedIndexTestListener* listener = new PartitionedIndexTestListener();
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
options.listeners.emplace_back(listener);
|
||||
std::vector<const Snapshot*> snapshots;
|
||||
Reopen(options);
|
||||
Random rnd(301);
|
||||
|
||||
for (int i = 0; i < 3000; i++) {
|
||||
int j = i % 30;
|
||||
std::string value = RandomString(&rnd, 10500);
|
||||
ASSERT_OK(Put("keykey_" + std::to_string(j), value));
|
||||
snapshots.push_back(db_->GetSnapshot());
|
||||
}
|
||||
Flush();
|
||||
for (auto s : snapshots) {
|
||||
db_->ReleaseSnapshot(s);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ROCKSDB_LITE
|
||||
|
||||
class PrefixFullBloomWithReverseComparator
|
||||
@@ -2100,6 +2068,10 @@ class MockPersistentCache : public PersistentCache {
|
||||
return PersistentCache::StatsType();
|
||||
}
|
||||
|
||||
uint64_t NewId() override {
|
||||
return last_id_.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
Status Insert(const Slice& page_key, const char* data,
|
||||
const size_t size) override {
|
||||
MutexLock _(&lock_);
|
||||
@@ -2140,6 +2112,7 @@ class MockPersistentCache : public PersistentCache {
|
||||
const bool is_compressed_ = true;
|
||||
size_t size_ = 0;
|
||||
const size_t max_size_ = 10 * 1024; // 10KiB
|
||||
std::atomic<uint64_t> last_id_{1};
|
||||
};
|
||||
|
||||
#ifdef OS_LINUX
|
||||
@@ -2263,10 +2236,7 @@ TEST_F(DBTest2, TestPerfContextIterCpuTime) {
|
||||
}
|
||||
#endif // OS_LINUX
|
||||
|
||||
// GetUniqueIdFromFile is not implemented on these platforms. Persistent cache
|
||||
// breaks when that function is not implemented and no regular block cache is
|
||||
// provided.
|
||||
#if !defined(OS_SOLARIS) && !defined(OS_WIN)
|
||||
#if !defined OS_SOLARIS
|
||||
TEST_F(DBTest2, PersistentCache) {
|
||||
int num_iter = 80;
|
||||
|
||||
@@ -2330,7 +2300,7 @@ TEST_F(DBTest2, PersistentCache) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !defined(OS_SOLARIS) && !defined(OS_WIN)
|
||||
#endif // !defined OS_SOLARIS
|
||||
|
||||
namespace {
|
||||
void CountSyncPoint() {
|
||||
|
||||
+13
-33
@@ -51,19 +51,9 @@ std::map<std::tuple<BackgroundErrorReason, Status::Code, Status::SubCode, bool>,
|
||||
Status::Code::kIOError, Status::SubCode::kNoSpace,
|
||||
false),
|
||||
Status::Severity::kHardError},
|
||||
// Errors during MANIFEST write
|
||||
{std::make_tuple(BackgroundErrorReason::kManifestWrite,
|
||||
Status::Code::kIOError, Status::SubCode::kNoSpace,
|
||||
true),
|
||||
Status::Severity::kHardError},
|
||||
{std::make_tuple(BackgroundErrorReason::kManifestWrite,
|
||||
Status::Code::kIOError, Status::SubCode::kNoSpace,
|
||||
false),
|
||||
Status::Severity::kHardError},
|
||||
};
|
||||
|
||||
std::map<std::tuple<BackgroundErrorReason, Status::Code, bool>,
|
||||
Status::Severity>
|
||||
std::map<std::tuple<BackgroundErrorReason, Status::Code, bool>, Status::Severity>
|
||||
DefaultErrorSeverityMap = {
|
||||
// Errors during BG compaction
|
||||
{std::make_tuple(BackgroundErrorReason::kCompaction,
|
||||
@@ -85,11 +75,11 @@ std::map<std::tuple<BackgroundErrorReason, Status::Code, bool>,
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush,
|
||||
Status::Code::kCorruption, false),
|
||||
Status::Severity::kNoError},
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush, Status::Code::kIOError,
|
||||
true),
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush,
|
||||
Status::Code::kIOError, true),
|
||||
Status::Severity::kFatalError},
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush, Status::Code::kIOError,
|
||||
false),
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush,
|
||||
Status::Code::kIOError, false),
|
||||
Status::Severity::kNoError},
|
||||
// Errors during Write
|
||||
{std::make_tuple(BackgroundErrorReason::kWriteCallback,
|
||||
@@ -104,36 +94,30 @@ std::map<std::tuple<BackgroundErrorReason, Status::Code, bool>,
|
||||
{std::make_tuple(BackgroundErrorReason::kWriteCallback,
|
||||
Status::Code::kIOError, false),
|
||||
Status::Severity::kNoError},
|
||||
{std::make_tuple(BackgroundErrorReason::kManifestWrite,
|
||||
Status::Code::kIOError, true),
|
||||
Status::Severity::kFatalError},
|
||||
{std::make_tuple(BackgroundErrorReason::kManifestWrite,
|
||||
Status::Code::kIOError, false),
|
||||
Status::Severity::kFatalError},
|
||||
};
|
||||
|
||||
std::map<std::tuple<BackgroundErrorReason, bool>, Status::Severity>
|
||||
DefaultReasonMap = {
|
||||
// Errors during BG compaction
|
||||
{std::make_tuple(BackgroundErrorReason::kCompaction, true),
|
||||
Status::Severity::kFatalError},
|
||||
Status::Severity::kFatalError},
|
||||
{std::make_tuple(BackgroundErrorReason::kCompaction, false),
|
||||
Status::Severity::kNoError},
|
||||
Status::Severity::kNoError},
|
||||
// Errors during BG flush
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush, true),
|
||||
Status::Severity::kFatalError},
|
||||
Status::Severity::kFatalError},
|
||||
{std::make_tuple(BackgroundErrorReason::kFlush, false),
|
||||
Status::Severity::kNoError},
|
||||
Status::Severity::kNoError},
|
||||
// Errors during Write
|
||||
{std::make_tuple(BackgroundErrorReason::kWriteCallback, true),
|
||||
Status::Severity::kFatalError},
|
||||
Status::Severity::kFatalError},
|
||||
{std::make_tuple(BackgroundErrorReason::kWriteCallback, false),
|
||||
Status::Severity::kFatalError},
|
||||
Status::Severity::kFatalError},
|
||||
// Errors during Memtable update
|
||||
{std::make_tuple(BackgroundErrorReason::kMemTable, true),
|
||||
Status::Severity::kFatalError},
|
||||
Status::Severity::kFatalError},
|
||||
{std::make_tuple(BackgroundErrorReason::kMemTable, false),
|
||||
Status::Severity::kFatalError},
|
||||
Status::Severity::kFatalError},
|
||||
};
|
||||
|
||||
void ErrorHandler::CancelErrorRecovery() {
|
||||
@@ -263,10 +247,6 @@ Status ErrorHandler::SetBGError(const IOStatus& bg_io_err,
|
||||
if (recovery_in_prog_ && recovery_error_.ok()) {
|
||||
recovery_error_ = bg_io_err;
|
||||
}
|
||||
if (BackgroundErrorReason::kManifestWrite == reason) {
|
||||
// Always returns ok
|
||||
db_->DisableFileDeletionsWithLock();
|
||||
}
|
||||
Status new_bg_io_err = bg_io_err;
|
||||
Status s;
|
||||
if (bg_io_err.GetDataLoss()) {
|
||||
|
||||
+3
-1
@@ -121,7 +121,9 @@ void EventHelpers::LogAndNotifyTableFileCreationFinished(
|
||||
<< table_properties.compression_options << "creation_time"
|
||||
<< table_properties.creation_time << "oldest_key_time"
|
||||
<< table_properties.oldest_key_time << "file_creation_time"
|
||||
<< table_properties.file_creation_time;
|
||||
<< table_properties.file_creation_time << "db_id"
|
||||
<< table_properties.db_id << "db_session_id"
|
||||
<< table_properties.db_session_id;
|
||||
|
||||
// user collected properties
|
||||
for (const auto& prop : table_properties.readable_properties) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "file/filename.h"
|
||||
#include "port/port.h"
|
||||
#include "port/stack_trace.h"
|
||||
#include "rocksdb/sst_file_reader.h"
|
||||
#include "rocksdb/sst_file_writer.h"
|
||||
#include "test_util/fault_injection_test_env.h"
|
||||
#include "test_util/testutil.h"
|
||||
@@ -2393,6 +2394,41 @@ TEST_F(ExternalSSTFileTest, IngestFileWrittenWithCompressionDictionary) {
|
||||
ASSERT_EQ(1, num_compression_dicts);
|
||||
}
|
||||
|
||||
// Very slow, not worth the cost to run regularly
|
||||
TEST_F(ExternalSSTFileTest, DISABLED_HugeBlockChecksum) {
|
||||
int max_checksum = static_cast<int>(kxxHash64);
|
||||
for (int i = 0; i <= max_checksum; ++i) {
|
||||
BlockBasedTableOptions table_options;
|
||||
table_options.checksum = static_cast<ChecksumType>(i);
|
||||
Options options = CurrentOptions();
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
|
||||
SstFileWriter sst_file_writer(EnvOptions(), options);
|
||||
|
||||
// 2^32 - 1, will lead to data block with more than 2^32 bytes
|
||||
size_t huge_size = port::kMaxUint32;
|
||||
|
||||
std::string f = sst_files_dir_ + "f.sst";
|
||||
ASSERT_OK(sst_file_writer.Open(f));
|
||||
{
|
||||
Random64 r(123);
|
||||
std::string huge(huge_size, 0);
|
||||
for (size_t j = 0; j + 7 < huge_size; j += 8) {
|
||||
EncodeFixed64(&huge[j], r.Next());
|
||||
}
|
||||
ASSERT_OK(sst_file_writer.Put("Huge", huge));
|
||||
}
|
||||
|
||||
ExternalSstFileInfo f_info;
|
||||
ASSERT_OK(sst_file_writer.Finish(&f_info));
|
||||
ASSERT_GT(f_info.file_size, uint64_t{huge_size} + 10);
|
||||
|
||||
SstFileReader sst_file_reader(options);
|
||||
ASSERT_OK(sst_file_reader.Open(f));
|
||||
ASSERT_OK(sst_file_reader.VerifyChecksum());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ExternalSSTFileTest, IngestFilesIntoMultipleColumnFamilies_Success) {
|
||||
std::unique_ptr<FaultInjectionTestEnv> fault_injection_env(
|
||||
new FaultInjectionTestEnv(env_));
|
||||
|
||||
+6
-2
@@ -97,8 +97,11 @@ FlushJob::FlushJob(const std::string& dbname, ColumnFamilyData* cfd,
|
||||
CompressionType output_compression, Statistics* stats,
|
||||
EventLogger* event_logger, bool measure_io_stats,
|
||||
const bool sync_output_directory, const bool write_manifest,
|
||||
Env::Priority thread_pri)
|
||||
Env::Priority thread_pri, const std::string& db_id,
|
||||
const std::string& db_session_id)
|
||||
: dbname_(dbname),
|
||||
db_id_(db_id),
|
||||
db_session_id_(db_session_id),
|
||||
cfd_(cfd),
|
||||
db_options_(db_options),
|
||||
mutable_cf_options_(mutable_cf_options),
|
||||
@@ -393,7 +396,8 @@ Status FlushJob::WriteLevel0Table() {
|
||||
mutable_cf_options_.paranoid_file_checks, cfd_->internal_stats(),
|
||||
TableFileCreationReason::kFlush, &io_s, event_logger_,
|
||||
job_context_->job_id, Env::IO_HIGH, &table_properties_, 0 /* level */,
|
||||
creation_time, oldest_key_time, write_hint, current_time);
|
||||
creation_time, oldest_key_time, write_hint, current_time, db_id_,
|
||||
db_session_id_);
|
||||
if (!io_s.ok()) {
|
||||
io_status_ = io_s;
|
||||
}
|
||||
|
||||
+4
-1
@@ -72,7 +72,8 @@ class FlushJob {
|
||||
CompressionType output_compression, Statistics* stats,
|
||||
EventLogger* event_logger, bool measure_io_stats,
|
||||
const bool sync_output_directory, const bool write_manifest,
|
||||
Env::Priority thread_pri);
|
||||
Env::Priority thread_pri, const std::string& db_id = "",
|
||||
const std::string& db_session_id = "");
|
||||
|
||||
~FlushJob();
|
||||
|
||||
@@ -103,6 +104,8 @@ class FlushJob {
|
||||
#endif // !ROCKSDB_LITE
|
||||
|
||||
const std::string& dbname_;
|
||||
const std::string db_id_;
|
||||
const std::string db_session_id_;
|
||||
ColumnFamilyData* cfd_;
|
||||
const ImmutableDBOptions& db_options_;
|
||||
const MutableCFOptions& mutable_cf_options_;
|
||||
|
||||
@@ -282,7 +282,6 @@ TEST_F(FlushJobTest, FlushMemTablesSingleColumnFamily) {
|
||||
assert(memtable_ids.size() == num_mems);
|
||||
uint64_t smallest_memtable_id = memtable_ids.front();
|
||||
uint64_t flush_memtable_id = smallest_memtable_id + num_mems_to_flush - 1;
|
||||
|
||||
FlushJob flush_job(dbname_, versions_->GetColumnFamilySet()->GetDefault(),
|
||||
db_options_, *cfd->GetLatestMutableCFOptions(),
|
||||
&flush_memtable_id, env_options_, versions_.get(), &mutex_,
|
||||
|
||||
@@ -798,7 +798,7 @@ bool InternalStats::HandleCurrentSuperVersionNumber(uint64_t* value,
|
||||
|
||||
bool InternalStats::HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
|
||||
Version* /*version*/) {
|
||||
*value = db->IsFileDeletionsEnabled() ? 1 : 0;
|
||||
*value = db->IsFileDeletionsEnabled();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-7
@@ -766,13 +766,7 @@ static bool SaveValue(void* arg, const char* entry) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
std::string msg("Unrecognized value type: " +
|
||||
std::to_string(static_cast<int>(type)) + ". ");
|
||||
msg.append("User key: " + user_key_slice.ToString(/*hex=*/true) + ". ");
|
||||
msg.append("seq: " + std::to_string(seq) + ".");
|
||||
*(s->status) = Status::Corruption(msg.c_str());
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -470,6 +470,7 @@ Status MemTableList::TryInstallMemtableFlushResults(
|
||||
}
|
||||
|
||||
// this can release and reacquire the mutex.
|
||||
vset->SetIOStatusOK();
|
||||
s = vset->LogAndApply(cfd, mutable_cf_options, edit_list, mu,
|
||||
db_directory);
|
||||
*io_s = vset->io_status();
|
||||
|
||||
+6
-1
@@ -183,6 +183,8 @@ class Repairer {
|
||||
}
|
||||
// Just create a DBImpl temporarily so we can reuse NewDB()
|
||||
DBImpl* db_impl = new DBImpl(db_options_, dbname_);
|
||||
// Also use this temp DBImpl to get a session id
|
||||
db_impl->GetDbSessionId(db_session_id_);
|
||||
status = db_impl->NewDB();
|
||||
delete db_impl;
|
||||
}
|
||||
@@ -229,6 +231,7 @@ class Repairer {
|
||||
};
|
||||
|
||||
std::string const dbname_;
|
||||
std::string db_session_id_;
|
||||
Env* const env_;
|
||||
const EnvOptions env_options_;
|
||||
const DBOptions db_options_;
|
||||
@@ -435,7 +438,9 @@ class Repairer {
|
||||
CompressionOptions(), false, nullptr /* internal_stats */,
|
||||
TableFileCreationReason::kRecovery, &io_s, nullptr /* event_logger */,
|
||||
0 /* job_id */, Env::IO_HIGH, nullptr /* table_properties */,
|
||||
-1 /* level */, current_time, write_hint);
|
||||
-1 /* level */, current_time, 0 /* oldest_key_time */, write_hint,
|
||||
0 /* file_creation_time */, "DB Repairer" /* db_id */,
|
||||
db_session_id_);
|
||||
ROCKS_LOG_INFO(db_options_.info_log,
|
||||
"Log #%" PRIu64 ": %d ops saved to Table #%" PRIu64 " %s",
|
||||
log, counter, meta.fd.GetNumber(),
|
||||
|
||||
+21
-28
@@ -3878,6 +3878,10 @@ Status VersionSet::ProcessManifestWrites(
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
||||
uint64_t new_manifest_file_size = 0;
|
||||
Status s;
|
||||
IOStatus io_s;
|
||||
|
||||
assert(pending_manifest_file_number_ == 0);
|
||||
if (!descriptor_log_ ||
|
||||
manifest_file_size_ > db_options_->max_manifest_file_size) {
|
||||
@@ -3907,9 +3911,6 @@ Status VersionSet::ProcessManifestWrites(
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t new_manifest_file_size = 0;
|
||||
Status s;
|
||||
IOStatus io_s;
|
||||
{
|
||||
FileOptions opt_file_opts = fs_->OptimizeForManifestWrite(file_options_);
|
||||
mu->Unlock();
|
||||
@@ -3946,9 +3947,9 @@ Status VersionSet::ProcessManifestWrites(
|
||||
std::string descriptor_fname =
|
||||
DescriptorFileName(dbname_, pending_manifest_file_number_);
|
||||
std::unique_ptr<FSWritableFile> descriptor_file;
|
||||
io_s = NewWritableFile(fs_, descriptor_fname, &descriptor_file,
|
||||
opt_file_opts);
|
||||
if (io_s.ok()) {
|
||||
s = NewWritableFile(fs_, descriptor_fname, &descriptor_file,
|
||||
opt_file_opts);
|
||||
if (s.ok()) {
|
||||
descriptor_file->SetPreallocationBlockSize(
|
||||
db_options_->manifest_preallocation_size);
|
||||
|
||||
@@ -3957,10 +3958,7 @@ Status VersionSet::ProcessManifestWrites(
|
||||
nullptr, db_options_->listeners));
|
||||
descriptor_log_.reset(
|
||||
new log::Writer(std::move(file_writer), 0, false));
|
||||
s = WriteCurrentStateToManifest(curr_state, descriptor_log_.get(),
|
||||
io_s);
|
||||
} else {
|
||||
s = io_s;
|
||||
s = WriteCurrentStateToManifest(curr_state, descriptor_log_.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3996,16 +3994,16 @@ Status VersionSet::ProcessManifestWrites(
|
||||
#endif /* !NDEBUG */
|
||||
io_s = descriptor_log_->AddRecord(record);
|
||||
if (!io_s.ok()) {
|
||||
io_status_ = io_s;
|
||||
s = io_s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (s.ok()) {
|
||||
io_s = SyncManifest(env_, db_options_, descriptor_log_->file());
|
||||
TEST_SYNC_POINT_CALLBACK(
|
||||
"VersionSet::ProcessManifestWrites:AfterSyncManifest", &io_s);
|
||||
}
|
||||
if (!io_s.ok()) {
|
||||
io_status_ = io_s;
|
||||
s = io_s;
|
||||
ROCKS_LOG_ERROR(db_options_->info_log, "MANIFEST write %s\n",
|
||||
s.ToString().c_str());
|
||||
@@ -4018,6 +4016,7 @@ Status VersionSet::ProcessManifestWrites(
|
||||
io_s = SetCurrentFile(fs_, dbname_, pending_manifest_file_number_,
|
||||
db_directory);
|
||||
if (!io_s.ok()) {
|
||||
io_status_ = io_s;
|
||||
s = io_s;
|
||||
}
|
||||
TEST_SYNC_POINT("VersionSet::ProcessManifestWrites:AfterNewManifest");
|
||||
@@ -4039,14 +4038,6 @@ Status VersionSet::ProcessManifestWrites(
|
||||
mu->Lock();
|
||||
}
|
||||
|
||||
if (!io_s.ok()) {
|
||||
if (io_status_.ok()) {
|
||||
io_status_ = io_s;
|
||||
}
|
||||
} else if (!io_status_.ok()) {
|
||||
io_status_ = io_s;
|
||||
}
|
||||
|
||||
// Append the old manifest file to the obsolete_manifest_ list to be deleted
|
||||
// by PurgeObsoleteFiles later.
|
||||
if (s.ok() && new_descriptor_log) {
|
||||
@@ -5300,7 +5291,7 @@ void VersionSet::MarkMinLogNumberToKeep2PC(uint64_t number) {
|
||||
|
||||
Status VersionSet::WriteCurrentStateToManifest(
|
||||
const std::unordered_map<uint32_t, MutableCFState>& curr_state,
|
||||
log::Writer* log, IOStatus& io_s) {
|
||||
log::Writer* log) {
|
||||
// TODO: Break up into multiple records to reduce memory usage on recovery?
|
||||
|
||||
// WARNING: This method doesn't hold a mutex!!
|
||||
@@ -5309,7 +5300,6 @@ Status VersionSet::WriteCurrentStateToManifest(
|
||||
// LogAndApply. Column family manipulations can only happen within LogAndApply
|
||||
// (the same single thread), so we're safe to iterate.
|
||||
|
||||
assert(io_s.ok());
|
||||
if (db_options_->write_dbid_to_manifest) {
|
||||
VersionEdit edit_for_db_id;
|
||||
assert(!db_id_.empty());
|
||||
@@ -5319,9 +5309,10 @@ Status VersionSet::WriteCurrentStateToManifest(
|
||||
return Status::Corruption("Unable to Encode VersionEdit:" +
|
||||
edit_for_db_id.DebugString(true));
|
||||
}
|
||||
io_s = log->AddRecord(db_id_record);
|
||||
IOStatus io_s = log->AddRecord(db_id_record);
|
||||
if (!io_s.ok()) {
|
||||
return io_s;
|
||||
io_status_ = io_s;
|
||||
return std::move(io_s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5348,9 +5339,10 @@ Status VersionSet::WriteCurrentStateToManifest(
|
||||
return Status::Corruption(
|
||||
"Unable to Encode VersionEdit:" + edit.DebugString(true));
|
||||
}
|
||||
io_s = log->AddRecord(record);
|
||||
IOStatus io_s = log->AddRecord(record);
|
||||
if (!io_s.ok()) {
|
||||
return io_s;
|
||||
io_status_ = io_s;
|
||||
return std::move(io_s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5400,9 +5392,10 @@ Status VersionSet::WriteCurrentStateToManifest(
|
||||
return Status::Corruption(
|
||||
"Unable to Encode VersionEdit:" + edit.DebugString(true));
|
||||
}
|
||||
io_s = log->AddRecord(record);
|
||||
IOStatus io_s = log->AddRecord(record);
|
||||
if (!io_s.ok()) {
|
||||
return io_s;
|
||||
io_status_ = io_s;
|
||||
return std::move(io_s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -1159,7 +1159,10 @@ class VersionSet {
|
||||
static uint64_t GetTotalSstFilesSize(Version* dummy_versions);
|
||||
|
||||
// Get the IO Status returned by written Manifest.
|
||||
const IOStatus& io_status() const { return io_status_; }
|
||||
IOStatus io_status() const { return io_status_; }
|
||||
|
||||
// Set the IO Status to OK. Called before Manifest write if needed.
|
||||
void SetIOStatusOK() { io_status_ = IOStatus::OK(); }
|
||||
|
||||
protected:
|
||||
using VersionBuilderMap =
|
||||
@@ -1202,7 +1205,7 @@ class VersionSet {
|
||||
// Save current contents to *log
|
||||
Status WriteCurrentStateToManifest(
|
||||
const std::unordered_map<uint32_t, MutableCFState>& curr_state,
|
||||
log::Writer* log, IOStatus& io_s);
|
||||
log::Writer* log);
|
||||
|
||||
void AppendVersion(ColumnFamilyData* column_family_data, Version* v);
|
||||
|
||||
|
||||
@@ -146,6 +146,7 @@ DECLARE_int32(reopen);
|
||||
DECLARE_double(bloom_bits);
|
||||
DECLARE_bool(use_block_based_filter);
|
||||
DECLARE_bool(partition_filters);
|
||||
DECLARE_bool(optimize_filters_for_memory);
|
||||
DECLARE_int32(index_type);
|
||||
DECLARE_string(db);
|
||||
DECLARE_string(secondaries_base);
|
||||
@@ -161,7 +162,7 @@ DECLARE_bool(statistics);
|
||||
DECLARE_bool(sync);
|
||||
DECLARE_bool(use_fsync);
|
||||
DECLARE_int32(kill_random_test);
|
||||
DECLARE_string(kill_prefix_blacklist);
|
||||
DECLARE_string(kill_exclude_prefixes);
|
||||
DECLARE_bool(disable_wal);
|
||||
DECLARE_uint64(recycle_log_file_num);
|
||||
DECLARE_int64(target_file_size_base);
|
||||
@@ -236,6 +237,10 @@ DECLARE_double(blob_db_gc_cutoff);
|
||||
DECLARE_int32(approximate_size_one_in);
|
||||
DECLARE_bool(sync_fault_injection);
|
||||
|
||||
DECLARE_bool(best_efforts_recovery);
|
||||
DECLARE_bool(skip_verifydb);
|
||||
DECLARE_bool(enable_compaction_filter);
|
||||
|
||||
const long KB = 1024;
|
||||
const int kRandomValueMaxFactor = 3;
|
||||
const int kValueMaxLen = 100;
|
||||
@@ -436,19 +441,10 @@ extern inline bool GetIntVal(std::string big_endian_key, uint64_t* key_p) {
|
||||
|
||||
assert(size_key <= key_gen_ctx.weights.size() * sizeof(uint64_t));
|
||||
|
||||
// Pad with zeros to make it a multiple of 8. This function may be called
|
||||
// with a prefix, in which case we return the first index that falls
|
||||
// inside or outside that prefix, dependeing on whether the prefix is
|
||||
// the start of upper bound of a scan
|
||||
unsigned int pad = sizeof(uint64_t) - (size_key % sizeof(uint64_t));
|
||||
if (pad < sizeof(uint64_t)) {
|
||||
big_endian_key.append(pad, '\0');
|
||||
size_key += pad;
|
||||
}
|
||||
|
||||
std::string little_endian_key;
|
||||
little_endian_key.resize(size_key);
|
||||
for (size_t start = 0; start < size_key; start += sizeof(uint64_t)) {
|
||||
for (size_t start = 0; start + sizeof(uint64_t) <= size_key;
|
||||
start += sizeof(uint64_t)) {
|
||||
size_t end = start + sizeof(uint64_t);
|
||||
for (size_t i = 0; i < sizeof(uint64_t); ++i) {
|
||||
little_endian_key[start + i] = big_endian_key[end - 1 - i];
|
||||
@@ -467,17 +463,40 @@ extern inline bool GetIntVal(std::string big_endian_key, uint64_t* key_p) {
|
||||
uint64_t pfx = prefixes[i];
|
||||
key += (pfx / key_gen_ctx.weights[i]) * key_gen_ctx.window +
|
||||
pfx % key_gen_ctx.weights[i];
|
||||
if (i < prefixes.size() - 1) {
|
||||
// The encoding writes a `key_gen_ctx.weights[i] - 1` that counts for
|
||||
// `key_gen_ctx.weights[i]` when there are more prefixes to come. So we
|
||||
// need to add back the one here as we're at a non-last prefix.
|
||||
++key;
|
||||
}
|
||||
}
|
||||
*key_p = key;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Given a string prefix, map it to the first corresponding index in the
|
||||
// expected values buffer.
|
||||
inline bool GetFirstIntValInPrefix(std::string big_endian_prefix,
|
||||
uint64_t* key_p) {
|
||||
size_t size_key = big_endian_prefix.size();
|
||||
// Pad with zeros to make it a multiple of 8. This function may be called
|
||||
// with a prefix, in which case we return the first index that falls
|
||||
// inside or outside that prefix, dependeing on whether the prefix is
|
||||
// the start of upper bound of a scan
|
||||
unsigned int pad = sizeof(uint64_t) - (size_key % sizeof(uint64_t));
|
||||
if (pad < sizeof(uint64_t)) {
|
||||
big_endian_prefix.append(pad, '\0');
|
||||
}
|
||||
return GetIntVal(std::move(big_endian_prefix), key_p);
|
||||
}
|
||||
|
||||
extern inline uint64_t GetPrefixKeyCount(const std::string& prefix,
|
||||
const std::string& ub) {
|
||||
uint64_t start = 0;
|
||||
uint64_t end = 0;
|
||||
|
||||
if (!GetIntVal(prefix, &start) || !GetIntVal(ub, &end)) {
|
||||
if (!GetFirstIntValInPrefix(prefix, &start) ||
|
||||
!GetFirstIntValInPrefix(ub, &end)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under both the GPLv2 (found in the
|
||||
// COPYING file in the root directory) and Apache 2.0 License
|
||||
// (found in the LICENSE.Apache file in the root directory).
|
||||
//
|
||||
// Copyright (c) 2011 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rocksdb/compaction_filter.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
// DbStressCompactionFilter is safe to use with db_stress as it does not perform
|
||||
// any mutation. It only makes `kRemove` decisions for keys that are already
|
||||
// non-existent according to the `SharedState`.
|
||||
class DbStressCompactionFilter : public CompactionFilter {
|
||||
public:
|
||||
DbStressCompactionFilter(SharedState* state, int cf_id)
|
||||
: state_(state), cf_id_(cf_id) {}
|
||||
|
||||
Decision FilterV2(int /*level*/, const Slice& key, ValueType /*value_type*/,
|
||||
const Slice& /*existing_value*/, std::string* /*new_value*/,
|
||||
std::string* /*skip_until*/) const override {
|
||||
if (state_ == nullptr) {
|
||||
return Decision::kKeep;
|
||||
}
|
||||
if (key.empty() || ('0' <= key[0] && key[0] <= '9')) {
|
||||
// It is likely leftover from a test_batches_snapshots run. Below this
|
||||
// conditional, the test_batches_snapshots key format is not handled
|
||||
// properly. Just keep it to be safe.
|
||||
return Decision::kKeep;
|
||||
}
|
||||
uint64_t key_num = 0;
|
||||
bool ok = GetIntVal(key.ToString(), &key_num);
|
||||
assert(ok);
|
||||
(void)ok;
|
||||
MutexLock key_lock(state_->GetMutexForKey(cf_id_, key_num));
|
||||
if (!state_->Exists(cf_id_, key_num)) {
|
||||
return Decision::kRemove;
|
||||
}
|
||||
return Decision::kKeep;
|
||||
}
|
||||
|
||||
const char* Name() const override { return "DbStressCompactionFilter"; }
|
||||
|
||||
private:
|
||||
SharedState* const state_;
|
||||
const int cf_id_;
|
||||
};
|
||||
|
||||
class DbStressCompactionFilterFactory : public CompactionFilterFactory {
|
||||
public:
|
||||
DbStressCompactionFilterFactory() : state_(nullptr) {}
|
||||
|
||||
void SetSharedState(SharedState* state) {
|
||||
MutexLock state_mutex_guard(&state_mutex_);
|
||||
state_ = state;
|
||||
}
|
||||
|
||||
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
|
||||
const CompactionFilter::Context& context) override {
|
||||
MutexLock state_mutex_guard(&state_mutex_);
|
||||
return std::unique_ptr<CompactionFilter>(
|
||||
new DbStressCompactionFilter(state_, context.column_family_id));
|
||||
}
|
||||
|
||||
const char* Name() const override {
|
||||
return "DbStressCompactionFilterFactory";
|
||||
}
|
||||
|
||||
private:
|
||||
port::Mutex state_mutex_;
|
||||
SharedState* state_;
|
||||
};
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
@@ -16,7 +16,7 @@ void ThreadBody(void* v) {
|
||||
ThreadState* thread = reinterpret_cast<ThreadState*>(v);
|
||||
SharedState* shared = thread->shared;
|
||||
|
||||
if (shared->ShouldVerifyAtBeginning()) {
|
||||
if (!FLAGS_skip_verifydb && shared->ShouldVerifyAtBeginning()) {
|
||||
thread->shared->GetStressTest()->VerifyDb(thread);
|
||||
}
|
||||
{
|
||||
@@ -42,7 +42,9 @@ void ThreadBody(void* v) {
|
||||
}
|
||||
}
|
||||
|
||||
thread->shared->GetStressTest()->VerifyDb(thread);
|
||||
if (!FLAGS_skip_verifydb) {
|
||||
thread->shared->GetStressTest()->VerifyDb(thread);
|
||||
}
|
||||
|
||||
{
|
||||
MutexLock l(shared->GetMutex());
|
||||
@@ -55,11 +57,8 @@ void ThreadBody(void* v) {
|
||||
|
||||
bool RunStressTest(StressTest* stress) {
|
||||
stress->InitDb();
|
||||
|
||||
SharedState shared(db_stress_env, stress);
|
||||
if (FLAGS_read_only) {
|
||||
stress->InitReadonlyDb(&shared);
|
||||
}
|
||||
stress->FinishInitDb(&shared);
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (FLAGS_sync_fault_injection) {
|
||||
@@ -118,6 +117,9 @@ bool RunStressTest(StressTest* stress) {
|
||||
if (FLAGS_test_batches_snapshots) {
|
||||
fprintf(stdout, "%s Limited verification already done during gets\n",
|
||||
db_stress_env->TimeToString((uint64_t)now / 1000000).c_str());
|
||||
} else if (FLAGS_skip_verifydb) {
|
||||
fprintf(stdout, "%s Verification skipped\n",
|
||||
db_stress_env->TimeToString((uint64_t)now / 1000000).c_str());
|
||||
} else {
|
||||
fprintf(stdout, "%s Starting verification\n",
|
||||
db_stress_env->TimeToString((uint64_t)now / 1000000).c_str());
|
||||
@@ -140,7 +142,8 @@ bool RunStressTest(StressTest* stress) {
|
||||
threads[i] = nullptr;
|
||||
}
|
||||
now = db_stress_env->NowMicros();
|
||||
if (!FLAGS_test_batches_snapshots && !shared.HasVerificationFailedYet()) {
|
||||
if (!FLAGS_skip_verifydb && !FLAGS_test_batches_snapshots &&
|
||||
!shared.HasVerificationFailedYet()) {
|
||||
fprintf(stdout, "%s Verification successful\n",
|
||||
db_stress_env->TimeToString(now / 1000000).c_str());
|
||||
}
|
||||
|
||||
@@ -361,6 +361,11 @@ DEFINE_bool(partition_filters, false,
|
||||
"use partitioned filters "
|
||||
"for block-based table");
|
||||
|
||||
DEFINE_bool(
|
||||
optimize_filters_for_memory,
|
||||
ROCKSDB_NAMESPACE::BlockBasedTableOptions().optimize_filters_for_memory,
|
||||
"Minimize memory footprint of filters");
|
||||
|
||||
DEFINE_int32(
|
||||
index_type,
|
||||
static_cast<int32_t>(
|
||||
@@ -414,10 +419,10 @@ static const bool FLAGS_kill_random_test_dummy __attribute__((__unused__)) =
|
||||
RegisterFlagValidator(&FLAGS_kill_random_test, &ValidateInt32Positive);
|
||||
extern int rocksdb_kill_odds;
|
||||
|
||||
DEFINE_string(kill_prefix_blacklist, "",
|
||||
DEFINE_string(kill_exclude_prefixes, "",
|
||||
"If non-empty, kill points with prefix in the list given will be"
|
||||
" skipped. Items are comma-separated.");
|
||||
extern std::vector<std::string> rocksdb_kill_prefix_blacklist;
|
||||
extern std::vector<std::string> rocksdb_kill_exclude_prefixes;
|
||||
|
||||
DEFINE_bool(disable_wal, false, "If true, do not write WAL for write.");
|
||||
|
||||
@@ -691,4 +696,13 @@ DEFINE_int32(read_fault_one_in, 1000,
|
||||
DEFINE_bool(sync_fault_injection, false,
|
||||
"If true, FaultInjectionTestFS will be used for write operations, "
|
||||
" and unsynced data in DB will lost after crash.");
|
||||
|
||||
DEFINE_bool(best_efforts_recovery, false,
|
||||
"If true, use best efforts recovery.");
|
||||
DEFINE_bool(skip_verifydb, false, "If true, skip VerifyDb() calls.");
|
||||
|
||||
DEFINE_bool(enable_compaction_filter, false,
|
||||
"If true, configures a compaction filter that returns a kRemove "
|
||||
"decision for deleted keys.");
|
||||
|
||||
#endif // GFLAGS
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#ifdef GFLAGS
|
||||
#include "db_stress_tool/db_stress_common.h"
|
||||
#include "db_stress_tool/db_stress_compaction_filter.h"
|
||||
#include "db_stress_tool/db_stress_driver.h"
|
||||
#include "rocksdb/convenience.h"
|
||||
#include "rocksdb/sst_file_manager.h"
|
||||
@@ -195,11 +196,18 @@ void StressTest::InitDb() {
|
||||
BuildOptionsTable();
|
||||
}
|
||||
|
||||
void StressTest::InitReadonlyDb(SharedState* shared) {
|
||||
uint64_t now = db_stress_env->NowMicros();
|
||||
fprintf(stdout, "%s Preloading db with %" PRIu64 " KVs\n",
|
||||
db_stress_env->TimeToString(now / 1000000).c_str(), FLAGS_max_key);
|
||||
PreloadDbAndReopenAsReadOnly(FLAGS_max_key, shared);
|
||||
void StressTest::FinishInitDb(SharedState* shared) {
|
||||
if (FLAGS_read_only) {
|
||||
uint64_t now = db_stress_env->NowMicros();
|
||||
fprintf(stdout, "%s Preloading db with %" PRIu64 " KVs\n",
|
||||
db_stress_env->TimeToString(now / 1000000).c_str(), FLAGS_max_key);
|
||||
PreloadDbAndReopenAsReadOnly(FLAGS_max_key, shared);
|
||||
}
|
||||
if (FLAGS_enable_compaction_filter) {
|
||||
reinterpret_cast<DbStressCompactionFilterFactory*>(
|
||||
options_.compaction_filter_factory.get())
|
||||
->SetSharedState(shared);
|
||||
}
|
||||
}
|
||||
|
||||
bool StressTest::VerifySecondaries() {
|
||||
@@ -1709,9 +1717,9 @@ void StressTest::PrintEnv() const {
|
||||
fprintf(stdout, "Memtablerep : %s\n", memtablerep);
|
||||
|
||||
fprintf(stdout, "Test kill odd : %d\n", rocksdb_kill_odds);
|
||||
if (!rocksdb_kill_prefix_blacklist.empty()) {
|
||||
if (!rocksdb_kill_exclude_prefixes.empty()) {
|
||||
fprintf(stdout, "Skipping kill points prefixes:\n");
|
||||
for (auto& p : rocksdb_kill_prefix_blacklist) {
|
||||
for (auto& p : rocksdb_kill_exclude_prefixes) {
|
||||
fprintf(stdout, " %s\n", p.c_str());
|
||||
}
|
||||
}
|
||||
@@ -1729,6 +1737,8 @@ void StressTest::PrintEnv() const {
|
||||
static_cast<int>(FLAGS_level_compaction_dynamic_level_bytes));
|
||||
fprintf(stdout, "Read fault one in : %d\n", FLAGS_read_fault_one_in);
|
||||
fprintf(stdout, "Sync fault injection : %d\n", FLAGS_sync_fault_injection);
|
||||
fprintf(stdout, "Best efforts recovery : %d\n",
|
||||
static_cast<int>(FLAGS_best_efforts_recovery));
|
||||
|
||||
fprintf(stdout, "------------------------------------------------\n");
|
||||
}
|
||||
@@ -1752,6 +1762,8 @@ void StressTest::Open() {
|
||||
static_cast<int32_t>(FLAGS_index_block_restart_interval);
|
||||
block_based_options.filter_policy = filter_policy_;
|
||||
block_based_options.partition_filters = FLAGS_partition_filters;
|
||||
block_based_options.optimize_filters_for_memory =
|
||||
FLAGS_optimize_filters_for_memory;
|
||||
block_based_options.index_type =
|
||||
static_cast<BlockBasedTableOptions::IndexType>(FLAGS_index_type);
|
||||
options_.table_factory.reset(
|
||||
@@ -1912,6 +1924,12 @@ void StressTest::Open() {
|
||||
} else {
|
||||
options_.merge_operator = MergeOperators::CreatePutOperator();
|
||||
}
|
||||
if (FLAGS_enable_compaction_filter) {
|
||||
options_.compaction_filter_factory =
|
||||
std::make_shared<DbStressCompactionFilterFactory>();
|
||||
}
|
||||
|
||||
options_.best_efforts_recovery = FLAGS_best_efforts_recovery;
|
||||
|
||||
fprintf(stdout, "DB path: [%s]\n", FLAGS_db.c_str());
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ class StressTest {
|
||||
bool BuildOptionsTable();
|
||||
|
||||
void InitDb();
|
||||
void InitReadonlyDb(SharedState*);
|
||||
// The initialization work is split into two parts to avoid a circular
|
||||
// dependency with `SharedState`.
|
||||
void FinishInitDb(SharedState*);
|
||||
|
||||
// Return false if verification fails.
|
||||
bool VerifySecondaries();
|
||||
|
||||
@@ -216,9 +216,39 @@ int db_stress_tool(int argc, char** argv) {
|
||||
"Must set -test_secondary=true if secondary_catch_up_one_in > 0.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (FLAGS_best_efforts_recovery && !FLAGS_skip_verifydb &&
|
||||
!FLAGS_disable_wal) {
|
||||
fprintf(stderr,
|
||||
"With best-efforts recovery, either skip_verifydb or disable_wal "
|
||||
"should be set to true.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (FLAGS_skip_verifydb) {
|
||||
if (FLAGS_verify_db_one_in > 0) {
|
||||
fprintf(stderr,
|
||||
"Must set -verify_db_one_in=0 if skip_verifydb is true.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (FLAGS_continuous_verification_interval > 0) {
|
||||
fprintf(stderr,
|
||||
"Must set -continuous_verification_interval=0 if skip_verifydb "
|
||||
"is true.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (FLAGS_enable_compaction_filter &&
|
||||
(FLAGS_acquire_snapshot_one_in > 0 || FLAGS_compact_range_one_in > 0 ||
|
||||
FLAGS_iterpercent > 0 || FLAGS_test_batches_snapshots ||
|
||||
FLAGS_test_cf_consistency)) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Error: acquire_snapshot_one_in, compact_range_one_in, iterpercent, "
|
||||
"test_batches_snapshots must all be 0 when using compaction filter\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rocksdb_kill_odds = FLAGS_kill_random_test;
|
||||
rocksdb_kill_prefix_blacklist = SplitString(FLAGS_kill_prefix_blacklist);
|
||||
rocksdb_kill_exclude_prefixes = SplitString(FLAGS_kill_exclude_prefixes);
|
||||
|
||||
unsigned int levels = FLAGS_max_key_len;
|
||||
std::vector<std::string> weights;
|
||||
|
||||
Vendored
+6
-2
@@ -555,14 +555,18 @@ class CompositeEnvWrapper : public Env {
|
||||
return env_target_->IncBackgroundThreadsIfNeeded(num, pri);
|
||||
}
|
||||
|
||||
void LowerThreadPoolIOPriority(Priority pool = LOW) override {
|
||||
void LowerThreadPoolIOPriority(Priority pool) override {
|
||||
env_target_->LowerThreadPoolIOPriority(pool);
|
||||
}
|
||||
|
||||
void LowerThreadPoolCPUPriority(Priority pool = LOW) override {
|
||||
void LowerThreadPoolCPUPriority(Priority pool) override {
|
||||
env_target_->LowerThreadPoolCPUPriority(pool);
|
||||
}
|
||||
|
||||
Status LowerThreadPoolCPUPriority(Priority pool, CpuPriority pri) override {
|
||||
return env_target_->LowerThreadPoolCPUPriority(pool, pri);
|
||||
}
|
||||
|
||||
std::string TimeToString(uint64_t time) override {
|
||||
return env_target_->TimeToString(time);
|
||||
}
|
||||
|
||||
Vendored
+20
-1
@@ -4,13 +4,14 @@
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "env/mock_env.h"
|
||||
#include "rocksdb/env.h"
|
||||
#include "rocksdb/env_encryption.h"
|
||||
#include "test_util/testharness.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
@@ -89,6 +90,24 @@ INSTANTIATE_TEST_CASE_P(EnvDefault, EnvMoreTestWithParam,
|
||||
static std::unique_ptr<Env> mock_env(new MockEnv(Env::Default()));
|
||||
INSTANTIATE_TEST_CASE_P(MockEnv, EnvBasicTestWithParam,
|
||||
::testing::Values(mock_env.get()));
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
// next statements run env test against default encryption code.
|
||||
static ROT13BlockCipher encrypt_block_rot13(32);
|
||||
|
||||
static CTREncryptionProvider encrypt_provider_ctr(encrypt_block_rot13);
|
||||
|
||||
static std::unique_ptr<Env> ecpt_env(NewEncryptedEnv(Env::Default(),
|
||||
&encrypt_provider_ctr));
|
||||
|
||||
static std::unique_ptr<Env> encrypt_env(
|
||||
new NormalizingEnvWrapper(ecpt_env.get()));
|
||||
INSTANTIATE_TEST_CASE_P(EncryptedEnv, EnvBasicTestWithParam,
|
||||
::testing::Values(encrypt_env.get()));
|
||||
INSTANTIATE_TEST_CASE_P(EncryptedEnv, EnvMoreTestWithParam,
|
||||
::testing::Values(encrypt_env.get()));
|
||||
#endif // ROCKSDB_LITE
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
static std::unique_ptr<Env> mem_env(NewMemEnv(Env::Default()));
|
||||
INSTANTIATE_TEST_CASE_P(MemEnv, EnvBasicTestWithParam,
|
||||
|
||||
Vendored
+272
-281
@@ -23,19 +23,6 @@ namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
|
||||
class EncryptedSequentialFile : public SequentialFile {
|
||||
private:
|
||||
std::unique_ptr<SequentialFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
uint64_t offset_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
// Default ctor. Given underlying sequential file is supposed to be at
|
||||
// offset == prefixLength.
|
||||
EncryptedSequentialFile(SequentialFile* f, BlockAccessCipherStream* s, size_t prefixLength)
|
||||
: file_(f), stream_(s), offset_(prefixLength), prefixLength_(prefixLength) {
|
||||
}
|
||||
|
||||
// Read up to "n" bytes from the file. "scratch[0..n-1]" may be
|
||||
// written by this routine. Sets "*result" to the data that was
|
||||
@@ -45,83 +32,73 @@ class EncryptedSequentialFile : public SequentialFile {
|
||||
// If an error was encountered, returns a non-OK status.
|
||||
//
|
||||
// REQUIRES: External synchronization
|
||||
Status Read(size_t n, Slice* result, char* scratch) override {
|
||||
assert(scratch);
|
||||
Status status = file_->Read(n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset_, (char*)result->data(), result->size());
|
||||
}
|
||||
offset_ += result->size(); // We've already ready data from disk, so update
|
||||
// offset_ even if decryption fails.
|
||||
Status EncryptedSequentialFile::Read(size_t n, Slice* result, char* scratch) {
|
||||
assert(scratch);
|
||||
Status status = file_->Read(n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset_, (char*)result->data(), result->size());
|
||||
}
|
||||
offset_ += result->size(); // We've already ready data from disk, so update
|
||||
// offset_ even if decryption fails.
|
||||
return status;
|
||||
}
|
||||
|
||||
// Skip "n" bytes from the file. This is guaranteed to be no
|
||||
// slower that reading the same data, but may be faster.
|
||||
//
|
||||
// If end of file is reached, skipping will stop at the end of the
|
||||
// file, and Skip will return OK.
|
||||
//
|
||||
// REQUIRES: External synchronization
|
||||
Status Skip(uint64_t n) override {
|
||||
auto status = file_->Skip(n);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
offset_ += n;
|
||||
// Skip "n" bytes from the file. This is guaranteed to be no
|
||||
// slower that reading the same data, but may be faster.
|
||||
//
|
||||
// If end of file is reached, skipping will stop at the end of the
|
||||
// file, and Skip will return OK.
|
||||
//
|
||||
// REQUIRES: External synchronization
|
||||
Status EncryptedSequentialFile::Skip(uint64_t n) {
|
||||
auto status = file_->Skip(n);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
offset_ += n;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Indicates the upper layers if the current SequentialFile implementation
|
||||
// uses direct IO.
|
||||
bool use_direct_io() const override { return file_->use_direct_io(); }
|
||||
// Indicates the upper layers if the current SequentialFile implementation
|
||||
// uses direct IO.
|
||||
bool EncryptedSequentialFile::use_direct_io() const {
|
||||
return file_->use_direct_io();
|
||||
}
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
size_t GetRequiredBufferAlignment() const override {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
size_t EncryptedSequentialFile::GetRequiredBufferAlignment() const {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
|
||||
// Remove any kind of caching of data from the offset to offset+length
|
||||
// of this file. If the length is 0, then it refers to the end of file.
|
||||
// If the system is not caching the file contents, then this is a noop.
|
||||
Status InvalidateCache(size_t offset, size_t length) override {
|
||||
return file_->InvalidateCache(offset + prefixLength_, length);
|
||||
}
|
||||
Status EncryptedSequentialFile::InvalidateCache(size_t offset, size_t length) {
|
||||
return file_->InvalidateCache(offset + prefixLength_, length);
|
||||
}
|
||||
|
||||
// Positioned Read for direct I/O
|
||||
// If Direct I/O enabled, offset, n, and scratch should be properly aligned
|
||||
Status PositionedRead(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) override {
|
||||
assert(scratch);
|
||||
offset += prefixLength_; // Skip prefix
|
||||
auto status = file_->PositionedRead(offset, n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
offset_ = offset + result->size();
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset, (char*)result->data(), result->size());
|
||||
}
|
||||
Status EncryptedSequentialFile::PositionedRead(uint64_t offset, size_t n,
|
||||
Slice* result, char* scratch) {
|
||||
assert(scratch);
|
||||
offset += prefixLength_; // Skip prefix
|
||||
auto status = file_->PositionedRead(offset, n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
};
|
||||
|
||||
// A file abstraction for randomly reading the contents of a file.
|
||||
class EncryptedRandomAccessFile : public RandomAccessFile {
|
||||
private:
|
||||
std::unique_ptr<RandomAccessFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
EncryptedRandomAccessFile(RandomAccessFile* f, BlockAccessCipherStream* s, size_t prefixLength)
|
||||
: file_(f), stream_(s), prefixLength_(prefixLength) { }
|
||||
offset_ = offset + result->size();
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset, (char*)result->data(), result->size());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Read up to "n" bytes from the file starting at "offset".
|
||||
// "scratch[0..n-1]" may be written by this routine. Sets "*result"
|
||||
@@ -133,26 +110,26 @@ class EncryptedRandomAccessFile : public RandomAccessFile {
|
||||
//
|
||||
// Safe for concurrent use by multiple threads.
|
||||
// If Direct I/O enabled, offset, n, and scratch should be aligned properly.
|
||||
Status Read(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) const override {
|
||||
assert(scratch);
|
||||
offset += prefixLength_;
|
||||
auto status = file_->Read(offset, n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset, (char*)result->data(), result->size());
|
||||
}
|
||||
Status EncryptedRandomAccessFile::Read(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) const {
|
||||
assert(scratch);
|
||||
offset += prefixLength_;
|
||||
auto status = file_->Read(offset, n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset, (char*)result->data(), result->size());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Readahead the file starting from offset by n bytes for caching.
|
||||
Status Prefetch(uint64_t offset, size_t n) override {
|
||||
//return Status::OK();
|
||||
return file_->Prefetch(offset + prefixLength_, n);
|
||||
}
|
||||
Status EncryptedRandomAccessFile::Prefetch(uint64_t offset, size_t n) {
|
||||
// return Status::OK();
|
||||
return file_->Prefetch(offset + prefixLength_, n);
|
||||
}
|
||||
|
||||
// Tries to get an unique ID for this file that will be the same each time
|
||||
// the file is opened (and will stay the same while the file is open).
|
||||
@@ -169,132 +146,128 @@ class EncryptedRandomAccessFile : public RandomAccessFile {
|
||||
// a single varint.
|
||||
//
|
||||
// Note: these IDs are only valid for the duration of the process.
|
||||
size_t GetUniqueId(char* id, size_t max_size) const override {
|
||||
return file_->GetUniqueId(id, max_size);
|
||||
};
|
||||
size_t EncryptedRandomAccessFile::GetUniqueId(char* id, size_t max_size) const {
|
||||
return file_->GetUniqueId(id, max_size);
|
||||
};
|
||||
|
||||
void Hint(AccessPattern pattern) override { file_->Hint(pattern); }
|
||||
void EncryptedRandomAccessFile::Hint(AccessPattern pattern) {
|
||||
file_->Hint(pattern);
|
||||
}
|
||||
|
||||
// Indicates the upper layers if the current RandomAccessFile implementation
|
||||
// uses direct IO.
|
||||
bool use_direct_io() const override { return file_->use_direct_io(); }
|
||||
bool EncryptedRandomAccessFile::use_direct_io() const {
|
||||
return file_->use_direct_io();
|
||||
}
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
size_t GetRequiredBufferAlignment() const override {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
size_t EncryptedRandomAccessFile::GetRequiredBufferAlignment() const {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
|
||||
// Remove any kind of caching of data from the offset to offset+length
|
||||
// of this file. If the length is 0, then it refers to the end of file.
|
||||
// If the system is not caching the file contents, then this is a noop.
|
||||
Status InvalidateCache(size_t offset, size_t length) override {
|
||||
return file_->InvalidateCache(offset + prefixLength_, length);
|
||||
}
|
||||
};
|
||||
Status EncryptedRandomAccessFile::InvalidateCache(size_t offset,
|
||||
size_t length) {
|
||||
return file_->InvalidateCache(offset + prefixLength_, length);
|
||||
}
|
||||
|
||||
// A file abstraction for sequential writing. The implementation
|
||||
// must provide buffering since callers may append small fragments
|
||||
// at a time to the file.
|
||||
class EncryptedWritableFile : public WritableFileWrapper {
|
||||
private:
|
||||
std::unique_ptr<WritableFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
// Default ctor. Prefix is assumed to be written already.
|
||||
EncryptedWritableFile(WritableFile* f, BlockAccessCipherStream* s, size_t prefixLength)
|
||||
: WritableFileWrapper(f), file_(f), stream_(s), prefixLength_(prefixLength) { }
|
||||
|
||||
Status Append(const Slice& data) override {
|
||||
AlignedBuffer buf;
|
||||
Status status;
|
||||
Slice dataToAppend(data);
|
||||
if (data.size() > 0) {
|
||||
auto offset = file_->GetFileSize(); // size including prefix
|
||||
// Encrypt in cloned buffer
|
||||
buf.Alignment(GetRequiredBufferAlignment());
|
||||
buf.AllocateNewBuffer(data.size());
|
||||
// TODO (sagar0): Modify AlignedBuffer.Append to allow doing a memmove
|
||||
// so that the next two lines can be replaced with buf.Append().
|
||||
memmove(buf.BufferStart(), data.data(), data.size());
|
||||
buf.Size(data.size());
|
||||
{
|
||||
PERF_TIMER_GUARD(encrypt_data_nanos);
|
||||
status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
dataToAppend = Slice(buf.BufferStart(), buf.CurrentSize());
|
||||
Status EncryptedWritableFile::Append(const Slice& data) {
|
||||
AlignedBuffer buf;
|
||||
Status status;
|
||||
Slice dataToAppend(data);
|
||||
if (data.size() > 0) {
|
||||
auto offset = file_->GetFileSize(); // size including prefix
|
||||
// Encrypt in cloned buffer
|
||||
buf.Alignment(GetRequiredBufferAlignment());
|
||||
buf.AllocateNewBuffer(data.size());
|
||||
// TODO (sagar0): Modify AlignedBuffer.Append to allow doing a memmove
|
||||
// so that the next two lines can be replaced with buf.Append().
|
||||
memmove(buf.BufferStart(), data.data(), data.size());
|
||||
buf.Size(data.size());
|
||||
{
|
||||
PERF_TIMER_GUARD(encrypt_data_nanos);
|
||||
status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
status = file_->Append(dataToAppend);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
dataToAppend = Slice(buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
status = file_->Append(dataToAppend);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Status PositionedAppend(const Slice& data, uint64_t offset) override {
|
||||
AlignedBuffer buf;
|
||||
Status status;
|
||||
Slice dataToAppend(data);
|
||||
offset += prefixLength_;
|
||||
if (data.size() > 0) {
|
||||
// Encrypt in cloned buffer
|
||||
buf.Alignment(GetRequiredBufferAlignment());
|
||||
buf.AllocateNewBuffer(data.size());
|
||||
memmove(buf.BufferStart(), data.data(), data.size());
|
||||
buf.Size(data.size());
|
||||
{
|
||||
PERF_TIMER_GUARD(encrypt_data_nanos);
|
||||
status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
dataToAppend = Slice(buf.BufferStart(), buf.CurrentSize());
|
||||
Status EncryptedWritableFile::PositionedAppend(const Slice& data,
|
||||
uint64_t offset) {
|
||||
AlignedBuffer buf;
|
||||
Status status;
|
||||
Slice dataToAppend(data);
|
||||
offset += prefixLength_;
|
||||
if (data.size() > 0) {
|
||||
// Encrypt in cloned buffer
|
||||
buf.Alignment(GetRequiredBufferAlignment());
|
||||
buf.AllocateNewBuffer(data.size());
|
||||
memmove(buf.BufferStart(), data.data(), data.size());
|
||||
buf.Size(data.size());
|
||||
{
|
||||
PERF_TIMER_GUARD(encrypt_data_nanos);
|
||||
status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
status = file_->PositionedAppend(dataToAppend, offset);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
dataToAppend = Slice(buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
status = file_->PositionedAppend(dataToAppend, offset);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Indicates the upper layers if the current WritableFile implementation
|
||||
// uses direct IO.
|
||||
bool use_direct_io() const override { return file_->use_direct_io(); }
|
||||
bool EncryptedWritableFile::use_direct_io() const {
|
||||
return file_->use_direct_io();
|
||||
}
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
size_t GetRequiredBufferAlignment() const override {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
size_t EncryptedWritableFile::GetRequiredBufferAlignment() const {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the size of valid data in the file.
|
||||
*/
|
||||
uint64_t GetFileSize() override {
|
||||
return file_->GetFileSize() - prefixLength_;
|
||||
}
|
||||
/*
|
||||
* Get the size of valid data in the file.
|
||||
*/
|
||||
uint64_t EncryptedWritableFile::GetFileSize() {
|
||||
return file_->GetFileSize() - prefixLength_;
|
||||
}
|
||||
|
||||
// Truncate is necessary to trim the file to the correct size
|
||||
// before closing. It is not always possible to keep track of the file
|
||||
// size due to whole pages writes. The behavior is undefined if called
|
||||
// with other writes to follow.
|
||||
Status Truncate(uint64_t size) override {
|
||||
return file_->Truncate(size + prefixLength_);
|
||||
}
|
||||
Status EncryptedWritableFile::Truncate(uint64_t size) {
|
||||
return file_->Truncate(size + prefixLength_);
|
||||
}
|
||||
|
||||
// Remove any kind of caching of data from the offset to offset+length
|
||||
// of this file. If the length is 0, then it refers to the end of file.
|
||||
// If the system is not caching the file contents, then this is a noop.
|
||||
// This call has no effect on dirty pages in the cache.
|
||||
Status InvalidateCache(size_t offset, size_t length) override {
|
||||
return file_->InvalidateCache(offset + prefixLength_, length);
|
||||
}
|
||||
Status EncryptedWritableFile::InvalidateCache(size_t offset, size_t length) {
|
||||
return file_->InvalidateCache(offset + prefixLength_, length);
|
||||
}
|
||||
|
||||
// Sync a file range with disk.
|
||||
// offset is the starting byte of the file range to be synchronized.
|
||||
@@ -302,111 +275,103 @@ class EncryptedWritableFile : public WritableFileWrapper {
|
||||
// This asks the OS to initiate flushing the cached data to disk,
|
||||
// without waiting for completion.
|
||||
// Default implementation does nothing.
|
||||
Status RangeSync(uint64_t offset, uint64_t nbytes) override {
|
||||
return file_->RangeSync(offset + prefixLength_, nbytes);
|
||||
}
|
||||
Status EncryptedWritableFile::RangeSync(uint64_t offset, uint64_t nbytes) {
|
||||
return file_->RangeSync(offset + prefixLength_, nbytes);
|
||||
}
|
||||
|
||||
// PrepareWrite performs any necessary preparation for a write
|
||||
// before the write actually occurs. This allows for pre-allocation
|
||||
// of space on devices where it can result in less file
|
||||
// fragmentation and/or less waste from over-zealous filesystem
|
||||
// pre-allocation.
|
||||
void PrepareWrite(size_t offset, size_t len) override {
|
||||
file_->PrepareWrite(offset + prefixLength_, len);
|
||||
}
|
||||
void EncryptedWritableFile::PrepareWrite(size_t offset, size_t len) {
|
||||
file_->PrepareWrite(offset + prefixLength_, len);
|
||||
}
|
||||
|
||||
// Pre-allocates space for a file.
|
||||
Status Allocate(uint64_t offset, uint64_t len) override {
|
||||
return file_->Allocate(offset + prefixLength_, len);
|
||||
}
|
||||
};
|
||||
Status EncryptedWritableFile::Allocate(uint64_t offset, uint64_t len) {
|
||||
return file_->Allocate(offset + prefixLength_, len);
|
||||
}
|
||||
|
||||
// A file abstraction for random reading and writing.
|
||||
class EncryptedRandomRWFile : public RandomRWFile {
|
||||
private:
|
||||
std::unique_ptr<RandomRWFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
EncryptedRandomRWFile(RandomRWFile* f, BlockAccessCipherStream* s, size_t prefixLength)
|
||||
: file_(f), stream_(s), prefixLength_(prefixLength) {}
|
||||
|
||||
// Indicates if the class makes use of direct I/O
|
||||
// If false you must pass aligned buffer to Write()
|
||||
bool use_direct_io() const override { return file_->use_direct_io(); }
|
||||
// Indicates if the class makes use of direct I/O
|
||||
// If false you must pass aligned buffer to Write()
|
||||
bool EncryptedRandomRWFile::use_direct_io() const {
|
||||
return file_->use_direct_io();
|
||||
}
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
size_t GetRequiredBufferAlignment() const override {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
size_t EncryptedRandomRWFile::GetRequiredBufferAlignment() const {
|
||||
return file_->GetRequiredBufferAlignment();
|
||||
}
|
||||
|
||||
// Write bytes in `data` at offset `offset`, Returns Status::OK() on success.
|
||||
// Pass aligned buffer when use_direct_io() returns true.
|
||||
Status Write(uint64_t offset, const Slice& data) override {
|
||||
AlignedBuffer buf;
|
||||
Status status;
|
||||
Slice dataToWrite(data);
|
||||
offset += prefixLength_;
|
||||
if (data.size() > 0) {
|
||||
// Encrypt in cloned buffer
|
||||
buf.Alignment(GetRequiredBufferAlignment());
|
||||
buf.AllocateNewBuffer(data.size());
|
||||
memmove(buf.BufferStart(), data.data(), data.size());
|
||||
buf.Size(data.size());
|
||||
{
|
||||
PERF_TIMER_GUARD(encrypt_data_nanos);
|
||||
status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
dataToWrite = Slice(buf.BufferStart(), buf.CurrentSize());
|
||||
Status EncryptedRandomRWFile::Write(uint64_t offset, const Slice& data) {
|
||||
AlignedBuffer buf;
|
||||
Status status;
|
||||
Slice dataToWrite(data);
|
||||
offset += prefixLength_;
|
||||
if (data.size() > 0) {
|
||||
// Encrypt in cloned buffer
|
||||
buf.Alignment(GetRequiredBufferAlignment());
|
||||
buf.AllocateNewBuffer(data.size());
|
||||
memmove(buf.BufferStart(), data.data(), data.size());
|
||||
buf.Size(data.size());
|
||||
{
|
||||
PERF_TIMER_GUARD(encrypt_data_nanos);
|
||||
status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
status = file_->Write(offset, dataToWrite);
|
||||
return status;
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
dataToWrite = Slice(buf.BufferStart(), buf.CurrentSize());
|
||||
}
|
||||
status = file_->Write(offset, dataToWrite);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Read up to `n` bytes starting from offset `offset` and store them in
|
||||
// result, provided `scratch` size should be at least `n`.
|
||||
// Returns Status::OK() on success.
|
||||
Status Read(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) const override {
|
||||
assert(scratch);
|
||||
offset += prefixLength_;
|
||||
auto status = file_->Read(offset, n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset, (char*)result->data(), result->size());
|
||||
}
|
||||
Status EncryptedRandomRWFile::Read(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) const {
|
||||
assert(scratch);
|
||||
offset += prefixLength_;
|
||||
auto status = file_->Read(offset, n, result, scratch);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
{
|
||||
PERF_TIMER_GUARD(decrypt_data_nanos);
|
||||
status = stream_->Decrypt(offset, (char*)result->data(), result->size());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Status Flush() override { return file_->Flush(); }
|
||||
Status EncryptedRandomRWFile::Flush() { return file_->Flush(); }
|
||||
|
||||
Status Sync() override { return file_->Sync(); }
|
||||
Status EncryptedRandomRWFile::Sync() { return file_->Sync(); }
|
||||
|
||||
Status Fsync() override { return file_->Fsync(); }
|
||||
Status EncryptedRandomRWFile::Fsync() { return file_->Fsync(); }
|
||||
|
||||
Status Close() override { return file_->Close(); }
|
||||
};
|
||||
Status EncryptedRandomRWFile::Close() { return file_->Close(); }
|
||||
|
||||
// EncryptedEnv implements an Env wrapper that adds encryption to files stored on disk.
|
||||
// EncryptedEnv implements an Env wrapper that adds encryption to files stored
|
||||
// on disk.
|
||||
class EncryptedEnv : public EnvWrapper {
|
||||
public:
|
||||
EncryptedEnv(Env* base_env, EncryptionProvider *provider)
|
||||
EncryptedEnv(Env* base_env, EncryptionProvider* provider)
|
||||
: EnvWrapper(base_env) {
|
||||
provider_ = provider;
|
||||
}
|
||||
|
||||
// NewSequentialFile opens a file for sequential reading.
|
||||
Status NewSequentialFile(const std::string& fname,
|
||||
std::unique_ptr<SequentialFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
virtual Status NewSequentialFile(const std::string& fname,
|
||||
std::unique_ptr<SequentialFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
result->reset();
|
||||
if (options.use_mmap_reads) {
|
||||
return Status::InvalidArgument();
|
||||
@@ -425,7 +390,8 @@ class EncryptedEnv : public EnvWrapper {
|
||||
// Read prefix
|
||||
prefixBuf.Alignment(underlying->GetRequiredBufferAlignment());
|
||||
prefixBuf.AllocateNewBuffer(prefixLength);
|
||||
status = underlying->Read(prefixLength, &prefixSlice, prefixBuf.BufferStart());
|
||||
status =
|
||||
underlying->Read(prefixLength, &prefixSlice, prefixBuf.BufferStart());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
@@ -433,18 +399,20 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
// Create cipher stream
|
||||
std::unique_ptr<BlockAccessCipherStream> stream;
|
||||
status = provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
status =
|
||||
provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
(*result) = std::unique_ptr<SequentialFile>(new EncryptedSequentialFile(underlying.release(), stream.release(), prefixLength));
|
||||
(*result) = std::unique_ptr<SequentialFile>(new EncryptedSequentialFile(
|
||||
std::move(underlying), std::move(stream), prefixLength));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// NewRandomAccessFile opens a file for random read access.
|
||||
Status NewRandomAccessFile(const std::string& fname,
|
||||
std::unique_ptr<RandomAccessFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
virtual Status NewRandomAccessFile(const std::string& fname,
|
||||
std::unique_ptr<RandomAccessFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
result->reset();
|
||||
if (options.use_mmap_reads) {
|
||||
return Status::InvalidArgument();
|
||||
@@ -463,7 +431,8 @@ class EncryptedEnv : public EnvWrapper {
|
||||
// Read prefix
|
||||
prefixBuf.Alignment(underlying->GetRequiredBufferAlignment());
|
||||
prefixBuf.AllocateNewBuffer(prefixLength);
|
||||
status = underlying->Read(0, prefixLength, &prefixSlice, prefixBuf.BufferStart());
|
||||
status = underlying->Read(0, prefixLength, &prefixSlice,
|
||||
prefixBuf.BufferStart());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
@@ -471,18 +440,20 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
// Create cipher stream
|
||||
std::unique_ptr<BlockAccessCipherStream> stream;
|
||||
status = provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
status =
|
||||
provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
(*result) = std::unique_ptr<RandomAccessFile>(new EncryptedRandomAccessFile(underlying.release(), stream.release(), prefixLength));
|
||||
(*result) = std::unique_ptr<RandomAccessFile>(new EncryptedRandomAccessFile(
|
||||
std::move(underlying), std::move(stream), prefixLength));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// NewWritableFile opens a file for sequential writing.
|
||||
Status NewWritableFile(const std::string& fname,
|
||||
std::unique_ptr<WritableFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
virtual Status NewWritableFile(const std::string& fname,
|
||||
std::unique_ptr<WritableFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
result->reset();
|
||||
if (options.use_mmap_writes) {
|
||||
return Status::InvalidArgument();
|
||||
@@ -512,11 +483,13 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
// Create cipher stream
|
||||
std::unique_ptr<BlockAccessCipherStream> stream;
|
||||
status = provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
status =
|
||||
provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
(*result) = std::unique_ptr<WritableFile>(new EncryptedWritableFile(underlying.release(), stream.release(), prefixLength));
|
||||
(*result) = std::unique_ptr<WritableFile>(new EncryptedWritableFile(
|
||||
std::move(underlying), std::move(stream), prefixLength));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@@ -527,9 +500,9 @@ class EncryptedEnv : public EnvWrapper {
|
||||
// returns non-OK.
|
||||
//
|
||||
// The returned file will only be accessed by one thread at a time.
|
||||
Status ReopenWritableFile(const std::string& fname,
|
||||
std::unique_ptr<WritableFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
virtual Status ReopenWritableFile(const std::string& fname,
|
||||
std::unique_ptr<WritableFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
result->reset();
|
||||
if (options.use_mmap_writes) {
|
||||
return Status::InvalidArgument();
|
||||
@@ -559,26 +532,29 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
// Create cipher stream
|
||||
std::unique_ptr<BlockAccessCipherStream> stream;
|
||||
status = provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
status =
|
||||
provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
(*result) = std::unique_ptr<WritableFile>(new EncryptedWritableFile(underlying.release(), stream.release(), prefixLength));
|
||||
(*result) = std::unique_ptr<WritableFile>(new EncryptedWritableFile(
|
||||
std::move(underlying), std::move(stream), prefixLength));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// Reuse an existing file by renaming it and opening it as writable.
|
||||
Status ReuseWritableFile(const std::string& fname,
|
||||
const std::string& old_fname,
|
||||
std::unique_ptr<WritableFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
virtual Status ReuseWritableFile(const std::string& fname,
|
||||
const std::string& old_fname,
|
||||
std::unique_ptr<WritableFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
result->reset();
|
||||
if (options.use_mmap_writes) {
|
||||
return Status::InvalidArgument();
|
||||
}
|
||||
// Open file using underlying Env implementation
|
||||
std::unique_ptr<WritableFile> underlying;
|
||||
Status status = EnvWrapper::ReuseWritableFile(fname, old_fname, &underlying, options);
|
||||
Status status =
|
||||
EnvWrapper::ReuseWritableFile(fname, old_fname, &underlying, options);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
@@ -601,11 +577,13 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
// Create cipher stream
|
||||
std::unique_ptr<BlockAccessCipherStream> stream;
|
||||
status = provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
status =
|
||||
provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
(*result) = std::unique_ptr<WritableFile>(new EncryptedWritableFile(underlying.release(), stream.release(), prefixLength));
|
||||
(*result) = std::unique_ptr<WritableFile>(new EncryptedWritableFile(
|
||||
std::move(underlying), std::move(stream), prefixLength));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@@ -614,9 +592,9 @@ class EncryptedEnv : public EnvWrapper {
|
||||
// *result and returns OK. On failure returns non-OK.
|
||||
//
|
||||
// The returned file will only be accessed by one thread at a time.
|
||||
Status NewRandomRWFile(const std::string& fname,
|
||||
std::unique_ptr<RandomRWFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
virtual Status NewRandomRWFile(const std::string& fname,
|
||||
std::unique_ptr<RandomRWFile>* result,
|
||||
const EnvOptions& options) override {
|
||||
result->reset();
|
||||
if (options.use_mmap_reads || options.use_mmap_writes) {
|
||||
return Status::InvalidArgument();
|
||||
@@ -639,14 +617,16 @@ class EncryptedEnv : public EnvWrapper {
|
||||
prefixBuf.AllocateNewBuffer(prefixLength);
|
||||
if (!isNewFile) {
|
||||
// File already exists, read prefix
|
||||
status = underlying->Read(0, prefixLength, &prefixSlice, prefixBuf.BufferStart());
|
||||
status = underlying->Read(0, prefixLength, &prefixSlice,
|
||||
prefixBuf.BufferStart());
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
prefixBuf.Size(prefixLength);
|
||||
} else {
|
||||
// File is new, initialize & write prefix
|
||||
provider_->CreateNewPrefix(fname, prefixBuf.BufferStart(), prefixLength);
|
||||
provider_->CreateNewPrefix(fname, prefixBuf.BufferStart(),
|
||||
prefixLength);
|
||||
prefixBuf.Size(prefixLength);
|
||||
prefixSlice = Slice(prefixBuf.BufferStart(), prefixBuf.CurrentSize());
|
||||
// Write prefix
|
||||
@@ -658,40 +638,51 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
// Create cipher stream
|
||||
std::unique_ptr<BlockAccessCipherStream> stream;
|
||||
status = provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
status =
|
||||
provider_->CreateCipherStream(fname, options, prefixSlice, &stream);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
(*result) = std::unique_ptr<RandomRWFile>(new EncryptedRandomRWFile(underlying.release(), stream.release(), prefixLength));
|
||||
(*result) = std::unique_ptr<RandomRWFile>(new EncryptedRandomRWFile(
|
||||
std::move(underlying), std::move(stream), prefixLength));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// Store in *result the attributes of the children of the specified directory.
|
||||
// In case the implementation lists the directory prior to iterating the files
|
||||
// and files are concurrently deleted, the deleted files will be omitted from
|
||||
// Store in *result the attributes of the children of the specified
|
||||
// directory.
|
||||
// In case the implementation lists the directory prior to iterating the
|
||||
// files
|
||||
// and files are concurrently deleted, the deleted files will be omitted
|
||||
// from
|
||||
// result.
|
||||
// The name attributes are relative to "dir".
|
||||
// Original contents of *results are dropped.
|
||||
// Returns OK if "dir" exists and "*result" contains its children.
|
||||
// NotFound if "dir" does not exist, the calling process does not have
|
||||
// NotFound if "dir" does not exist, the calling process does not
|
||||
// have
|
||||
// permission to access "dir", or if "dir" is invalid.
|
||||
// IOError if an IO Error was encountered
|
||||
Status GetChildrenFileAttributes(
|
||||
virtual Status GetChildrenFileAttributes(
|
||||
const std::string& dir, std::vector<FileAttributes>* result) override {
|
||||
auto status = EnvWrapper::GetChildrenFileAttributes(dir, result);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
size_t prefixLength = provider_->GetPrefixLength();
|
||||
for (auto it = std::begin(*result); it!=std::end(*result); ++it) {
|
||||
assert(it->size_bytes >= prefixLength);
|
||||
for (auto it = std::begin(*result); it != std::end(*result); ++it) {
|
||||
// assert(it->size_bytes >= prefixLength);
|
||||
// breaks env_basic_test when called on directory containing
|
||||
// directories
|
||||
// which makes subtraction of prefixLength worrisome since
|
||||
// FileAttributes does not identify directories
|
||||
it->size_bytes -= prefixLength;
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// Store the size of fname in *file_size.
|
||||
Status GetFileSize(const std::string& fname, uint64_t* file_size) override {
|
||||
virtual Status GetFileSize(const std::string& fname,
|
||||
uint64_t* file_size) override {
|
||||
auto status = EnvWrapper::GetFileSize(fname, file_size);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
@@ -703,7 +694,7 @@ class EncryptedEnv : public EnvWrapper {
|
||||
}
|
||||
|
||||
private:
|
||||
EncryptionProvider *provider_;
|
||||
EncryptionProvider* provider_;
|
||||
};
|
||||
|
||||
// Returns an Env that encrypts data when stored on disk and decrypts data when
|
||||
|
||||
Vendored
+3
-3
@@ -12,7 +12,6 @@
|
||||
#define ROCKSDB_HDFS_FILE_C
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@@ -124,8 +123,9 @@ class HdfsReadableFile : virtual public SequentialFile,
|
||||
Status s;
|
||||
ROCKS_LOG_DEBUG(mylog, "[hdfs] HdfsReadableFile preading %s\n",
|
||||
filename_.c_str());
|
||||
ssize_t bytes_read = hdfsPread(fileSys_, hfile_, offset,
|
||||
(void*)scratch, (tSize)n);
|
||||
tSize bytes_read =
|
||||
hdfsPread(fileSys_, hfile_, offset, static_cast<void*>(scratch),
|
||||
static_cast<tSize>(n));
|
||||
ROCKS_LOG_DEBUG(mylog, "[hdfs] HdfsReadableFile pread %s\n",
|
||||
filename_.c_str());
|
||||
*result = Slice(scratch, (bytes_read < 0) ? 0 : bytes_read);
|
||||
|
||||
Vendored
+14
-11
@@ -41,7 +41,7 @@
|
||||
#include <time.h>
|
||||
#include <algorithm>
|
||||
// Get nano time includes
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD)
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_GNU_KFREEBSD)
|
||||
#elif defined(__MACH__)
|
||||
#include <Availability.h>
|
||||
#include <mach/clock.h>
|
||||
@@ -249,7 +249,8 @@ class PosixEnv : public CompositeEnvWrapper {
|
||||
}
|
||||
|
||||
uint64_t NowNanos() override {
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX)
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_GNU_KFREEBSD) || \
|
||||
defined(OS_AIX)
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return static_cast<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
|
||||
@@ -269,8 +270,8 @@ class PosixEnv : public CompositeEnvWrapper {
|
||||
}
|
||||
|
||||
uint64_t NowCPUNanos() override {
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX) || \
|
||||
(defined(__MACH__) && defined(__MAC_10_12))
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_GNU_KFREEBSD) || \
|
||||
defined(OS_AIX) || (defined(__MACH__) && defined(__MAC_10_12))
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
|
||||
return static_cast<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
|
||||
@@ -329,7 +330,7 @@ class PosixEnv : public CompositeEnvWrapper {
|
||||
thread_pools_[pri].IncBackgroundThreadsIfNeeded(num);
|
||||
}
|
||||
|
||||
void LowerThreadPoolIOPriority(Priority pool = LOW) override {
|
||||
void LowerThreadPoolIOPriority(Priority pool) override {
|
||||
assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH);
|
||||
#ifdef OS_LINUX
|
||||
thread_pools_[pool].LowerIOPriority();
|
||||
@@ -338,13 +339,15 @@ class PosixEnv : public CompositeEnvWrapper {
|
||||
#endif
|
||||
}
|
||||
|
||||
void LowerThreadPoolCPUPriority(Priority pool = LOW) override {
|
||||
void LowerThreadPoolCPUPriority(Priority pool) override {
|
||||
assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH);
|
||||
#ifdef OS_LINUX
|
||||
thread_pools_[pool].LowerCPUPriority();
|
||||
#else
|
||||
(void)pool;
|
||||
#endif
|
||||
thread_pools_[pool].LowerCPUPriority(CpuPriority::kLow);
|
||||
}
|
||||
|
||||
Status LowerThreadPoolCPUPriority(Priority pool, CpuPriority pri) override {
|
||||
assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH);
|
||||
thread_pools_[pool].LowerCPUPriority(pri);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
std::string TimeToString(uint64_t secondsSince1970) override {
|
||||
|
||||
Vendored
+75
-2
@@ -202,6 +202,79 @@ TEST_F(EnvPosixTest, DISABLED_FilePermission) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(EnvPosixTest, LowerThreadPoolCpuPriority) {
|
||||
std::atomic<CpuPriority> from_priority(CpuPriority::kNormal);
|
||||
std::atomic<CpuPriority> to_priority(CpuPriority::kNormal);
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"ThreadPoolImpl::BGThread::BeforeSetCpuPriority", [&](void* pri) {
|
||||
from_priority.store(*reinterpret_cast<CpuPriority*>(pri));
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"ThreadPoolImpl::BGThread::AfterSetCpuPriority", [&](void* pri) {
|
||||
to_priority.store(*reinterpret_cast<CpuPriority*>(pri));
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
env_->SetBackgroundThreads(1, Env::BOTTOM);
|
||||
env_->SetBackgroundThreads(1, Env::HIGH);
|
||||
|
||||
auto RunTask = [&](Env::Priority pool) {
|
||||
std::atomic<bool> called(false);
|
||||
env_->Schedule(&SetBool, &called, pool);
|
||||
for (int i = 0; i < kDelayMicros; i++) {
|
||||
if (called.load()) {
|
||||
break;
|
||||
}
|
||||
Env::Default()->SleepForMicroseconds(1);
|
||||
}
|
||||
ASSERT_TRUE(called.load());
|
||||
};
|
||||
|
||||
{
|
||||
// Same priority, no-op.
|
||||
env_->LowerThreadPoolCPUPriority(Env::Priority::BOTTOM,
|
||||
CpuPriority::kNormal);
|
||||
RunTask(Env::Priority::BOTTOM);
|
||||
ASSERT_EQ(from_priority, CpuPriority::kNormal);
|
||||
ASSERT_EQ(to_priority, CpuPriority::kNormal);
|
||||
}
|
||||
|
||||
{
|
||||
// Higher priority, no-op.
|
||||
env_->LowerThreadPoolCPUPriority(Env::Priority::BOTTOM, CpuPriority::kHigh);
|
||||
RunTask(Env::Priority::BOTTOM);
|
||||
ASSERT_EQ(from_priority, CpuPriority::kNormal);
|
||||
ASSERT_EQ(to_priority, CpuPriority::kNormal);
|
||||
}
|
||||
|
||||
{
|
||||
// Lower priority from kNormal -> kLow.
|
||||
env_->LowerThreadPoolCPUPriority(Env::Priority::BOTTOM, CpuPriority::kLow);
|
||||
RunTask(Env::Priority::BOTTOM);
|
||||
ASSERT_EQ(from_priority, CpuPriority::kNormal);
|
||||
ASSERT_EQ(to_priority, CpuPriority::kLow);
|
||||
}
|
||||
|
||||
{
|
||||
// Lower priority from kLow -> kIdle.
|
||||
env_->LowerThreadPoolCPUPriority(Env::Priority::BOTTOM, CpuPriority::kIdle);
|
||||
RunTask(Env::Priority::BOTTOM);
|
||||
ASSERT_EQ(from_priority, CpuPriority::kLow);
|
||||
ASSERT_EQ(to_priority, CpuPriority::kIdle);
|
||||
}
|
||||
|
||||
{
|
||||
// Lower priority from kNormal -> kIdle for another pool.
|
||||
env_->LowerThreadPoolCPUPriority(Env::Priority::HIGH, CpuPriority::kIdle);
|
||||
RunTask(Env::Priority::HIGH);
|
||||
ASSERT_EQ(from_priority, CpuPriority::kNormal);
|
||||
ASSERT_EQ(to_priority, CpuPriority::kIdle);
|
||||
}
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(EnvPosixTest, MemoryMappedFileBuffer) {
|
||||
@@ -1047,7 +1120,7 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueIDConcurrent) {
|
||||
|
||||
// Collect and check whether the IDs are unique.
|
||||
std::unordered_set<std::string> ids;
|
||||
for (const std::string fname : fnames) {
|
||||
for (const std::string& fname : fnames) {
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
std::string unique_id;
|
||||
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions));
|
||||
@@ -1061,7 +1134,7 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueIDConcurrent) {
|
||||
}
|
||||
|
||||
// Delete the files
|
||||
for (const std::string fname : fnames) {
|
||||
for (const std::string& fname : fnames) {
|
||||
ASSERT_OK(env_->DeleteFile(fname));
|
||||
}
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -150,11 +150,11 @@ bool PosixPositionedWrite(int fd, const char* buf, size_t nbyte, off_t offset) {
|
||||
#endif
|
||||
|
||||
bool IsSyncFileRangeSupported(int fd) {
|
||||
// The approach taken in this function is to build a blacklist of cases where
|
||||
// we know `sync_file_range` definitely will not work properly despite passing
|
||||
// the compile-time check (`ROCKSDB_RANGESYNC_PRESENT`). If we are unsure, or
|
||||
// if any of the checks fail in unexpected ways, we allow `sync_file_range` to
|
||||
// be used. This way should minimize risk of impacting existing use cases.
|
||||
// This function tracks and checks for cases where we know `sync_file_range`
|
||||
// definitely will not work properly despite passing the compile-time check
|
||||
// (`ROCKSDB_RANGESYNC_PRESENT`). If we are unsure, or if any of the checks
|
||||
// fail in unexpected ways, we allow `sync_file_range` to be used. This way
|
||||
// should minimize risk of impacting existing use cases.
|
||||
struct statfs buf;
|
||||
int ret = fstatfs(fd, &buf);
|
||||
assert(ret == 0);
|
||||
@@ -176,7 +176,7 @@ bool IsSyncFileRangeSupported(int fd) {
|
||||
// ("Function not implemented").
|
||||
return false;
|
||||
}
|
||||
// None of the cases on the blacklist matched, so allow `sync_file_range` use.
|
||||
// None of the known cases matched, so allow `sync_file_range` use.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
add_executable(simple_example
|
||||
simple_example.cc)
|
||||
target_link_libraries(simple_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(column_families_example
|
||||
column_families_example.cc)
|
||||
target_link_libraries(column_families_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(compact_files_example
|
||||
compact_files_example.cc)
|
||||
target_link_libraries(compact_files_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(c_simple_example
|
||||
c_simple_example.c)
|
||||
target_link_libraries(c_simple_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(optimistic_transaction_example
|
||||
optimistic_transaction_example.cc)
|
||||
target_link_libraries(optimistic_transaction_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(transaction_example
|
||||
transaction_example.cc)
|
||||
target_link_libraries(transaction_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(compaction_filter_example
|
||||
compaction_filter_example.cc)
|
||||
target_link_libraries(compaction_filter_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(options_file_example
|
||||
options_file_example.cc)
|
||||
target_link_libraries(options_file_example
|
||||
${ROCKSDB_LIB})
|
||||
|
||||
add_executable(multi_processes_example
|
||||
EXCLUDE_FROM_ALL
|
||||
multi_processes_example.cc)
|
||||
target_link_libraries(multi_processes_example
|
||||
${ROCKSDB_LIB})
|
||||
@@ -68,7 +68,7 @@ int main() {
|
||||
}
|
||||
|
||||
PinnableSlice pinnable_val;
|
||||
db->Get(ReadOptions(), db->DefaultColumnFamily(), "key1", &pinnable_val);
|
||||
s = db->Get(ReadOptions(), db->DefaultColumnFamily(), "key1", &pinnable_val);
|
||||
assert(s.IsNotFound());
|
||||
// Reset PinnableSlice after each use and before each reuse
|
||||
pinnable_val.Reset();
|
||||
|
||||
@@ -132,7 +132,7 @@ class RandomAccessFileReader {
|
||||
|
||||
FSRandomAccessFile* file() { return file_.get(); }
|
||||
|
||||
std::string file_name() const { return file_name_; }
|
||||
const std::string& file_name() const { return file_name_; }
|
||||
|
||||
bool use_direct_io() const { return file_->use_direct_io(); }
|
||||
|
||||
|
||||
+2
-6
@@ -162,10 +162,7 @@ class HdfsEnv : public Env {
|
||||
return posixEnv->TimeToString(number);
|
||||
}
|
||||
|
||||
static uint64_t gettid() {
|
||||
assert(sizeof(pthread_t) <= sizeof(uint64_t));
|
||||
return (uint64_t)pthread_self();
|
||||
}
|
||||
static uint64_t gettid() { return Env::Default()->GetThreadID(); }
|
||||
|
||||
uint64_t GetThreadID() const override { return HdfsEnv::gettid(); }
|
||||
|
||||
@@ -209,8 +206,7 @@ class HdfsEnv : public Env {
|
||||
std::string portStr = (rem == 0 ? remaining :
|
||||
remaining.substr(0, rem));
|
||||
|
||||
tPort port;
|
||||
port = atoi(portStr.c_str());
|
||||
tPort port = static_cast<tPort>(atoi(portStr.c_str()));
|
||||
if (port == 0) {
|
||||
throw HdfsFatalException("Bad host-port for hdfs " + uri);
|
||||
}
|
||||
|
||||
@@ -1266,6 +1266,8 @@ class DB {
|
||||
// updated, false if user attempted to call if with seqnum <= current value.
|
||||
virtual bool SetPreserveDeletesSequenceNumber(SequenceNumber seqnum) = 0;
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
|
||||
// Prevent file deletions. Compactions will continue to occur,
|
||||
// but no obsolete files will be deleted. Calling this multiple
|
||||
// times have the same effect as calling it once.
|
||||
@@ -1282,7 +1284,6 @@ class DB {
|
||||
// threads call EnableFileDeletions()
|
||||
virtual Status EnableFileDeletions(bool force = true) = 0;
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
// GetLiveFiles followed by GetSortedWalFiles can generate a lossless backup
|
||||
|
||||
// Retrieve the list of all files in the database. The files are
|
||||
@@ -1543,6 +1544,13 @@ class DB {
|
||||
// Returns Status::OK if identity could be set properly
|
||||
virtual Status GetDbIdentity(std::string& identity) const = 0;
|
||||
|
||||
// Return a unique identifier for each DB object that is opened
|
||||
// This DB session ID should be unique among all open DB instances on all
|
||||
// hosts, and should be unique among re-openings of the same or other DBs.
|
||||
// (Two open DBs have the same identity from other function GetDbIdentity when
|
||||
// one is physically copied from the other.)
|
||||
virtual Status GetDbSessionId(std::string& session_id) const = 0;
|
||||
|
||||
// Returns default column family handle
|
||||
virtual ColumnFamilyHandle* DefaultColumnFamily() const = 0;
|
||||
|
||||
|
||||
+20
-2
@@ -61,6 +61,13 @@ class FileSystem;
|
||||
|
||||
const size_t kDefaultPageSize = 4 * 1024;
|
||||
|
||||
enum class CpuPriority {
|
||||
kIdle = 0,
|
||||
kLow = 1,
|
||||
kNormal = 2,
|
||||
kHigh = 3,
|
||||
};
|
||||
|
||||
// Options while opening a file to read/write
|
||||
struct EnvOptions {
|
||||
// Construct with default Options
|
||||
@@ -474,6 +481,13 @@ class Env {
|
||||
// Lower IO priority for threads from the specified pool.
|
||||
virtual void LowerThreadPoolIOPriority(Priority /*pool*/ = LOW) {}
|
||||
|
||||
// Lower CPU priority for threads from the specified pool.
|
||||
virtual Status LowerThreadPoolCPUPriority(Priority /*pool*/,
|
||||
CpuPriority /*pri*/) {
|
||||
return Status::NotSupported(
|
||||
"Env::LowerThreadPoolCPUPriority(Priority, CpuPriority) not supported");
|
||||
}
|
||||
|
||||
// Lower CPU priority for threads from the specified pool.
|
||||
virtual void LowerThreadPoolCPUPriority(Priority /*pool*/ = LOW) {}
|
||||
|
||||
@@ -1355,14 +1369,18 @@ class EnvWrapper : public Env {
|
||||
return target_->IncBackgroundThreadsIfNeeded(num, pri);
|
||||
}
|
||||
|
||||
void LowerThreadPoolIOPriority(Priority pool = LOW) override {
|
||||
void LowerThreadPoolIOPriority(Priority pool) override {
|
||||
target_->LowerThreadPoolIOPriority(pool);
|
||||
}
|
||||
|
||||
void LowerThreadPoolCPUPriority(Priority pool = LOW) override {
|
||||
void LowerThreadPoolCPUPriority(Priority pool) override {
|
||||
target_->LowerThreadPoolCPUPriority(pool);
|
||||
}
|
||||
|
||||
Status LowerThreadPoolCPUPriority(Priority pool, CpuPriority pri) override {
|
||||
return target_->LowerThreadPoolCPUPriority(pool, pri);
|
||||
}
|
||||
|
||||
std::string TimeToString(uint64_t time) override {
|
||||
return target_->TimeToString(time);
|
||||
}
|
||||
|
||||
@@ -169,8 +169,10 @@ class CTREncryptionProvider : public EncryptionProvider {
|
||||
virtual ~CTREncryptionProvider() {}
|
||||
|
||||
// GetPrefixLength returns the length of the prefix that is added to every
|
||||
// file and used for storing encryption options. For optimal performance, the
|
||||
// prefix length should be a multiple of the page size.
|
||||
// file
|
||||
// and used for storing encryption options.
|
||||
// For optimal performance, the prefix length should be a multiple of
|
||||
// the page size.
|
||||
virtual size_t GetPrefixLength() override;
|
||||
|
||||
// CreateNewPrefix initialized an allocated block of prefix memory
|
||||
@@ -194,13 +196,243 @@ class CTREncryptionProvider : public EncryptionProvider {
|
||||
size_t blockSize);
|
||||
|
||||
// CreateCipherStreamFromPrefix creates a block access cipher stream for a
|
||||
// file given given name and options. The given prefix is already decrypted.
|
||||
// file given
|
||||
// given name and options. The given prefix is already decrypted.
|
||||
virtual Status CreateCipherStreamFromPrefix(
|
||||
const std::string& fname, const EnvOptions& options,
|
||||
uint64_t initialCounter, const Slice& iv, const Slice& prefix,
|
||||
std::unique_ptr<BlockAccessCipherStream>* result);
|
||||
};
|
||||
|
||||
class EncryptedSequentialFile : public SequentialFile {
|
||||
protected:
|
||||
std::unique_ptr<SequentialFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
uint64_t offset_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
// Default ctor. Given underlying sequential file is supposed to be at
|
||||
// offset == prefixLength.
|
||||
EncryptedSequentialFile(std::unique_ptr<SequentialFile>&& f,
|
||||
std::unique_ptr<BlockAccessCipherStream>&& s,
|
||||
size_t prefixLength)
|
||||
: file_(std::move(f)),
|
||||
stream_(std::move(s)),
|
||||
offset_(prefixLength),
|
||||
prefixLength_(prefixLength) {}
|
||||
|
||||
// Read up to "n" bytes from the file. "scratch[0..n-1]" may be
|
||||
// written by this routine. Sets "*result" to the data that was
|
||||
// read (including if fewer than "n" bytes were successfully read).
|
||||
// May set "*result" to point at data in "scratch[0..n-1]", so
|
||||
// "scratch[0..n-1]" must be live when "*result" is used.
|
||||
// If an error was encountered, returns a non-OK status.
|
||||
//
|
||||
// REQUIRES: External synchronization
|
||||
virtual Status Read(size_t n, Slice* result, char* scratch) override;
|
||||
|
||||
// Skip "n" bytes from the file. This is guaranteed to be no
|
||||
// slower that reading the same data, but may be faster.
|
||||
//
|
||||
// If end of file is reached, skipping will stop at the end of the
|
||||
// file, and Skip will return OK.
|
||||
//
|
||||
// REQUIRES: External synchronization
|
||||
virtual Status Skip(uint64_t n) override;
|
||||
|
||||
// Indicates the upper layers if the current SequentialFile implementation
|
||||
// uses direct IO.
|
||||
virtual bool use_direct_io() const override;
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
virtual size_t GetRequiredBufferAlignment() const override;
|
||||
|
||||
// Remove any kind of caching of data from the offset to offset+length
|
||||
// of this file. If the length is 0, then it refers to the end of file.
|
||||
// If the system is not caching the file contents, then this is a noop.
|
||||
virtual Status InvalidateCache(size_t offset, size_t length) override;
|
||||
|
||||
// Positioned Read for direct I/O
|
||||
// If Direct I/O enabled, offset, n, and scratch should be properly aligned
|
||||
virtual Status PositionedRead(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) override;
|
||||
};
|
||||
|
||||
// A file abstraction for randomly reading the contents of a file.
|
||||
class EncryptedRandomAccessFile : public RandomAccessFile {
|
||||
protected:
|
||||
std::unique_ptr<RandomAccessFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
EncryptedRandomAccessFile(std::unique_ptr<RandomAccessFile>&& f,
|
||||
std::unique_ptr<BlockAccessCipherStream>&& s,
|
||||
size_t prefixLength)
|
||||
: file_(std::move(f)),
|
||||
stream_(std::move(s)),
|
||||
prefixLength_(prefixLength) {}
|
||||
|
||||
// Read up to "n" bytes from the file starting at "offset".
|
||||
// "scratch[0..n-1]" may be written by this routine. Sets "*result"
|
||||
// to the data that was read (including if fewer than "n" bytes were
|
||||
// successfully read). May set "*result" to point at data in
|
||||
// "scratch[0..n-1]", so "scratch[0..n-1]" must be live when
|
||||
// "*result" is used. If an error was encountered, returns a non-OK
|
||||
// status.
|
||||
//
|
||||
// Safe for concurrent use by multiple threads.
|
||||
// If Direct I/O enabled, offset, n, and scratch should be aligned properly.
|
||||
virtual Status Read(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) const override;
|
||||
|
||||
// Readahead the file starting from offset by n bytes for caching.
|
||||
virtual Status Prefetch(uint64_t offset, size_t n) override;
|
||||
|
||||
// Tries to get an unique ID for this file that will be the same each time
|
||||
// the file is opened (and will stay the same while the file is open).
|
||||
// Furthermore, it tries to make this ID at most "max_size" bytes. If such an
|
||||
// ID can be created this function returns the length of the ID and places it
|
||||
// in "id"; otherwise, this function returns 0, in which case "id"
|
||||
// may not have been modified.
|
||||
//
|
||||
// This function guarantees, for IDs from a given environment, two unique ids
|
||||
// cannot be made equal to each other by adding arbitrary bytes to one of
|
||||
// them. That is, no unique ID is the prefix of another.
|
||||
//
|
||||
// This function guarantees that the returned ID will not be interpretable as
|
||||
// a single varint.
|
||||
//
|
||||
// Note: these IDs are only valid for the duration of the process.
|
||||
virtual size_t GetUniqueId(char* id, size_t max_size) const override;
|
||||
|
||||
virtual void Hint(AccessPattern pattern) override;
|
||||
|
||||
// Indicates the upper layers if the current RandomAccessFile implementation
|
||||
// uses direct IO.
|
||||
virtual bool use_direct_io() const override;
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
virtual size_t GetRequiredBufferAlignment() const override;
|
||||
|
||||
// Remove any kind of caching of data from the offset to offset+length
|
||||
// of this file. If the length is 0, then it refers to the end of file.
|
||||
// If the system is not caching the file contents, then this is a noop.
|
||||
virtual Status InvalidateCache(size_t offset, size_t length) override;
|
||||
};
|
||||
|
||||
// A file abstraction for sequential writing. The implementation
|
||||
// must provide buffering since callers may append small fragments
|
||||
// at a time to the file.
|
||||
class EncryptedWritableFile : public WritableFileWrapper {
|
||||
protected:
|
||||
std::unique_ptr<WritableFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
// Default ctor. Prefix is assumed to be written already.
|
||||
EncryptedWritableFile(std::unique_ptr<WritableFile>&& f,
|
||||
std::unique_ptr<BlockAccessCipherStream>&& s,
|
||||
size_t prefixLength)
|
||||
: WritableFileWrapper(f.get()),
|
||||
file_(std::move(f)),
|
||||
stream_(std::move(s)),
|
||||
prefixLength_(prefixLength) {}
|
||||
|
||||
Status Append(const Slice& data) override;
|
||||
|
||||
Status PositionedAppend(const Slice& data, uint64_t offset) override;
|
||||
|
||||
// Indicates the upper layers if the current WritableFile implementation
|
||||
// uses direct IO.
|
||||
virtual bool use_direct_io() const override;
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
virtual size_t GetRequiredBufferAlignment() const override;
|
||||
|
||||
/*
|
||||
* Get the size of valid data in the file.
|
||||
*/
|
||||
virtual uint64_t GetFileSize() override;
|
||||
|
||||
// Truncate is necessary to trim the file to the correct size
|
||||
// before closing. It is not always possible to keep track of the file
|
||||
// size due to whole pages writes. The behavior is undefined if called
|
||||
// with other writes to follow.
|
||||
virtual Status Truncate(uint64_t size) override;
|
||||
|
||||
// Remove any kind of caching of data from the offset to offset+length
|
||||
// of this file. If the length is 0, then it refers to the end of file.
|
||||
// If the system is not caching the file contents, then this is a noop.
|
||||
// This call has no effect on dirty pages in the cache.
|
||||
virtual Status InvalidateCache(size_t offset, size_t length) override;
|
||||
|
||||
// Sync a file range with disk.
|
||||
// offset is the starting byte of the file range to be synchronized.
|
||||
// nbytes specifies the length of the range to be synchronized.
|
||||
// This asks the OS to initiate flushing the cached data to disk,
|
||||
// without waiting for completion.
|
||||
// Default implementation does nothing.
|
||||
virtual Status RangeSync(uint64_t offset, uint64_t nbytes) override;
|
||||
|
||||
// PrepareWrite performs any necessary preparation for a write
|
||||
// before the write actually occurs. This allows for pre-allocation
|
||||
// of space on devices where it can result in less file
|
||||
// fragmentation and/or less waste from over-zealous filesystem
|
||||
// pre-allocation.
|
||||
virtual void PrepareWrite(size_t offset, size_t len) override;
|
||||
|
||||
// Pre-allocates space for a file.
|
||||
virtual Status Allocate(uint64_t offset, uint64_t len) override;
|
||||
};
|
||||
|
||||
// A file abstraction for random reading and writing.
|
||||
class EncryptedRandomRWFile : public RandomRWFile {
|
||||
protected:
|
||||
std::unique_ptr<RandomRWFile> file_;
|
||||
std::unique_ptr<BlockAccessCipherStream> stream_;
|
||||
size_t prefixLength_;
|
||||
|
||||
public:
|
||||
EncryptedRandomRWFile(std::unique_ptr<RandomRWFile>&& f,
|
||||
std::unique_ptr<BlockAccessCipherStream>&& s,
|
||||
size_t prefixLength)
|
||||
: file_(std::move(f)),
|
||||
stream_(std::move(s)),
|
||||
prefixLength_(prefixLength) {}
|
||||
|
||||
// Indicates if the class makes use of direct I/O
|
||||
// If false you must pass aligned buffer to Write()
|
||||
virtual bool use_direct_io() const override;
|
||||
|
||||
// Use the returned alignment value to allocate
|
||||
// aligned buffer for Direct I/O
|
||||
virtual size_t GetRequiredBufferAlignment() const override;
|
||||
|
||||
// Write bytes in `data` at offset `offset`, Returns Status::OK() on success.
|
||||
// Pass aligned buffer when use_direct_io() returns true.
|
||||
virtual Status Write(uint64_t offset, const Slice& data) override;
|
||||
|
||||
// Read up to `n` bytes starting from offset `offset` and store them in
|
||||
// result, provided `scratch` size should be at least `n`.
|
||||
// Returns Status::OK() on success.
|
||||
virtual Status Read(uint64_t offset, size_t n, Slice* result,
|
||||
char* scratch) const override;
|
||||
|
||||
virtual Status Flush() override;
|
||||
|
||||
virtual Status Sync() override;
|
||||
|
||||
virtual Status Fsync() override;
|
||||
|
||||
virtual Status Close() override;
|
||||
};
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
|
||||
#endif // !defined(ROCKSDB_LITE)
|
||||
@@ -117,7 +117,6 @@ enum class BackgroundErrorReason {
|
||||
kCompaction,
|
||||
kWriteCallback,
|
||||
kMemTable,
|
||||
kManifestWrite,
|
||||
};
|
||||
|
||||
enum class WriteStallCondition {
|
||||
|
||||
@@ -51,13 +51,6 @@ class InternalKeyComparator;
|
||||
class WalFilter;
|
||||
class FileSystem;
|
||||
|
||||
enum class CpuPriority {
|
||||
kIdle = 0,
|
||||
kLow = 1,
|
||||
kNormal = 2,
|
||||
kHigh = 3,
|
||||
};
|
||||
|
||||
// DB contents are stored in a set of blocks, each of which holds a
|
||||
// sequence of key,value pairs. Each block may be compressed before
|
||||
// being stored in a file. The following enum describes which
|
||||
|
||||
@@ -56,6 +56,12 @@ class PersistentCache {
|
||||
virtual StatsType Stats() = 0;
|
||||
|
||||
virtual std::string GetPrintableOptions() const = 0;
|
||||
|
||||
// Return a new numeric id. May be used by multiple clients who are
|
||||
// sharding the same persistent cache to partition the key space. Typically
|
||||
// the client will allocate a new id at startup and prepend the id to its
|
||||
// cache keys.
|
||||
virtual uint64_t NewId() = 0;
|
||||
};
|
||||
|
||||
// Factor method to create a new persistent cache
|
||||
|
||||
@@ -200,6 +200,40 @@ struct BlockBasedTableOptions {
|
||||
// incompatible with block-based filters.
|
||||
bool partition_filters = false;
|
||||
|
||||
// EXPERIMENTAL Option to generate Bloom filters that minimize memory
|
||||
// internal fragmentation.
|
||||
//
|
||||
// When false, malloc_usable_size is not available, or format_version < 5,
|
||||
// filters are generated without regard to internal fragmentation when
|
||||
// loaded into memory (historical behavior). When true (and
|
||||
// malloc_usable_size is available and format_version >= 5), then Bloom
|
||||
// filters are generated to "round up" and "round down" their sizes to
|
||||
// minimize internal fragmentation when loaded into memory, assuming the
|
||||
// reading DB has the same memory allocation characteristics as the
|
||||
// generating DB. This option does not break forward or backward
|
||||
// compatibility.
|
||||
//
|
||||
// While individual filters will vary in bits/key and false positive rate
|
||||
// when setting is true, the implementation attempts to maintain a weighted
|
||||
// average FP rate for filters consistent with this option set to false.
|
||||
//
|
||||
// With Jemalloc for example, this setting is expected to save about 10% of
|
||||
// the memory footprint and block cache charge of filters, while increasing
|
||||
// disk usage of filters by about 1-2% due to encoding efficiency losses
|
||||
// with variance in bits/key.
|
||||
//
|
||||
// NOTE: Because some memory counted by block cache might be unmapped pages
|
||||
// within internal fragmentation, this option can increase observed RSS
|
||||
// memory usage. With cache_index_and_filter_blocks=true, this option makes
|
||||
// the block cache better at using space it is allowed.
|
||||
//
|
||||
// NOTE: Do not set to true if you do not trust malloc_usable_size. With
|
||||
// this option, RocksDB might access an allocated memory object beyond its
|
||||
// original size if malloc_usable_size says it is safe to do so. While this
|
||||
// can be considered bad practice, it should not produce undefined behavior
|
||||
// unless malloc_usable_size is buggy or broken.
|
||||
bool optimize_filters_for_memory = false;
|
||||
|
||||
// Use delta encoding to compress keys in blocks.
|
||||
// ReadOptions::pin_data requires this option to be disabled.
|
||||
//
|
||||
|
||||
@@ -30,6 +30,8 @@ typedef std::map<std::string, std::string> UserCollectedProperties;
|
||||
|
||||
// table properties' human-readable names in the property block.
|
||||
struct TablePropertiesNames {
|
||||
static const std::string kDbId;
|
||||
static const std::string kDbSessionId;
|
||||
static const std::string kDataSize;
|
||||
static const std::string kIndexSize;
|
||||
static const std::string kIndexPartitions;
|
||||
@@ -193,6 +195,17 @@ struct TableProperties {
|
||||
// Actual SST file creation time. 0 means unknown.
|
||||
uint64_t file_creation_time = 0;
|
||||
|
||||
// DB identity
|
||||
// db_id is an identifier generated the first time the DB is created
|
||||
// If DB identity is unset or unassigned, `db_id` will be an empty string.
|
||||
std::string db_id;
|
||||
|
||||
// DB session identity
|
||||
// db_session_id is an identifier that gets reset every time the DB is opened
|
||||
// If DB session identity is unset or unassigned, `db_session_id` will be an
|
||||
// empty string.
|
||||
std::string db_session_id;
|
||||
|
||||
// Name of the column family with which this SST file is associated.
|
||||
// If column family is unknown, `column_family_name` will be an empty string.
|
||||
std::string column_family_name;
|
||||
|
||||
@@ -400,6 +400,10 @@ class StackableDB : public DB {
|
||||
return db_->GetDbIdentity(identity);
|
||||
}
|
||||
|
||||
virtual Status GetDbSessionId(std::string& session_id) const override {
|
||||
return db_->GetDbSessionId(session_id);
|
||||
}
|
||||
|
||||
using DB::SetOptions;
|
||||
virtual Status SetOptions(ColumnFamilyHandle* column_family_handle,
|
||||
const std::unordered_map<std::string, std::string>&
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define ROCKSDB_MAJOR 6
|
||||
#define ROCKSDB_MINOR 11
|
||||
#define ROCKSDB_PATCH 7
|
||||
#define ROCKSDB_PATCH 0
|
||||
|
||||
// Do not use these. We made the mistake of declaring macros starting with
|
||||
// double underscore. Now we have to live with our choice. We'll deprecate these
|
||||
|
||||
@@ -656,7 +656,7 @@ Status GetStringFromStruct(
|
||||
std::string* opt_string) {
|
||||
assert(opt_string);
|
||||
opt_string->clear();
|
||||
for (const auto iter : type_info) {
|
||||
for (const auto& iter : type_info) {
|
||||
const auto& opt_info = iter.second;
|
||||
// If the option is no longer used in rocksdb and marked as deprecated,
|
||||
// we skip it in the serialization.
|
||||
|
||||
@@ -42,10 +42,10 @@ const char kSpecialChar = 'z';
|
||||
typedef std::vector<std::pair<size_t, size_t>> OffsetGap;
|
||||
|
||||
void FillWithSpecialChar(char* start_ptr, size_t total_size,
|
||||
const OffsetGap& blacklist,
|
||||
const OffsetGap& excluded,
|
||||
char special_char = kSpecialChar) {
|
||||
size_t offset = 0;
|
||||
for (auto& pair : blacklist) {
|
||||
for (auto& pair : excluded) {
|
||||
std::memset(start_ptr + offset, special_char, pair.first - offset);
|
||||
offset = pair.first + pair.second;
|
||||
}
|
||||
@@ -53,10 +53,10 @@ void FillWithSpecialChar(char* start_ptr, size_t total_size,
|
||||
}
|
||||
|
||||
int NumUnsetBytes(char* start_ptr, size_t total_size,
|
||||
const OffsetGap& blacklist) {
|
||||
const OffsetGap& excluded) {
|
||||
int total_unset_bytes_base = 0;
|
||||
size_t offset = 0;
|
||||
for (auto& pair : blacklist) {
|
||||
for (auto& pair : excluded) {
|
||||
for (char* ptr = start_ptr + offset; ptr < start_ptr + pair.first; ptr++) {
|
||||
if (*ptr == kSpecialChar) {
|
||||
total_unset_bytes_base++;
|
||||
@@ -72,11 +72,11 @@ int NumUnsetBytes(char* start_ptr, size_t total_size,
|
||||
return total_unset_bytes_base;
|
||||
}
|
||||
|
||||
// Return true iff two structs are the same except blacklist fields.
|
||||
// Return true iff two structs are the same except excluded fields.
|
||||
bool CompareBytes(char* start_ptr1, char* start_ptr2, size_t total_size,
|
||||
const OffsetGap& blacklist) {
|
||||
const OffsetGap& excluded) {
|
||||
size_t offset = 0;
|
||||
for (auto& pair : blacklist) {
|
||||
for (auto& pair : excluded) {
|
||||
for (; offset < pair.first; offset++) {
|
||||
if (*(start_ptr1 + offset) != *(start_ptr2 + offset)) {
|
||||
return false;
|
||||
@@ -99,11 +99,11 @@ bool CompareBytes(char* start_ptr1, char* start_ptr2, size_t total_size,
|
||||
// GetBlockBasedTableOptionsFromString() and add the option to the input string
|
||||
// passed to the GetBlockBasedTableOptionsFromString() in this test.
|
||||
// If it is a complicated type, you also need to add the field to
|
||||
// kBbtoBlacklist, and maybe add customized verification for it.
|
||||
// kBbtoExcluded, and maybe add customized verification for it.
|
||||
TEST_F(OptionsSettableTest, BlockBasedTableOptionsAllFieldsSettable) {
|
||||
// Items in the form of <offset, size>. Need to be in ascending order
|
||||
// and not overlapping. Need to updated if new pointer-option is added.
|
||||
const OffsetGap kBbtoBlacklist = {
|
||||
const OffsetGap kBbtoExcluded = {
|
||||
{offsetof(struct BlockBasedTableOptions, flush_block_policy_factory),
|
||||
sizeof(std::shared_ptr<FlushBlockPolicyFactory>)},
|
||||
{offsetof(struct BlockBasedTableOptions, block_cache),
|
||||
@@ -128,20 +128,20 @@ TEST_F(OptionsSettableTest, BlockBasedTableOptionsAllFieldsSettable) {
|
||||
// copy a well constructed struct to this memory and see how many special
|
||||
// bytes left.
|
||||
BlockBasedTableOptions* bbto = new (bbto_ptr) BlockBasedTableOptions();
|
||||
FillWithSpecialChar(bbto_ptr, sizeof(BlockBasedTableOptions), kBbtoBlacklist);
|
||||
FillWithSpecialChar(bbto_ptr, sizeof(BlockBasedTableOptions), kBbtoExcluded);
|
||||
// It based on the behavior of compiler that padding bytes are not changed
|
||||
// when copying the struct. It's prone to failure when compiler behavior
|
||||
// changes. We verify there is unset bytes to detect the case.
|
||||
*bbto = BlockBasedTableOptions();
|
||||
int unset_bytes_base =
|
||||
NumUnsetBytes(bbto_ptr, sizeof(BlockBasedTableOptions), kBbtoBlacklist);
|
||||
NumUnsetBytes(bbto_ptr, sizeof(BlockBasedTableOptions), kBbtoExcluded);
|
||||
ASSERT_GT(unset_bytes_base, 0);
|
||||
bbto->~BlockBasedTableOptions();
|
||||
|
||||
// Construct the base option passed into
|
||||
// GetBlockBasedTableOptionsFromString().
|
||||
bbto = new (bbto_ptr) BlockBasedTableOptions();
|
||||
FillWithSpecialChar(bbto_ptr, sizeof(BlockBasedTableOptions), kBbtoBlacklist);
|
||||
FillWithSpecialChar(bbto_ptr, sizeof(BlockBasedTableOptions), kBbtoExcluded);
|
||||
// This option is not setable:
|
||||
bbto->use_delta_encoding = true;
|
||||
|
||||
@@ -149,7 +149,7 @@ TEST_F(OptionsSettableTest, BlockBasedTableOptionsAllFieldsSettable) {
|
||||
BlockBasedTableOptions* new_bbto =
|
||||
new (new_bbto_ptr) BlockBasedTableOptions();
|
||||
FillWithSpecialChar(new_bbto_ptr, sizeof(BlockBasedTableOptions),
|
||||
kBbtoBlacklist);
|
||||
kBbtoExcluded);
|
||||
|
||||
// Need to update the option string if a new option is added.
|
||||
ASSERT_OK(GetBlockBasedTableOptionsFromString(
|
||||
@@ -167,6 +167,7 @@ TEST_F(OptionsSettableTest, BlockBasedTableOptionsAllFieldsSettable) {
|
||||
"block_size_deviation=8;block_restart_interval=4; "
|
||||
"metadata_block_size=1024;"
|
||||
"partition_filters=false;"
|
||||
"optimize_filters_for_memory=true;"
|
||||
"index_block_restart_interval=4;"
|
||||
"filter_policy=bloomfilter:4:true;whole_key_filtering=1;"
|
||||
"format_version=1;"
|
||||
@@ -178,7 +179,7 @@ TEST_F(OptionsSettableTest, BlockBasedTableOptionsAllFieldsSettable) {
|
||||
|
||||
ASSERT_EQ(unset_bytes_base,
|
||||
NumUnsetBytes(new_bbto_ptr, sizeof(BlockBasedTableOptions),
|
||||
kBbtoBlacklist));
|
||||
kBbtoExcluded));
|
||||
|
||||
ASSERT_TRUE(new_bbto->block_cache.get() != nullptr);
|
||||
ASSERT_TRUE(new_bbto->block_cache_compressed.get() != nullptr);
|
||||
@@ -198,9 +199,9 @@ TEST_F(OptionsSettableTest, BlockBasedTableOptionsAllFieldsSettable) {
|
||||
// GetDBOptionsFromString() and add the option to the input string passed to
|
||||
// DBOptionsFromString()in this test.
|
||||
// If it is a complicated type, you also need to add the field to
|
||||
// kDBOptionsBlacklist, and maybe add customized verification for it.
|
||||
// kDBOptionsExcluded, and maybe add customized verification for it.
|
||||
TEST_F(OptionsSettableTest, DBOptionsAllFieldsSettable) {
|
||||
const OffsetGap kDBOptionsBlacklist = {
|
||||
const OffsetGap kDBOptionsExcluded = {
|
||||
{offsetof(struct DBOptions, env), sizeof(Env*)},
|
||||
{offsetof(struct DBOptions, rate_limiter),
|
||||
sizeof(std::shared_ptr<RateLimiter>)},
|
||||
@@ -228,22 +229,22 @@ TEST_F(OptionsSettableTest, DBOptionsAllFieldsSettable) {
|
||||
// copy a well constructed struct to this memory and see how many special
|
||||
// bytes left.
|
||||
DBOptions* options = new (options_ptr) DBOptions();
|
||||
FillWithSpecialChar(options_ptr, sizeof(DBOptions), kDBOptionsBlacklist);
|
||||
FillWithSpecialChar(options_ptr, sizeof(DBOptions), kDBOptionsExcluded);
|
||||
// It based on the behavior of compiler that padding bytes are not changed
|
||||
// when copying the struct. It's prone to failure when compiler behavior
|
||||
// changes. We verify there is unset bytes to detect the case.
|
||||
*options = DBOptions();
|
||||
int unset_bytes_base =
|
||||
NumUnsetBytes(options_ptr, sizeof(DBOptions), kDBOptionsBlacklist);
|
||||
NumUnsetBytes(options_ptr, sizeof(DBOptions), kDBOptionsExcluded);
|
||||
ASSERT_GT(unset_bytes_base, 0);
|
||||
options->~DBOptions();
|
||||
|
||||
options = new (options_ptr) DBOptions();
|
||||
FillWithSpecialChar(options_ptr, sizeof(DBOptions), kDBOptionsBlacklist);
|
||||
FillWithSpecialChar(options_ptr, sizeof(DBOptions), kDBOptionsExcluded);
|
||||
|
||||
char* new_options_ptr = new char[sizeof(DBOptions)];
|
||||
DBOptions* new_options = new (new_options_ptr) DBOptions();
|
||||
FillWithSpecialChar(new_options_ptr, sizeof(DBOptions), kDBOptionsBlacklist);
|
||||
FillWithSpecialChar(new_options_ptr, sizeof(DBOptions), kDBOptionsExcluded);
|
||||
|
||||
// Need to update the option string if a new option is added.
|
||||
ASSERT_OK(
|
||||
@@ -327,7 +328,7 @@ TEST_F(OptionsSettableTest, DBOptionsAllFieldsSettable) {
|
||||
new_options));
|
||||
|
||||
ASSERT_EQ(unset_bytes_base, NumUnsetBytes(new_options_ptr, sizeof(DBOptions),
|
||||
kDBOptionsBlacklist));
|
||||
kDBOptionsExcluded));
|
||||
|
||||
options->~DBOptions();
|
||||
new_options->~DBOptions();
|
||||
@@ -349,12 +350,12 @@ inline int offset_of(T1 T2::*member) {
|
||||
// GetColumnFamilyOptionsFromString() and add the option to the input
|
||||
// string passed to GetColumnFamilyOptionsFromString()in this test.
|
||||
// If it is a complicated type, you also need to add the field to
|
||||
// kColumnFamilyOptionsBlacklist, and maybe add customized verification
|
||||
// kColumnFamilyOptionsExcluded, and maybe add customized verification
|
||||
// for it.
|
||||
TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
// options in the blacklist need to appear in the same order as in
|
||||
// options in the excluded set need to appear in the same order as in
|
||||
// ColumnFamilyOptions.
|
||||
const OffsetGap kColumnFamilyOptionsBlacklist = {
|
||||
const OffsetGap kColumnFamilyOptionsExcluded = {
|
||||
{offset_of(&ColumnFamilyOptions::inplace_callback),
|
||||
sizeof(UpdateStatus(*)(char*, uint32_t*, Slice, std::string*))},
|
||||
{offset_of(
|
||||
@@ -393,7 +394,7 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
// bytes left.
|
||||
ColumnFamilyOptions* options = new (options_ptr) ColumnFamilyOptions();
|
||||
FillWithSpecialChar(options_ptr, sizeof(ColumnFamilyOptions),
|
||||
kColumnFamilyOptionsBlacklist);
|
||||
kColumnFamilyOptionsExcluded);
|
||||
|
||||
// It based on the behavior of compiler that padding bytes are not changed
|
||||
// when copying the struct. It's prone to failure when compiler behavior
|
||||
@@ -405,13 +406,13 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
options->max_mem_compaction_level = 0;
|
||||
|
||||
int unset_bytes_base = NumUnsetBytes(options_ptr, sizeof(ColumnFamilyOptions),
|
||||
kColumnFamilyOptionsBlacklist);
|
||||
kColumnFamilyOptionsExcluded);
|
||||
ASSERT_GT(unset_bytes_base, 0);
|
||||
options->~ColumnFamilyOptions();
|
||||
|
||||
options = new (options_ptr) ColumnFamilyOptions();
|
||||
FillWithSpecialChar(options_ptr, sizeof(ColumnFamilyOptions),
|
||||
kColumnFamilyOptionsBlacklist);
|
||||
kColumnFamilyOptionsExcluded);
|
||||
|
||||
// Following options are not settable through
|
||||
// GetColumnFamilyOptionsFromString():
|
||||
@@ -427,7 +428,7 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
ColumnFamilyOptions* new_options =
|
||||
new (new_options_ptr) ColumnFamilyOptions();
|
||||
FillWithSpecialChar(new_options_ptr, sizeof(ColumnFamilyOptions),
|
||||
kColumnFamilyOptionsBlacklist);
|
||||
kColumnFamilyOptionsExcluded);
|
||||
|
||||
// Need to update the option string if a new option is added.
|
||||
ASSERT_OK(GetColumnFamilyOptionsFromString(
|
||||
@@ -490,7 +491,7 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
|
||||
ASSERT_EQ(unset_bytes_base,
|
||||
NumUnsetBytes(new_options_ptr, sizeof(ColumnFamilyOptions),
|
||||
kColumnFamilyOptionsBlacklist));
|
||||
kColumnFamilyOptionsExcluded));
|
||||
|
||||
ColumnFamilyOptions rnd_filled_options = *new_options;
|
||||
|
||||
@@ -502,7 +503,7 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
|
||||
// Test copying to mutabable and immutable options and copy back the mutable
|
||||
// part.
|
||||
const OffsetGap kMutableCFOptionsBlacklist = {
|
||||
const OffsetGap kMutableCFOptionsExcluded = {
|
||||
{offset_of(&MutableCFOptions::prefix_extractor),
|
||||
sizeof(std::shared_ptr<const SliceTransform>)},
|
||||
{offset_of(&MutableCFOptions::max_bytes_for_level_multiplier_additional),
|
||||
@@ -517,16 +518,16 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
const char kMySpecialChar = 'x';
|
||||
char* mcfo1_ptr = new char[sizeof(MutableCFOptions)];
|
||||
FillWithSpecialChar(mcfo1_ptr, sizeof(MutableCFOptions),
|
||||
kMutableCFOptionsBlacklist, kMySpecialChar);
|
||||
kMutableCFOptionsExcluded, kMySpecialChar);
|
||||
char* mcfo2_ptr = new char[sizeof(MutableCFOptions)];
|
||||
FillWithSpecialChar(mcfo2_ptr, sizeof(MutableCFOptions),
|
||||
kMutableCFOptionsBlacklist, kMySpecialChar);
|
||||
kMutableCFOptionsExcluded, kMySpecialChar);
|
||||
|
||||
// A clean column family options is constructed after filling the same special
|
||||
// char as the initial one. So that the padding bytes are the same.
|
||||
char* cfo_clean_ptr = new char[sizeof(ColumnFamilyOptions)];
|
||||
FillWithSpecialChar(cfo_clean_ptr, sizeof(ColumnFamilyOptions),
|
||||
kColumnFamilyOptionsBlacklist);
|
||||
kColumnFamilyOptionsExcluded);
|
||||
rnd_filled_options.num_levels = 66;
|
||||
ColumnFamilyOptions* cfo_clean = new (cfo_clean_ptr) ColumnFamilyOptions();
|
||||
|
||||
@@ -536,7 +537,7 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) {
|
||||
MutableCFOptions* mcfo2 = new (mcfo2_ptr) MutableCFOptions(cfo_back);
|
||||
|
||||
ASSERT_TRUE(CompareBytes(mcfo1_ptr, mcfo2_ptr, sizeof(MutableCFOptions),
|
||||
kMutableCFOptionsBlacklist));
|
||||
kMutableCFOptionsExcluded));
|
||||
|
||||
cfo_clean->~ColumnFamilyOptions();
|
||||
mcfo1->~MutableCFOptions();
|
||||
|
||||
+6
-14
@@ -647,12 +647,7 @@ TEST_F(OptionsTest, GetBlockBasedTableOptionsFromString) {
|
||||
"block_cache=1M;block_cache_compressed=1k;block_size=1024;"
|
||||
"block_size_deviation=8;block_restart_interval=4;"
|
||||
"format_version=5;whole_key_filtering=1;"
|
||||
"filter_policy=bloomfilter:4.567:false;"
|
||||
// A bug caused read_amp_bytes_per_bit to be a large integer in OPTIONS
|
||||
// file generated by 6.10 to 6.14. Though bug is fixed in these releases,
|
||||
// we need to handle the case of loading OPTIONS file generated before the
|
||||
// fix.
|
||||
"read_amp_bytes_per_bit=17179869185;",
|
||||
"filter_policy=bloomfilter:4.567:false;",
|
||||
&new_opt));
|
||||
ASSERT_TRUE(new_opt.cache_index_and_filter_blocks);
|
||||
ASSERT_EQ(new_opt.index_type, BlockBasedTableOptions::kHashSearch);
|
||||
@@ -673,9 +668,6 @@ TEST_F(OptionsTest, GetBlockBasedTableOptionsFromString) {
|
||||
dynamic_cast<const BloomFilterPolicy&>(*new_opt.filter_policy);
|
||||
EXPECT_EQ(bfp.GetMillibitsPerKey(), 4567);
|
||||
EXPECT_EQ(bfp.GetWholeBitsPerKey(), 5);
|
||||
// Verify that only the lower 32bits are stored in
|
||||
// new_opt.read_amp_bytes_per_bit.
|
||||
EXPECT_EQ(1U, new_opt.read_amp_bytes_per_bit);
|
||||
|
||||
// unknown option
|
||||
ASSERT_NOK(GetBlockBasedTableOptionsFromString(
|
||||
@@ -1287,7 +1279,7 @@ TEST_F(OptionsTest, ConvertOptionsTest) {
|
||||
// This test suite tests the old APIs into the Configure options methods.
|
||||
// Once those APIs are officially deprecated, this test suite can be deleted.
|
||||
class OptionsOldApiTest : public testing::Test {};
|
||||
|
||||
|
||||
TEST_F(OptionsOldApiTest, GetOptionsFromMapTest) {
|
||||
std::unordered_map<std::string, std::string> cf_options_map = {
|
||||
{"write_buffer_size", "1"},
|
||||
@@ -1752,7 +1744,7 @@ TEST_F(OptionsOldApiTest, GetColumnFamilyOptionsFromStringTest) {
|
||||
ASSERT_TRUE(new_cf_opt.memtable_factory != nullptr);
|
||||
ASSERT_EQ(std::string(new_cf_opt.memtable_factory->Name()), "SkipListFactory");
|
||||
}
|
||||
|
||||
|
||||
TEST_F(OptionsOldApiTest, GetBlockBasedTableOptionsFromString) {
|
||||
BlockBasedTableOptions table_opt;
|
||||
BlockBasedTableOptions new_opt;
|
||||
@@ -1927,7 +1919,7 @@ TEST_F(OptionsOldApiTest, GetBlockBasedTableOptionsFromString) {
|
||||
->GetHighPriPoolRatio(),
|
||||
0.5);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(OptionsOldApiTest, GetPlainTableOptionsFromString) {
|
||||
PlainTableOptions table_opt;
|
||||
PlainTableOptions new_opt;
|
||||
@@ -1958,7 +1950,7 @@ TEST_F(OptionsOldApiTest, GetPlainTableOptionsFromString) {
|
||||
"encoding_type=kPrefixXX",
|
||||
&new_opt));
|
||||
}
|
||||
|
||||
|
||||
TEST_F(OptionsOldApiTest, GetOptionsFromStringTest) {
|
||||
Options base_options, new_options;
|
||||
base_options.write_buffer_size = 20;
|
||||
@@ -2516,7 +2508,7 @@ TEST_F(OptionsParserTest, Readahead) {
|
||||
uint64_t file_size = 0;
|
||||
ASSERT_OK(env_->GetFileSize(kOptionsFileName, &file_size));
|
||||
assert(file_size > 0);
|
||||
|
||||
|
||||
RocksDBOptionsParser parser;
|
||||
|
||||
env_->num_seq_file_read_ = 0;
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ namespace port {
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD)
|
||||
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_GNU_KFREEBSD)
|
||||
const char* GetExecutableName() {
|
||||
static char name[1024];
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ LIB_SOURCES = \
|
||||
tools/dump/db_dump_tool.cc \
|
||||
trace_replay/trace_replay.cc \
|
||||
trace_replay/block_cache_tracer.cc \
|
||||
trace_replay/io_tracer.cc \
|
||||
util/build_version.cc \
|
||||
util/coding.cc \
|
||||
util/compaction_job_stats_impl.cc \
|
||||
@@ -437,8 +438,9 @@ MAIN_SOURCES = \
|
||||
tools/ldb_cmd_test.cc \
|
||||
tools/reduce_levels_test.cc \
|
||||
tools/sst_dump_test.cc \
|
||||
tools/trace_analyzer_test.cc \
|
||||
tools/trace_analyzer_test.cc \
|
||||
trace_replay/block_cache_tracer_test.cc \
|
||||
trace_replay/io_tracer_test.cc \
|
||||
util/autovector_test.cc \
|
||||
util/bloom_test.cc \
|
||||
util/coding_test.cc \
|
||||
|
||||
@@ -374,6 +374,10 @@ struct BlockBasedTableBuilder::Rep {
|
||||
const uint64_t target_file_size;
|
||||
uint64_t file_creation_time = 0;
|
||||
|
||||
// DB IDs
|
||||
const std::string db_id;
|
||||
const std::string db_session_id;
|
||||
|
||||
std::vector<std::unique_ptr<IntTblPropCollector>> table_properties_collectors;
|
||||
|
||||
std::unique_ptr<ParallelCompressionRep> pc_rep;
|
||||
@@ -447,7 +451,8 @@ struct BlockBasedTableBuilder::Rep {
|
||||
const CompressionOptions& _compression_opts, const bool skip_filters,
|
||||
const int _level_at_creation, const std::string& _column_family_name,
|
||||
const uint64_t _creation_time, const uint64_t _oldest_key_time,
|
||||
const uint64_t _target_file_size, const uint64_t _file_creation_time)
|
||||
const uint64_t _target_file_size, const uint64_t _file_creation_time,
|
||||
const std::string& _db_id, const std::string& _db_session_id)
|
||||
: ioptions(_ioptions),
|
||||
moptions(_moptions),
|
||||
table_options(table_opt),
|
||||
@@ -488,7 +493,9 @@ struct BlockBasedTableBuilder::Rep {
|
||||
creation_time(_creation_time),
|
||||
oldest_key_time(_oldest_key_time),
|
||||
target_file_size(_target_file_size),
|
||||
file_creation_time(_file_creation_time) {
|
||||
file_creation_time(_file_creation_time),
|
||||
db_id(_db_id),
|
||||
db_session_id(_db_session_id) {
|
||||
for (uint32_t i = 0; i < compression_opts.parallel_threads; i++) {
|
||||
compression_ctxs[i].reset(new CompressionContext(compression_type));
|
||||
}
|
||||
@@ -698,7 +705,8 @@ BlockBasedTableBuilder::BlockBasedTableBuilder(
|
||||
const CompressionOptions& compression_opts, const bool skip_filters,
|
||||
const std::string& column_family_name, const int level_at_creation,
|
||||
const uint64_t creation_time, const uint64_t oldest_key_time,
|
||||
const uint64_t target_file_size, const uint64_t file_creation_time) {
|
||||
const uint64_t target_file_size, const uint64_t file_creation_time,
|
||||
const std::string& db_id, const std::string& db_session_id) {
|
||||
BlockBasedTableOptions sanitized_table_options(table_options);
|
||||
if (sanitized_table_options.format_version == 0 &&
|
||||
sanitized_table_options.checksum != kCRC32c) {
|
||||
@@ -711,18 +719,18 @@ BlockBasedTableBuilder::BlockBasedTableBuilder(
|
||||
sanitized_table_options.format_version = 1;
|
||||
}
|
||||
|
||||
rep_ = new Rep(ioptions, moptions, sanitized_table_options,
|
||||
internal_comparator, int_tbl_prop_collector_factories,
|
||||
column_family_id, file, compression_type,
|
||||
sample_for_compression, compression_opts, skip_filters,
|
||||
level_at_creation, column_family_name, creation_time,
|
||||
oldest_key_time, target_file_size, file_creation_time);
|
||||
rep_ = new Rep(
|
||||
ioptions, moptions, sanitized_table_options, internal_comparator,
|
||||
int_tbl_prop_collector_factories, column_family_id, file,
|
||||
compression_type, sample_for_compression, compression_opts, skip_filters,
|
||||
level_at_creation, column_family_name, creation_time, oldest_key_time,
|
||||
target_file_size, file_creation_time, db_id, db_session_id);
|
||||
|
||||
if (rep_->filter_builder != nullptr) {
|
||||
rep_->filter_builder->StartBlock(0);
|
||||
}
|
||||
if (table_options.block_cache_compressed.get() != nullptr) {
|
||||
BlockBasedTable::GenerateCachePrefix(
|
||||
BlockBasedTable::GenerateCachePrefix<Cache, FSWritableFile>(
|
||||
table_options.block_cache_compressed.get(), file->writable_file(),
|
||||
&rep_->compressed_cache_key_prefix[0],
|
||||
&rep_->compressed_cache_key_prefix_size);
|
||||
@@ -1085,42 +1093,43 @@ void BlockBasedTableBuilder::WriteRawBlock(const Slice& block_contents,
|
||||
if (io_s.ok()) {
|
||||
char trailer[kBlockTrailerSize];
|
||||
trailer[0] = type;
|
||||
char* trailer_without_type = trailer + 1;
|
||||
uint32_t checksum = 0;
|
||||
switch (r->table_options.checksum) {
|
||||
case kNoChecksum:
|
||||
EncodeFixed32(trailer_without_type, 0);
|
||||
break;
|
||||
case kCRC32c: {
|
||||
auto crc = crc32c::Value(block_contents.data(), block_contents.size());
|
||||
crc = crc32c::Extend(crc, trailer, 1); // Extend to cover block type
|
||||
EncodeFixed32(trailer_without_type, crc32c::Mask(crc));
|
||||
uint32_t crc =
|
||||
crc32c::Value(block_contents.data(), block_contents.size());
|
||||
// Extend to cover compression type
|
||||
crc = crc32c::Extend(crc, trailer, 1);
|
||||
checksum = crc32c::Mask(crc);
|
||||
break;
|
||||
}
|
||||
case kxxHash: {
|
||||
XXH32_state_t* const state = XXH32_createState();
|
||||
XXH32_reset(state, 0);
|
||||
XXH32_update(state, block_contents.data(),
|
||||
static_cast<uint32_t>(block_contents.size()));
|
||||
XXH32_update(state, trailer, 1); // Extend to cover block type
|
||||
EncodeFixed32(trailer_without_type, XXH32_digest(state));
|
||||
XXH32_update(state, block_contents.data(), block_contents.size());
|
||||
// Extend to cover compression type
|
||||
XXH32_update(state, trailer, 1);
|
||||
checksum = XXH32_digest(state);
|
||||
XXH32_freeState(state);
|
||||
break;
|
||||
}
|
||||
case kxxHash64: {
|
||||
XXH64_state_t* const state = XXH64_createState();
|
||||
XXH64_reset(state, 0);
|
||||
XXH64_update(state, block_contents.data(),
|
||||
static_cast<uint32_t>(block_contents.size()));
|
||||
XXH64_update(state, trailer, 1); // Extend to cover block type
|
||||
EncodeFixed32(
|
||||
trailer_without_type,
|
||||
static_cast<uint32_t>(XXH64_digest(state) & // lower 32 bits
|
||||
uint64_t{0xffffffff}));
|
||||
XXH64_update(state, block_contents.data(), block_contents.size());
|
||||
// Extend to cover compression type
|
||||
XXH64_update(state, trailer, 1);
|
||||
checksum = Lower32of64(XXH64_digest(state));
|
||||
XXH64_freeState(state);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
EncodeFixed32(trailer + 1, checksum);
|
||||
assert(io_s.ok());
|
||||
TEST_SYNC_POINT_CALLBACK(
|
||||
"BlockBasedTableBuilder::WriteRawBlock:TamperWithChecksum",
|
||||
@@ -1445,6 +1454,8 @@ void BlockBasedTableBuilder::WritePropertiesBlock(
|
||||
rep_->props.creation_time = rep_->creation_time;
|
||||
rep_->props.oldest_key_time = rep_->oldest_key_time;
|
||||
rep_->props.file_creation_time = rep_->file_creation_time;
|
||||
rep_->props.db_id = rep_->db_id;
|
||||
rep_->props.db_session_id = rep_->db_session_id;
|
||||
|
||||
// Add basic properties
|
||||
property_block_builder.AddTableProperty(rep_->props);
|
||||
|
||||
@@ -51,7 +51,8 @@ class BlockBasedTableBuilder : public TableBuilder {
|
||||
const std::string& column_family_name, const int level_at_creation,
|
||||
const uint64_t creation_time = 0, const uint64_t oldest_key_time = 0,
|
||||
const uint64_t target_file_size = 0,
|
||||
const uint64_t file_creation_time = 0);
|
||||
const uint64_t file_creation_time = 0, const std::string& db_id = "",
|
||||
const std::string& db_session_id = "");
|
||||
|
||||
// No copying allowed
|
||||
BlockBasedTableBuilder(const BlockBasedTableBuilder&) = delete;
|
||||
|
||||
@@ -268,6 +268,10 @@ static std::unordered_map<std::string, OptionTypeInfo>
|
||||
{offsetof(struct BlockBasedTableOptions, partition_filters),
|
||||
OptionType::kBoolean, OptionVerificationType::kNormal,
|
||||
OptionTypeFlags::kNone, 0}},
|
||||
{"optimize_filters_for_memory",
|
||||
{offsetof(struct BlockBasedTableOptions, optimize_filters_for_memory),
|
||||
OptionType::kBoolean, OptionVerificationType::kNormal,
|
||||
OptionTypeFlags::kNone, 0}},
|
||||
{"filter_policy",
|
||||
{offsetof(struct BlockBasedTableOptions, filter_policy),
|
||||
OptionType::kUnknown, OptionVerificationType::kByNameAllowFromNull,
|
||||
@@ -327,24 +331,8 @@ static std::unordered_map<std::string, OptionTypeInfo>
|
||||
OptionTypeFlags::kNone, 0}},
|
||||
{"read_amp_bytes_per_bit",
|
||||
{offsetof(struct BlockBasedTableOptions, read_amp_bytes_per_bit),
|
||||
OptionType::kUInt32T, OptionVerificationType::kNormal,
|
||||
OptionTypeFlags::kNone, 0,
|
||||
[](const ConfigOptions& /*opts*/, const std::string& /*name*/,
|
||||
const std::string& value, char* addr) {
|
||||
// A workaround to fix a bug in 6.10, 6.11, 6.12, 6.13
|
||||
// and 6.14. The bug will write out 8 bytes to OPTIONS file from the
|
||||
// starting address of BlockBasedTableOptions.read_amp_bytes_per_bit
|
||||
// which is actually a uint32. Consequently, the value of
|
||||
// read_amp_bytes_per_bit written in the OPTIONS file is wrong.
|
||||
// From 6.15, RocksDB will try to parse the read_amp_bytes_per_bit
|
||||
// from OPTIONS file as a uint32. To be able to load OPTIONS file
|
||||
// generated by affected releases before the fix, we need to
|
||||
// manually parse read_amp_bytes_per_bit with this special hack.
|
||||
uint64_t read_amp_bytes_per_bit = ParseUint64(value);
|
||||
*(reinterpret_cast<uint32_t*>(addr)) =
|
||||
static_cast<uint32_t>(read_amp_bytes_per_bit);
|
||||
return Status::OK();
|
||||
}}},
|
||||
OptionType::kSizeT, OptionVerificationType::kNormal,
|
||||
OptionTypeFlags::kNone, 0}},
|
||||
{"enable_index_compression",
|
||||
{offsetof(struct BlockBasedTableOptions, enable_index_compression),
|
||||
OptionType::kBoolean, OptionVerificationType::kNormal,
|
||||
@@ -455,7 +443,8 @@ TableBuilder* BlockBasedTableFactory::NewTableBuilder(
|
||||
table_builder_options.creation_time,
|
||||
table_builder_options.oldest_key_time,
|
||||
table_builder_options.target_file_size,
|
||||
table_builder_options.file_creation_time);
|
||||
table_builder_options.file_creation_time, table_builder_options.db_id,
|
||||
table_builder_options.db_session_id);
|
||||
|
||||
return table_builder;
|
||||
}
|
||||
|
||||
@@ -452,44 +452,21 @@ void BlockBasedTable::SetupCacheKeyPrefix(Rep* rep) {
|
||||
rep->cache_key_prefix_size = 0;
|
||||
rep->compressed_cache_key_prefix_size = 0;
|
||||
if (rep->table_options.block_cache != nullptr) {
|
||||
GenerateCachePrefix(rep->table_options.block_cache.get(), rep->file->file(),
|
||||
&rep->cache_key_prefix[0], &rep->cache_key_prefix_size);
|
||||
GenerateCachePrefix<Cache, FSRandomAccessFile>(
|
||||
rep->table_options.block_cache.get(), rep->file->file(),
|
||||
&rep->cache_key_prefix[0], &rep->cache_key_prefix_size);
|
||||
}
|
||||
if (rep->table_options.persistent_cache != nullptr) {
|
||||
GenerateCachePrefix(/*cache=*/nullptr, rep->file->file(),
|
||||
&rep->persistent_cache_key_prefix[0],
|
||||
&rep->persistent_cache_key_prefix_size);
|
||||
GenerateCachePrefix<PersistentCache, FSRandomAccessFile>(
|
||||
rep->table_options.persistent_cache.get(), rep->file->file(),
|
||||
&rep->persistent_cache_key_prefix[0],
|
||||
&rep->persistent_cache_key_prefix_size);
|
||||
}
|
||||
if (rep->table_options.block_cache_compressed != nullptr) {
|
||||
GenerateCachePrefix(rep->table_options.block_cache_compressed.get(),
|
||||
rep->file->file(), &rep->compressed_cache_key_prefix[0],
|
||||
&rep->compressed_cache_key_prefix_size);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockBasedTable::GenerateCachePrefix(Cache* cc, FSRandomAccessFile* file,
|
||||
char* buffer, size_t* size) {
|
||||
// generate an id from the file
|
||||
*size = file->GetUniqueId(buffer, kMaxCacheKeyPrefixSize);
|
||||
|
||||
// If the prefix wasn't generated or was too long,
|
||||
// create one from the cache.
|
||||
if (cc != nullptr && *size == 0) {
|
||||
char* end = EncodeVarint64(buffer, cc->NewId());
|
||||
*size = static_cast<size_t>(end - buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockBasedTable::GenerateCachePrefix(Cache* cc, FSWritableFile* file,
|
||||
char* buffer, size_t* size) {
|
||||
// generate an id from the file
|
||||
*size = file->GetUniqueId(buffer, kMaxCacheKeyPrefixSize);
|
||||
|
||||
// If the prefix wasn't generated or was too long,
|
||||
// create one from the cache.
|
||||
if (cc != nullptr && *size == 0) {
|
||||
char* end = EncodeVarint64(buffer, cc->NewId());
|
||||
*size = static_cast<size_t>(end - buffer);
|
||||
GenerateCachePrefix<Cache, FSRandomAccessFile>(
|
||||
rep->table_options.block_cache_compressed.get(), rep->file->file(),
|
||||
&rep->compressed_cache_key_prefix[0],
|
||||
&rep->compressed_cache_key_prefix_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,9 +776,9 @@ Status BlockBasedTable::TryReadPropertiesWithGlobalSeqno(
|
||||
EncodeFixed64(
|
||||
tmp_buf.get() + global_seqno_offset - props_block_handle.offset(), 0);
|
||||
}
|
||||
uint32_t value = DecodeFixed32(tmp_buf.get() + block_size + 1);
|
||||
s = ROCKSDB_NAMESPACE::VerifyChecksum(rep_->footer.checksum(),
|
||||
tmp_buf.get(), block_size + 1, value);
|
||||
s = ROCKSDB_NAMESPACE::VerifyBlockChecksum(
|
||||
rep_->footer.checksum(), tmp_buf.get(), block_size,
|
||||
rep_->file->file_name(), props_block_handle.offset());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -1751,15 +1728,14 @@ void BlockBasedTable::RetrieveMultipleBlocks(
|
||||
if (options.verify_checksums) {
|
||||
PERF_TIMER_GUARD(block_checksum_time);
|
||||
const char* data = req.result.data();
|
||||
uint32_t expected =
|
||||
DecodeFixed32(data + req_offset + handle.size() + 1);
|
||||
// Since the scratch might be shared. the offset of the data block in
|
||||
// Since the scratch might be shared, the offset of the data block in
|
||||
// the buffer might not be 0. req.result.data() only point to the
|
||||
// begin address of each read request, we need to add the offset
|
||||
// in each read request. Checksum is stored in the block trailer,
|
||||
// which is handle.size() + 1.
|
||||
s = ROCKSDB_NAMESPACE::VerifyChecksum(
|
||||
footer.checksum(), data + req_offset, handle.size() + 1, expected);
|
||||
// beyond the payload size.
|
||||
s = ROCKSDB_NAMESPACE::VerifyBlockChecksum(
|
||||
footer.checksum(), data + req_offset, handle.size(),
|
||||
rep_->file->file_name(), handle.offset());
|
||||
TEST_SYNC_POINT_CALLBACK("RetrieveMultipleBlocks:VerifyChecksum", &s);
|
||||
}
|
||||
} else if (!use_shared_buffer) {
|
||||
|
||||
@@ -439,10 +439,19 @@ class BlockBasedTable : public TableReader {
|
||||
static void SetupCacheKeyPrefix(Rep* rep);
|
||||
|
||||
// Generate a cache key prefix from the file
|
||||
static void GenerateCachePrefix(Cache* cc, FSRandomAccessFile* file,
|
||||
char* buffer, size_t* size);
|
||||
static void GenerateCachePrefix(Cache* cc, FSWritableFile* file, char* buffer,
|
||||
size_t* size);
|
||||
template <typename TCache, typename TFile>
|
||||
static void GenerateCachePrefix(TCache* cc, TFile* file, char* buffer,
|
||||
size_t* size) {
|
||||
// generate an id from the file
|
||||
*size = file->GetUniqueId(buffer, kMaxCacheKeyPrefixSize);
|
||||
|
||||
// If the prefix wasn't generated or was too long,
|
||||
// create one from the cache.
|
||||
if (cc != nullptr && *size == 0) {
|
||||
char* end = EncodeVarint64(buffer, cc->NewId());
|
||||
*size = static_cast<size_t>(end - buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// Size of all data blocks, maybe approximate
|
||||
uint64_t GetApproximateDataSize();
|
||||
|
||||
@@ -28,9 +28,12 @@ namespace {
|
||||
// See description in FastLocalBloomImpl
|
||||
class FastLocalBloomBitsBuilder : public BuiltinFilterBitsBuilder {
|
||||
public:
|
||||
explicit FastLocalBloomBitsBuilder(const int millibits_per_key)
|
||||
// Non-null aggregate_rounding_balance implies optimize_filters_for_memory
|
||||
explicit FastLocalBloomBitsBuilder(
|
||||
const int millibits_per_key,
|
||||
std::atomic<int64_t>* aggregate_rounding_balance)
|
||||
: millibits_per_key_(millibits_per_key),
|
||||
num_probes_(FastLocalBloomImpl::ChooseNumProbes(millibits_per_key_)) {
|
||||
aggregate_rounding_balance_(aggregate_rounding_balance) {
|
||||
assert(millibits_per_key >= 1000);
|
||||
}
|
||||
|
||||
@@ -48,33 +51,36 @@ class FastLocalBloomBitsBuilder : public BuiltinFilterBitsBuilder {
|
||||
}
|
||||
|
||||
virtual Slice Finish(std::unique_ptr<const char[]>* buf) override {
|
||||
size_t num_entry = hash_entries_.size();
|
||||
std::unique_ptr<char[]> mutable_buf;
|
||||
uint32_t len_with_metadata =
|
||||
CalculateSpace(static_cast<uint32_t>(hash_entries_.size()));
|
||||
char* data = new char[len_with_metadata];
|
||||
memset(data, 0, len_with_metadata);
|
||||
CalculateAndAllocate(num_entry, &mutable_buf, /*update_balance*/ true);
|
||||
|
||||
assert(data);
|
||||
assert(mutable_buf);
|
||||
assert(len_with_metadata >= 5);
|
||||
|
||||
// Compute num_probes after any rounding / adjustments
|
||||
int num_probes = GetNumProbes(num_entry, len_with_metadata);
|
||||
|
||||
uint32_t len = len_with_metadata - 5;
|
||||
if (len > 0) {
|
||||
AddAllEntries(data, len);
|
||||
AddAllEntries(mutable_buf.get(), len, num_probes);
|
||||
}
|
||||
|
||||
assert(hash_entries_.empty());
|
||||
|
||||
// See BloomFilterPolicy::GetBloomBitsReader re: metadata
|
||||
// -1 = Marker for newer Bloom implementations
|
||||
data[len] = static_cast<char>(-1);
|
||||
mutable_buf[len] = static_cast<char>(-1);
|
||||
// 0 = Marker for this sub-implementation
|
||||
data[len + 1] = static_cast<char>(0);
|
||||
mutable_buf[len + 1] = static_cast<char>(0);
|
||||
// num_probes (and 0 in upper bits for 64-byte block size)
|
||||
data[len + 2] = static_cast<char>(num_probes_);
|
||||
mutable_buf[len + 2] = static_cast<char>(num_probes);
|
||||
// rest of metadata stays zero
|
||||
|
||||
const char* const_data = data;
|
||||
buf->reset(const_data);
|
||||
assert(hash_entries_.empty());
|
||||
|
||||
return Slice(data, len_with_metadata);
|
||||
Slice rv(mutable_buf.get(), len_with_metadata);
|
||||
*buf = std::move(mutable_buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int CalculateNumEntry(const uint32_t bytes) override {
|
||||
@@ -84,26 +90,163 @@ class FastLocalBloomBitsBuilder : public BuiltinFilterBitsBuilder {
|
||||
}
|
||||
|
||||
uint32_t CalculateSpace(const int num_entry) override {
|
||||
uint32_t num_cache_lines = 0;
|
||||
if (millibits_per_key_ > 0 && num_entry > 0) {
|
||||
num_cache_lines = static_cast<uint32_t>(
|
||||
(int64_t{num_entry} * millibits_per_key_ + 511999) / 512000);
|
||||
}
|
||||
return num_cache_lines * 64 + /*metadata*/ 5;
|
||||
// NB: the BuiltinFilterBitsBuilder API presumes len fits in uint32_t.
|
||||
return static_cast<uint32_t>(
|
||||
CalculateAndAllocate(static_cast<size_t>(num_entry),
|
||||
/* buf */ nullptr,
|
||||
/*update_balance*/ false));
|
||||
}
|
||||
|
||||
double EstimatedFpRate(size_t keys, size_t bytes) override {
|
||||
return FastLocalBloomImpl::EstimatedFpRate(keys, bytes - /*metadata*/ 5,
|
||||
num_probes_, /*hash bits*/ 64);
|
||||
// To choose size using malloc_usable_size, we have to actually allocate.
|
||||
uint32_t CalculateAndAllocate(size_t num_entry, std::unique_ptr<char[]>* buf,
|
||||
bool update_balance) {
|
||||
std::unique_ptr<char[]> tmpbuf;
|
||||
|
||||
// If not for cache line blocks in the filter, what would the target
|
||||
// length in bytes be?
|
||||
size_t raw_target_len = static_cast<size_t>(
|
||||
(uint64_t{num_entry} * millibits_per_key_ + 7999) / 8000);
|
||||
|
||||
if (raw_target_len >= size_t{0xffffffc0}) {
|
||||
// Max supported for this data structure implementation
|
||||
raw_target_len = size_t{0xffffffc0};
|
||||
}
|
||||
|
||||
// Round up to nearest multiple of 64 (block size). This adjustment is
|
||||
// used for target FP rate only so that we don't receive complaints about
|
||||
// lower FP rate vs. historic Bloom filter behavior.
|
||||
uint32_t target_len =
|
||||
static_cast<uint32_t>(raw_target_len + 63) & ~uint32_t{63};
|
||||
|
||||
// Return value set to a default; overwritten in some cases
|
||||
uint32_t rv = target_len + /* metadata */ 5;
|
||||
#ifdef ROCKSDB_MALLOC_USABLE_SIZE
|
||||
if (aggregate_rounding_balance_ != nullptr) {
|
||||
// Do optimize_filters_for_memory, using malloc_usable_size.
|
||||
// Approach: try to keep FP rate balance better than or on
|
||||
// target (negative aggregate_rounding_balance_). We can then select a
|
||||
// lower bound filter size (within reasonable limits) that gets us as
|
||||
// close to on target as possible. We request allocation for that filter
|
||||
// size and use malloc_usable_size to "round up" to the actual
|
||||
// allocation size.
|
||||
|
||||
// Although it can be considered bad practice to use malloc_usable_size
|
||||
// to access an object beyond its original size, this approach should
|
||||
// quite general: working for all allocators that properly support
|
||||
// malloc_usable_size.
|
||||
|
||||
// Race condition on balance is OK because it can only cause temporary
|
||||
// skew in rounding up vs. rounding down, as long as updates are atomic
|
||||
// and relative.
|
||||
int64_t balance = aggregate_rounding_balance_->load();
|
||||
|
||||
double target_fp_rate = EstimatedFpRate(num_entry, target_len + 5);
|
||||
double rv_fp_rate = target_fp_rate;
|
||||
|
||||
if (balance < 0) {
|
||||
// See formula for BloomFilterPolicy::aggregate_rounding_balance_
|
||||
double for_balance_fp_rate =
|
||||
-balance / double{0x100000000} + target_fp_rate;
|
||||
|
||||
// To simplify, we just try a few modified smaller sizes. This also
|
||||
// caps how much we vary filter size vs. target, to avoid outlier
|
||||
// behavior from excessive variance.
|
||||
for (uint64_t maybe_len64 :
|
||||
{uint64_t{3} * target_len / 4, uint64_t{13} * target_len / 16,
|
||||
uint64_t{7} * target_len / 8, uint64_t{15} * target_len / 16}) {
|
||||
uint32_t maybe_len =
|
||||
static_cast<uint32_t>(maybe_len64) & ~uint32_t{63};
|
||||
double maybe_fp_rate = EstimatedFpRate(num_entry, maybe_len + 5);
|
||||
if (maybe_fp_rate <= for_balance_fp_rate) {
|
||||
rv = maybe_len + /* metadata */ 5;
|
||||
rv_fp_rate = maybe_fp_rate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter blocks are loaded into block cache with their block trailer.
|
||||
// We need to make sure that's accounted for in choosing a
|
||||
// fragmentation-friendly size.
|
||||
const uint32_t kExtraPadding = kBlockTrailerSize;
|
||||
size_t requested = rv + kExtraPadding;
|
||||
|
||||
// Allocate and get usable size
|
||||
tmpbuf.reset(new char[requested]);
|
||||
size_t usable = malloc_usable_size(tmpbuf.get());
|
||||
|
||||
if (usable - usable / 4 > requested) {
|
||||
// Ratio greater than 4/3 is too much for utilizing, if it's
|
||||
// not a buggy or mislinked malloc_usable_size implementation.
|
||||
// Non-linearity of FP rates with bits/key means rapidly
|
||||
// diminishing returns in overall accuracy for additional
|
||||
// storage on disk.
|
||||
// Nothing to do, except assert that the result is accurate about
|
||||
// the usable size. (Assignment never used.)
|
||||
assert(tmpbuf[usable - 1] = 'x');
|
||||
} else if (usable > requested) {
|
||||
// Adjust for reasonably larger usable size
|
||||
size_t usable_len = (usable - kExtraPadding - /* metadata */ 5);
|
||||
if (usable_len >= size_t{0xffffffc0}) {
|
||||
// Max supported for this data structure implementation
|
||||
usable_len = size_t{0xffffffc0};
|
||||
}
|
||||
|
||||
rv = (static_cast<uint32_t>(usable_len) & ~uint32_t{63}) +
|
||||
/* metadata */ 5;
|
||||
rv_fp_rate = EstimatedFpRate(num_entry, rv);
|
||||
} else {
|
||||
// Too small means bad malloc_usable_size
|
||||
assert(usable == requested);
|
||||
}
|
||||
memset(tmpbuf.get(), 0, rv);
|
||||
|
||||
if (update_balance) {
|
||||
int64_t diff = static_cast<int64_t>((rv_fp_rate - target_fp_rate) *
|
||||
double{0x100000000});
|
||||
*aggregate_rounding_balance_ += diff;
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void)update_balance;
|
||||
#endif // ROCKSDB_MALLOC_USABLE_SIZE
|
||||
if (buf) {
|
||||
if (tmpbuf) {
|
||||
*buf = std::move(tmpbuf);
|
||||
} else {
|
||||
buf->reset(new char[rv]());
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
double EstimatedFpRate(size_t keys, size_t len_with_metadata) override {
|
||||
int num_probes = GetNumProbes(keys, len_with_metadata);
|
||||
return FastLocalBloomImpl::EstimatedFpRate(
|
||||
keys, len_with_metadata - /*metadata*/ 5, num_probes, /*hash bits*/ 64);
|
||||
}
|
||||
|
||||
private:
|
||||
void AddAllEntries(char* data, uint32_t len) {
|
||||
// Compute num_probes after any rounding / adjustments
|
||||
int GetNumProbes(size_t keys, size_t len_with_metadata) {
|
||||
uint64_t millibits = uint64_t{len_with_metadata - 5} * 8000;
|
||||
int actual_millibits_per_key =
|
||||
static_cast<int>(millibits / std::max(keys, size_t{1}));
|
||||
// BEGIN XXX/TODO(peterd): preserving old/default behavior for now to
|
||||
// minimize unit test churn. Remove this some time.
|
||||
if (!aggregate_rounding_balance_) {
|
||||
actual_millibits_per_key = millibits_per_key_;
|
||||
}
|
||||
// END XXX/TODO
|
||||
return FastLocalBloomImpl::ChooseNumProbes(actual_millibits_per_key);
|
||||
}
|
||||
|
||||
void AddAllEntries(char* data, uint32_t len, int num_probes) {
|
||||
// Simple version without prefetching:
|
||||
//
|
||||
// for (auto h : hash_entries_) {
|
||||
// FastLocalBloomImpl::AddHash(Lower32of64(h), Upper32of64(h), len,
|
||||
// num_probes_, data);
|
||||
// num_probes, data);
|
||||
// }
|
||||
|
||||
const size_t num_entries = hash_entries_.size();
|
||||
@@ -129,7 +272,7 @@ class FastLocalBloomBitsBuilder : public BuiltinFilterBitsBuilder {
|
||||
uint32_t& hash_ref = hashes[i & kBufferMask];
|
||||
uint32_t& byte_offset_ref = byte_offsets[i & kBufferMask];
|
||||
// Process (add)
|
||||
FastLocalBloomImpl::AddHashPrepared(hash_ref, num_probes_,
|
||||
FastLocalBloomImpl::AddHashPrepared(hash_ref, num_probes,
|
||||
data + byte_offset_ref);
|
||||
// And buffer
|
||||
uint64_t h = hash_entries_.front();
|
||||
@@ -141,13 +284,16 @@ class FastLocalBloomBitsBuilder : public BuiltinFilterBitsBuilder {
|
||||
|
||||
// Finish processing
|
||||
for (i = 0; i <= kBufferMask && i < num_entries; ++i) {
|
||||
FastLocalBloomImpl::AddHashPrepared(hashes[i], num_probes_,
|
||||
FastLocalBloomImpl::AddHashPrepared(hashes[i], num_probes,
|
||||
data + byte_offsets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Target allocation per added key, in thousandths of a bit.
|
||||
int millibits_per_key_;
|
||||
int num_probes_;
|
||||
// See BloomFilterPolicy::aggregate_rounding_balance_. If nullptr,
|
||||
// always "round up" like historic behavior.
|
||||
std::atomic<int64_t>* aggregate_rounding_balance_;
|
||||
// A deque avoids unnecessary copying of already-saved values
|
||||
// and has near-minimal peak memory use.
|
||||
std::deque<uint64_t> hash_entries_;
|
||||
@@ -457,7 +603,7 @@ const std::vector<BloomFilterPolicy::Mode> BloomFilterPolicy::kAllUserModes = {
|
||||
};
|
||||
|
||||
BloomFilterPolicy::BloomFilterPolicy(double bits_per_key, Mode mode)
|
||||
: mode_(mode), warned_(false) {
|
||||
: mode_(mode), warned_(false), aggregate_rounding_balance_(0) {
|
||||
// Sanitize bits_per_key
|
||||
if (bits_per_key < 1.0) {
|
||||
bits_per_key = 1.0;
|
||||
@@ -549,6 +695,7 @@ FilterBitsBuilder* BloomFilterPolicy::GetFilterBitsBuilder() const {
|
||||
FilterBitsBuilder* BloomFilterPolicy::GetBuilderWithContext(
|
||||
const FilterBuildingContext& context) const {
|
||||
Mode cur = mode_;
|
||||
bool offm = context.table_options.optimize_filters_for_memory;
|
||||
// Unusual code construction so that we can have just
|
||||
// one exhaustive switch without (risky) recursion
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
@@ -563,7 +710,8 @@ FilterBitsBuilder* BloomFilterPolicy::GetBuilderWithContext(
|
||||
case kDeprecatedBlock:
|
||||
return nullptr;
|
||||
case kFastLocalBloom:
|
||||
return new FastLocalBloomBitsBuilder(millibits_per_key_);
|
||||
return new FastLocalBloomBitsBuilder(
|
||||
millibits_per_key_, offm ? &aggregate_rounding_balance_ : nullptr);
|
||||
case kLegacyBloom:
|
||||
if (whole_bits_per_key_ >= 14 && context.info_log &&
|
||||
!warned_.load(std::memory_order_relaxed)) {
|
||||
|
||||
@@ -135,6 +135,16 @@ class BloomFilterPolicy : public FilterPolicy {
|
||||
// only report once per BloomFilterPolicy instance, to keep the noise down.)
|
||||
mutable std::atomic<bool> warned_;
|
||||
|
||||
// State for implementing optimize_filters_for_memory. Essentially, this
|
||||
// tracks a surplus or deficit in total FP rate of filters generated by
|
||||
// builders under this policy vs. what would have been generated without
|
||||
// optimize_filters_for_memory.
|
||||
//
|
||||
// To avoid floating point weirdness, the actual value is
|
||||
// Sum over all generated filters f:
|
||||
// (predicted_fp_rate(f) - predicted_fp_rate(f|o_f_f_m=false)) * 2^32
|
||||
mutable std::atomic<int64_t> aggregate_rounding_balance_;
|
||||
|
||||
// For newer Bloom filter implementation(s)
|
||||
FilterBitsReader* GetBloomBitsReader(const Slice& contents) const;
|
||||
};
|
||||
|
||||
@@ -104,15 +104,6 @@ void PartitionedIndexBuilder::MakeNewSubIndexBuilder() {
|
||||
comparator_, table_opt_.index_block_restart_interval,
|
||||
table_opt_.format_version, use_value_delta_encoding_,
|
||||
table_opt_.index_shortening, /* include_first_key */ false);
|
||||
|
||||
// Set sub_index_builder_->seperator_is_key_plus_seq_ to true if
|
||||
// seperator_is_key_plus_seq_ is true (internal-key mode) (set to false by
|
||||
// default on Creation) so that flush policy can point to
|
||||
// sub_index_builder_->index_block_builder_
|
||||
if (seperator_is_key_plus_seq_) {
|
||||
sub_index_builder_->seperator_is_key_plus_seq_ = true;
|
||||
}
|
||||
|
||||
flush_policy_.reset(FlushBlockBySizePolicyFactory::NewFlushBlockPolicy(
|
||||
table_opt_.metadata_block_size, table_opt_.block_size_deviation,
|
||||
// Note: this is sub-optimal since sub_index_builder_ could later reset
|
||||
@@ -138,15 +129,9 @@ void PartitionedIndexBuilder::AddIndexEntry(
|
||||
}
|
||||
sub_index_builder_->AddIndexEntry(last_key_in_current_block,
|
||||
first_key_in_next_block, block_handle);
|
||||
if (!seperator_is_key_plus_seq_ &&
|
||||
sub_index_builder_->seperator_is_key_plus_seq_) {
|
||||
// then we need to apply it to all sub-index builders and reset
|
||||
// flush_policy to point to Block Builder of sub_index_builder_ that store
|
||||
// internal keys.
|
||||
if (sub_index_builder_->seperator_is_key_plus_seq_) {
|
||||
// then we need to apply it to all sub-index builders
|
||||
seperator_is_key_plus_seq_ = true;
|
||||
flush_policy_.reset(FlushBlockBySizePolicyFactory::NewFlushBlockPolicy(
|
||||
table_opt_.metadata_block_size, table_opt_.block_size_deviation,
|
||||
sub_index_builder_->index_block_builder_));
|
||||
}
|
||||
sub_index_last_key_ = std::string(*last_key_in_current_block);
|
||||
entries_.push_back(
|
||||
@@ -176,15 +161,9 @@ void PartitionedIndexBuilder::AddIndexEntry(
|
||||
sub_index_builder_->AddIndexEntry(last_key_in_current_block,
|
||||
first_key_in_next_block, block_handle);
|
||||
sub_index_last_key_ = std::string(*last_key_in_current_block);
|
||||
if (!seperator_is_key_plus_seq_ &&
|
||||
sub_index_builder_->seperator_is_key_plus_seq_) {
|
||||
// then we need to apply it to all sub-index builders and reset
|
||||
// flush_policy to point to Block Builder of sub_index_builder_ that store
|
||||
// internal keys.
|
||||
if (sub_index_builder_->seperator_is_key_plus_seq_) {
|
||||
// then we need to apply it to all sub-index builders
|
||||
seperator_is_key_plus_seq_ = true;
|
||||
flush_policy_.reset(FlushBlockBySizePolicyFactory::NewFlushBlockPolicy(
|
||||
table_opt_.metadata_block_size, table_opt_.block_size_deviation,
|
||||
sub_index_builder_->index_block_builder_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ void PartitionIndexReader::CacheDependencies(bool pin) {
|
||||
|
||||
assert(s.ok() || block.GetValue() == nullptr);
|
||||
if (s.ok() && block.GetValue() != nullptr) {
|
||||
if (block.IsCached() || block.GetOwnValue()) {
|
||||
if (block.IsCached()) {
|
||||
if (pin) {
|
||||
partition_map_[handle.offset()] = std::move(block);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
#include "table/block_based/reader_common.h"
|
||||
|
||||
#include "monitoring/perf_context_imp.h"
|
||||
#include "util/coding.h"
|
||||
#include "util/crc32c.h"
|
||||
#include "util/hash.h"
|
||||
#include "util/string_util.h"
|
||||
#include "util/xxhash.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
@@ -18,29 +22,42 @@ void ForceReleaseCachedEntry(void* arg, void* h) {
|
||||
cache->Release(handle, true /* force_erase */);
|
||||
}
|
||||
|
||||
Status VerifyChecksum(const ChecksumType type, const char* buf, size_t len,
|
||||
uint32_t expected) {
|
||||
Status VerifyBlockChecksum(ChecksumType type, const char* data,
|
||||
size_t block_size, const std::string& file_name,
|
||||
uint64_t offset) {
|
||||
PERF_TIMER_GUARD(block_checksum_time);
|
||||
// After block_size bytes is compression type (1 byte), which is part of
|
||||
// the checksummed section.
|
||||
size_t len = block_size + 1;
|
||||
// And then the stored checksum value (4 bytes).
|
||||
uint32_t stored = DecodeFixed32(data + len);
|
||||
|
||||
Status s;
|
||||
uint32_t actual = 0;
|
||||
uint32_t computed = 0;
|
||||
switch (type) {
|
||||
case kNoChecksum:
|
||||
break;
|
||||
case kCRC32c:
|
||||
expected = crc32c::Unmask(expected);
|
||||
actual = crc32c::Value(buf, len);
|
||||
stored = crc32c::Unmask(stored);
|
||||
computed = crc32c::Value(data, len);
|
||||
break;
|
||||
case kxxHash:
|
||||
actual = XXH32(buf, static_cast<int>(len), 0);
|
||||
computed = XXH32(data, len, 0);
|
||||
break;
|
||||
case kxxHash64:
|
||||
actual = static_cast<uint32_t>(XXH64(buf, static_cast<int>(len), 0) &
|
||||
uint64_t{0xffffffff});
|
||||
computed = Lower32of64(XXH64(data, len, 0));
|
||||
break;
|
||||
default:
|
||||
s = Status::Corruption("unknown checksum type");
|
||||
s = Status::Corruption(
|
||||
"unknown checksum type " + ToString(type) + " from footer of " +
|
||||
file_name + ", while checking block at offset " + ToString(offset) +
|
||||
" size " + ToString(block_size));
|
||||
}
|
||||
if (s.ok() && actual != expected) {
|
||||
s = Status::Corruption("properties block checksum mismatched");
|
||||
if (s.ok() && stored != computed) {
|
||||
s = Status::Corruption(
|
||||
"block checksum mismatch: stored = " + ToString(stored) +
|
||||
", computed = " + ToString(computed) + " in " + file_name +
|
||||
" offset " + ToString(offset) + " size " + ToString(block_size));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ inline MemoryAllocator* GetMemoryAllocatorForCompressedBlock(
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
extern Status VerifyChecksum(const ChecksumType type, const char* buf,
|
||||
size_t len, uint32_t expected);
|
||||
// Assumes block has a trailer as in format.h. file_name and offset provided
|
||||
// for generating a diagnostic message in returned status.
|
||||
extern Status VerifyBlockChecksum(ChecksumType type, const char* data,
|
||||
size_t block_size,
|
||||
const std::string& file_name,
|
||||
uint64_t offset);
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
+4
-35
@@ -19,51 +19,20 @@
|
||||
#include "rocksdb/env.h"
|
||||
#include "table/block_based/block.h"
|
||||
#include "table/block_based/block_based_table_reader.h"
|
||||
#include "table/block_based/reader_common.h"
|
||||
#include "table/format.h"
|
||||
#include "table/persistent_cache_helper.h"
|
||||
#include "util/coding.h"
|
||||
#include "util/compression.h"
|
||||
#include "util/crc32c.h"
|
||||
#include "util/stop_watch.h"
|
||||
#include "util/string_util.h"
|
||||
#include "util/xxhash.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
inline void BlockFetcher::CheckBlockChecksum() {
|
||||
// Check the crc of the type and the block contents
|
||||
if (read_options_.verify_checksums) {
|
||||
const char* data = slice_.data(); // Pointer to where Read put the data
|
||||
PERF_TIMER_GUARD(block_checksum_time);
|
||||
uint32_t value = DecodeFixed32(data + block_size_ + 1);
|
||||
uint32_t actual = 0;
|
||||
switch (footer_.checksum()) {
|
||||
case kNoChecksum:
|
||||
break;
|
||||
case kCRC32c:
|
||||
value = crc32c::Unmask(value);
|
||||
actual = crc32c::Value(data, block_size_ + 1);
|
||||
break;
|
||||
case kxxHash:
|
||||
actual = XXH32(data, static_cast<int>(block_size_) + 1, 0);
|
||||
break;
|
||||
case kxxHash64:
|
||||
actual = static_cast<uint32_t>(
|
||||
XXH64(data, static_cast<int>(block_size_) + 1, 0) &
|
||||
uint64_t{0xffffffff});
|
||||
break;
|
||||
default:
|
||||
status_ = Status::Corruption(
|
||||
"unknown checksum type " + ToString(footer_.checksum()) + " in " +
|
||||
file_->file_name() + " offset " + ToString(handle_.offset()) +
|
||||
" size " + ToString(block_size_));
|
||||
}
|
||||
if (status_.ok() && actual != value) {
|
||||
status_ = Status::Corruption(
|
||||
"block checksum mismatch: expected " + ToString(actual) + ", got " +
|
||||
ToString(value) + " in " + file_->file_name() + " offset " +
|
||||
ToString(handle_.offset()) + " size " + ToString(block_size_));
|
||||
}
|
||||
status_ = ROCKSDB_NAMESPACE::VerifyBlockChecksum(
|
||||
footer_.checksum(), slice_.data(), block_size_, file_->file_name(),
|
||||
handle_.offset());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ CuckooTableBuilder::CuckooTableBuilder(
|
||||
const Comparator* user_comparator, uint32_t cuckoo_block_size,
|
||||
bool use_module_hash, bool identity_as_first_hash,
|
||||
uint64_t (*get_slice_hash)(const Slice&, uint32_t, uint64_t),
|
||||
uint32_t column_family_id, const std::string& column_family_name)
|
||||
uint32_t column_family_id, const std::string& column_family_name,
|
||||
const std::string& db_id, const std::string& db_session_id)
|
||||
: num_hash_func_(2),
|
||||
file_(file),
|
||||
max_hash_table_ratio_(max_hash_table_ratio),
|
||||
@@ -79,6 +80,8 @@ CuckooTableBuilder::CuckooTableBuilder(
|
||||
properties_.filter_size = 0;
|
||||
properties_.column_family_id = column_family_id;
|
||||
properties_.column_family_name = column_family_name;
|
||||
properties_.db_id = db_id;
|
||||
properties_.db_session_id = db_session_id;
|
||||
}
|
||||
|
||||
void CuckooTableBuilder::Add(const Slice& key, const Slice& value) {
|
||||
|
||||
@@ -22,15 +22,14 @@ namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
class CuckooTableBuilder: public TableBuilder {
|
||||
public:
|
||||
CuckooTableBuilder(WritableFileWriter* file, double max_hash_table_ratio,
|
||||
uint32_t max_num_hash_func, uint32_t max_search_depth,
|
||||
const Comparator* user_comparator,
|
||||
uint32_t cuckoo_block_size, bool use_module_hash,
|
||||
bool identity_as_first_hash,
|
||||
uint64_t (*get_slice_hash)(const Slice&, uint32_t,
|
||||
uint64_t),
|
||||
uint32_t column_family_id,
|
||||
const std::string& column_family_name);
|
||||
CuckooTableBuilder(
|
||||
WritableFileWriter* file, double max_hash_table_ratio,
|
||||
uint32_t max_num_hash_func, uint32_t max_search_depth,
|
||||
const Comparator* user_comparator, uint32_t cuckoo_block_size,
|
||||
bool use_module_hash, bool identity_as_first_hash,
|
||||
uint64_t (*get_slice_hash)(const Slice&, uint32_t, uint64_t),
|
||||
uint32_t column_family_id, const std::string& column_family_name,
|
||||
const std::string& db_id = "", const std::string& db_session_id = "");
|
||||
// No copying allowed
|
||||
CuckooTableBuilder(const CuckooTableBuilder&) = delete;
|
||||
void operator=(const CuckooTableBuilder&) = delete;
|
||||
|
||||
@@ -40,7 +40,8 @@ TableBuilder* CuckooTableFactory::NewTableBuilder(
|
||||
table_builder_options.internal_comparator.user_comparator(),
|
||||
table_options_.cuckoo_block_size, table_options_.use_module_hash,
|
||||
table_options_.identity_as_first_hash, nullptr /* get_slice_hash */,
|
||||
column_family_id, table_builder_options.column_family_name);
|
||||
column_family_id, table_builder_options.column_family_name,
|
||||
table_builder_options.db_id, table_builder_options.db_session_id);
|
||||
}
|
||||
|
||||
std::string CuckooTableFactory::GetPrintableTableOptions() const {
|
||||
|
||||
+1
-1
@@ -220,7 +220,7 @@ Status ReadFooterFromFile(RandomAccessFileReader* file,
|
||||
uint64_t file_size, Footer* footer,
|
||||
uint64_t enforce_table_magic_number = 0);
|
||||
|
||||
// 1-byte type + 32-bit crc
|
||||
// 1-byte compression type + 32-bit checksum
|
||||
static const size_t kBlockTrailerSize = 5;
|
||||
|
||||
// Make block size calculation for IO less error prone
|
||||
|
||||
@@ -142,11 +142,6 @@ class IteratorWrapperBase {
|
||||
return result_.value_prepared;
|
||||
}
|
||||
|
||||
Slice user_key() const {
|
||||
assert(Valid());
|
||||
return iter_->user_key();
|
||||
}
|
||||
|
||||
private:
|
||||
void Update() {
|
||||
valid_ = iter_->Valid();
|
||||
|
||||
@@ -96,6 +96,8 @@ void PropertyBlockBuilder::AddTableProperty(const TableProperties& props) {
|
||||
if (props.file_creation_time > 0) {
|
||||
Add(TablePropertiesNames::kFileCreationTime, props.file_creation_time);
|
||||
}
|
||||
Add(TablePropertiesNames::kDbId, props.db_id);
|
||||
Add(TablePropertiesNames::kDbSessionId, props.db_session_id);
|
||||
|
||||
if (!props.filter_policy_name.empty()) {
|
||||
Add(TablePropertiesNames::kFilterPolicy, props.filter_policy_name);
|
||||
@@ -311,6 +313,10 @@ Status ReadProperties(const Slice& handle_value, RandomAccessFileReader* file,
|
||||
continue;
|
||||
}
|
||||
*(pos->second) = val;
|
||||
} else if (key == TablePropertiesNames::kDbId) {
|
||||
new_table_properties->db_id = raw_val.ToString();
|
||||
} else if (key == TablePropertiesNames::kDbSessionId) {
|
||||
new_table_properties->db_session_id = raw_val.ToString();
|
||||
} else if (key == TablePropertiesNames::kFilterPolicy) {
|
||||
new_table_properties->filter_policy_name = raw_val.ToString();
|
||||
} else if (key == TablePropertiesNames::kColumnFamilyName) {
|
||||
|
||||
@@ -64,7 +64,8 @@ PlainTableBuilder::PlainTableBuilder(
|
||||
EncodingType encoding_type, size_t index_sparseness,
|
||||
uint32_t bloom_bits_per_key, const std::string& column_family_name,
|
||||
uint32_t num_probes, size_t huge_page_tlb_size, double hash_table_ratio,
|
||||
bool store_index_in_file)
|
||||
bool store_index_in_file, const std::string& db_id,
|
||||
const std::string& db_session_id)
|
||||
: ioptions_(ioptions),
|
||||
moptions_(moptions),
|
||||
bloom_block_(num_probes),
|
||||
@@ -97,6 +98,8 @@ PlainTableBuilder::PlainTableBuilder(
|
||||
properties_.format_version = (encoding_type == kPlain) ? 0 : 1;
|
||||
properties_.column_family_id = column_family_id;
|
||||
properties_.column_family_name = column_family_name;
|
||||
properties_.db_id = db_id;
|
||||
properties_.db_session_id = db_session_id;
|
||||
properties_.prefix_extractor_name = moptions_.prefix_extractor != nullptr
|
||||
? moptions_.prefix_extractor->Name()
|
||||
: "nullptr";
|
||||
|
||||
@@ -45,7 +45,8 @@ class PlainTableBuilder: public TableBuilder {
|
||||
size_t index_sparseness, uint32_t bloom_bits_per_key,
|
||||
const std::string& column_family_name, uint32_t num_probes = 6,
|
||||
size_t huge_page_tlb_size = 0, double hash_table_ratio = 0,
|
||||
bool store_index_in_file = false);
|
||||
bool store_index_in_file = false, const std::string& db_id = "",
|
||||
const std::string& db_session_id = "");
|
||||
// No copying allowed
|
||||
PlainTableBuilder(const PlainTableBuilder&) = delete;
|
||||
void operator=(const PlainTableBuilder&) = delete;
|
||||
|
||||
@@ -76,7 +76,8 @@ TableBuilder* PlainTableFactory::NewTableBuilder(
|
||||
table_options_.index_sparseness, table_options_.bloom_bits_per_key,
|
||||
table_builder_options.column_family_name, 6,
|
||||
table_options_.huge_page_tlb_size, table_options_.hash_table_ratio,
|
||||
table_options_.store_index_in_file);
|
||||
table_options_.store_index_in_file, table_builder_options.db_id,
|
||||
table_builder_options.db_session_id);
|
||||
}
|
||||
|
||||
std::string PlainTableFactory::GetPrintableTableOptions() const {
|
||||
|
||||
@@ -237,12 +237,22 @@ Status SstFileWriter::Open(const std::string& file_path) {
|
||||
r->column_family_name = "";
|
||||
cf_id = TablePropertiesCollectorFactory::Context::kUnknownColumnFamily;
|
||||
}
|
||||
|
||||
// SstFileWriter is used to create sst files that can be added to database
|
||||
// later. Therefore, no real db_id and db_session_id are associated with it.
|
||||
// Here we mimic the way db_session_id behaves by resetting the db_session_id
|
||||
// every time SstFileWriter is used, and in this case db_id is set to be "SST
|
||||
// Writer".
|
||||
std::string db_session_id = r->ioptions.env->GenerateUniqueId();
|
||||
if (!db_session_id.empty() && db_session_id.back() == '\n') {
|
||||
db_session_id.pop_back();
|
||||
}
|
||||
TableBuilderOptions table_builder_options(
|
||||
r->ioptions, r->mutable_cf_options, r->internal_comparator,
|
||||
&int_tbl_prop_collector_factories, compression_type,
|
||||
sample_for_compression, compression_opts, r->skip_filters,
|
||||
r->column_family_name, unknown_level);
|
||||
r->column_family_name, unknown_level, 0 /* creation_time */,
|
||||
0 /* oldest_key_time */, 0 /* target_file_size */,
|
||||
0 /* file_creation_time */, "SST Writer" /* db_id */, db_session_id);
|
||||
r->file_writer.reset(new WritableFileWriter(
|
||||
NewLegacyWritableFileWrapper(std::move(sst_file)), file_path,
|
||||
r->env_options, r->ioptions.env, nullptr /* stats */,
|
||||
|
||||
@@ -97,7 +97,8 @@ struct TableBuilderOptions {
|
||||
const std::string& _column_family_name, int _level,
|
||||
const uint64_t _creation_time = 0, const int64_t _oldest_key_time = 0,
|
||||
const uint64_t _target_file_size = 0,
|
||||
const uint64_t _file_creation_time = 0)
|
||||
const uint64_t _file_creation_time = 0, const std::string& _db_id = "",
|
||||
const std::string& _db_session_id = "")
|
||||
: ioptions(_ioptions),
|
||||
moptions(_moptions),
|
||||
internal_comparator(_internal_comparator),
|
||||
@@ -111,7 +112,10 @@ struct TableBuilderOptions {
|
||||
creation_time(_creation_time),
|
||||
oldest_key_time(_oldest_key_time),
|
||||
target_file_size(_target_file_size),
|
||||
file_creation_time(_file_creation_time) {}
|
||||
file_creation_time(_file_creation_time),
|
||||
db_id(_db_id),
|
||||
db_session_id(_db_session_id) {}
|
||||
|
||||
const ImmutableCFOptions& ioptions;
|
||||
const MutableCFOptions& moptions;
|
||||
const InternalKeyComparator& internal_comparator;
|
||||
@@ -127,6 +131,8 @@ struct TableBuilderOptions {
|
||||
const int64_t oldest_key_time;
|
||||
const uint64_t target_file_size;
|
||||
const uint64_t file_creation_time;
|
||||
const std::string db_id;
|
||||
const std::string db_session_id;
|
||||
};
|
||||
|
||||
// TableBuilder provides the interface used to build a Table
|
||||
|
||||
Loaded 100 of 120 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user