mirror of
https://github.com/facebook/rocksdb.git
synced 2026-07-07 14:47:40 +08:00
Compare commits
109 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fec822a96e | |||
| fa8cfaa774 | |||
| 13d55eba73 | |||
| 1192897aad | |||
| f2c0eb41ef | |||
| b6ca6d886e | |||
| a40466d963 | |||
| a0ad7887c9 | |||
| 6cceef9497 | |||
| 1f7a286413 | |||
| de7b8e8f7d | |||
| 741539da9b | |||
| 7e2223f4ab | |||
| eddfee8f56 | |||
| 3745f2e234 | |||
| 0f493506d9 | |||
| 779c7b58d1 | |||
| ffb7788d45 | |||
| 75c1ffd4e3 | |||
| f6fabdb64f | |||
| 8fae7ff39d | |||
| 43d60bfe9e | |||
| 8c0790bdf8 | |||
| a004c2d850 | |||
| fe053a26aa | |||
| 8ba4204b28 | |||
| b0ecf86f6e | |||
| 1cec28d82d | |||
| 30295a4b92 | |||
| 1f20db7a31 | |||
| f8987bc7b9 | |||
| 30f42e00ba | |||
| 6ccfbd4a86 | |||
| 5b324a2160 | |||
| 02941016d0 | |||
| 2d13302949 | |||
| 214869aacd | |||
| 5bf78183db | |||
| e292aa95b3 | |||
| 123030ffee | |||
| 5f66923d1e | |||
| 7785264e5a | |||
| ad43a5fbe8 | |||
| f7677f0b6b | |||
| c9252b9ac0 | |||
| 4d30cfd1fc | |||
| 61c3e93a74 | |||
| 521cd8b31d | |||
| 77d9ed7f63 | |||
| 6d4a8144e0 | |||
| 4026c3cc08 | |||
| e18d41e08c | |||
| 4975341aef | |||
| 8d33fe7c70 | |||
| 01084e7e8e | |||
| 7affaee1c4 | |||
| 828f6d189e | |||
| 1ede57e5b0 | |||
| 82085868e2 | |||
| 0493154a73 | |||
| a214d3f1f8 | |||
| 2b9e8dc925 | |||
| 8c3bd2c3e9 | |||
| 76b8cce2f7 | |||
| 10e4f4745e | |||
| 2d68f30425 | |||
| b5922eab11 | |||
| 8053b9414f | |||
| 5177a8e6c2 | |||
| 3883a8d05e | |||
| 768de6e50d | |||
| 62f05627be | |||
| 9ef369c606 | |||
| 30dba7f41a | |||
| 023fbb074a | |||
| 26a501b5d1 | |||
| e492562651 | |||
| a0db079fdd | |||
| 9270dc8149 | |||
| 638354e766 | |||
| c724aeb67e | |||
| 364eb88151 | |||
| d7afd3bb3b | |||
| ae30c71c6b | |||
| 91b31112ed | |||
| 7f32e2cabc | |||
| 81fa943ca0 | |||
| a3ba3e8a6e | |||
| e82af29adb | |||
| acfa68ccff | |||
| 8bf167a194 | |||
| 97551b72d7 | |||
| d1ab4bf12c | |||
| e42af37ea7 | |||
| 54d13c0af9 | |||
| 2904bc64dc | |||
| 88d7d2df75 | |||
| 367f2b0fdf | |||
| 07a5a0a804 | |||
| 01d8c7720f | |||
| cba33621bd | |||
| 554a123295 | |||
| 459236341c | |||
| c48b020e92 | |||
| 3daabe2db3 | |||
| 805a476a5f | |||
| 21723bbbef | |||
| a2c96df7d7 | |||
| 87c554b492 |
@@ -1,9 +0,0 @@
|
||||
name: install-jdk8-on-macos
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Install JDK 8 on macos
|
||||
run: |-
|
||||
HOMEBREW_NO_AUTO_UPDATE=1 brew tap bell-sw/liberica
|
||||
HOMEBREW_NO_AUTO_UPDATE=1 brew install --cask liberica-jdk8
|
||||
shell: bash
|
||||
@@ -2,6 +2,13 @@ name: pre-steps
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Dump ulimits for diagnostics
|
||||
run: |
|
||||
echo "=== ulimits (soft) ==="
|
||||
ulimit -a -S || true
|
||||
echo "=== ulimits (hard) ==="
|
||||
ulimit -a -H || true
|
||||
shell: bash
|
||||
- name: Install lld linker for faster builds
|
||||
run: apt-get update -y && apt-get install -y lld 2>/dev/null || true
|
||||
shell: bash
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
name: setup-jdk-on-macos
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Set up JDK on macos
|
||||
run: |-
|
||||
set -euo pipefail
|
||||
|
||||
JAVA_HOME="$(/usr/libexec/java_home -v 21)"
|
||||
|
||||
echo "JAVA_HOME=${JAVA_HOME}" >> "$GITHUB_ENV"
|
||||
echo "JAVAC_ARGS=--release 8" >> "$GITHUB_ENV"
|
||||
echo "${JAVA_HOME}/bin" >> "$GITHUB_PATH"
|
||||
echo "Using JDK at ${JAVA_HOME}"
|
||||
"${JAVA_HOME}/bin/java" -version
|
||||
"${JAVA_HOME}/bin/javac" -version
|
||||
shell: bash
|
||||
@@ -3,7 +3,7 @@ inputs:
|
||||
suite-run:
|
||||
description: Comma-separated list of test suites to run (empty to skip C++ tests)
|
||||
required: false
|
||||
default: arena_test,db_basic_test,db_test,db_test2,db_merge_operand_test,bloom_test,c_test,coding_test,crc32c_test,dynamic_bloom_test,env_basic_test,env_test,hash_test,random_test
|
||||
default: arena_test,db_basic_test,db_test,db_etc2_test,db_merge_operand_test,bloom_test,c_test,coding_test,crc32c_test,dynamic_bloom_test,env_basic_test,env_test,hash_test,random_test
|
||||
run-java:
|
||||
description: Whether to run Java tests
|
||||
required: false
|
||||
@@ -11,8 +11,49 @@ inputs:
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Detect Visual Studio generator
|
||||
id: detect_vs
|
||||
shell: pwsh
|
||||
run: |
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$vswhere = Join-Path ([Environment]::GetFolderPath("ProgramFilesX86")) "Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if (!(Test-Path $vswhere)) {
|
||||
throw "vswhere.exe was not found at $vswhere"
|
||||
}
|
||||
|
||||
$vsInstallationsJson = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -format json -utf8
|
||||
$vsInstallations = @($vsInstallationsJson | ConvertFrom-Json)
|
||||
if ($vsInstallations.Count -eq 0) {
|
||||
throw "No Visual Studio instance with C++ tools was found."
|
||||
}
|
||||
|
||||
$vsInstallation = $vsInstallations[0]
|
||||
$vsMajor = [int]$vsInstallation.catalog.productLineVersion
|
||||
if ($vsMajor -eq 0) {
|
||||
$vsMajor = [int]($vsInstallation.installationVersion.Split(".")[0])
|
||||
}
|
||||
|
||||
$generatorLine = cmake --help | Where-Object {
|
||||
$_ -match "^\*?\s*Visual Studio $vsMajor\s+\d{4}\s*="
|
||||
} | Select-Object -First 1
|
||||
if (!$generatorLine) {
|
||||
throw "CMake does not support a Visual Studio generator for VS major version $vsMajor."
|
||||
}
|
||||
|
||||
$cmakeGenerator = ($generatorLine -replace "^\*?\s*", "" -replace "\s*=.*$", "").Trim()
|
||||
$vsVersionRange = "[{0}.0,{1}.0)" -f $vsMajor, ($vsMajor + 1)
|
||||
|
||||
echo "Detected Visual Studio at $($vsInstallation.installationPath)"
|
||||
echo "Using CMake generator: $cmakeGenerator"
|
||||
echo "Using setup-msbuild vs-version: $vsVersionRange"
|
||||
|
||||
"CMAKE_GENERATOR=$cmakeGenerator" >> $env:GITHUB_ENV
|
||||
"vs_version=$vsVersionRange" >> $env:GITHUB_OUTPUT
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.3.1
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
with:
|
||||
vs-version: ${{ steps.detect_vs.outputs.vs_version }}
|
||||
- name: ccache
|
||||
uses: hendrikmuhs/ccache-action@v1.2
|
||||
with:
|
||||
@@ -32,15 +73,23 @@ runs:
|
||||
CMAKE_HOME: C:/Program Files/CMake
|
||||
CMAKE_BIN: C:/Program Files/CMake/bin/cmake.exe
|
||||
CTEST_BIN: C:/Program Files/CMake/bin/ctest.exe
|
||||
JAVA_HOME: C:/Program Files/BellSoft/LibericaJDK-8
|
||||
SNAPPY_HOME: ${{ github.workspace }}/thirdparty/snappy-1.2.2
|
||||
SNAPPY_INCLUDE: ${{ github.workspace }}/thirdparty/snappy-1.2.2;${{ github.workspace }}/thirdparty/snappy-1.2.2/build
|
||||
SNAPPY_LIB_DEBUG: ${{ github.workspace }}/thirdparty/snappy-1.2.2/build/Debug/snappy.lib
|
||||
run: |-
|
||||
# NOTE: if ... Exit $LASTEXITCODE lines needed to exit and report failure
|
||||
echo ===================== Install Dependencies =====================
|
||||
choco install liberica8jdk -y
|
||||
if(!$?) { Exit $LASTEXITCODE }
|
||||
if (!$env:JAVA_HOME -or !(Test-Path (Join-Path $env:JAVA_HOME "bin\javac.exe"))) {
|
||||
$javac = Get-Command javac -ErrorAction SilentlyContinue
|
||||
if (!$javac) {
|
||||
Write-Error "javac was not found on PATH and JAVA_HOME is not set."
|
||||
Exit 1
|
||||
}
|
||||
$env:JAVA_HOME = Split-Path (Split-Path $javac.Source -Parent) -Parent
|
||||
}
|
||||
echo "JAVA_HOME=$env:JAVA_HOME"
|
||||
& "$env:JAVA_HOME\bin\java.exe" -version
|
||||
& "$env:JAVA_HOME\bin\javac.exe" -version
|
||||
mkdir $Env:THIRDPARTY_HOME
|
||||
cd $Env:THIRDPARTY_HOME
|
||||
echo "Building Snappy dependency..."
|
||||
@@ -53,11 +102,11 @@ runs:
|
||||
cd build
|
||||
& cmake -G "$Env:CMAKE_GENERATOR" .. -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF
|
||||
if(!$?) { Exit $LASTEXITCODE }
|
||||
msbuild Snappy.sln -maxCpuCount -property:Configuration=Debug -property:Platform=x64
|
||||
cmake --build . --config Debug --parallel 32 -- /p:Platform=x64
|
||||
if(!$?) { Exit $LASTEXITCODE }
|
||||
echo ======================== Build RocksDB =========================
|
||||
cd ${{ github.workspace }}
|
||||
$env:Path = $env:JAVA_HOME + ";" + $env:Path
|
||||
$env:Path = "$env:JAVA_HOME\bin;" + $env:Path
|
||||
mkdir build
|
||||
cd build
|
||||
& cmake -G "$Env:CMAKE_GENERATOR" -DCMAKE_BUILD_TYPE=Debug -DWIN_CI=1 -DPORTABLE="$Env:CMAKE_PORTABLE" -DSNAPPY=1 -DXPRESS=1 -DJNI=1 ..
|
||||
@@ -65,7 +114,7 @@ runs:
|
||||
cd ..
|
||||
echo "Building with VS version: $Env:CMAKE_GENERATOR"
|
||||
# use more parallel processes than the number of processes available, as most of the compile command would be cache hit
|
||||
msbuild build/rocksdb.sln /m:32 /p:LinkIncremental=false -property:Configuration=Debug -property:Platform=x64
|
||||
cmake --build build --config Debug --parallel 32 -- /p:LinkIncremental=false /p:Platform=x64
|
||||
if(!$?) { Exit $LASTEXITCODE }
|
||||
echo ========================= Test RocksDB =========================
|
||||
$suiteRun = "${{ inputs.suite-run }}"
|
||||
|
||||
@@ -113,11 +113,10 @@ jobs:
|
||||
- run: "USE_FOLLY=1 LIB_MODE=static DEBUG_LEVEL=0 V=1 make -j20 release"
|
||||
- run: "(mkdir build && cd build && cmake -DUSE_FOLLY=1 -DWITH_GFLAGS=1 -DROCKSDB_BUILD_SHARED=0 -DCMAKE_BUILD_TYPE=Release .. && make VERBOSE=1 -j20 && ctest -j20)"
|
||||
- uses: "./.github/actions/post-steps"
|
||||
build-windows-vs2022-avx2:
|
||||
build-windows-msvc-avx2:
|
||||
if: ${{ github.repository_owner == 'facebook' }}
|
||||
runs-on: windows-2022
|
||||
runs-on: windows-8-core
|
||||
env:
|
||||
CMAKE_GENERATOR: Visual Studio 17 2022
|
||||
CMAKE_PORTABLE: AVX2
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.0
|
||||
|
||||
@@ -314,6 +314,23 @@ jobs:
|
||||
- run: CC=clang-21 CXX=clang++-21 USE_CLANG=1 make -j32 all microbench
|
||||
- run: make clean
|
||||
- run: CC=clang-21 CXX=clang++-21 USE_CLANG=1 DEBUG_LEVEL=0 make -j32 release
|
||||
- name: Install clang-format-21 for C API gen checks
|
||||
run: apt-get update && apt-get install -y clang-format-21
|
||||
- name: Check C API codegen (link-complete, backward-compatible, up to date)
|
||||
# Run the make target in STRICT mode so this core CI job HARD-FAILS rather
|
||||
# than silently skipping if a prerequisite (clang++, clang-format, or the
|
||||
# compat baseline ref) is ever missing. See `make check-c-api-gen`.
|
||||
run: |
|
||||
# The container checkout is owned by a different user, so git refuses to
|
||||
# operate on it ("dubious ownership") -- mark it safe for the `git fetch`
|
||||
# and the `git show` the compat checker runs.
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
git config --global --add safe.directory '*'
|
||||
git fetch --no-tags --depth=1 origin main
|
||||
CXX=clang++-21 make check-c-api-gen \
|
||||
CHECK_C_API_GEN_STRICT=1 \
|
||||
API_COMPAT_REF=FETCH_HEAD \
|
||||
CLANG_FORMAT_BINARY=clang-format-21
|
||||
- uses: "./.github/actions/teardown-ccache"
|
||||
if: always()
|
||||
- uses: "./.github/actions/post-steps"
|
||||
@@ -373,14 +390,17 @@ jobs:
|
||||
crash_duration: 240
|
||||
container:
|
||||
image: ghcr.io/facebook/rocksdb_ubuntu:22.1
|
||||
options: --shm-size=16gb
|
||||
options: --shm-size=16gb --ulimit nofile=1048576:1048576
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.0
|
||||
- uses: "./.github/actions/pre-steps"
|
||||
- uses: "./.github/actions/setup-ccache"
|
||||
with:
|
||||
cache-key-prefix: mini-crashtest
|
||||
- run: ulimit -S -n `ulimit -H -n` && make V=1 -j8 CRASH_TEST_EXT_ARGS='--duration=${{ matrix.crash_duration }} --max_key=2500000' ${{ matrix.crash_test_target }}
|
||||
- run: |
|
||||
ulimit -S -n $(ulimit -Hn) # Raise open files soft limit to hard limit
|
||||
echo "Updated ulimit -Hn: $(ulimit -Hn) -Sn: $(ulimit -Sn)"
|
||||
make V=1 -j8 CRASH_TEST_EXT_ARGS='--duration=${{ matrix.crash_duration }} --max_key=2500000' ${{ matrix.crash_test_target }}
|
||||
- uses: "./.github/actions/teardown-ccache"
|
||||
if: always()
|
||||
- uses: "./.github/actions/post-steps"
|
||||
@@ -522,8 +542,8 @@ jobs:
|
||||
- uses: "./.github/actions/post-steps"
|
||||
# ======================== Windows with Tests ======================= #
|
||||
# NOTE: some windows jobs are in "nightly" to save resources
|
||||
build-windows-vs2022:
|
||||
if: needs.config.outputs.only_job == 'build-windows-vs2022' || (needs.config.outputs.only_job == '' && github.repository_owner == 'facebook')
|
||||
build-windows-msvc:
|
||||
if: needs.config.outputs.only_job == 'build-windows-msvc' || (needs.config.outputs.only_job == '' && github.repository_owner == 'facebook')
|
||||
needs: config
|
||||
runs-on: windows-8-core
|
||||
strategy:
|
||||
@@ -534,13 +554,12 @@ jobs:
|
||||
suite_run: db_test
|
||||
run_java: "false"
|
||||
- test_shard: other
|
||||
suite_run: arena_test,db_basic_test,db_test2,db_merge_operand_test,bloom_test,c_test,coding_test,crc32c_test,dynamic_bloom_test,env_basic_test,env_test,hash_test,random_test
|
||||
suite_run: arena_test,db_basic_test,db_etc2_test,db_merge_operand_test,bloom_test,c_test,coding_test,crc32c_test,dynamic_bloom_test,env_basic_test,env_test,hash_test,random_test
|
||||
run_java: "false"
|
||||
- test_shard: java
|
||||
suite_run: ""
|
||||
run_java: "true"
|
||||
env:
|
||||
CMAKE_GENERATOR: Visual Studio 17 2022
|
||||
CMAKE_PORTABLE: 1
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.0
|
||||
@@ -600,7 +619,6 @@ jobs:
|
||||
needs: config
|
||||
runs-on: macos-15-xlarge
|
||||
env:
|
||||
JAVA_HOME: "/Library/Java/JavaVirtualMachines/liberica-jdk-8.jdk/Contents/Home"
|
||||
ROCKSDB_DISABLE_JEMALLOC: 1
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.0
|
||||
@@ -612,7 +630,7 @@ jobs:
|
||||
cache-key-prefix: macos-java
|
||||
- uses: "./.github/actions/increase-max-open-files-on-macos"
|
||||
- uses: "./.github/actions/install-gflags-on-macos"
|
||||
- uses: "./.github/actions/install-jdk8-on-macos"
|
||||
- uses: "./.github/actions/setup-jdk-on-macos"
|
||||
- uses: "./.github/actions/pre-steps-macos"
|
||||
- name: Set Java Environment
|
||||
run: |-
|
||||
@@ -628,8 +646,6 @@ jobs:
|
||||
if: needs.config.outputs.only_job == 'build-macos-java-static' || (needs.config.outputs.only_job == '' && github.repository_owner == 'facebook')
|
||||
needs: config
|
||||
runs-on: macos-15-xlarge
|
||||
env:
|
||||
JAVA_HOME: "/Library/Java/JavaVirtualMachines/liberica-jdk-8.jdk/Contents/Home"
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.0
|
||||
- uses: maxim-lobanov/setup-xcode@v1.6.0
|
||||
@@ -640,7 +656,7 @@ jobs:
|
||||
cache-key-prefix: macos-java-static
|
||||
- uses: "./.github/actions/increase-max-open-files-on-macos"
|
||||
- uses: "./.github/actions/install-gflags-on-macos"
|
||||
- uses: "./.github/actions/install-jdk8-on-macos"
|
||||
- uses: "./.github/actions/setup-jdk-on-macos"
|
||||
- uses: "./.github/actions/pre-steps-macos"
|
||||
- name: Set Java Environment
|
||||
run: |-
|
||||
@@ -656,8 +672,6 @@ jobs:
|
||||
if: needs.config.outputs.only_job == 'build-macos-java-static-universal' || (needs.config.outputs.only_job == '' && github.repository_owner == 'facebook')
|
||||
needs: config
|
||||
runs-on: macos-15-xlarge
|
||||
env:
|
||||
JAVA_HOME: "/Library/Java/JavaVirtualMachines/liberica-jdk-8.jdk/Contents/Home"
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.0
|
||||
- uses: maxim-lobanov/setup-xcode@v1.6.0
|
||||
@@ -668,7 +682,7 @@ jobs:
|
||||
cache-key-prefix: macos-java-static-universal
|
||||
- uses: "./.github/actions/increase-max-open-files-on-macos"
|
||||
- uses: "./.github/actions/install-gflags-on-macos"
|
||||
- uses: "./.github/actions/install-jdk8-on-macos"
|
||||
- uses: "./.github/actions/setup-jdk-on-macos"
|
||||
- uses: "./.github/actions/pre-steps-macos"
|
||||
- name: Set Java Environment
|
||||
run: |-
|
||||
|
||||
+5
-1
@@ -1,5 +1,7 @@
|
||||
make_config.mk
|
||||
rocksdb.pc
|
||||
.build_signature
|
||||
build_tools/__pycache__/
|
||||
|
||||
*.a
|
||||
*.arc
|
||||
@@ -52,7 +54,7 @@ GRTAGS
|
||||
GTAGS
|
||||
rocksdb_dump
|
||||
rocksdb_undump
|
||||
db_test2
|
||||
db_etc2_test
|
||||
trace_analyzer
|
||||
block_cache_trace_analyzer
|
||||
io_tracer_parser
|
||||
@@ -88,6 +90,8 @@ fbcode/
|
||||
fbcode
|
||||
buckifier/*.pyc
|
||||
buckifier/__pycache__
|
||||
tools/__pycache__/
|
||||
tools/c_api_gen/__pycache__/
|
||||
.arcconfig
|
||||
|
||||
compile_commands.json
|
||||
|
||||
@@ -35,6 +35,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
|
||||
"db/blob/blob_file_partition_manager.cc",
|
||||
"db/blob/blob_file_reader.cc",
|
||||
"db/blob/blob_garbage_meter.cc",
|
||||
"db/blob/blob_gen2_format.cc",
|
||||
"db/blob/blob_log_format.cc",
|
||||
"db/blob/blob_log_sequential_reader.cc",
|
||||
"db/blob/blob_log_writer.cc",
|
||||
@@ -4868,6 +4869,12 @@ cpp_unittest_wrapper(name="db_encryption_test",
|
||||
extra_compiler_flags=[])
|
||||
|
||||
|
||||
cpp_unittest_wrapper(name="db_etc2_test",
|
||||
srcs=["db/db_etc2_test.cc"],
|
||||
deps=[":rocksdb_test_lib"],
|
||||
extra_compiler_flags=[])
|
||||
|
||||
|
||||
cpp_unittest_wrapper(name="db_etc3_test",
|
||||
srcs=["db/db_etc3_test.cc"],
|
||||
deps=[":rocksdb_test_lib"],
|
||||
@@ -5024,12 +5031,6 @@ cpp_unittest_wrapper(name="db_test",
|
||||
extra_compiler_flags=[])
|
||||
|
||||
|
||||
cpp_unittest_wrapper(name="db_test2",
|
||||
srcs=["db/db_test2.cc"],
|
||||
deps=[":rocksdb_test_lib"],
|
||||
extra_compiler_flags=[])
|
||||
|
||||
|
||||
cpp_unittest_wrapper(name="db_universal_compaction_test",
|
||||
srcs=["db/db_universal_compaction_test.cc"],
|
||||
deps=[":rocksdb_test_lib"],
|
||||
@@ -5795,3 +5796,5 @@ cpp_unittest_wrapper(name="write_unprepared_transaction_test",
|
||||
|
||||
|
||||
export_file(name = "tools/db_crashtest.py")
|
||||
|
||||
export_file(name = "tools/fault_injection_log_parser.py")
|
||||
|
||||
@@ -38,7 +38,7 @@ This document provides guidance for generating and reviewing code in the RocksDB
|
||||
|
||||
**SIMD and Vectorization:** Leverage SIMD instructions (SSE, AVX) for data-parallel operations when appropriate. Structure data to enable auto-vectorization by the compiler. Consider explicit SIMD intrinsics for critical hot paths like checksum computation, encoding/decoding, and bulk data processing.
|
||||
|
||||
**Branch Prediction:** Minimize unpredictable branches in hot paths. Use `LIKELY`/`UNLIKELY` macros to hint branch prediction. Consider branchless alternatives for simple conditionals. Order switch cases and if-else chains by frequency.
|
||||
**Branch Prediction:** Minimize unpredictable branches in hot paths. Use `LIKELY`/`UNLIKELY` macros to hint branch prediction, e.g. for error cases and other rare or otherwise costly cases, but NOT for predicting popular configurations. Consider branchless alternatives for simple conditionals. Order switch cases and if-else chains by frequency.
|
||||
|
||||
**Memory and Resource Management:** Be mindful of memory allocations, especially in hot paths. Use RAII patterns, smart pointers, and RocksDB's memory management utilities appropriately.
|
||||
|
||||
@@ -149,6 +149,26 @@ Cache management is critical for RocksDB's performance.
|
||||
|
||||
When reviewing RocksDB code (or preparing code for review), use this checklist:
|
||||
|
||||
### Contract Boundaries
|
||||
- [ ] Is each behavior owned by the right layer? High-level policy (for example,
|
||||
"compaction wants this I/O mode") should live at the caller/policy layer, while
|
||||
lower layers should expose generic mechanisms (for example, "open a fresh
|
||||
reader", "skip shared cache insertion", or "use these FileOptions").
|
||||
- [ ] Do comments and names describe local contracts rather than leaking a
|
||||
specific caller's rationale into reusable APIs? Generic code should not need to
|
||||
know about one current use case unless the API itself is intentionally
|
||||
use-case-specific.
|
||||
- [ ] Does each flag or parameter control one coherent behavior? If one boolean
|
||||
starts implying ownership, cache policy, I/O mode, prefetching, and caller
|
||||
identity, split it into explicit flags or an options struct.
|
||||
- [ ] Could a future caller use this lower-level API without accidentally
|
||||
inheriting assumptions from compaction, backup, user reads, or a particular
|
||||
table format? If not, tighten the contract with assertions, clearer names, or
|
||||
a narrower API.
|
||||
- [ ] Are implementation details not being used as policy signals? Prefer an
|
||||
explicit contract over inferring behavior from incidental fields such as file
|
||||
options, cache handles, or current table-reader state.
|
||||
|
||||
### Correctness
|
||||
- [ ] Does the change preserve database semantics (e.g., snapshot isolation, key ordering)?
|
||||
- [ ] Are all error cases handled appropriately?
|
||||
@@ -204,18 +224,93 @@ The following patterns emerged as frequent sources of review feedback:
|
||||
|
||||
10. **Platform Compatibility:** Ensure changes work correctly on all supported platforms (Linux, Windows, macOS) and with all supported compilers (GCC, Clang, MSVC).
|
||||
|
||||
11. **Contract Boundary Leaks:** When a change plumbs a new option or use-case
|
||||
specific behavior through multiple subsystems, review the call chain for
|
||||
contract leaks. Caller-specific rationale belongs at the call site or public API
|
||||
documentation; reusable layers should expose precise, layer-local capabilities.
|
||||
Watch especially for comments mentioning one caller in generic code, booleans
|
||||
that silently bundle several behaviors, and downstream code inferring policy
|
||||
from an implementation detail instead of an explicit option.
|
||||
|
||||
---
|
||||
|
||||
## Important tips
|
||||
|
||||
### Build system
|
||||
* There are 3 build system. Make, CMake, BUCK(meta internal).
|
||||
* There are 3 build system. Make for git clones, BUCK (meta internal) for hg
|
||||
clones, and CMake for some special cases.
|
||||
* When a new .cc file is added, update Makefile, CMakeLists.txt, src.mk, BUCK.
|
||||
* Don't manually edit BUCK file, after updating src.mk, run
|
||||
/usr/local/bin/python3 buckifier/buckify_rocksdb.py to update it
|
||||
* Use make to build and run the test. CMake and BUCK are not used locally.
|
||||
* Use `make dbg` command to build all of the unit test in debug mode.
|
||||
* For -j in make command, use the number of CPU cores to decide it.
|
||||
* When searching for references to something (a symbol, library, etc.), do not
|
||||
restrict or truncate your search based on presumed relevance or scope. It is
|
||||
important and time-saving to keep the repo reasonably consistent across
|
||||
different build systems, programming languages, and even between
|
||||
documentation and implementation.
|
||||
|
||||
### Avoiding mixed build modes with Make (use `AUTO_CLEAN=1`)
|
||||
|
||||
Object files are written to the same paths regardless of build flags, so
|
||||
reusing objects from a prior build with different flags causes confusing
|
||||
linker errors, etc. This problem is essentially avoidable by ALWAYS using
|
||||
`AUTO_CLEAN=1 make -j<n> <something>` for manual make invocations. This
|
||||
will automatically clean object files if the build parameters/flavor have
|
||||
changed. The `build_tools/rockstest.sh` / `rocksptest.sh` helpers described
|
||||
below set `AUTO_CLEAN=1` for you.
|
||||
|
||||
### Source checks
|
||||
* Run `make check-sources` before committing. This catches non-ASCII
|
||||
characters in source files and other source-level issues that CI will
|
||||
reject. In particular, **do not use Unicode characters** (em dashes,
|
||||
smart quotes, etc.) in comments or strings -- use ASCII equivalents
|
||||
(`--` instead of em dash, `'` instead of smart quote, etc.).
|
||||
|
||||
### License headers
|
||||
* Every new source file needs a license header. For a file that does **not**
|
||||
carry an outside/third-party copyright, use the standard Meta dual-licensed
|
||||
header (the dual-license designation is required -- a bare
|
||||
"All Rights Reserved" copyright is not an acceptable open-source header):
|
||||
```
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
// 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).
|
||||
```
|
||||
Use a `#` comment prefix instead of `//` for shell, Python, and Makefile
|
||||
fragments.
|
||||
* Files derived from an external source (e.g. LevelDB) keep their original
|
||||
upstream copyright line in addition to the header above.
|
||||
|
||||
### RTTI and dynamic_cast
|
||||
* Production code and `db_stress` must build in **release mode
|
||||
(`-fno-rtti`)**. Do not use `dynamic_cast` anywhere except unit tests.
|
||||
Use `static_cast_with_check` from `util/cast_util.h` (validates with
|
||||
`dynamic_cast` in debug builds, plain `static_cast` in release).
|
||||
* Unit tests (`*_test.cc`) are built in debug mode with RTTI enabled.
|
||||
|
||||
### Cross-platform / portability
|
||||
Local `make` only exercises Linux with GCC/Clang, but CI
|
||||
(`.github/workflows/pr-jobs.yml` and `nightly.yml`) gates on a much wider
|
||||
matrix, so portability breaks are invisible locally until CI fails. Code must
|
||||
build (and where noted, run tests) across:
|
||||
|
||||
| Axis | Must support |
|
||||
|------|--------------|
|
||||
| OS | Linux (x86_64 + ARM), macOS, Windows |
|
||||
| Compiler | GCC, Clang (libstdc++ **and** libc++), AppleClang, **MSVC (VS2022)**, MinGW (Linux cross-compile, build-only, no gflags) |
|
||||
| Build system | Make, CMake, and BUCK (internal) -- keep all in sync (see "Build system" above) |
|
||||
| Config | release (`-fno-rtti`), `ASSERT_STATUS_CHECKED`, ASAN/UBSAN/TSAN, folly, unity build, JNI/Java |
|
||||
|
||||
Treat these as constraints to satisfy and infer the specifics from them before
|
||||
adding any system header, libc call, or compiler-specific construct. The most
|
||||
common trap: anything that compiles under GCC/Clang on Linux but not under
|
||||
**MSVC/MinGW** -- e.g. unguarded POSIX-only headers/functions (`<unistd.h>`,
|
||||
`<sys/*.h>`, `getpid`, `_exit`, ...) or GCC/Clang extensions
|
||||
(`__attribute__`, `__builtin_*`, VLAs, `alloca`). Prefer the `port::`/`Env`
|
||||
abstractions; otherwise guard with `#ifdef OS_WIN` (POSIX `<unistd.h>` ->
|
||||
Windows `<process.h>`). Because libc++ is also tested, include what you use
|
||||
rather than relying on libstdc++ transitive includes.
|
||||
|
||||
### Unit Test
|
||||
* After all of the unit tests are added, review them and try to extract common
|
||||
@@ -224,14 +319,26 @@ The following patterns emerged as frequent sources of review feedback:
|
||||
* Don't use sleep to wait for certain events to happen. This will cause test to
|
||||
be flaky. Instead, use sync point to synchronize thread progress.
|
||||
* Cap unit test execution with 60 seconds timeout.
|
||||
* When there are multiple unit tests need to be executed, try to use
|
||||
gtest_parallel.py if available. E.g.
|
||||
python3 ${GTEST_PARALLEL}/gtest_parallel.py ./table_test
|
||||
* After writing a test, stress-test for flakiness:
|
||||
* To build and run unit tests locally, prefer these helper scripts:
|
||||
* `build_tools/rocksptest.sh <test_binary> [more_binaries...] [args...]`
|
||||
builds the binary(ies) with parallel make and `AUTO_CLEAN=1` and runs
|
||||
them under gtest-parallel, sharding the test cases across CPUs. Prefer
|
||||
this whenever running more than a couple of test cases, e.g.
|
||||
`build_tools/rocksptest.sh table_test` or
|
||||
`build_tools/rocksptest.sh db_test env_test --gtest_filter=*Foo*`.
|
||||
* `build_tools/rockstest.sh <test_binary> [args...]` builds with parallel
|
||||
make and `AUTO_CLEAN=1` and runs the binary directly (serially).
|
||||
Use it only for a very small number of test cases, e.g.
|
||||
`build_tools/rockstest.sh db_test --gtest_filter=*MixedSlowdown*`.
|
||||
* After writing a test, stress-test for flakiness (AUTO_CLEAN handles the
|
||||
rebuild needed by the `COERCE_CONTEXT_SWITCH=1` flag change):
|
||||
```bash
|
||||
COERCE_CONTEXT_SWITCH=1 make {test_binary}
|
||||
./{test_binary} --gtest_filter="*YourTestName*" --gtest_repeat=5
|
||||
COERCE_CONTEXT_SWITCH=1 build_tools/rockstest.sh {test_binary} -r100 \
|
||||
--gtest_filter="*YourTestName*"
|
||||
```
|
||||
* For CI-style flaky tests that do not reproduce with `gtest_parallel.py`,
|
||||
`--gtest_repeat`, or normal coerce-mode runs, inspect
|
||||
`tools/gtest_parallel_repro.py --help`.
|
||||
|
||||
### Unit test dedup guidelines
|
||||
* Extract helper functions for repeated patterns such as object
|
||||
@@ -284,12 +391,13 @@ The following patterns emerged as frequent sources of review feedback:
|
||||
* Blog post authors must be defined in `docs/_data/authors.yml` to be displayed
|
||||
|
||||
### Final verification of the change
|
||||
* Execute make clean to clean all of the changes.
|
||||
* Execute make check to build all of the changes and execute all of the tests.
|
||||
Note that executing all of the tests could take multiple minutes.
|
||||
* Run `ASSERT_STATUS_CHECKED=1 make check` to verify all Status objects are
|
||||
properly checked. This catches missing error handling that can lead to
|
||||
silent data corruption.
|
||||
* Execute `AUTO_CLEAN=1 make check` to build all of the changes and execute all
|
||||
of the tests. `AUTO_CLEAN=1` ensures a clean rebuild if your previous build
|
||||
used different parameters. Note that executing all of the tests could take
|
||||
multiple minutes.
|
||||
* Run `AUTO_CLEAN=1 ASSERT_STATUS_CHECKED=1 make check` to verify all Status
|
||||
objects are properly checked. This catches missing error handling that can
|
||||
lead to silent data corruption.
|
||||
|
||||
### Monitoring make check progress
|
||||
* Use `make check-progress` to get machine-parseable JSON progress while
|
||||
@@ -297,7 +405,7 @@ The following patterns emerged as frequent sources of review feedback:
|
||||
builds without timeout issues.
|
||||
* Run `make check` in background, then poll progress:
|
||||
```bash
|
||||
make check &
|
||||
AUTO_CLEAN=1 make check &
|
||||
# Poll periodically:
|
||||
make check-progress
|
||||
```
|
||||
@@ -322,9 +430,10 @@ The following patterns emerged as frequent sources of review feedback:
|
||||
|
||||
### Executing benchmark using db_bench
|
||||
* Since the goal is to measure performance, we need to build a release binary
|
||||
using `make clean && DEBUG_LEVEL=0 make db_bench`. If there is an engine
|
||||
crash due to bug, we need to switch back to debug build. Make sure to run
|
||||
`make clean` before running `make dbg`.
|
||||
using `AUTO_CLEAN=1 DEBUG_LEVEL=0 make db_bench`. If there is an engine
|
||||
crash due to a bug, switch back to a debug build with
|
||||
`AUTO_CLEAN=1 make dbg`; `AUTO_CLEAN=1` handles the release<->debug rebuild
|
||||
automatically.
|
||||
|
||||
### Formatting code
|
||||
* After making change, use `make format-auto` to auto-apply formatting without
|
||||
|
||||
+51
-10
@@ -420,13 +420,6 @@ if(WITH_NUMA)
|
||||
list(APPEND THIRDPARTY_LIBS NUMA::NUMA)
|
||||
endif()
|
||||
|
||||
option(WITH_TBB "build with Threading Building Blocks (TBB)" OFF)
|
||||
if(WITH_TBB)
|
||||
find_package(TBB REQUIRED)
|
||||
add_definitions(-DTBB)
|
||||
list(APPEND THIRDPARTY_LIBS TBB::TBB)
|
||||
endif()
|
||||
|
||||
# Stall notifications eat some performance from inserts
|
||||
option(DISABLE_STALL_NOTIF "Build with stall notifications" OFF)
|
||||
if(DISABLE_STALL_NOTIF)
|
||||
@@ -654,6 +647,8 @@ if(USE_FOLLY)
|
||||
FMT_INST_PATH)
|
||||
exec_program(ls ARGS -d ${FOLLY_INST_PATH}/../gflags* OUTPUT_VARIABLE
|
||||
GFLAGS_INST_PATH)
|
||||
exec_program(ls ARGS -d ${FOLLY_INST_PATH}/../glog* OUTPUT_VARIABLE
|
||||
GLOG_INST_PATH)
|
||||
set(Boost_DIR ${BOOST_INST_PATH}/lib/cmake/Boost-1.83.0)
|
||||
if(EXISTS ${FMT_INST_PATH}/lib64)
|
||||
set(fmt_DIR ${FMT_INST_PATH}/lib64/cmake/fmt)
|
||||
@@ -661,16 +656,61 @@ if(USE_FOLLY)
|
||||
set(fmt_DIR ${FMT_INST_PATH}/lib/cmake/fmt)
|
||||
endif()
|
||||
set(gflags_DIR ${GFLAGS_INST_PATH}/lib/cmake/gflags)
|
||||
if(EXISTS ${GLOG_INST_PATH}/lib64/cmake/glog)
|
||||
set(GLOG_CMAKE_DIR ${GLOG_INST_PATH}/lib64/cmake/glog)
|
||||
elseif(EXISTS ${GLOG_INST_PATH}/lib/cmake/glog)
|
||||
set(GLOG_CMAKE_DIR ${GLOG_INST_PATH}/lib/cmake/glog)
|
||||
endif()
|
||||
if(NOT GLOG_CMAKE_DIR)
|
||||
find_library(GETDEPS_GLOG_LIBRARY NAMES glogd glog
|
||||
PATHS ${GLOG_INST_PATH}/lib64 ${GLOG_INST_PATH}/lib
|
||||
NO_DEFAULT_PATH)
|
||||
if(NOT GETDEPS_GLOG_LIBRARY OR
|
||||
NOT EXISTS ${GLOG_INST_PATH}/include/glog/logging.h)
|
||||
message(FATAL_ERROR "Could not find getdeps glog under "
|
||||
"${GLOG_INST_PATH}")
|
||||
endif()
|
||||
set(GLOG_CMAKE_DIR ${CMAKE_CURRENT_BINARY_DIR}/getdeps-glog-cmake)
|
||||
file(MAKE_DIRECTORY ${GLOG_CMAKE_DIR})
|
||||
file(WRITE ${GLOG_CMAKE_DIR}/glog-config.cmake
|
||||
"if(NOT TARGET glog::glog)\n"
|
||||
" add_library(glog::glog UNKNOWN IMPORTED)\n"
|
||||
" set_target_properties(glog::glog PROPERTIES\n"
|
||||
" IMPORTED_LOCATION \"${GETDEPS_GLOG_LIBRARY}\"\n"
|
||||
" INTERFACE_INCLUDE_DIRECTORIES \"${GLOG_INST_PATH}/include\")\n"
|
||||
"endif()\n"
|
||||
"set(glog_FOUND TRUE)\n"
|
||||
"set(Glog_FOUND TRUE)\n"
|
||||
"set(GLOG_FOUND TRUE)\n"
|
||||
"set(GLOG_LIBRARY \"${GETDEPS_GLOG_LIBRARY}\")\n"
|
||||
"set(GLOG_LIBRARIES \"${GETDEPS_GLOG_LIBRARY}\")\n"
|
||||
"set(GLOG_INCLUDE_DIR \"${GLOG_INST_PATH}/include\")\n")
|
||||
endif()
|
||||
set(glog_DIR ${GLOG_CMAKE_DIR})
|
||||
set(Glog_DIR ${GLOG_CMAKE_DIR})
|
||||
# Unlike gflags, glog may also be installed system-wide. Pre-resolve the
|
||||
# getdeps copy so folly-config.cmake cannot fall back to another version.
|
||||
find_package(glog CONFIG REQUIRED PATHS ${GLOG_CMAKE_DIR}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
exec_program(sed ARGS -i 's/gflags_shared//g'
|
||||
${FOLLY_INST_PATH}/lib/cmake/folly/folly-targets.cmake)
|
||||
|
||||
include(${FOLLY_INST_PATH}/lib/cmake/folly/folly-config.cmake)
|
||||
|
||||
# Fix gflags library name for debug builds
|
||||
# Fix gflags library name for debug builds. The getdeps gflags shared
|
||||
# library is versioned (e.g. libgflags_debug.so.2.3), so resolve the
|
||||
# actual file by glob rather than hard-coding a version.
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
file(GLOB GFLAGS_DEBUG_SHARED_LIBS
|
||||
"${GFLAGS_INST_PATH}/lib/libgflags_debug.so.*")
|
||||
if(NOT GFLAGS_DEBUG_SHARED_LIBS)
|
||||
message(FATAL_ERROR
|
||||
"Could not find getdeps libgflags_debug.so under ${GFLAGS_INST_PATH}/lib")
|
||||
endif()
|
||||
list(GET GFLAGS_DEBUG_SHARED_LIBS 0 GFLAGS_DEBUG_SHARED_LIB)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${GFLAGS_INST_PATH}/lib")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GFLAGS_INST_PATH}/lib/libgflags_debug.so.2.2")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GFLAGS_DEBUG_SHARED_LIB}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -737,6 +777,7 @@ set(SOURCES
|
||||
db/blob/blob_file_meta.cc
|
||||
db/blob/blob_file_reader.cc
|
||||
db/blob/blob_garbage_meter.cc
|
||||
db/blob/blob_gen2_format.cc
|
||||
db/blob/blob_log_format.cc
|
||||
db/blob/blob_log_sequential_reader.cc
|
||||
db/blob/blob_log_writer.cc
|
||||
@@ -1453,6 +1494,7 @@ if(WITH_TESTS)
|
||||
db/db_clip_test.cc
|
||||
db/db_dynamic_level_test.cc
|
||||
db/db_encryption_test.cc
|
||||
db/db_etc2_test.cc
|
||||
db/db_etc3_test.cc
|
||||
db/db_flush_test.cc
|
||||
db/db_inplace_update_test.cc
|
||||
@@ -1476,7 +1518,6 @@ if(WITH_TESTS)
|
||||
db/db_table_properties_test.cc
|
||||
db/db_tailing_iter_test.cc
|
||||
db/db_test.cc
|
||||
db/db_test2.cc
|
||||
db/db_logical_block_size_cache_test.cc
|
||||
db/db_universal_compaction_test.cc
|
||||
db/db_wal_test.cc
|
||||
|
||||
+84
@@ -1,6 +1,90 @@
|
||||
# Rocksdb Change Log
|
||||
> NOTE: Entries for next release do not go here. Follow instructions in `unreleased_history/README.txt`
|
||||
|
||||
## 11.6.0 (07/02/2026)
|
||||
### New Features
|
||||
* Added EXPERIMENTAL embedded blob SST support through `SstFileWriter::OpenWithEmbeddedBlobs()`, storing eligible large values as same-file blob records in block-based SST files and resolving them transparently for reads. This niche feature currently supports uncompressed embedded blobs only; compression options are placeholders and compression support is deferred to follow-up work.
|
||||
|
||||
### Public API Changes
|
||||
* Expanded the C API (`include/rocksdb/c.h`) with a large set of new `rocksdb_*` functions, mostly option getters/setters plus table-properties, job/event-listener, and metadata accessors, a WAL filter, a ReadOptions table filter, and a backup exclude-files callback. Many are now produced by a new semi-automated generator (`tools/c_api_gen/`) from the C++ headers; `include/rocksdb/c.h` remains a single self-contained header and the signatures of pre-existing functions are unchanged.
|
||||
|
||||
### Bug Fixes
|
||||
* Reverted PR14831 that made range_lock_manager aware of reverse-order CF
|
||||
* Fixed a bug in `RandomAccessFileReader::ReadAsync` where an already-aligned direct-IO read request with a null `scratch` and a caller-provided `aligned_buf` would take the "already aligned" fast path and submit the null buffer to the underlying async read (e.g. a null iovec base to io_uring, failing with EFAULT). This could surface as spurious iterator failures during async prefetch (MultiScan with async IO) on direct-IO databases. The async path now allocates a backing buffer in this case, matching the synchronous `Read` path.
|
||||
* Fixed a bug where closing a read-only DB instance could delete live SST files created by a concurrent read-write DB sharing the same directory.
|
||||
|
||||
## 11.5.0 (06/16/2026)
|
||||
### New Features
|
||||
* External table readers that open files through `ExternalTableOptions::fs` now update RocksDB SST/file-read statistics and file IO listener callbacks, making external file IO activity visible in existing read metrics.
|
||||
* Added `DB::PrepareFileIngestion()`, a two-phase form of `IngestExternalFile`/`IngestExternalFiles`. `PrepareFileIngestion()` performs all of the work that does not require the DB mutex (validating the arguments, reading each external file's metadata, and linking/copying the files into the DB) and returns an opaque `FileIngestionHandle`. `DB::CommitFileIngestionHandle()` (or `DB::CommitFileIngestionHandles()` for several handles at once) then makes the prepared files visible; multiple handles are committed atomically in a single MANIFEST write, or none are. `FileIngestionHandle::Abort()` (or simply destroying the handle) cancels a prepared ingestion and rolls it back. This gives flexibility to the application to Prepare a file separately from when its committed, and may shorten an applications critical path on `IngestExternalFile`.
|
||||
* Added two stats histograms reporting the per-call latency (in microseconds) of each successful `IngestExternalFile`/`IngestExternalFiles` call, split by phase: `rocksdb.ingest.external.file.prepare.micros` (argument validation and reading/validating/linking the external files, which does not block live writes) and `rocksdb.ingest.external.file.run.micros` (the ingestion performed under the DB mutex while live writes are blocked). Failed ingestions are not recorded.
|
||||
* Added `DBOptions::use_direct_io_for_compaction_reads` (default false). When enabled, compaction-input SST reads use `O_DIRECT` while user reads remain buffered, avoiding page-cache eviction of hot user-read data by sequential compaction scans. Pair with `use_direct_io_for_flush_and_compaction = true` on write-heavy workloads for direct I/O on both compaction inputs and outputs. Rejected at Open when combined with `allow_mmap_reads = true`. No-op when `use_direct_reads = true` is already set (since all reads are already direct).
|
||||
|
||||
### Public API Changes
|
||||
* `DB::GetPreparedFileInfoForExternalSstIngestion()` can now prepare metadata for a live DB-generated SST file so it can be passed to `IngestExternalFileArg::file_infos`. The input path must exactly match a live table file owned by the source DB, and the returned metadata handle must outlive the ingestion.
|
||||
* `ExternalSstFileInfo` gained a `prepared_file_info` member produced by `SstFileWriter::Finish`, and `IngestExternalFileArg` gained a `file_infos` field: a vector of borrowed `const PreparedFileInfo*` pointers, parallel to `external_files`. The owning `ExternalSstFileInfo::prepared_file_info` handle must outlive the ingestion. When set, `IngestExternalFiles()` reuses the supplied per-file metadata instead of re-opening and scanning each file to recompute it, avoiding that extra I/O.
|
||||
* Corrected the public C++ option spelling from `memtable_veirfy_per_key_checksum_on_seek` to `memtable_verify_per_key_checksum_on_seek`. RocksDB continues to accept the old misspelled OPTIONS-file key for compatibility, while newly serialized OPTIONS files use the corrected key.
|
||||
* Added experimental read-scoped block buffer provider API, configured through `ReadOptions::read_scoped_block_buffer_provider`, for supported block-based table iterator scans and MultiScan reads to use caller-provided read-scoped storage for final data-block contents. When configured, supported provider-backed scan data-block reads bypass the data-block cache. The provider is ignored when mmap reads are enabled. RocksDB may still use ordinary temporary scratch for serialized block bytes, such as when a block may be compressed. Get and MultiGet do not currently provide API guarantees for this provider.
|
||||
* Added `FileSystem::SyncFile()` and `Env::SyncFile()` public APIs for syncing or fsyncing a file by name without requiring callers to reopen it as writable.
|
||||
|
||||
### Behavior Changes
|
||||
* The default `compression` for column families is now `kLZ4Compression` rather than `kSnappyCompression`. This affects only column families that do not explicitly set `compression`, and only newly-written SST files. The change is fully compatible: existing data remains readable with no migration needed, as RocksDB selects the decompressor per block. LZ4 offers slightly better compression ratios and decompression CPU efficiency vs. Snappy and similar compression CPU, tested across various server CPUs. When support is not compiled in, the fallback path for default compression is LZ4 -> Snappy -> NoCompression.
|
||||
* Disable parallel compression (ignore `CompressionOptions::parallel_threads`) for fast built-in compressors: Snappy, LZ4 (accelerated, not LZ4HC), and accelerated levels of ZSTD (level < 0). These do not generally benefit from parallel compression. This behavior can be overridden with a custom Compressor from a custom CompressionManager.
|
||||
* `PosixFileSystem::OptimizeForCompactionTableRead` now delegates to the base `FileSystem::OptimizeForCompactionTableRead` implementation before applying its Linux-only compaction-readahead clamp (added for #12038). The returned `FileOptions::use_direct_reads` therefore reflects `DBOptions::use_direct_reads`, consistent with the base class and with other `FileSystem` implementations. Previously the override ignored the base implementation and keyed both the returned options and the Linux readahead clamp off the incoming `FileOptions` rather than `DBOptions`. At the in-tree call site the incoming `FileOptions::use_direct_reads` already matches `DBOptions::use_direct_reads`, so this is effectively a no-op for existing configurations; it removes a latent inconsistency where a caller passing `FileOptions` whose `use_direct_reads` disagreed with `DBOptions` would have had the global flag silently ignored for compaction-input reads on Linux. (Note: the `#12038` readahead clamp still keys off the global `use_direct_reads`; it is not skipped for the compaction-only `use_direct_io_for_compaction_reads` path, since that flag enables O_DIRECT after this hook runs.)
|
||||
* Brought more unity to `kLZ4Compression` and `kLZ4HCCompression` by giving each access to the other's compression levels. Negative (fast) values previously only available to LZ4 and positive (slow) values previously only available to LZ4HC are now available to both, so configuring a non-default `compression_opts.level` now selects the LZ4 compressor variant. This is a behavior change for previously tolerated but dubious configurations such as positive compression level with `kLZ4Compression`. `kLZ4Compression` and `kLZ4HCCompression` keep their effective default levels, equivalent to -1 and 9 respectively.
|
||||
* Removed a discontinuity in `kZSTD` compression levels at `compression_opts.level == 0` by mapping that setting to `level = -1` rather than to `level = 3` as the ZSTD library does internally. This improves the compression auto-tuning landscape.
|
||||
|
||||
### Bug Fixes
|
||||
* Fixed a bug where the range lock manager would crash with an assertion failure when using a reverse comparator column family.
|
||||
|
||||
### Performance Improvements
|
||||
* Reduced commit latency when ingesting many external files by allowing `IngestExternalFileOptions::file_opening_threads` to open table readers for committed ingested files using multiple threads.
|
||||
* Reduced commit latency for large external file ingestions into the last level by adding `IngestExternalFileOptions::prefetch_lmax_index_and_filter_blocks`, which can skip commit-time index and filter block prefetching for cache-backed table metadata.
|
||||
|
||||
## 11.4.0 (06/02/2026)
|
||||
### Public API Changes
|
||||
* Added `rocksdb_options_set_memtable_batch_lookup_optimization()` and `rocksdb_options_get_memtable_batch_lookup_optimization()` to the C API, exposing the existing `AdvancedColumnFamilyOptions::memtable_batch_lookup_optimization` field. This allows C API users (and downstream language bindings) to enable the skip-list memtable's batch-lookup optimization for `MultiGet`, which caches the search path between consecutive keys and reduces per-key cost from O(log N) to O(log d) where d is the distance between consecutive keys.
|
||||
* Added `rocksdb_readoptions_set_optimize_multiget_for_io()` and `rocksdb_readoptions_get_optimize_multiget_for_io()` to the C API, exposing the existing `ReadOptions::optimize_multiget_for_io` field. This allows C API users (and downstream language bindings) to opt out of the multi-level parallel MultiGet path, which only takes effect when the library is built with `USE_COROUTINES`.
|
||||
* Added `rocksdb_block_based_table_index_block_search_type_auto` enum constant and the `rocksdb_block_based_options_set_uniform_cv_threshold()` setter to the C API. The constant exposes `BlockSearchType::kAuto`, and the setter exposes `BlockBasedTableOptions::uniform_cv_threshold`. Both are required for `kAuto` index-block search to take effect from the C API: without setting `uniform_cv_threshold >= 0`, the per-block `is_uniform` footer bit is never written, and `kAuto` falls back to binary search at read time.
|
||||
* Added `EventListener::OnDBShutdownBegin`, a callback that fires once when a DB begins shutdown, including when RocksDB cleans up a failed `DB::Open()` attempt.
|
||||
* Added a new PerfContext counter `blob_cache_read_byte` for blob cache bytes read.
|
||||
|
||||
### Behavior Changes
|
||||
* Remote compaction now falls back to local compaction when the primary cannot deserialize a successful `CompactionServiceResult` before installing any remote output files.
|
||||
* StringToMap (rocksdb/convenience.h) now preserves the outer braces of nested values so each map entry is in self-contained form and can be embedded directly into another `key=value;` string (e.g. SetOptions) without losing inner ';' delimiters. A new symmetric MapToString utility is provided.
|
||||
|
||||
### Bug Fixes
|
||||
* Fixed a bug where `AbortAllCompactions()` could leave automatic compaction work unscheduled when aborting before the background worker picked it, causing compaction and write stalls until DB restart.
|
||||
* Fix a bug where db had a false positive compaction corruption error due to remote compaction service result with `has_accurate_num_input_records=false` not being serialized.
|
||||
* Fixed WritePrepared TransactionDB cleanup after retryable commit or rollback write failures so prepared transactions remain rollbackable instead of leaving unresolved prepared state.
|
||||
* Fix a rare corruption bug for tiered compaction that incorrectly moved last level range tombstones into proximal level. This corruption error is surfaced when force_consistency_checks is enabled.
|
||||
|
||||
### Performance Improvements
|
||||
* Reduce the likelihood of user-facing metadata operations blocking on MANIFEST rotation when file creation is slow, such as on remote storage. MANIFEST write batches containing foreground edits from `CreateColumnFamily()`, `DropColumnFamily()`, `CreateColumnFamilyWithImport()`, `IngestExternalFile()`, and `DeleteFilesInRanges()` now get a relaxed file size threshold for triggering MANIFEST rotation; background-only MANIFEST write batches, such as compaction and flush, continue to use the normal threshold. This change should make auto-tuning manifest file size more attractive (see `max_manifest_file_size` and `max_manifest_space_amp_pct` options).
|
||||
|
||||
|
||||
## 11.3.0 (05/15/2026)
|
||||
### New Features
|
||||
* Add experimental DB option `async_wal_precreate` to precreate the next WAL file in a background thread and reduce foreground WAL rotation latency. The option is sanitized to false when WAL recycling is enabled.
|
||||
* Added a new `EventListener::OnCompactionPreCommit` callback that fires after a compaction job finishes but before its input files are released (i.e. while `FileMetaData::being_compacted` is still true). Listeners that maintain bookkeeping of which files are currently being compacted can clean up such state in this new callback to avoid races with concurrent compaction picking, where another thread might pick up the same files for a new compaction immediately after `being_compacted` is flipped back to false but before `OnCompactionCompleted` fires. The default implementation is a no-op so this is not a breaking change.
|
||||
* Add mutable DBOption `optimize_manifest_for_recovery` (default false). When enabled, RocksDB can reduce recovery work after a clean shutdown, which may lower DB::Open latency on warm reopens.
|
||||
* Added public utility APIs `ParseCompressionNameForDisplay()` to convert `TableProperties::compression_name` into a human-readable compression name for both legacy and format_version 7+ SST metadata, including custom `CompressionManager`-provided display names for custom compression types.
|
||||
* Add `reuse_manifest_on_open` DBOption (default false). When enabled, DB::Open reuses the existing MANIFEST file for append instead of creating a fresh one, avoiding the cost of serializing the entire database state into a new MANIFEST on the first post-open write. To prevent this feature from interfering with manifest file size auto-tuning, an extra forward-compatible field is now always added to the MANIFEST (to track the last "compacted" size).
|
||||
|
||||
### Behavior Changes
|
||||
* Read-only open with `error_if_wal_file_exists=true` now tolerates empty WAL files so empty precreated WALs do not prevent inspection.
|
||||
* WriteCommitted TransactionDB now matches WritePrepared and WriteUnprepared compaction filtering in both single- and two-write-queue modes: a compaction filter's FilterMergeOperand will not be invoked on merge operands at or below the latest published sequence number.
|
||||
|
||||
### Bug Fixes
|
||||
* Fixed blob-backed wide-column merge reads to preserve correct status
|
||||
propagation and resolution across memtable, read-only, and secondary DB
|
||||
paths.
|
||||
* Fixed a bug where `DB::GetCreationTimeOfOldestFile()` could return inaccurate results instead of the real creation time when called shortly after opening a legacy DB (one whose manifest lacks `file_creation_time`) with `open_files_async = true`. The API now waits for background SST file loading to complete only when needed; modern DBs are unaffected.
|
||||
* Fixed merge reads against wide-column/blob-backed base values to preserve precise failure statuses, including `GetMergeOperands()` and direct-write memtable reads.
|
||||
* Fix bug in range tombstone synthesis that covers live keys added during an IngestExternalFile
|
||||
* Reject the empty string as a column family name in `DB::CreateColumnFamily` / `DB::CreateColumnFamilies`. Previously such calls returned OK and a usable handle, but the column family was not persisted in the manifest, so any data written to it was silently lost on DB reopen.
|
||||
* Fixed a bug where a WriteCommitted TransactionDB using commit-bypass WBWI ingestion could drop an entry that is still visible at the published sequence boundary.
|
||||
|
||||
## 11.2.0 (04/18/2026)
|
||||
### New Features
|
||||
* Added experimental `DBOptions::fast_sst_open` option. When enabled, RocksDB retrieves opaque file system metadata for SST files after flush, compaction, and external file ingestion, persists it in the MANIFEST, and passes it back to the file system on subsequent file opens to accelerate DB open time.
|
||||
|
||||
@@ -288,7 +288,7 @@ endif
|
||||
endif
|
||||
|
||||
export JAVAC_ARGS
|
||||
CLEAN_FILES += make_config.mk rocksdb.pc
|
||||
CLEAN_FILES += rocksdb.pc
|
||||
|
||||
ifeq ($(V), 1)
|
||||
$(info $(shell uname -a))
|
||||
@@ -327,6 +327,9 @@ missing_make_config_paths := $(shell \
|
||||
$(foreach path, $(missing_make_config_paths), \
|
||||
$(warning Warning: $(path) does not exist))
|
||||
|
||||
# This (the first rule) must depend on "all".
|
||||
default: all
|
||||
|
||||
ifeq ($(PLATFORM), OS_AIX)
|
||||
# no debug info
|
||||
else ifneq ($(PLATFORM), IOS)
|
||||
@@ -485,9 +488,6 @@ ifdef ROCKSDB_MODIFY_NPHASH
|
||||
PLATFORM_CXXFLAGS += -DROCKSDB_MODIFY_NPHASH=1
|
||||
endif
|
||||
|
||||
# This (the first rule) must depend on "all".
|
||||
default: all
|
||||
|
||||
WARNING_FLAGS = -W -Wextra -Wall -Wsign-compare -Wshadow \
|
||||
-Wunused-parameter
|
||||
|
||||
@@ -764,7 +764,6 @@ util/build_version.cc: $(filter-out $(OBJ_DIR)/util/build_version.o, $(LIB_OBJEC
|
||||
$(AM_V_at)$(gen_build_version) > $@
|
||||
endif
|
||||
CLEAN_FILES += util/build_version.cc
|
||||
|
||||
default: all
|
||||
|
||||
#-----------------------------------------------
|
||||
@@ -809,7 +808,8 @@ endif # PLATFORM_SHARED_EXT
|
||||
.PHONY: check clean coverage ldb_tests package dbg gen-pc build_size \
|
||||
release tags tags0 valgrind_check format static_lib shared_lib all \
|
||||
rocksdbjavastatic rocksdbjava install install-static install-shared \
|
||||
uninstall analyze tools tools_lib check-headers checkout_folly clang-tidy
|
||||
uninstall analyze tools tools_lib check-headers checkout_folly clang-tidy \
|
||||
check-c-api-c_test
|
||||
|
||||
# Auto-configure git hooks on first build so developers do not need to run
|
||||
# "make install-hooks" manually. This is a no-op if already set.
|
||||
@@ -887,23 +887,43 @@ coverage: clean
|
||||
parallel_tests = $(patsubst %,parallel_%,$(PARALLEL_TEST))
|
||||
.PHONY: gen_parallel_tests $(parallel_tests)
|
||||
# Shard size controls how many test cases run per process. The actual number
|
||||
# of shards per binary is: min(ceil(test_count / GTEST_SHARD_SIZE), NCORES * 8)
|
||||
# of shards per binary is: min(ceil(test_count / shard_size), NCORES * 8)
|
||||
# This adapts to machine size: many small shards on beefy machines, fewer
|
||||
# larger shards on CI (typically 2-4 cores).
|
||||
GTEST_SHARD_SIZE ?= 10
|
||||
NCORES ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
||||
|
||||
# Per-binary overrides for GTEST_SHARD_SIZE, used to chop up binaries whose
|
||||
# individual test cases are slow enough that the default of 10 leaves one
|
||||
# shard on the critical path of "make check". Format: whitespace-separated
|
||||
# tokens "BINARY:SIZE". Sizes were tuned from `make suggest-slow-tests`
|
||||
# output to keep max shard time under ~20s on a beefy box. Reducing too far
|
||||
# adds per-shard fixed overhead, so don't use 1 unless individual tests are
|
||||
# >5s.
|
||||
SHARD_SIZE_OVERRIDES ?= \
|
||||
point_lock_manager_stress_test:1 \
|
||||
external_sst_file_test:1 \
|
||||
external_sst_file_basic_test:2 \
|
||||
db_test:3 \
|
||||
compaction_service_test:1
|
||||
|
||||
$(parallel_tests):
|
||||
$(AM_V_at)TEST_BINARY=$(patsubst parallel_%,%,$@); \
|
||||
TEST_COUNT=` \
|
||||
(./$$TEST_BINARY --gtest_list_tests 2>/dev/null || echo " list_failure") \
|
||||
| grep -c '^ '`; \
|
||||
if [ "$$TEST_COUNT" -le 0 ]; then TEST_COUNT=1; fi; \
|
||||
SHARD_SIZE=$(GTEST_SHARD_SIZE); \
|
||||
for o in $(SHARD_SIZE_OVERRIDES); do \
|
||||
case "$$o" in \
|
||||
"$$TEST_BINARY":*) SHARD_SIZE=$${o#*:} ;; \
|
||||
esac; \
|
||||
done; \
|
||||
MAX_SHARDS=$$(( $(NCORES) * 8 )); \
|
||||
NUM_SHARDS=$$(( (TEST_COUNT + $(GTEST_SHARD_SIZE) - 1) / $(GTEST_SHARD_SIZE) )); \
|
||||
NUM_SHARDS=$$(( (TEST_COUNT + SHARD_SIZE - 1) / SHARD_SIZE )); \
|
||||
if [ "$$NUM_SHARDS" -gt "$$MAX_SHARDS" ]; then NUM_SHARDS=$$MAX_SHARDS; fi; \
|
||||
if [ "$$NUM_SHARDS" -le 0 ]; then NUM_SHARDS=1; fi; \
|
||||
echo " Generating $$NUM_SHARDS shards for $$TEST_BINARY ($$TEST_COUNT tests)"; \
|
||||
echo " Generating $$NUM_SHARDS shards for $$TEST_BINARY ($$TEST_COUNT tests, shard_size=$$SHARD_SIZE)"; \
|
||||
SHARD_IDX=0; \
|
||||
while [ "$$SHARD_IDX" -lt "$$NUM_SHARDS" ]; do \
|
||||
if [ -n "$(CI_TOTAL_SHARDS)" ] && [ $$(( $$SHARD_IDX % $(CI_TOTAL_SHARDS) )) -ne $(CI_SHARD_INDEX) ]; then \
|
||||
@@ -929,31 +949,64 @@ gen_parallel_tests:
|
||||
$(AM_V_at)$(FIND) t -type f -name 'run-*' -exec rm -f {} \;
|
||||
$(MAKE) $(parallel_tests)
|
||||
|
||||
# Reorder input lines (which are one per test) so that the
|
||||
# longest-running tests appear first in the output.
|
||||
# Do this by prefixing each selected name with its duration,
|
||||
# sort the resulting names, and remove the leading numbers.
|
||||
# FIXME: the "100" we prepend is a fake time, for now.
|
||||
# FIXME: squirrel away timings from each run and use them
|
||||
# (when present) on subsequent runs to order these tests.
|
||||
# Reorder input lines (one per test or per shard) so the longest-running
|
||||
# tests/shards start first under "make check" parallel scheduling. The trick
|
||||
# is to prefix matched names with a fake duration (100), sort numerically
|
||||
# descending, then strip the prefix. Slow-matched tests therefore come ahead
|
||||
# of all unmatched tests; ordering within each group is unspecified.
|
||||
#
|
||||
# Without this reordering, these two tests would happen to start only
|
||||
# after almost all other tests had completed, thus adding 100 seconds
|
||||
# to the duration of parallel "make check". That's the difference
|
||||
# between 4 minutes (old) and 2m20s (new).
|
||||
# Why this matters: gnu_parallel hands out jobs in input order. If a slow
|
||||
# test starts only after most others have finished, the run is bottlenecked
|
||||
# on its tail. Front-loading slow tests overlaps them with the bulk of
|
||||
# faster ones for much better wall-clock time.
|
||||
#
|
||||
# 152.120 PASS t/DBTest.FileCreationRandomFailure
|
||||
# 107.816 PASS t/DBTest.EncodeDecompressedBlockSizeTest
|
||||
# Maintenance:
|
||||
# 1) Run `make check` so LOG is up-to-date.
|
||||
# 2) Run `make suggest-slow-tests` to see candidate slow binaries.
|
||||
# 3) Add binaries with high per-shard time (slow critical path) or high
|
||||
# total time across many shards (need early queueing for fan-out).
|
||||
# Each alternative is wrapped in `^.*NAME.*$$` so the *whole input line* is
|
||||
# captured into $$1; then `s,(...),100 $$1,` prepends "100 " to the line.
|
||||
#
|
||||
# With sharded test execution, prioritize binaries known to be slow.
|
||||
# These generate many shards and should start early for good load balancing.
|
||||
# Tiers below are based on observed timings (see suggest-slow-tests).
|
||||
# Tier 1: max single-shard time >= 30s (critical-path bottlenecks).
|
||||
# Tier 2: max single-shard time 15-30s.
|
||||
# Tier 3: huge total time across many tiny shards; front-loading them keeps
|
||||
# the tail of the run busy while big shards finish.
|
||||
slow_test_regexp = \
|
||||
^.*block_based_table_reader_test.*$$|^.*table_test.*$$|^.*block_test.*$$|^.*write_prepared_transaction_test.*$$|^.*transaction_test.*$$|^.*external_sst_file_test.*$$|^.*db_wal_test.*$$|^.*db_with_timestamp_basic_test.*$$|^.*db_test-.*$$
|
||||
^.*point_lock_manager_stress_test.*$$|^.*db_test.*$$|^.*external_sst_file_test.*$$|^.*compaction_service_test.*$$|^.*corruption_test.*$$|^.*comparator_db_test.*$$|^.*external_sst_file_basic_test.*$$|^.*rate_limiter_test.*$$|^.*db_compaction_test.*$$|^.*write_prepared_transaction_test.*$$|^.*db_merge_operator_test.*$$|\
|
||||
^.*db_dynamic_level_test.*$$|^.*db_bloom_filter_test.*$$|^.*error_handler_fs_test.*$$|^.*merge_helper_test.*$$|^.*transaction_test.*$$|^.*db_kv_checksum_test.*$$|^.*inlineskiplist_test.*$$|\
|
||||
^.*db_with_timestamp_basic_test.*$$|^.*table_test.*$$|^.*db_wal_test.*$$|^.*block_based_table_reader_test.*$$|^.*block_test.*$$
|
||||
prioritize_long_running_tests = \
|
||||
perl -pe 's,($(slow_test_regexp)),100 $$1,' \
|
||||
| sort -k1,1gr \
|
||||
| sed 's/^[.0-9]* //'
|
||||
|
||||
# Helper: print binaries observed to be slow in the last `make check` run.
|
||||
# Use this to decide whether `slow_test_regexp` above needs updating.
|
||||
# Aggregates per-binary across shards; flags any binary whose max single-shard
|
||||
# time is >= 20s OR whose total time is >= 200s.
|
||||
.PHONY: suggest-slow-tests
|
||||
suggest-slow-tests:
|
||||
@if [ ! -s LOG ]; then \
|
||||
echo "No (or empty) LOG file. Run 'make check' first." >&2; exit 1; \
|
||||
fi
|
||||
@bash -c '$(quoted_perl_command)' < LOG | awk '\
|
||||
{ \
|
||||
t=$$1; name=$$3; \
|
||||
sub(/^t\/run-/, "", name); \
|
||||
sub(/-shard-[0-9]+$$/, "", name); \
|
||||
total[name] += t; \
|
||||
if (t > max[name]) max[name] = t; \
|
||||
count[name]++; \
|
||||
} \
|
||||
END { \
|
||||
printf "%8s %8s %5s %s\n", "TOTAL_s", "MAX_s", "SHRDS", "BINARY"; \
|
||||
for (n in total) \
|
||||
if (max[n] >= 20 || total[n] >= 200) \
|
||||
printf "%8.1f %8.1f %5d %s\n", total[n], max[n], count[n], n; \
|
||||
}' | (read header; echo "$$header"; sort -k2,2gr)
|
||||
|
||||
# "make check" uses
|
||||
# Run with "make J=1 check" to disable parallelism in "make check".
|
||||
# Run with "make J=200% check" to run two parallel jobs per core.
|
||||
@@ -990,7 +1043,7 @@ check_0:
|
||||
awk -v s=$(CI_SHARD_INDEX) -v n=$(CI_TOTAL_SHARDS) '(NR-1)%n==s'; \
|
||||
else cat; fi; \
|
||||
fi; \
|
||||
find t -name 'run-*' -print; \
|
||||
$(FIND) t -name 'run-*' -print; \
|
||||
} \
|
||||
| $(prioritize_long_running_tests) \
|
||||
| grep -E '$(tests-regexp)' \
|
||||
@@ -1012,7 +1065,7 @@ valgrind_check_0:
|
||||
' run "make watch-log" in a separate window' ''; \
|
||||
{ \
|
||||
printf './%s\n' $(filter-out $(PARALLEL_TEST) %skiplist_test options_settable_test, $(TESTS)); \
|
||||
find t -name 'run-*' -print; \
|
||||
$(FIND) t -name 'run-*' -print; \
|
||||
} \
|
||||
| $(prioritize_long_running_tests) \
|
||||
| grep -E '$(tests-regexp)' \
|
||||
@@ -1074,8 +1127,89 @@ ifndef SKIP_FORMAT_BUCK_CHECKS
|
||||
$(MAKE) check-buck-targets
|
||||
$(MAKE) check-sources
|
||||
$(MAKE) check-workflow-yaml
|
||||
$(MAKE) check-c-api-gen
|
||||
endif
|
||||
|
||||
# Check that the auto-generated C API files are up to date. It regenerates the
|
||||
# fragments and the inlined c.h/c.cc and compares them against a snapshot of the
|
||||
# checked-in copies (no net change when everything is up to date). It requires
|
||||
# clang++ (libclang, used to parse the C++ headers) and clang-format. When those
|
||||
# are unavailable the staleness/compat sub-checks are SKIPPED with a message so
|
||||
# `make check` still works without the codegen toolchain; the link-completeness
|
||||
# sub-check always runs (it needs no toolchain).
|
||||
#
|
||||
# Pin the formatter to match CI by setting CLANG_FORMAT_BINARY, e.g.:
|
||||
# make check-c-api-gen CLANG_FORMAT_BINARY=clang-format-21
|
||||
# This target is part of `make check` and is skipped by SKIP_FORMAT_BUCK_CHECKS.
|
||||
#
|
||||
# Set CHECK_C_API_GEN_STRICT=1 to turn every "skip" below into a hard error, so a
|
||||
# core CI job that runs this target cannot silently regress to a no-op if a
|
||||
# prerequisite (clang++, or the compat baseline ref) goes missing. The dedicated
|
||||
# build-linux-clang-21-no_test_run CI job runs this target with the flag set.
|
||||
# Any non-empty value other than 0/no/false enables strict mode.
|
||||
CLANG_FORMAT_BINARY ?=
|
||||
# Backward-compatibility baseline for the C API (signature-level) check. CI
|
||||
# overrides this with the PR's merge target; locally it falls back to main /
|
||||
# origin/main and is skipped if neither resolves.
|
||||
API_COMPAT_REF ?= main
|
||||
CHECK_C_API_GEN_STRICT ?=
|
||||
check-c-api-gen:
|
||||
# Link-completeness is a property of the checked-in c.h/c.cc and needs no
|
||||
# clang toolchain, so it always runs: every declared public C API function
|
||||
# must have exactly one definition (guards against dropped wrappers that
|
||||
# would break downstream language bindings at link time).
|
||||
$(PYTHON) tools/c_api_gen/check_api_completeness.py
|
||||
# Backward-compatibility: no public C function may be removed or have its
|
||||
# signature changed vs the baseline. Skipped if the baseline ref is not
|
||||
# resolvable locally (CI passes an explicit ref), unless CHECK_C_API_GEN_STRICT.
|
||||
@strict=""; case "$(CHECK_C_API_GEN_STRICT)" in ""|0|no|NO|false|FALSE) ;; *) strict=1 ;; esac; \
|
||||
ref=""; \
|
||||
if git rev-parse --verify --quiet "$(API_COMPAT_REF)^{commit}" >/dev/null; then ref="$(API_COMPAT_REF)"; \
|
||||
elif git rev-parse --verify --quiet "origin/$(API_COMPAT_REF)^{commit}" >/dev/null; then ref="origin/$(API_COMPAT_REF)"; fi; \
|
||||
if [ -n "$$ref" ]; then \
|
||||
$(PYTHON) tools/c_api_gen/check_api_compatibility.py --ref "$$ref"; \
|
||||
elif [ -n "$$strict" ]; then \
|
||||
echo "ERROR: C API compat baseline '$(API_COMPAT_REF)' not resolvable and CHECK_C_API_GEN_STRICT is set" >&2; exit 1; \
|
||||
else \
|
||||
echo "Skipping C API backward-compatibility check ($(API_COMPAT_REF) not found; set API_COMPAT_REF)"; \
|
||||
fi
|
||||
# Staleness: regenerate and confirm the checked-in output is current. Needs a
|
||||
# clang++ (the generator parses C++ ASTs); detect one the way the generator
|
||||
# does (a clang in $(CXX) -- which may be ccache-prefixed/versioned -- else a
|
||||
# bare/versioned clang++ on PATH) rather than testing $(CXX) verbatim.
|
||||
@strict=""; case "$(CHECK_C_API_GEN_STRICT)" in ""|0|no|NO|false|FALSE) ;; *) strict=1 ;; esac; \
|
||||
cf_arg=""; \
|
||||
if [ -n "$(CLANG_FORMAT_BINARY)" ]; then cf_arg="--clang-format $(CLANG_FORMAT_BINARY)"; fi; \
|
||||
have_clang=""; \
|
||||
for c in $$(printf '%s\n' $(CXX) | grep -i clang) clang++ clang++-21 clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13; do \
|
||||
if command -v "$$c" >/dev/null 2>&1; then have_clang=1; break; fi; \
|
||||
done; \
|
||||
if [ -n "$$have_clang" ]; then \
|
||||
$(PYTHON) tools/c_api_gen/verify_generated_up_to_date.py $$cf_arg; \
|
||||
elif [ -n "$$strict" ]; then \
|
||||
echo "ERROR: no clang++ found and CHECK_C_API_GEN_STRICT is set; cannot run the C API staleness check" >&2; exit 1; \
|
||||
else \
|
||||
echo "Skipping C API codegen staleness check (no clang++ found; install clang++ or set CXX to a clang to enable)"; \
|
||||
fi
|
||||
|
||||
# Quick local validation for C API generation plus the focused C API test.
|
||||
# This verifies the checked-in generated fragments as well as the inlined
|
||||
# include/rocksdb/c.h and db/c.cc outputs, then runs c_test in an isolated
|
||||
# TEST_TMPDIR to avoid stale-state failures.
|
||||
check-c-api-c_test:
|
||||
$(PYTHON) tools/c_api_gen/verify_generated_up_to_date.py
|
||||
$(MAKE) c_test
|
||||
@tmpdir=$$(mktemp -d); \
|
||||
trap 'rm -rf "$$tmpdir"' EXIT; \
|
||||
echo "===== Running c_test with TEST_TMPDIR=$$tmpdir"; \
|
||||
if command -v timeout >/dev/null 2>&1; then \
|
||||
TEST_TMPDIR="$$tmpdir" timeout 60 ./c_test; \
|
||||
elif command -v gtimeout >/dev/null 2>&1; then \
|
||||
TEST_TMPDIR="$$tmpdir" gtimeout 60 ./c_test; \
|
||||
else \
|
||||
TEST_TMPDIR="$$tmpdir" ./c_test; \
|
||||
fi
|
||||
|
||||
# TODO add ldb_tests
|
||||
check_some: $(ROCKSDBTESTS_SUBSET)
|
||||
for t in $(ROCKSDBTESTS_SUBSET); do echo "===== Running $$t (`date`)"; ./$$t || exit 1; done
|
||||
@@ -1225,16 +1359,32 @@ rocksdb.h rocksdb.cc: build_tools/amalgamate.py Makefile $(LIB_SOURCES) unity.cc
|
||||
build_tools/amalgamate.py -I. -i./include unity.cc -x include/rocksdb/c.h -H rocksdb.h -o rocksdb.cc
|
||||
|
||||
clean: clean-ext-libraries-all clean-rocks clean-rocksjava
|
||||
# Removed here rather than in clean-rocks (via CLEAN_FILES) so the build-parameter
|
||||
# auto-clean, which runs clean-rocks, doesn't delete the make_config.mk already
|
||||
# included by the in-progress make.
|
||||
@rm -f make_config.mk
|
||||
|
||||
clean-not-downloaded: clean-ext-libraries-bin clean-rocks clean-not-downloaded-rocksjava
|
||||
@rm -f make_config.mk
|
||||
|
||||
clean-rocks:
|
||||
# Not practical to exactly match all versions/variants in naming (e.g. debug or not)
|
||||
rm -f ${LIBNAME}*.so* ${LIBNAME}*.a
|
||||
rm -f $(BENCHMARKS) $(TOOLS) $(TESTS) $(PARALLEL_TEST) $(MICROBENCHS)
|
||||
rm -rf $(CLEAN_FILES) ios-x86 ios-arm scan_build_report
|
||||
$(FIND) . -name "*.[oda]" -exec rm -f {} \;
|
||||
$(FIND) . -type f \( -name "*.gcda" -o -name "*.gcno" \) -exec rm -f {} \;
|
||||
@echo Removing link targets
|
||||
@rm -f ${LIBNAME}*.so* ${LIBNAME}*.a $(BENCHMARKS) $(TOOLS) $(TESTS) $(PARALLEL_TEST) $(MICROBENCHS)
|
||||
@echo Finding and cleaning other files
|
||||
@rm -rf $(CLEAN_FILES) ios-x86 ios-arm scan_build_report
|
||||
@if $(FIND) Makefile -regextype awk &> /dev/null; then \
|
||||
$(FIND) . -regextype awk \
|
||||
-regex '.*/([.].*|third-party)' -prune -o \
|
||||
-type f -regex '.*[.]([oda]|gcda|gcno)' -exec rm -f {} \; ; \
|
||||
else \
|
||||
$(FIND) . -name "*.[oda]" -exec rm -f {} \; ; \
|
||||
fi
|
||||
# Remove the build signature(s) LAST. Done after the object files are gone so
|
||||
# that a Ctrl+C partway through clean leaves the old signature in place: it
|
||||
# still matches the leftover objects, so a later build with different
|
||||
# parameters is still detected (signature usefulness is preserved).
|
||||
@rm -f $(BUILD_SIG_FILE) jl/.build_signature jls/.build_signature
|
||||
|
||||
clean-rocksjava: clean-rocks
|
||||
rm -rf jl jls
|
||||
@@ -1247,7 +1397,7 @@ clean-ext-libraries-all:
|
||||
rm -rf bzip2* snappy* zlib* lz4* zstd*
|
||||
|
||||
clean-ext-libraries-bin:
|
||||
find . -maxdepth 1 -type d \( -name bzip2\* -or -name snappy\* -or -name zlib\* -or -name lz4\* -or -name zstd\* \) -prune -exec rm -rf {} \;
|
||||
$(FIND) . -maxdepth 1 -type d \( -name bzip2\* -or -name snappy\* -or -name zlib\* -or -name lz4\* -or -name zstd\* \) -prune -exec rm -rf {} \;
|
||||
|
||||
tags:
|
||||
ctags -R .
|
||||
@@ -1525,7 +1675,7 @@ db_open_with_config_test: $(OBJ_DIR)/db/db_open_with_config_test.o $(TEST_LIBRAR
|
||||
db_test: $(OBJ_DIR)/db/db_test.o $(TEST_LIBRARY) $(LIBRARY)
|
||||
$(AM_LINK)
|
||||
|
||||
db_test2: $(OBJ_DIR)/db/db_test2.o $(TEST_LIBRARY) $(LIBRARY)
|
||||
db_etc2_test: $(OBJ_DIR)/db/db_etc2_test.o $(TEST_LIBRARY) $(LIBRARY)
|
||||
$(AM_LINK)
|
||||
|
||||
db_etc3_test: $(OBJ_DIR)/db/db_etc3_test.o $(TEST_LIBRARY) $(LIBRARY)
|
||||
@@ -2268,6 +2418,101 @@ ifeq ($(PLATFORM), OS_OPENBSD)
|
||||
endif
|
||||
export SHA256_CMD
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Build parameter change detection
|
||||
# ----------------------------------------------------------------------------
|
||||
# RocksDB writes object files to the same $(OBJ_DIR) paths regardless of
|
||||
# DEBUG_LEVEL, sanitizers (ASAN/TSAN/UBSAN), ASSERT_STATUS_CHECKED, RTTI, LTO,
|
||||
# COERCE_CONTEXT_SWITCH, etc. Most of those are applied in this Makefile after
|
||||
# `include make_config.mk` and are therefore NOT reflected in make_config.mk,
|
||||
# so switching them and rebuilding silently mixes incompatible object files.
|
||||
# To guard against that, we hash the fully-resolved compile/link parameters
|
||||
# (which already embed make_config.mk via PLATFORM_*) and compare against the
|
||||
# value recorded from the previous build. On mismatch the build stops so the
|
||||
# user can `make clean`. Knobs:
|
||||
# AUTO_CLEAN=1
|
||||
# run `make clean-rocks` automatically on mismatch
|
||||
# ALLOW_BUILD_PARAMETER_CHANGE=1
|
||||
# skip the check entirely (e.g. intentionally mixing DEBUG_LEVEL=1 and
|
||||
# DEBUG_LEVEL=2)
|
||||
# The signature is stored per-$(OBJ_DIR), so Java (jl/jls) builds are tracked
|
||||
# independently from the default build.
|
||||
BUILD_SIG_FILE := $(OBJ_DIR)/.build_signature
|
||||
# NOTE: deliberately NOT added to CLEAN_FILES. The signature is removed as the
|
||||
# very last step of clean-rocks so that an interrupted clean keeps it (see
|
||||
# clean-rocks), preserving change detection across a Ctrl+C'd clean.
|
||||
|
||||
# Goals that do not compile object files into the tree (pure utilities,
|
||||
# informational, source/config checks): the change check is irrelevant for them.
|
||||
BUILD_SIG_NONBUILD_GOALS := \
|
||||
clean clean-rocks clean-not-downloaded clean-rocksjava \
|
||||
clean-not-downloaded-rocksjava clean-ext-libraries-all \
|
||||
clean-ext-libraries-bin \
|
||||
format format-auto check-format check-buck-targets check-headers \
|
||||
check-sources check-workflow-yaml check-progress clang-tidy \
|
||||
tags tags0 package jclean checkout_folly build_folly \
|
||||
watch-log dump-log suggest-slow-tests list_all_tests gen-pc \
|
||||
gen_parallel_tests check-c-api-gen \
|
||||
setup-hooks install-hooks uninstall-hooks uninstall db_crashtest_tests
|
||||
# Goals that clean before building (depend on or invoke `clean`): they manage
|
||||
# their own freshness, so the check must not block them (it would error before
|
||||
# their built-in clean runs).
|
||||
BUILD_SIG_NONBUILD_GOALS += \
|
||||
release coverage build_size analyze analyze_incremental \
|
||||
asan_check asan_crash_test asan_crash_test_with_atomic_flush \
|
||||
asan_crash_test_with_txn asan_crash_test_with_best_efforts_recovery \
|
||||
whitebox_asan_crash_test blackbox_asan_crash_test \
|
||||
ubsan_check ubsan_crash_test ubsan_crash_test_with_atomic_flush \
|
||||
ubsan_crash_test_with_txn ubsan_crash_test_with_best_efforts_recovery \
|
||||
whitebox_ubsan_crash_test blackbox_ubsan_crash_test
|
||||
|
||||
# Goals that explicitly clean; never trip the check when one is requested.
|
||||
BUILD_SIG_CLEAN_GOALS := \
|
||||
clean clean-rocks clean-not-downloaded clean-rocksjava \
|
||||
clean-not-downloaded-rocksjava clean-ext-libraries-all \
|
||||
clean-ext-libraries-bin
|
||||
|
||||
BUILD_SIG_GOALS := $(if $(MAKECMDGOALS),$(MAKECMDGOALS),all)
|
||||
BUILD_SIG_DO_BUILD := $(filter-out $(BUILD_SIG_NONBUILD_GOALS),$(BUILD_SIG_GOALS))
|
||||
BUILD_SIG_CLEANING := $(filter $(BUILD_SIG_CLEAN_GOALS),$(MAKECMDGOALS))
|
||||
# Dry runs (-n/--just-print) must not write the stamp, clean, or error; the
|
||||
# parse-time $(shell) below would otherwise run even under -n. Note that
|
||||
# actual options are canonicalized and shorted as possible such that all
|
||||
# short options are in the first word of MAKEFLAGS.
|
||||
BUILD_SIG_DRYRUN := $(findstring n,$(firstword -$(MAKEFLAGS)))
|
||||
|
||||
# Only enforce at the top level. Sub-makes (e.g. `check` invokes
|
||||
# $(MAKE) gen_parallel_tests / check-c-api-gen / check_0) inherit the parent's
|
||||
# build flags, so the top-level check already covers them; re-checking inside a
|
||||
# sub-make only causes spurious failures.
|
||||
ifneq ($(ALLOW_BUILD_PARAMETER_CHANGE),1)
|
||||
ifeq ($(MAKELEVEL),0)
|
||||
ifeq ($(BUILD_SIG_DRYRUN),)
|
||||
ifeq ($(BUILD_SIG_CLEANING),)
|
||||
ifneq ($(BUILD_SIG_DO_BUILD),)
|
||||
BUILD_SIG := $(shell printf '%s' '$(CC)|$(CXX)|$(CFLAGS)|$(CXXFLAGS)|$(LDFLAGS)|$(EXEC_LDFLAGS)' | $(SHA256_CMD) | cut -d ' ' -f 1)
|
||||
BUILD_SIG_OLD := $(shell cat $(BUILD_SIG_FILE) 2>/dev/null)
|
||||
ifneq ($(BUILD_SIG_OLD),)
|
||||
ifneq ($(BUILD_SIG_OLD),$(BUILD_SIG))
|
||||
ifeq ($(AUTO_CLEAN),1)
|
||||
$(info *** Build parameters changed since last build (OBJ_DIR=$(OBJ_DIR)); running 'make clean-rocks' because AUTO_CLEAN=1)
|
||||
BUILD_SIG_CLEAN_OUTPUT := $(shell $(MAKE) clean-rocks 1>&2)
|
||||
ifneq ($(.SHELLSTATUS),0)
|
||||
$(error AUTO_CLEAN: 'make clean-rocks' failed (exit $(.SHELLSTATUS)); not building against a partially-cleaned tree)
|
||||
endif
|
||||
else
|
||||
$(error Build parameters changed since the last build (OBJ_DIR=$(OBJ_DIR)). Existing object files are stale and must be removed. Run 'make clean', or set AUTO_CLEAN=1 to clean automatically, or ALLOW_BUILD_PARAMETER_CHANGE=1 to build anyway)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
# Record the current signature for the next build.
|
||||
BUILD_SIG_WRITE := $(shell mkdir -p $(OBJ_DIR) 2>/dev/null; printf '%s\n' '$(BUILD_SIG)' > $(BUILD_SIG_FILE))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
zlib-$(ZLIB_VER).tar.gz:
|
||||
curl --fail --output zlib-$(ZLIB_VER).tar.gz --location ${ZLIB_DOWNLOAD_BASE}/zlib-$(ZLIB_VER).tar.gz
|
||||
ZLIB_SHA256_ACTUAL=`$(SHA256_CMD) zlib-$(ZLIB_VER).tar.gz | cut -d ' ' -f 1`; \
|
||||
|
||||
@@ -360,6 +360,7 @@ def generate_buck(repo_path, deps_map):
|
||||
extra_compiler_flags=json.dumps(deps["extra_compiler_flags"]),
|
||||
)
|
||||
BUCK.export_file("tools/db_crashtest.py")
|
||||
BUCK.export_file("tools/fault_injection_log_parser.py")
|
||||
|
||||
print(ColorString.info("Generated BUCK Summary:"))
|
||||
print(ColorString.info("- %d libs" % BUCK.total_lib))
|
||||
|
||||
@@ -118,6 +118,12 @@ class TARGETSBuilder:
|
||||
self.total_bin = self.total_bin + 1
|
||||
|
||||
def add_c_test(self):
|
||||
# The actual c_test_bin target is defined by add_c_test_wrapper in the
|
||||
# internal //rocks/buckifier:defs.bzl (not in this OSS repo). db/c_test.c
|
||||
# #includes the generated c_api_gen/*.inc fragments, so under Buck's
|
||||
# hermetic sandbox that wrapper must expose them as headers, e.g.
|
||||
# headers = native.glob(["c_api_gen/**/*.inc"])
|
||||
# (Make/CMake resolve the include via -I. / PROJECT_SOURCE_DIR.)
|
||||
with open(self.path, "ab") as targets_file:
|
||||
targets_file.write(
|
||||
b"""
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
# -DLZ4 if the LZ4 library is present
|
||||
# -DZSTD if the ZSTD library is present
|
||||
# -DNUMA if the NUMA library is present
|
||||
# -DTBB if the TBB library is present
|
||||
# -DMEMKIND if the memkind library is present
|
||||
#
|
||||
# Using gflags in rocksdb:
|
||||
@@ -424,19 +423,6 @@ EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! test $ROCKSDB_DISABLE_TBB; then
|
||||
# Test whether tbb is available
|
||||
$CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o test.o -ltbb 2>/dev/null <<EOF
|
||||
#include <tbb/tbb.h>
|
||||
int main() {}
|
||||
EOF
|
||||
if [ "$?" = 0 ]; then
|
||||
COMMON_FLAGS="$COMMON_FLAGS -DTBB"
|
||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -ltbb"
|
||||
JAVA_LDFLAGS="$JAVA_LDFLAGS -ltbb"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! test $ROCKSDB_DISABLE_JEMALLOC; then
|
||||
# Test whether jemalloc is available
|
||||
if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o test.o -ljemalloc \
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved.
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# 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).
|
||||
#
|
||||
# Check for some simple mistakes in public headers (on the command line)
|
||||
# that should prevent commit or push
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
# The file is generated using update_dependencies.sh.
|
||||
GCC_BASE=/mnt/gvfs/third-party2/gcc/62de5a92e5f23c661c3d4b9f322e04eb14e7a5bd/11.x/centos8-native/886b5eb
|
||||
CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/1f6edd1ff15c99c861afc8f3cd69054cd974dd64/15/platform010/72a2ff8
|
||||
LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/d1129753c8361ac8e9453c0f4291337a4507ebe6/11.x/platform010/5684a5a
|
||||
GLIBC_BASE=/mnt/gvfs/third-party2/glibc/fed6e93d87571fb162734c86636119d45a398963/2.34/platform010/f259413
|
||||
SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/31a346126a1f3b64812c362511cb04cc1bd40855/1.1.8/platform010/76ebdda
|
||||
ZLIB_BASE=/mnt/gvfs/third-party2/zlib/0c65c05468b5a38cef1a106a1f526463e120c8dd/1.2.8/platform010/76ebdda
|
||||
GCC_BASE=/mnt/gvfs/third-party2/gcc/e9cb2d4550b5a95024125084420342d256b349cd/11.x/centos9-native/3bed279
|
||||
CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/4e46e6967e15412702e51960c69790a78933856f/21/platform010/72a2ff8
|
||||
LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/63c5179edc90fec473e53c1b2f92269c65c39e07/11.x/platform010/5684a5a
|
||||
GLIBC_BASE=/mnt/gvfs/third-party2/glibc/b4a6248a76a163bcccb1e4751e247712c535846e/2.34/platform010/f259413
|
||||
SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/ef895164499fdfedb9d9b9c85520de10aa8ff9ca/1.1.8/platform010/76ebdda
|
||||
ZLIB_BASE=/mnt/gvfs/third-party2/zlib/643dbf0136f869562485cfcb2953f5cab60447ef/1.2.8/platform010/76ebdda
|
||||
BZIP2_BASE=/mnt/gvfs/third-party2/bzip2/09703139cfc376bd8a82642385a0e97726b28287/1.0.6/platform010/76ebdda
|
||||
LZ4_BASE=/mnt/gvfs/third-party2/lz4/ff23d17b932725cc1734a14896a8b67c518ba169/1.9.4/platform010/76ebdda
|
||||
ZSTD_BASE=/mnt/gvfs/third-party2/zstd/576397d8b1d9cea7306ad1e454d5e55caaa2ff1c/1.4.x/platform010/64091f4
|
||||
GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/fecac07861cb829f5e60dbeff0503d3272db73c0/2.2.0/platform010/76ebdda
|
||||
JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/0bb3f5756788ce26e2e16a1cb2f2af2c59b51abe/master/platform010/f57cc4a
|
||||
LZ4_BASE=/mnt/gvfs/third-party2/lz4/823bf8e000654abef784311296ffc8166d9d3986/1.9.4/platform010/76ebdda
|
||||
ZSTD_BASE=/mnt/gvfs/third-party2/zstd/0cda78647b5712bec7ec6d9ba2f0dcdabfb6f44f/1.4.x/platform010/64091f4
|
||||
GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/a02e0de00945729ad553c187c64e86b57f45a33b/2.2.0/platform010/76ebdda
|
||||
JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/a1a50742bec7195bfafb594e174ea45dc197a420/master/platform010/779a252
|
||||
NUMA_BASE=/mnt/gvfs/third-party2/numa/5b602edd46fda54cdd7ea45f77dbe4061206e174/2.0.11/platform010/76ebdda
|
||||
LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/97cac22a149c2e202917e05d44e87e516b68216f/1.4/platform010/5074a48
|
||||
TBB_BASE=/mnt/gvfs/third-party2/tbb/53953ebc4e3eda85ad6fc3e429ba146035e97b90/2018_U5/platform010/76ebdda
|
||||
LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/f3cce2e1a79ac8d64e102886603a6997d6e88640/1.8/platform010/76ebdda
|
||||
LIBURING_BASE=/mnt/gvfs/third-party2/liburing/a98e2d137007e3ebf7f33bd6f99c2c56bdaf8488/20210212/platform010/76ebdda
|
||||
BENCHMARK_BASE=/mnt/gvfs/third-party2/benchmark/780c7a0f9cf0967961e69ad08e61cddd85d61821/trunk/platform010/76ebdda
|
||||
KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/624a2f8f6c93c3c1df8aa4a6255d8202631a6c80/fb/platform010/da39a3e
|
||||
BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/39579e8603b48b3540f8b0633f43adf29acccb8b/2.37/centos8-native/da39a3e
|
||||
VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/cd9cc656d49ecb53797ce4d055e49fde29fd57ff/3.19.0/platform010/76ebdda
|
||||
KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/0883cccda758e68b47e4c04e4fa01142e1f60f32/fb/platform010/da39a3e
|
||||
BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/1d5d19135a406a941d3a441eb2bf506bb9d19210/2.43/centos9-native/be7139e
|
||||
VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/3e2b7ccc315c9a0f2b678ce6fd774f4970f9bf3b/3.22.0/platform010/76ebdda
|
||||
|
||||
@@ -87,15 +87,6 @@ if test -z $PIC_BUILD; then
|
||||
LIBUNWIND="$LIBUNWIND_BASE/lib/libunwind.a"
|
||||
fi
|
||||
|
||||
# location of TBB
|
||||
TBB_INCLUDE=" -isystem $TBB_BASE/include/"
|
||||
if test -z $PIC_BUILD; then
|
||||
TBB_LIBS="$TBB_BASE/lib/libtbb.a"
|
||||
else
|
||||
TBB_LIBS="$TBB_BASE/lib/libtbb_pic.a"
|
||||
fi
|
||||
CFLAGS+=" -DTBB"
|
||||
|
||||
test "$USE_SSE" || USE_SSE=1
|
||||
export USE_SSE
|
||||
test "$PORTABLE" || PORTABLE=1
|
||||
@@ -104,7 +95,7 @@ export PORTABLE
|
||||
BINUTILS="$BINUTILS_BASE/bin"
|
||||
AR="$BINUTILS/ar"
|
||||
|
||||
DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE"
|
||||
DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE"
|
||||
|
||||
STDLIBS="-L $GCC_BASE/lib64"
|
||||
|
||||
@@ -150,17 +141,17 @@ CFLAGS+=" $DEPS_INCLUDE"
|
||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT"
|
||||
CXXFLAGS+=" $CFLAGS"
|
||||
|
||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
|
||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB"
|
||||
EXEC_LDFLAGS+=" -B$BINUTILS/gold"
|
||||
EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/gcc-5-glibc-2.23/lib/ld.so"
|
||||
EXEC_LDFLAGS+=" $LIBUNWIND"
|
||||
EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/gcc-5-glibc-2.23/lib"
|
||||
# required by libtbb
|
||||
# dynamic loading
|
||||
EXEC_LDFLAGS+=" -ldl"
|
||||
|
||||
PLATFORM_LDFLAGS="$LIBGCC_LIBS $GLIBC_LIBS $STDLIBS -lgcc -lstdc++"
|
||||
|
||||
EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $TBB_LIBS"
|
||||
EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS"
|
||||
|
||||
VALGRIND_VER="$VALGRIND_BASE/bin/"
|
||||
|
||||
|
||||
@@ -82,11 +82,6 @@ CFLAGS+=" -DNUMA"
|
||||
# location of libunwind
|
||||
LIBUNWIND="$LIBUNWIND_BASE/lib/libunwind${MAYBE_PIC}.a"
|
||||
|
||||
# location of TBB
|
||||
TBB_INCLUDE=" -isystem $TBB_BASE/include/"
|
||||
TBB_LIBS="$TBB_BASE/lib/libtbb${MAYBE_PIC}.a"
|
||||
CFLAGS+=" -DTBB"
|
||||
|
||||
# location of LIBURING
|
||||
LIBURING_INCLUDE=" -isystem $LIBURING_BASE/include/"
|
||||
LIBURING_LIBS="$LIBURING_BASE/lib/liburing${MAYBE_PIC}.a"
|
||||
@@ -101,7 +96,7 @@ BINUTILS="$BINUTILS_BASE/bin"
|
||||
AR="$BINUTILS/ar"
|
||||
AS="$BINUTILS/as"
|
||||
|
||||
DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE $LIBURING_INCLUDE $BENCHMARK_INCLUDE"
|
||||
DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $LIBURING_INCLUDE $BENCHMARK_INCLUDE"
|
||||
|
||||
STDLIBS="-L $GCC_BASE/lib64"
|
||||
|
||||
@@ -157,18 +152,18 @@ CFLAGS+=" $DEPS_INCLUDE"
|
||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_IOURING_PRESENT"
|
||||
CXXFLAGS+=" $CFLAGS"
|
||||
|
||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $LIBURING_LIBS $BENCHMARK_LIBS"
|
||||
EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/platform010/lib/ld.so"
|
||||
EXEC_LDFLAGS+=" $LIBUNWIND"
|
||||
EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/platform010/lib"
|
||||
EXEC_LDFLAGS+=" -Wl,-rpath=$GCC_BASE/lib64"
|
||||
# required by libtbb
|
||||
# dynamic loading
|
||||
EXEC_LDFLAGS+=" -ldl"
|
||||
|
||||
PLATFORM_LDFLAGS="$LIBGCC_LIBS $GLIBC_LIBS $STDLIBS -lgcc -lstdc++"
|
||||
PLATFORM_LDFLAGS+=" -B$BINUTILS"
|
||||
|
||||
EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $TBB_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
||||
EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
||||
|
||||
VALGRIND_VER="$VALGRIND_BASE/bin/"
|
||||
|
||||
|
||||
@@ -1,62 +1,188 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# This source code is licensed under both the GPLv2 (found in the COPYING file in the root directory)
|
||||
# and the Apache 2.0 License (found in the LICENSE.Apache file in the root directory).
|
||||
"""
|
||||
Pre-download packages with unreliable mirrors using fallback mirrors.
|
||||
Reads package info from folly's getdeps manifest files.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import hashlib
|
||||
import subprocess
|
||||
import configparser
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
def sha256_file(path):
|
||||
"""Calculate SHA256 hash of a file."""
|
||||
h = hashlib.sha256()
|
||||
try:
|
||||
with open(path, 'rb') as f:
|
||||
for chunk in iter(lambda: f.read(65536), b''):
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
except Exception:
|
||||
return None
|
||||
DOWNLOAD_TIMEOUT_SECONDS = 120
|
||||
DOWNLOAD_CHUNK_BYTES = 64 * 1024
|
||||
MAX_DOWNLOAD_BYTES = 50 * 1024 * 1024
|
||||
|
||||
def parse_manifest(manifest_path):
|
||||
"""Parse a getdeps manifest file to extract download info."""
|
||||
config = configparser.ConfigParser()
|
||||
try:
|
||||
config.read(manifest_path)
|
||||
if 'download' in config:
|
||||
return {
|
||||
'url': config['download'].get('url', ''),
|
||||
'sha256': config['download'].get('sha256', ''),
|
||||
}
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def get_fallback_mirrors(url):
|
||||
"""Get fallback mirror URLs for a given URL."""
|
||||
# Fallback mirror patterns for known unreliable hosts
|
||||
mirror_fallbacks = {
|
||||
"ftp.gnu.org/gnu/": [
|
||||
"https://mirrors.kernel.org/gnu/",
|
||||
"https://ftpmirror.gnu.org/gnu/",
|
||||
"https://ftp.gnu.org/gnu/",
|
||||
],
|
||||
MIRROR_FALLBACKS = {
|
||||
"ftpmirror.gnu.org/gnu/": [
|
||||
"https://mirrors.kernel.org/gnu/",
|
||||
"https://ftpmirror.gnu.org/gnu/",
|
||||
"https://ftp.gnu.org/gnu/",
|
||||
],
|
||||
"ftp.gnu.org/gnu/": [
|
||||
"https://mirrors.kernel.org/gnu/",
|
||||
"https://ftpmirror.gnu.org/gnu/",
|
||||
"https://ftp.gnu.org/gnu/",
|
||||
],
|
||||
}
|
||||
|
||||
for pattern, mirrors in mirror_fallbacks.items():
|
||||
# These packages must have URLs matching MIRROR_FALLBACKS; other packages are
|
||||
# left for getdeps.py's normal download path.
|
||||
PACKAGES_TO_CHECK = ("autoconf", "automake", "libtool", "libiberty")
|
||||
|
||||
|
||||
def sha256_file(path):
|
||||
"""Calculate SHA256 hash of a file."""
|
||||
h = hashlib.sha256()
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(65536), b""):
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def parse_manifest(manifest_path):
|
||||
"""Parse a getdeps manifest file to extract download info."""
|
||||
# folly manifests can contain bare keys in sections unrelated to downloads.
|
||||
config = configparser.ConfigParser(allow_no_value=True, interpolation=None)
|
||||
try:
|
||||
with open(manifest_path, encoding="utf-8") as manifest_file:
|
||||
config.read_file(manifest_file)
|
||||
except Exception as ex:
|
||||
print(f" {os.path.basename(manifest_path)}: WARNING - parse failed: {ex}")
|
||||
return None
|
||||
|
||||
if "download" in config:
|
||||
return {
|
||||
"url": config["download"].get("url", ""),
|
||||
"sha256": config["download"].get("sha256", ""),
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
def file_size(path):
|
||||
try:
|
||||
return os.path.getsize(path)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def get_fallback_mirrors(url):
|
||||
"""Get fallback mirror URLs for a given URL."""
|
||||
for pattern, mirrors in MIRROR_FALLBACKS.items():
|
||||
if pattern in url:
|
||||
# Extract the path after the pattern
|
||||
path_start = url.find(pattern) + len(pattern)
|
||||
path = url[path_start:]
|
||||
return [mirror + path for mirror in mirrors]
|
||||
return [url] # No fallback, use original
|
||||
return []
|
||||
|
||||
|
||||
def download_url(url, filepath):
|
||||
"""Download URL to filepath without leaving partial files behind."""
|
||||
tmp_filepath = filepath + ".tmp"
|
||||
if os.path.exists(tmp_filepath):
|
||||
os.remove(tmp_filepath)
|
||||
|
||||
request = urllib.request.Request(
|
||||
url, headers={"User-Agent": "rocksdb-getdeps-fallback/1.0"}
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(
|
||||
request, timeout=DOWNLOAD_TIMEOUT_SECONDS
|
||||
) as response, open(tmp_filepath, "wb") as output:
|
||||
copied = 0
|
||||
while True:
|
||||
chunk = response.read(DOWNLOAD_CHUNK_BYTES)
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
copied += len(chunk)
|
||||
if copied > MAX_DOWNLOAD_BYTES:
|
||||
raise Exception(
|
||||
f"download exceeds {MAX_DOWNLOAD_BYTES} bytes"
|
||||
)
|
||||
output.write(chunk)
|
||||
os.replace(tmp_filepath, filepath)
|
||||
finally:
|
||||
if os.path.exists(tmp_filepath):
|
||||
os.remove(tmp_filepath)
|
||||
|
||||
|
||||
def prepare_download(package, info, download_dir, cache_dir):
|
||||
url = info["url"]
|
||||
expected_sha256 = info["sha256"]
|
||||
mirrors = get_fallback_mirrors(url)
|
||||
if not mirrors:
|
||||
return False
|
||||
|
||||
if not expected_sha256:
|
||||
print(f" {package}: WARNING - skipped fallback without sha256")
|
||||
return False
|
||||
|
||||
# getdeps uses format: {package}-{filename}
|
||||
filename = f"{package}-{os.path.basename(url)}"
|
||||
filepath = os.path.join(download_dir, filename)
|
||||
cache_path = os.path.join(cache_dir, filename)
|
||||
|
||||
# Check if already valid.
|
||||
actual_sha256 = sha256_file(filepath) if os.path.exists(filepath) else None
|
||||
if actual_sha256 == expected_sha256:
|
||||
print(f" {filename}: OK (already downloaded)")
|
||||
return True
|
||||
if actual_sha256 is not None:
|
||||
print(
|
||||
f" {filename}: WARNING - removing invalid download "
|
||||
f"sha256={actual_sha256}"
|
||||
)
|
||||
os.remove(filepath)
|
||||
|
||||
# The cache is only an opportunistic single-build accelerator; callers
|
||||
# should not share it across concurrent builds without external locking.
|
||||
actual_sha256 = sha256_file(cache_path) if os.path.exists(cache_path) else None
|
||||
if actual_sha256 == expected_sha256:
|
||||
print(f" {filename}: OK (from cache)")
|
||||
shutil.copy2(cache_path, filepath)
|
||||
return True
|
||||
if actual_sha256 is not None:
|
||||
print(
|
||||
f" {filename}: WARNING - removing invalid cache "
|
||||
f"sha256={actual_sha256}"
|
||||
)
|
||||
os.remove(cache_path)
|
||||
|
||||
# Try fallback mirrors.
|
||||
for mirror_url in mirrors:
|
||||
print(f" {filename}: trying {mirror_url}...")
|
||||
try:
|
||||
download_url(mirror_url, filepath)
|
||||
except Exception as ex:
|
||||
print(f" {filename}: WARNING - download failed: {ex}")
|
||||
continue
|
||||
|
||||
actual_sha256 = sha256_file(filepath)
|
||||
if actual_sha256 == expected_sha256:
|
||||
size = file_size(filepath)
|
||||
print(f" {filename}: OK (downloaded, {size} bytes)")
|
||||
shutil.copy2(filepath, cache_path)
|
||||
return True
|
||||
|
||||
size = file_size(filepath)
|
||||
print(
|
||||
f" {filename}: WARNING - sha256 mismatch from {mirror_url}: "
|
||||
f"expected={expected_sha256} actual={actual_sha256} size={size}"
|
||||
)
|
||||
os.remove(filepath)
|
||||
|
||||
print(f" {filename}: WARNING - all mirrors failed")
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 4:
|
||||
@@ -64,60 +190,39 @@ def main():
|
||||
sys.exit(1)
|
||||
|
||||
download_dir, cache_dir, manifests_dir = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
os.makedirs(download_dir, exist_ok=True)
|
||||
os.makedirs(cache_dir, exist_ok=True)
|
||||
|
||||
# Packages known to have unreliable mirrors
|
||||
packages_to_check = ["autoconf", "automake", "libtool"]
|
||||
|
||||
for package in packages_to_check:
|
||||
checked = 0
|
||||
ready = 0
|
||||
for package in PACKAGES_TO_CHECK:
|
||||
manifest_path = os.path.join(manifests_dir, package)
|
||||
if not os.path.exists(manifest_path):
|
||||
if not os.path.isfile(manifest_path):
|
||||
continue
|
||||
|
||||
info = parse_manifest(manifest_path)
|
||||
if not info or not info['url'] or not info['sha256']:
|
||||
if not info or not info["url"]:
|
||||
continue
|
||||
|
||||
# Determine filename from URL
|
||||
url = info['url']
|
||||
expected_sha256 = info['sha256']
|
||||
url_filename = os.path.basename(url)
|
||||
|
||||
# getdeps uses format: {package}-{filename}
|
||||
filename = f"{package}-{url_filename}"
|
||||
filepath = os.path.join(download_dir, filename)
|
||||
cache_path = os.path.join(cache_dir, filename)
|
||||
|
||||
# Check if already valid
|
||||
if os.path.exists(filepath) and sha256_file(filepath) == expected_sha256:
|
||||
print(f" {filename}: OK (already downloaded)")
|
||||
if not info["sha256"]:
|
||||
print(f" {package}: WARNING - skipped fallback without sha256")
|
||||
continue
|
||||
|
||||
# Check cache
|
||||
if os.path.exists(cache_path) and sha256_file(cache_path) == expected_sha256:
|
||||
print(f" {filename}: OK (from cache)")
|
||||
subprocess.run(['cp', cache_path, filepath], check=True)
|
||||
if not get_fallback_mirrors(info["url"]):
|
||||
print(
|
||||
f" {package}: WARNING - skipped fallback without known mirror "
|
||||
f"for {info['url']}"
|
||||
)
|
||||
continue
|
||||
|
||||
# Try fallback mirrors
|
||||
mirrors = get_fallback_mirrors(url)
|
||||
downloaded = False
|
||||
for mirror_url in mirrors:
|
||||
print(f" {filename}: trying {mirror_url}...")
|
||||
checked += 1
|
||||
try:
|
||||
subprocess.run(['wget', '-q', '-O', filepath, mirror_url], check=True, timeout=120)
|
||||
if sha256_file(filepath) == expected_sha256:
|
||||
print(f" {filename}: OK (downloaded)")
|
||||
subprocess.run(['cp', filepath, cache_path], check=False)
|
||||
downloaded = True
|
||||
break
|
||||
else:
|
||||
os.remove(filepath)
|
||||
except Exception:
|
||||
if os.path.exists(filepath):
|
||||
os.remove(filepath)
|
||||
if prepare_download(package, info, download_dir, cache_dir):
|
||||
ready += 1
|
||||
except Exception as ex:
|
||||
print(f" {package}: WARNING - fallback preparation failed: {ex}")
|
||||
|
||||
if not downloaded:
|
||||
print(f" {filename}: WARNING - all mirrors failed")
|
||||
print(f" fallback mirror downloads ready: {ready}/{checked}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2017 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import gtest_parallel
|
||||
import sys
|
||||
|
||||
sys.exit(gtest_parallel.main())
|
||||
@@ -0,0 +1,959 @@
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# This source code is licensed under both the GPLv2 (found in the COPYING file in the root directory)
|
||||
# and the Apache 2.0 License (found in the LICENSE.Apache file in the root directory).
|
||||
|
||||
# Copyright 2013 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import errno
|
||||
from functools import total_ordering
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
import multiprocessing
|
||||
import optparse
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
|
||||
if sys.version_info.major >= 3:
|
||||
long = int
|
||||
import _pickle as cPickle
|
||||
import _thread as thread
|
||||
else:
|
||||
import cPickle
|
||||
import thread
|
||||
|
||||
from pickle import HIGHEST_PROTOCOL as PICKLE_HIGHEST_PROTOCOL
|
||||
|
||||
if sys.platform == 'win32':
|
||||
import msvcrt
|
||||
else:
|
||||
import fcntl
|
||||
|
||||
|
||||
# An object that catches SIGINT sent to the Python process and notices
|
||||
# if processes passed to wait() die by SIGINT (we need to look for
|
||||
# both of those cases, because pressing Ctrl+C can result in either
|
||||
# the main process or one of the subprocesses getting the signal).
|
||||
#
|
||||
# Before a SIGINT is seen, wait(p) will simply call p.wait() and
|
||||
# return the result. Once a SIGINT has been seen (in the main process
|
||||
# or a subprocess, including the one the current call is waiting for),
|
||||
# wait(p) will call p.terminate() and raise ProcessWasInterrupted.
|
||||
class SigintHandler(object):
|
||||
class ProcessWasInterrupted(Exception):
|
||||
pass
|
||||
|
||||
sigint_returncodes = {
|
||||
-signal.SIGINT, # Unix
|
||||
-1073741510, # Windows
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.__lock = threading.Lock()
|
||||
self.__processes = set()
|
||||
self.__got_sigint = False
|
||||
signal.signal(signal.SIGINT, lambda signal_num, frame: self.interrupt())
|
||||
|
||||
def __on_sigint(self):
|
||||
self.__got_sigint = True
|
||||
while self.__processes:
|
||||
try:
|
||||
self.__processes.pop().terminate()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def interrupt(self):
|
||||
with self.__lock:
|
||||
self.__on_sigint()
|
||||
|
||||
def got_sigint(self):
|
||||
with self.__lock:
|
||||
return self.__got_sigint
|
||||
|
||||
def wait(self, p, timeout_per_test):
|
||||
with self.__lock:
|
||||
if self.__got_sigint:
|
||||
p.terminate()
|
||||
self.__processes.add(p)
|
||||
try:
|
||||
code = p.wait(timeout_per_test)
|
||||
except subprocess.TimeoutExpired :
|
||||
p.terminate()
|
||||
self.__processes.remove(p)
|
||||
code = -errno.ETIME
|
||||
with self.__lock:
|
||||
self.__processes.discard(p)
|
||||
if code in self.sigint_returncodes:
|
||||
self.__on_sigint()
|
||||
if self.__got_sigint:
|
||||
raise self.ProcessWasInterrupted
|
||||
return code
|
||||
|
||||
|
||||
sigint_handler = SigintHandler()
|
||||
|
||||
|
||||
# Return the width of the terminal, or None if it couldn't be
|
||||
# determined (e.g. because we're not being run interactively).
|
||||
def term_width(out):
|
||||
if not out.isatty():
|
||||
return None
|
||||
try:
|
||||
p = subprocess.Popen(["stty", "size"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
(out, err) = p.communicate()
|
||||
if p.returncode != 0 or err:
|
||||
return None
|
||||
return int(out.split()[1])
|
||||
except (IndexError, OSError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
# Output transient and permanent lines of text. If several transient
|
||||
# lines are written in sequence, the new will overwrite the old. We
|
||||
# use this to ensure that lots of unimportant info (tests passing)
|
||||
# won't drown out important info (tests failing).
|
||||
class Outputter(object):
|
||||
def __init__(self, out_file):
|
||||
self.__out_file = out_file
|
||||
self.__previous_line_was_transient = False
|
||||
self.__width = term_width(out_file) # Line width, or None if not a tty.
|
||||
|
||||
def transient_line(self, msg):
|
||||
if self.__width is None:
|
||||
self.__out_file.write(msg + "\n")
|
||||
self.__out_file.flush()
|
||||
else:
|
||||
self.__out_file.write("\r" + msg[:self.__width].ljust(self.__width))
|
||||
self.__previous_line_was_transient = True
|
||||
|
||||
def flush_transient_output(self):
|
||||
if self.__previous_line_was_transient:
|
||||
self.__out_file.write("\n")
|
||||
self.__previous_line_was_transient = False
|
||||
|
||||
def permanent_line(self, msg):
|
||||
self.flush_transient_output()
|
||||
self.__out_file.write(msg + "\n")
|
||||
if self.__width is None:
|
||||
self.__out_file.flush()
|
||||
|
||||
|
||||
def get_save_file_path():
|
||||
"""Return path to file for saving transient data."""
|
||||
if sys.platform == 'win32':
|
||||
default_cache_path = os.path.join(os.path.expanduser('~'), 'AppData',
|
||||
'Local')
|
||||
cache_path = os.environ.get('LOCALAPPDATA', default_cache_path)
|
||||
else:
|
||||
# We don't use xdg module since it's not a standard.
|
||||
default_cache_path = os.path.join(os.path.expanduser('~'), '.cache')
|
||||
cache_path = os.environ.get('XDG_CACHE_HOME', default_cache_path)
|
||||
|
||||
if os.path.isdir(cache_path):
|
||||
return os.path.join(cache_path, 'gtest-parallel')
|
||||
else:
|
||||
sys.stderr.write('Directory {} does not exist'.format(cache_path))
|
||||
return os.path.join(os.path.expanduser('~'), '.gtest-parallel-times')
|
||||
|
||||
|
||||
@total_ordering
|
||||
class Task(object):
|
||||
"""Stores information about a task (single execution of a test).
|
||||
|
||||
This class stores information about the test to be executed (gtest binary and
|
||||
test name), and its result (log file, exit code and runtime).
|
||||
Each task is uniquely identified by the gtest binary, the test name and an
|
||||
execution number that increases each time the test is executed.
|
||||
Additionaly we store the last execution time, so that next time the test is
|
||||
executed, the slowest tests are run first.
|
||||
"""
|
||||
|
||||
def __init__(self, test_binary, test_name, test_command, execution_number,
|
||||
last_execution_time, output_dir):
|
||||
self.test_name = test_name
|
||||
self.output_dir = output_dir
|
||||
self.test_binary = test_binary
|
||||
self.test_command = test_command
|
||||
self.execution_number = execution_number
|
||||
self.last_execution_time = last_execution_time
|
||||
|
||||
self.exit_code = None
|
||||
self.runtime_ms = None
|
||||
|
||||
self.test_id = (test_binary, test_name)
|
||||
self.task_id = (test_binary, test_name, self.execution_number)
|
||||
|
||||
self.log_file = Task._logname(self.output_dir, self.test_binary, test_name,
|
||||
self.execution_number)
|
||||
|
||||
def __sorting_key(self):
|
||||
# Unseen or failing tests (both missing execution time) take precedence over
|
||||
# execution time. Tests are greater (seen as slower) when missing times so
|
||||
# that they are executed first.
|
||||
return (1 if self.last_execution_time is None else 0,
|
||||
self.last_execution_time)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__sorting_key() == other.__sorting_key()
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.__sorting_key() < other.__sorting_key()
|
||||
|
||||
@staticmethod
|
||||
def _normalize(string):
|
||||
return re.sub('[^A-Za-z0-9]', '_', string)
|
||||
|
||||
@staticmethod
|
||||
def _logname(output_dir, test_binary, test_name, execution_number):
|
||||
# Store logs to temporary files if there is no output_dir.
|
||||
if output_dir is None:
|
||||
(log_handle, log_name) = tempfile.mkstemp(prefix='gtest_parallel_',
|
||||
suffix=".log")
|
||||
os.close(log_handle)
|
||||
return log_name
|
||||
|
||||
log_name = '%s-%s-%d.log' % (Task._normalize(os.path.basename(test_binary)),
|
||||
Task._normalize(test_name), execution_number)
|
||||
|
||||
return os.path.join(output_dir, log_name)
|
||||
|
||||
def run(self, timeout_per_test):
|
||||
begin = time.time()
|
||||
with open(self.log_file, 'w') as log:
|
||||
task = subprocess.Popen(self.test_command, stdout=log, stderr=log)
|
||||
try:
|
||||
self.exit_code = sigint_handler.wait(task, timeout_per_test)
|
||||
except sigint_handler.ProcessWasInterrupted:
|
||||
thread.exit()
|
||||
self.runtime_ms = int(1000 * (time.time() - begin))
|
||||
self.last_execution_time = None if self.exit_code else self.runtime_ms
|
||||
|
||||
|
||||
class TaskManager(object):
|
||||
"""Executes the tasks and stores the passed, failed and interrupted tasks.
|
||||
|
||||
When a task is run, this class keeps track if it passed, failed or was
|
||||
interrupted. After a task finishes it calls the relevant functions of the
|
||||
Logger, TestResults and TestTimes classes, and in case of failure, retries the
|
||||
test as specified by the --retry_failed flag.
|
||||
"""
|
||||
|
||||
def __init__(self, times, logger, test_results, task_factory, times_to_retry,
|
||||
initial_execution_number):
|
||||
self.times = times
|
||||
self.logger = logger
|
||||
self.test_results = test_results
|
||||
self.task_factory = task_factory
|
||||
self.times_to_retry = times_to_retry
|
||||
self.initial_execution_number = initial_execution_number
|
||||
|
||||
self.global_exit_code = 0
|
||||
|
||||
self.passed = []
|
||||
self.failed = []
|
||||
self.started = {}
|
||||
self.timed_out = []
|
||||
self.execution_number = {}
|
||||
|
||||
self.lock = threading.Lock()
|
||||
|
||||
def __get_next_execution_number(self, test_id):
|
||||
with self.lock:
|
||||
next_execution_number = self.execution_number.setdefault(
|
||||
test_id, self.initial_execution_number)
|
||||
self.execution_number[test_id] += 1
|
||||
return next_execution_number
|
||||
|
||||
def __register_start(self, task):
|
||||
with self.lock:
|
||||
self.started[task.task_id] = task
|
||||
|
||||
def register_exit(self, task):
|
||||
self.logger.log_exit(task)
|
||||
self.times.record_test_time(task.test_binary, task.test_name,
|
||||
task.last_execution_time)
|
||||
if self.test_results:
|
||||
self.test_results.log(task.test_name, task.runtime_ms / 1000.0,
|
||||
task.exit_code)
|
||||
|
||||
with self.lock:
|
||||
self.started.pop(task.task_id)
|
||||
if task.exit_code == 0:
|
||||
self.passed.append(task)
|
||||
elif task.exit_code == -errno.ETIME:
|
||||
self.timed_out.append(task)
|
||||
else:
|
||||
self.failed.append(task)
|
||||
|
||||
def run_task(self, task, timeout_per_test):
|
||||
for try_number in range(self.times_to_retry + 1):
|
||||
self.__register_start(task)
|
||||
task.run(timeout_per_test)
|
||||
self.register_exit(task)
|
||||
|
||||
if task.exit_code == 0:
|
||||
break
|
||||
|
||||
if try_number < self.times_to_retry:
|
||||
execution_number = self.__get_next_execution_number(task.test_id)
|
||||
# We need create a new Task instance. Each task represents a single test
|
||||
# execution, with its own runtime, exit code and log file.
|
||||
task = self.task_factory(task.test_binary, task.test_name,
|
||||
task.test_command, execution_number,
|
||||
task.last_execution_time, task.output_dir)
|
||||
|
||||
with self.lock:
|
||||
if task.exit_code != 0:
|
||||
self.global_exit_code = task.exit_code
|
||||
|
||||
|
||||
class FilterFormat(object):
|
||||
def __init__(self, output_dir):
|
||||
if sys.stdout.isatty():
|
||||
# stdout needs to be unbuffered since the output is interactive.
|
||||
if isinstance(sys.stdout, io.TextIOWrapper):
|
||||
# workaround for https://bugs.python.org/issue17404
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.detach(),
|
||||
line_buffering=True,
|
||||
write_through=True,
|
||||
newline='\n')
|
||||
else:
|
||||
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
|
||||
|
||||
self.output_dir = output_dir
|
||||
|
||||
self.total_tasks = 0
|
||||
self.finished_tasks = 0
|
||||
self.out = Outputter(sys.stdout)
|
||||
self.stdout_lock = threading.Lock()
|
||||
|
||||
def move_to(self, destination_dir, tasks):
|
||||
if self.output_dir is None:
|
||||
return
|
||||
|
||||
destination_dir = os.path.join(self.output_dir, destination_dir)
|
||||
os.makedirs(destination_dir)
|
||||
for task in tasks:
|
||||
shutil.move(task.log_file, destination_dir)
|
||||
|
||||
def print_tests(self, message, tasks, print_try_number, print_test_command):
|
||||
self.out.permanent_line("%s (%s/%s):" %
|
||||
(message, len(tasks), self.total_tasks))
|
||||
for task in sorted(tasks):
|
||||
runtime_ms = 'Interrupted'
|
||||
if task.runtime_ms is not None:
|
||||
runtime_ms = '%d ms' % task.runtime_ms
|
||||
if print_test_command:
|
||||
try:
|
||||
cmd_str = " ".join(task.test_command)
|
||||
except TypeError:
|
||||
cmd_str = task.test_command
|
||||
self.out.permanent_line(
|
||||
"%11s: %s%s" %
|
||||
(runtime_ms, cmd_str,
|
||||
(" (try #%d)" % task.execution_number) if print_try_number else ""))
|
||||
else:
|
||||
self.out.permanent_line(
|
||||
"%11s: %s %s%s" %
|
||||
(runtime_ms, task.test_binary, task.test_name,
|
||||
(" (try #%d)" % task.execution_number) if print_try_number else ""))
|
||||
|
||||
def log_exit(self, task):
|
||||
with self.stdout_lock:
|
||||
self.finished_tasks += 1
|
||||
self.out.transient_line("[%d/%d] %s (%d ms)" %
|
||||
(self.finished_tasks, self.total_tasks,
|
||||
task.test_name, task.runtime_ms))
|
||||
if task.exit_code != 0:
|
||||
signal_name = None
|
||||
if task.exit_code < 0:
|
||||
try:
|
||||
signal_name = signal.Signals(-task.exit_code).name
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
with open(task.log_file) as f:
|
||||
for line in f.readlines():
|
||||
self.out.permanent_line(line.rstrip())
|
||||
if task.exit_code is None:
|
||||
self.out.permanent_line("[%d/%d] %s aborted after %d ms" %
|
||||
(self.finished_tasks, self.total_tasks,
|
||||
task.test_name, task.runtime_ms))
|
||||
elif task.exit_code == -errno.ETIME:
|
||||
self.out.permanent_line(
|
||||
"\033[31m[ TIMEOUT ]\033[0m %s timed out after %d s"
|
||||
% (task.test_name, task.runtime_ms/1000))
|
||||
elif signal_name is not None:
|
||||
self.out.permanent_line(
|
||||
"[%d/%d] %s killed by signal %s (%d ms)" %
|
||||
(self.finished_tasks, self.total_tasks, task.test_name,
|
||||
signal_name, task.runtime_ms))
|
||||
else:
|
||||
self.out.permanent_line(
|
||||
"[%d/%d] %s returned with exit code %d (%d ms)" %
|
||||
(self.finished_tasks, self.total_tasks, task.test_name,
|
||||
task.exit_code, task.runtime_ms))
|
||||
|
||||
if self.output_dir is None:
|
||||
# Try to remove the file 100 times (sleeping for 0.1 second in between).
|
||||
# This is a workaround for a process handle seemingly holding on to the
|
||||
# file for too long inside os.subprocess. This workaround is in place
|
||||
# until we figure out a minimal repro to report upstream (or a better
|
||||
# suspect) to prevent os.remove exceptions.
|
||||
num_tries = 100
|
||||
for i in range(num_tries):
|
||||
try:
|
||||
os.remove(task.log_file)
|
||||
except OSError as e:
|
||||
if e.errno is not errno.ENOENT:
|
||||
if i is num_tries - 1:
|
||||
self.out.permanent_line('Could not remove temporary log file: ' +
|
||||
str(e))
|
||||
else:
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
break
|
||||
|
||||
def log_tasks(self, total_tasks):
|
||||
self.total_tasks += total_tasks
|
||||
self.out.transient_line("[0/%d] Running tests..." % self.total_tasks)
|
||||
|
||||
def summarize(self, passed_tasks, failed_tasks, interrupted_tasks):
|
||||
stats = {}
|
||||
|
||||
def add_stats(stats, task, idx):
|
||||
task_key = (task.test_binary, task.test_name)
|
||||
if not task_key in stats:
|
||||
# (passed, failed, interrupted) task_key is added as tie breaker to get
|
||||
# alphabetic sorting on equally-stable tests
|
||||
stats[task_key] = [0, 0, 0, task_key]
|
||||
stats[task_key][idx] += 1
|
||||
|
||||
for task in passed_tasks:
|
||||
add_stats(stats, task, 0)
|
||||
for task in failed_tasks:
|
||||
add_stats(stats, task, 1)
|
||||
for task in interrupted_tasks:
|
||||
add_stats(stats, task, 2)
|
||||
|
||||
self.out.permanent_line("SUMMARY:")
|
||||
for task_key in sorted(stats, key=stats.__getitem__):
|
||||
(num_passed, num_failed, num_interrupted, _) = stats[task_key]
|
||||
(test_binary, task_name) = task_key
|
||||
total_runs = num_passed + num_failed + num_interrupted
|
||||
if num_passed == total_runs:
|
||||
continue
|
||||
self.out.permanent_line(" %s %s passed %d / %d times%s." %
|
||||
(test_binary, task_name, num_passed, total_runs,
|
||||
"" if num_interrupted == 0 else
|
||||
(" (%d interrupted)" % num_interrupted)))
|
||||
|
||||
def flush(self):
|
||||
self.out.flush_transient_output()
|
||||
|
||||
|
||||
class CollectTestResults(object):
|
||||
def __init__(self, json_dump_filepath):
|
||||
self.test_results_lock = threading.Lock()
|
||||
self.json_dump_file = open(json_dump_filepath, 'w')
|
||||
self.test_results = {
|
||||
"interrupted": False,
|
||||
"path_delimiter": ".",
|
||||
# Third version of the file format. See the link in the flag description
|
||||
# for details.
|
||||
"version": 3,
|
||||
"seconds_since_epoch": int(time.time()),
|
||||
"num_failures_by_type": {
|
||||
"PASS": 0,
|
||||
"FAIL": 0,
|
||||
"TIMEOUT": 0,
|
||||
},
|
||||
"tests": {},
|
||||
}
|
||||
|
||||
def log(self, test, runtime_seconds, exit_code):
|
||||
if exit_code is None:
|
||||
actual_result = "TIMEOUT"
|
||||
elif exit_code == 0:
|
||||
actual_result = "PASS"
|
||||
else:
|
||||
actual_result = "FAIL"
|
||||
with self.test_results_lock:
|
||||
self.test_results['num_failures_by_type'][actual_result] += 1
|
||||
results = self.test_results['tests']
|
||||
for name in test.split('.'):
|
||||
results = results.setdefault(name, {})
|
||||
|
||||
if results:
|
||||
results['actual'] += ' ' + actual_result
|
||||
results['times'].append(runtime_seconds)
|
||||
else: # This is the first invocation of the test
|
||||
results['actual'] = actual_result
|
||||
results['times'] = [runtime_seconds]
|
||||
results['time'] = runtime_seconds
|
||||
results['expected'] = 'PASS'
|
||||
|
||||
def dump_to_file_and_close(self):
|
||||
json.dump(self.test_results, self.json_dump_file)
|
||||
self.json_dump_file.close()
|
||||
|
||||
|
||||
# Record of test runtimes. Has built-in locking.
|
||||
class TestTimes(object):
|
||||
class LockedFile(object):
|
||||
def __init__(self, filename, mode):
|
||||
self._filename = filename
|
||||
self._mode = mode
|
||||
self._fo = None
|
||||
|
||||
def __enter__(self):
|
||||
self._fo = open(self._filename, self._mode)
|
||||
|
||||
# Regardless of opening mode we always seek to the beginning of file.
|
||||
# This simplifies code working with LockedFile and also ensures that
|
||||
# we lock (and unlock below) always the same region in file on win32.
|
||||
self._fo.seek(0)
|
||||
|
||||
try:
|
||||
if sys.platform == 'win32':
|
||||
# We are locking here fixed location in file to use it as
|
||||
# an exclusive lock on entire file.
|
||||
msvcrt.locking(self._fo.fileno(), msvcrt.LK_LOCK, 1)
|
||||
else:
|
||||
fcntl.flock(self._fo.fileno(), fcntl.LOCK_EX)
|
||||
except IOError:
|
||||
self._fo.close()
|
||||
raise
|
||||
|
||||
return self._fo
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
# Flush any buffered data to disk. This is needed to prevent race
|
||||
# condition which happens from the moment of releasing file lock
|
||||
# till closing the file.
|
||||
self._fo.flush()
|
||||
|
||||
try:
|
||||
if sys.platform == 'win32':
|
||||
self._fo.seek(0)
|
||||
msvcrt.locking(self._fo.fileno(), msvcrt.LK_UNLCK, 1)
|
||||
else:
|
||||
fcntl.flock(self._fo.fileno(), fcntl.LOCK_UN)
|
||||
finally:
|
||||
self._fo.close()
|
||||
|
||||
return exc_value is None
|
||||
|
||||
def __init__(self, save_file):
|
||||
"Create new object seeded with saved test times from the given file."
|
||||
self.__times = {} # (test binary, test name) -> runtime in ms
|
||||
|
||||
# Protects calls to record_test_time(); other calls are not
|
||||
# expected to be made concurrently.
|
||||
self.__lock = threading.Lock()
|
||||
|
||||
try:
|
||||
with TestTimes.LockedFile(save_file, 'rb') as fd:
|
||||
times = TestTimes.__read_test_times_file(fd)
|
||||
except IOError:
|
||||
# We couldn't obtain the lock.
|
||||
return
|
||||
|
||||
# Discard saved times if the format isn't right.
|
||||
if type(times) is not dict:
|
||||
return
|
||||
for ((test_binary, test_name), runtime) in times.items():
|
||||
if (type(test_binary) is not str or type(test_name) is not str
|
||||
or type(runtime) not in {int, long, type(None)}):
|
||||
return
|
||||
|
||||
self.__times = times
|
||||
|
||||
def get_test_time(self, binary, testname):
|
||||
"""Return the last duration for the given test as an integer number of
|
||||
milliseconds, or None if the test failed or if there's no record for it."""
|
||||
return self.__times.get((binary, testname), None)
|
||||
|
||||
def record_test_time(self, binary, testname, runtime_ms):
|
||||
"""Record that the given test ran in the specified number of
|
||||
milliseconds. If the test failed, runtime_ms should be None."""
|
||||
with self.__lock:
|
||||
self.__times[(binary, testname)] = runtime_ms
|
||||
|
||||
def write_to_file(self, save_file):
|
||||
"Write all the times to file."
|
||||
try:
|
||||
with TestTimes.LockedFile(save_file, 'a+b') as fd:
|
||||
times = TestTimes.__read_test_times_file(fd)
|
||||
|
||||
if times is None:
|
||||
times = self.__times
|
||||
else:
|
||||
times.update(self.__times)
|
||||
|
||||
# We erase data from file while still holding a lock to it. This
|
||||
# way reading old test times and appending new ones are atomic
|
||||
# for external viewer.
|
||||
fd.seek(0)
|
||||
fd.truncate()
|
||||
with gzip.GzipFile(fileobj=fd, mode='wb') as gzf:
|
||||
cPickle.dump(times, gzf, PICKLE_HIGHEST_PROTOCOL)
|
||||
except IOError:
|
||||
pass # ignore errors---saving the times isn't that important
|
||||
|
||||
@staticmethod
|
||||
def __read_test_times_file(fd):
|
||||
try:
|
||||
with gzip.GzipFile(fileobj=fd, mode='rb') as gzf:
|
||||
times = cPickle.load(gzf)
|
||||
except Exception:
|
||||
# File doesn't exist, isn't readable, is malformed---whatever.
|
||||
# Just ignore it.
|
||||
return None
|
||||
else:
|
||||
return times
|
||||
|
||||
|
||||
def find_tests(binaries, additional_args, options, times):
|
||||
test_count = 0
|
||||
tasks = []
|
||||
for test_binary in binaries:
|
||||
command = [test_binary] + additional_args
|
||||
if options.gtest_also_run_disabled_tests:
|
||||
command += ['--gtest_also_run_disabled_tests']
|
||||
|
||||
list_command = command + ['--gtest_list_tests']
|
||||
if options.gtest_filter != '':
|
||||
list_command += ['--gtest_filter=' + options.gtest_filter]
|
||||
|
||||
try:
|
||||
test_list = subprocess.check_output(list_command,
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError as e:
|
||||
sys.exit("%s: %s\n%s" % (test_binary, str(e), e.output))
|
||||
|
||||
try:
|
||||
test_list = test_list.split('\n')
|
||||
except TypeError:
|
||||
# subprocess.check_output() returns bytes in python3
|
||||
test_list = test_list.decode(sys.stdout.encoding).split('\n')
|
||||
|
||||
command += ['--gtest_color=' + options.gtest_color]
|
||||
|
||||
test_group = ''
|
||||
for line in test_list:
|
||||
if not line.strip():
|
||||
continue
|
||||
if line[0] != " ":
|
||||
# Remove comments for typed tests and strip whitespace.
|
||||
test_group = line.split('#')[0].strip()
|
||||
continue
|
||||
# Remove comments for parameterized tests and strip whitespace.
|
||||
line = line.split('#')[0].strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
test_name = test_group + line
|
||||
if not options.gtest_also_run_disabled_tests and 'DISABLED_' in test_name:
|
||||
continue
|
||||
|
||||
# Skip PRE_ tests which are used by Chromium.
|
||||
if '.PRE_' in test_name:
|
||||
continue
|
||||
|
||||
last_execution_time = times.get_test_time(test_binary, test_name)
|
||||
if options.failed and last_execution_time is not None:
|
||||
continue
|
||||
|
||||
test_command = command + ['--gtest_filter=' + test_name]
|
||||
if (test_count - options.shard_index) % options.shard_count == 0:
|
||||
for execution_number in range(options.repeat):
|
||||
tasks.append(
|
||||
Task(test_binary, test_name, test_command, execution_number + 1,
|
||||
last_execution_time, options.output_dir))
|
||||
|
||||
test_count += 1
|
||||
|
||||
# Sort the tasks to run the slowest tests first, so that faster ones can be
|
||||
# finished in parallel.
|
||||
return sorted(tasks, reverse=True)
|
||||
|
||||
|
||||
def execute_tasks(tasks, pool_size, task_manager, timeout_seconds,
|
||||
timeout_per_test, serialize_test_cases):
|
||||
class WorkerFn(object):
|
||||
def __init__(self, tasks, running_groups, timeout_per_test):
|
||||
self.tasks = tasks
|
||||
self.running_groups = running_groups
|
||||
self.timeout_per_test = timeout_per_test
|
||||
self.task_lock = threading.Lock()
|
||||
|
||||
def __call__(self):
|
||||
while True:
|
||||
with self.task_lock:
|
||||
for task_id in range(len(self.tasks)):
|
||||
task = self.tasks[task_id]
|
||||
|
||||
if self.running_groups is not None:
|
||||
test_group = task.test_name.split('.')[0]
|
||||
if test_group in self.running_groups:
|
||||
# Try to find other non-running test group.
|
||||
continue
|
||||
else:
|
||||
self.running_groups.add(test_group)
|
||||
|
||||
del self.tasks[task_id]
|
||||
break
|
||||
else:
|
||||
# Either there is no tasks left or number or remaining test
|
||||
# cases (groups) is less than number or running threads.
|
||||
return
|
||||
|
||||
task_manager.run_task(task, self.timeout_per_test)
|
||||
|
||||
if self.running_groups is not None:
|
||||
with self.task_lock:
|
||||
self.running_groups.remove(test_group)
|
||||
|
||||
def start_daemon(func):
|
||||
t = threading.Thread(target=func)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
return t
|
||||
|
||||
timeout = None
|
||||
try:
|
||||
if timeout_seconds:
|
||||
timeout = threading.Timer(timeout_seconds, sigint_handler.interrupt)
|
||||
timeout.start()
|
||||
running_groups = set() if serialize_test_cases else None
|
||||
worker_fn = WorkerFn(tasks, running_groups, timeout_per_test)
|
||||
workers = [start_daemon(worker_fn) for _ in range(pool_size)]
|
||||
for worker in workers:
|
||||
worker.join()
|
||||
finally:
|
||||
if timeout:
|
||||
timeout.cancel()
|
||||
for task in list(task_manager.started.values()):
|
||||
task.runtime_ms = timeout_seconds * 1000
|
||||
task_manager.register_exit(task)
|
||||
|
||||
|
||||
def default_options_parser():
|
||||
parser = optparse.OptionParser(
|
||||
usage='usage: %prog [options] binary [binary ...] -- [additional args]')
|
||||
|
||||
parser.add_option('-d',
|
||||
'--output_dir',
|
||||
type='string',
|
||||
default=None,
|
||||
help='Output directory for test logs. Logs will be '
|
||||
'available under gtest-parallel-logs/, so '
|
||||
'--output_dir=/tmp will results in all logs being '
|
||||
'available under /tmp/gtest-parallel-logs/.')
|
||||
parser.add_option('-r',
|
||||
'--repeat',
|
||||
type='int',
|
||||
default=1,
|
||||
help='Number of times to execute all the tests.')
|
||||
parser.add_option('--retry_failed',
|
||||
type='int',
|
||||
default=0,
|
||||
help='Number of times to repeat failed tests.')
|
||||
parser.add_option('--failed',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='run only failed and new tests')
|
||||
parser.add_option('-w',
|
||||
'--workers',
|
||||
type='int',
|
||||
default=multiprocessing.cpu_count(),
|
||||
help='number of workers to spawn')
|
||||
parser.add_option('--gtest_color',
|
||||
type='string',
|
||||
default='yes',
|
||||
help='color output')
|
||||
parser.add_option('--gtest_filter',
|
||||
type='string',
|
||||
default='',
|
||||
help='test filter')
|
||||
parser.add_option('--gtest_also_run_disabled_tests',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='run disabled tests too')
|
||||
parser.add_option(
|
||||
'--print_test_times',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='list the run time of each test at the end of execution')
|
||||
parser.add_option(
|
||||
'--print_test_command',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Print full test command instead of name')
|
||||
parser.add_option('--shard_count',
|
||||
type='int',
|
||||
default=1,
|
||||
help='total number of shards (for sharding test execution '
|
||||
'between multiple machines)')
|
||||
parser.add_option('--shard_index',
|
||||
type='int',
|
||||
default=0,
|
||||
help='zero-indexed number identifying this shard (for '
|
||||
'sharding test execution between multiple machines)')
|
||||
parser.add_option(
|
||||
'--dump_json_test_results',
|
||||
type='string',
|
||||
default=None,
|
||||
help='Saves the results of the tests as a JSON machine-'
|
||||
'readable file. The format of the file is specified at '
|
||||
'https://www.chromium.org/developers/the-json-test-results-format')
|
||||
parser.add_option('--timeout',
|
||||
type='int',
|
||||
default=None,
|
||||
help='Interrupt all remaining processes after the given '
|
||||
'time (in seconds).')
|
||||
parser.add_option('--timeout_per_test',
|
||||
type='int',
|
||||
default=None,
|
||||
help='Interrupt single processes after the given '
|
||||
'time (in seconds).')
|
||||
parser.add_option('--serialize_test_cases',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Do not run tests from the same test '
|
||||
'case in parallel.')
|
||||
return parser
|
||||
|
||||
|
||||
def main():
|
||||
# Remove additional arguments (anything after --).
|
||||
additional_args = []
|
||||
|
||||
for i in range(len(sys.argv)):
|
||||
if sys.argv[i] == '--':
|
||||
additional_args = sys.argv[i + 1:]
|
||||
sys.argv = sys.argv[:i]
|
||||
break
|
||||
|
||||
parser = default_options_parser()
|
||||
(options, binaries) = parser.parse_args()
|
||||
|
||||
if (options.output_dir is not None and not os.path.isdir(options.output_dir)):
|
||||
parser.error('--output_dir value must be an existing directory, '
|
||||
'current value is "%s"' % options.output_dir)
|
||||
|
||||
# Append gtest-parallel-logs to log output, this is to avoid deleting user
|
||||
# data if an user passes a directory where files are already present. If a
|
||||
# user specifies --output_dir=Docs/, we'll create Docs/gtest-parallel-logs
|
||||
# and clean that directory out on startup, instead of nuking Docs/.
|
||||
if options.output_dir:
|
||||
options.output_dir = os.path.join(options.output_dir, 'gtest-parallel-logs')
|
||||
|
||||
if binaries == []:
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
if options.shard_count < 1:
|
||||
parser.error("Invalid number of shards: %d. Must be at least 1." %
|
||||
options.shard_count)
|
||||
if not (0 <= options.shard_index < options.shard_count):
|
||||
parser.error("Invalid shard index: %d. Must be between 0 and %d "
|
||||
"(less than the number of shards)." %
|
||||
(options.shard_index, options.shard_count - 1))
|
||||
|
||||
# Check that all test binaries have an unique basename. That way we can ensure
|
||||
# the logs are saved to unique files even when two different binaries have
|
||||
# common tests.
|
||||
unique_binaries = set(os.path.basename(binary) for binary in binaries)
|
||||
assert len(unique_binaries) == len(binaries), (
|
||||
"All test binaries must have an unique basename.")
|
||||
|
||||
if options.output_dir:
|
||||
# Remove files from old test runs.
|
||||
if os.path.isdir(options.output_dir):
|
||||
shutil.rmtree(options.output_dir)
|
||||
# Create directory for test log output.
|
||||
try:
|
||||
os.makedirs(options.output_dir)
|
||||
except OSError as e:
|
||||
# Ignore errors if this directory already exists.
|
||||
if e.errno != errno.EEXIST or not os.path.isdir(options.output_dir):
|
||||
raise e
|
||||
|
||||
test_results = None
|
||||
if options.dump_json_test_results is not None:
|
||||
test_results = CollectTestResults(options.dump_json_test_results)
|
||||
|
||||
save_file = get_save_file_path()
|
||||
|
||||
times = TestTimes(save_file)
|
||||
logger = FilterFormat(options.output_dir)
|
||||
|
||||
task_manager = TaskManager(times, logger, test_results, Task,
|
||||
options.retry_failed, options.repeat + 1)
|
||||
|
||||
tasks = find_tests(binaries, additional_args, options, times)
|
||||
logger.log_tasks(len(tasks))
|
||||
execute_tasks(tasks, options.workers, task_manager, options.timeout,
|
||||
options.timeout_per_test, options.serialize_test_cases)
|
||||
|
||||
print_try_number = options.retry_failed > 0 or options.repeat > 1
|
||||
if task_manager.passed:
|
||||
logger.move_to('passed', task_manager.passed)
|
||||
if options.print_test_times:
|
||||
logger.print_tests('PASSED TESTS', task_manager.passed, print_try_number, options.print_test_command)
|
||||
|
||||
if task_manager.failed:
|
||||
logger.print_tests('FAILED TESTS', task_manager.failed, print_try_number, options.print_test_command)
|
||||
logger.move_to('failed', task_manager.failed)
|
||||
|
||||
if task_manager.timed_out:
|
||||
logger.print_tests('TIMED OUT TESTS', task_manager.timed_out, print_try_number, options.print_test_command)
|
||||
logger.move_to('timed_out', task_manager.timed_out)
|
||||
|
||||
if task_manager.started:
|
||||
logger.print_tests('INTERRUPTED TESTS', task_manager.started.values(),
|
||||
print_try_number, options.print_test_command)
|
||||
logger.move_to('interrupted', task_manager.started.values())
|
||||
|
||||
if options.repeat > 1 and (task_manager.failed or task_manager.started):
|
||||
logger.summarize(task_manager.passed, task_manager.failed,
|
||||
task_manager.started.values())
|
||||
|
||||
logger.flush()
|
||||
times.write_to_file(save_file)
|
||||
if test_results:
|
||||
test_results.dump_to_file_and_close()
|
||||
|
||||
if sigint_handler.got_sigint():
|
||||
return -signal.SIGINT
|
||||
|
||||
return task_manager.global_exit_code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# 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).
|
||||
#
|
||||
# Build RocksDB unit test binaries and run them under gtest-parallel,
|
||||
# which shards the test cases across CPUs for faster execution.
|
||||
#
|
||||
# Hardened version of a simple `make <bin> && gtest-parallel ./<bin>` helper:
|
||||
# * AUTO_CLEAN=1 so the Makefile automatically runs a clean when the build
|
||||
# parameters (DEBUG_LEVEL, sanitizers, ASSERT_STATUS_CHECKED, RTTI, etc.)
|
||||
# have changed since the last build, preventing stale/mixed object files.
|
||||
# * Parallel build with -j<NCORES>, computed the same way the Makefile does.
|
||||
# * Uses the gtest-parallel checked in alongside this script (build_tools/),
|
||||
# so it works regardless of PATH.
|
||||
# * `set -euo pipefail` so any failure stops the script.
|
||||
#
|
||||
# Run from the repository root.
|
||||
#
|
||||
# Accepts one or more test binaries (gtest-parallel pools all their test cases
|
||||
# into one shared worker queue). The leading non-option arguments are treated as
|
||||
# binaries; everything from the first option onward is forwarded to
|
||||
# gtest-parallel / the test binaries.
|
||||
#
|
||||
# Example usage:
|
||||
# build_tools/rocksptest.sh db_test
|
||||
# build_tools/rocksptest.sh db_test -r1000 --gtest_filter=*MixedSlowdown*
|
||||
# build_tools/rocksptest.sh db_test env_test db_basic_test
|
||||
# build_tools/rocksptest.sh db_test env_test --gtest_filter=*Foo*
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$#" -lt 1 ]; then
|
||||
echo "usage: $0 <test_binary> [more_test_binaries...] [gtest-parallel/test args...]" >&2
|
||||
echo "example: $0 db_test env_test -r1000 --gtest_filter=*MixedSlowdown*" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# First argument must be a test binary, not an option (catches a forgotten name).
|
||||
if [ "${1#-}" != "$1" ]; then
|
||||
echo "$0: first argument must be a test binary name, not an option ('$1')" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Collect the leading non-option arguments as test binaries; everything from the
|
||||
# first option onward is forwarded to gtest-parallel / the test binaries.
|
||||
BINS=()
|
||||
while [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; do
|
||||
BINS+=("$1")
|
||||
shift
|
||||
done
|
||||
|
||||
# Paths as gtest-parallel expects them (relative to the current directory).
|
||||
BIN_PATHS=()
|
||||
for b in "${BINS[@]}"; do
|
||||
BIN_PATHS+=("./$b")
|
||||
done
|
||||
|
||||
# Directory of this script, so we use the gtest-parallel checked in next to it.
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
# Compute parallelism the same way the Makefile computes NCORES.
|
||||
NCORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
||||
|
||||
make AUTO_CLEAN=1 -j"$NCORES" "${BINS[@]}"
|
||||
"$SCRIPT_DIR/gtest-parallel" "${BIN_PATHS[@]}" "$@"
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# 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).
|
||||
#
|
||||
# Build a single RocksDB unit test binary and run it directly (serially).
|
||||
# Only recommended with --gtest_filter=... because of speed. See also
|
||||
# build_tools/rocksptest.sh
|
||||
#
|
||||
# Hardened version of a simple `make <bin> && ./<bin>` helper:
|
||||
# * AUTO_CLEAN=1 so the Makefile automatically runs a clean when the build
|
||||
# parameters (DEBUG_LEVEL, sanitizers, ASSERT_STATUS_CHECKED, RTTI, etc.)
|
||||
# have changed since the last build, preventing stale/mixed object files.
|
||||
# * Parallel build with -j<NCORES>, computed the same way the Makefile does.
|
||||
# * `set -euo pipefail` so any failure stops the script.
|
||||
#
|
||||
# Run from the repository root.
|
||||
#
|
||||
# Example usage:
|
||||
# build_tools/rockstest.sh db_test --gtest_filter=*MixedSlowdown*
|
||||
# build_tools/rockstest.sh env_test # Slow to run many tests serially
|
||||
#
|
||||
# Install mode:
|
||||
# build_tools/rockstest.sh install
|
||||
# Creates ~/bin/rockstest and ~/bin/rocksptest shims that defer to
|
||||
# build_tools/rockstest.sh / rocksptest.sh in whatever directory you run
|
||||
# them from, so you can just type `rockstest db_test` from any rocksdb
|
||||
# source root.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Install mode: write thin ~/bin shims that defer to the build_tools scripts in
|
||||
# the current directory.
|
||||
if [ "${1:-}" = "install" ]; then
|
||||
mkdir -p "$HOME/bin"
|
||||
for name in rockstest rocksptest; do
|
||||
dest="$HOME/bin/$name"
|
||||
cat > "$dest" <<EOF
|
||||
#!/usr/bin/env bash
|
||||
# Auto-generated by 'build_tools/rockstest.sh install'. Defers to
|
||||
# build_tools/$name.sh in the current rocksdb source root.
|
||||
if [ -x build_tools/$name.sh ]; then
|
||||
exec build_tools/$name.sh "\$@"
|
||||
else
|
||||
echo "build_tools/$name.sh not found (Not in a rocksdb source root directory?)" >&2
|
||||
exit 1
|
||||
fi
|
||||
EOF
|
||||
chmod +x "$dest"
|
||||
echo "Installed $dest"
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$#" -lt 1 ]; then
|
||||
echo "usage: $0 <test_binary> [test args...]" >&2
|
||||
echo " $0 install # create ~/bin/rockstest and ~/bin/rocksptest shims" >&2
|
||||
echo "example: $0 db_test --gtest_filter=*MixedSlowdown*" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# First argument must be a test binary, not an option (catches a forgotten name).
|
||||
if [ "${1#-}" != "$1" ]; then
|
||||
echo "$0: first argument must be a test binary name, not an option ('$1')" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BIN=$1
|
||||
shift
|
||||
|
||||
# Compute parallelism the same way the Makefile computes NCORES.
|
||||
NCORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
||||
|
||||
make AUTO_CLEAN=1 -j"$NCORES" "$BIN"
|
||||
./"$BIN" "$@"
|
||||
@@ -75,17 +75,33 @@ touch "$OUTPUT"
|
||||
echo "Writing dependencies to $OUTPUT"
|
||||
|
||||
# Compilers locations
|
||||
GCC_BASE=`readlink -f $TP2_LATEST/gcc/11.x/centos8-native/*/`
|
||||
CLANG_BASE=`readlink -f $TP2_LATEST/llvm-fb/15/platform010/*/`
|
||||
# GCC is pinned to 11.x because the only newer GCC in third-party2 (13.x) is
|
||||
# built for centos9/glibc>=2.35 -- its libgcc_s.so.1 has a hard reference
|
||||
# to _dl_find_object@GLIBC_2.35, but platform010 ships glibc 2.34. Bumping
|
||||
# GCC requires a platform with glibc >= 2.35.
|
||||
GCC_BASE=`readlink -f $TP2_LATEST/gcc/11.x/centos9-native/*/`
|
||||
# Clang is pinned to the latest tested major (21). Bump deliberately.
|
||||
CLANG_BASE=`readlink -f $TP2_LATEST/llvm-fb/21/platform010/*/`
|
||||
|
||||
log_header
|
||||
log_variable GCC_BASE
|
||||
log_variable CLANG_BASE
|
||||
|
||||
# Libraries locations
|
||||
# libgcc is pinned to 11.x to match the GCC 11 compiler above (libstdc++/
|
||||
# libgcc runtime, ABI, and C++ headers). Bump in lockstep with GCC_BASE.
|
||||
get_lib_base libgcc 11.x platform010
|
||||
# glibc 2.34 is the platform010 ABI baseline (ld.so + libc); it is also the
|
||||
# only version available in third-party2, and defines the platform -- do
|
||||
# not bump independently.
|
||||
get_lib_base glibc 2.34 platform010
|
||||
get_lib_base snappy LATEST platform010
|
||||
# zlib is pinned to 1.2.8: it is the latest version with an x86_64
|
||||
# platform010 build (1.2.13 / 1.3.1 are centos9 / aarch64 only). At time of
|
||||
# writing, LATEST here doesn't work: get_lib_base picks the newest version
|
||||
# dir first and only then appends the platform, with no fallback -- so
|
||||
# LATEST would resolve to 1.3.1, find no platform010 build, and emit an
|
||||
# empty ZLIB_BASE.
|
||||
get_lib_base zlib 1.2.8 platform010
|
||||
get_lib_base bzip2 LATEST platform010
|
||||
get_lib_base lz4 LATEST platform010
|
||||
@@ -94,12 +110,11 @@ get_lib_base gflags LATEST platform010
|
||||
get_lib_base jemalloc LATEST platform010
|
||||
get_lib_base numa LATEST platform010
|
||||
get_lib_base libunwind LATEST platform010
|
||||
get_lib_base tbb 2018_U5 platform010
|
||||
get_lib_base liburing LATEST platform010
|
||||
get_lib_base benchmark LATEST platform010
|
||||
|
||||
get_lib_base kernel-headers fb platform010
|
||||
get_lib_base binutils LATEST centos8-native
|
||||
get_lib_base binutils LATEST centos9-native
|
||||
get_lib_base valgrind LATEST platform010
|
||||
|
||||
git diff $OUTPUT
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'BlockBasedOptions simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_block_based_options_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_block_based_options_subset.cc.inc
|
||||
|
||||
/* BlockBasedOptions simple */
|
||||
|
||||
void rocksdb_block_based_options_set_data_block_hash_ratio(
|
||||
rocksdb_block_based_table_options_t* options, double v) {
|
||||
options->rep.data_block_hash_table_util_ratio = v;
|
||||
}
|
||||
|
||||
void rocksdb_block_based_options_set_top_level_index_pinning_tier(
|
||||
rocksdb_block_based_table_options_t* options, int v) {
|
||||
options->rep.metadata_cache_options.top_level_index_pinning =
|
||||
static_cast<ROCKSDB_NAMESPACE::PinningTier>(v);
|
||||
}
|
||||
|
||||
void rocksdb_block_based_options_set_partition_pinning_tier(
|
||||
rocksdb_block_based_table_options_t* options, int v) {
|
||||
options->rep.metadata_cache_options.partition_pinning =
|
||||
static_cast<ROCKSDB_NAMESPACE::PinningTier>(v);
|
||||
}
|
||||
|
||||
void rocksdb_block_based_options_set_unpartitioned_pinning_tier(
|
||||
rocksdb_block_based_table_options_t* options, int v) {
|
||||
options->rep.metadata_cache_options.unpartitioned_pinning =
|
||||
static_cast<ROCKSDB_NAMESPACE::PinningTier>(v);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'BlockBasedOptions simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_block_based_options_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_block_based_options_subset.cc.inc
|
||||
|
||||
/* BlockBasedOptions simple */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_block_based_options_set_data_block_hash_ratio(
|
||||
rocksdb_block_based_table_options_t* options, double v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_block_based_options_set_top_level_index_pinning_tier(
|
||||
rocksdb_block_based_table_options_t* options, int v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_block_based_options_set_partition_pinning_tier(
|
||||
rocksdb_block_based_table_options_t* options, int v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_block_based_options_set_unpartitioned_pinning_tier(
|
||||
rocksdb_block_based_table_options_t* options, int v);
|
||||
@@ -0,0 +1,21 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'CuckooOptions simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_cuckoo_options_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_cuckoo_options_subset.cc.inc
|
||||
|
||||
/* CuckooOptions simple */
|
||||
|
||||
void rocksdb_cuckoo_options_set_hash_ratio(
|
||||
rocksdb_cuckoo_table_options_t* options, double v) {
|
||||
options->rep.hash_table_ratio = v;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'CuckooOptions simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_cuckoo_options_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_cuckoo_options_subset.cc.inc
|
||||
|
||||
/* CuckooOptions simple */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_set_hash_ratio(
|
||||
rocksdb_cuckoo_table_options_t* options, double v);
|
||||
@@ -0,0 +1,189 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'DB data operations'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_db_simple_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_db_simple_subset.cc.inc
|
||||
|
||||
/* DB data operations */
|
||||
|
||||
void rocksdb_put(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr,
|
||||
db->rep->Put(options->rep, Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_put_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* val,
|
||||
size_t vallen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Put(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, column_family->rep,
|
||||
Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_merge(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* val,
|
||||
size_t vallen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Merge(options->rep, Slice(key, keylen),
|
||||
Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_merge_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* val,
|
||||
size_t vallen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Merge(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_write(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr) {
|
||||
SaveError(errptr, db->rep->Write(options->rep, &batch->rep));
|
||||
}
|
||||
|
||||
void rocksdb_put_with_ts(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->Put(options->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_put_cf_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr,
|
||||
db->rep->Put(options->rep, column_family->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_cf_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->SingleDelete(options->rep, Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete_cf(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->SingleDelete(options->rep, column_family->rep,
|
||||
Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen,
|
||||
const char* ts, size_t tslen, char** errptr) {
|
||||
SaveError(errptr, db->rep->SingleDelete(options->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr) {
|
||||
SaveError(errptr,
|
||||
db->rep->SingleDelete(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_range_cf(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* start_key, size_t start_key_len,
|
||||
const char* end_key, size_t end_key_len,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->DeleteRange(options->rep, column_family->rep,
|
||||
Slice(start_key, start_key_len),
|
||||
Slice(end_key, end_key_len)));
|
||||
}
|
||||
|
||||
void rocksdb_flush(rocksdb_t* db, const rocksdb_flushoptions_t* options,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->Flush(options->rep));
|
||||
}
|
||||
|
||||
void rocksdb_flush_cf(rocksdb_t* db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->Flush(options->rep, column_family->rep));
|
||||
}
|
||||
|
||||
void rocksdb_flush_wal(rocksdb_t* db, unsigned char sync, char** errptr) {
|
||||
SaveError(errptr, db->rep->FlushWAL(sync));
|
||||
}
|
||||
|
||||
void rocksdb_pause_background_work(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->PauseBackgroundWork());
|
||||
}
|
||||
|
||||
void rocksdb_continue_background_work(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->ContinueBackgroundWork());
|
||||
}
|
||||
|
||||
void rocksdb_disable_file_deletions(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->DisableFileDeletions());
|
||||
}
|
||||
|
||||
void rocksdb_enable_file_deletions(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->EnableFileDeletions());
|
||||
}
|
||||
|
||||
void rocksdb_verify_checksum(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->VerifyChecksum());
|
||||
}
|
||||
|
||||
void rocksdb_verify_file_checksums(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->VerifyFileChecksums(ReadOptions()));
|
||||
}
|
||||
|
||||
void rocksdb_destroy_db(const rocksdb_options_t* options, const char* name,
|
||||
char** errptr) {
|
||||
SaveError(errptr, DestroyDB(name, options->rep));
|
||||
}
|
||||
|
||||
void rocksdb_repair_db(const rocksdb_options_t* options, const char* name,
|
||||
char** errptr) {
|
||||
SaveError(errptr, RepairDB(name, options->rep));
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'DB data operations'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_db_simple_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_db_simple_subset.cc.inc
|
||||
|
||||
/* DB data operations */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_merge(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_merge_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_write(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_range_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* start_key,
|
||||
size_t start_key_len, const char* end_key, size_t end_key_len,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_flush(
|
||||
rocksdb_t* db, const rocksdb_flushoptions_t* options, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_flush_cf(
|
||||
rocksdb_t* db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_flush_wal(rocksdb_t* db,
|
||||
unsigned char sync,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_pause_background_work(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_continue_background_work(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_enable_file_deletions(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_verify_checksum(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_verify_file_checksums(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_destroy_db(
|
||||
const rocksdb_options_t* options, const char* name, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_repair_db(
|
||||
const rocksdb_options_t* options, const char* name, char** errptr);
|
||||
@@ -0,0 +1,255 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/auto_simple_bindings.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Sources:
|
||||
// - include/rocksdb/listener.h
|
||||
// - tools/c_api_gen/auto_simple_bindings_blocklist.json
|
||||
// - include/rocksdb/c.h
|
||||
// - tools/c_api_gen/c_base.cc
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/auto_simple_bindings.py
|
||||
|
||||
// Output group: Auto-discovered JobInfo metadata simple
|
||||
|
||||
/* FlushJobInfo */
|
||||
|
||||
uint32_t rocksdb_flushjobinfo_cf_id(const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.cf_id;
|
||||
}
|
||||
|
||||
const char* rocksdb_flushjobinfo_cf_name(const rocksdb_flushjobinfo_t* info,
|
||||
size_t* size) {
|
||||
*size = info->rep.cf_name.size();
|
||||
return info->rep.cf_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_flushjobinfo_file_path(const rocksdb_flushjobinfo_t* info,
|
||||
size_t* size) {
|
||||
*size = info->rep.file_path.size();
|
||||
return info->rep.file_path.data();
|
||||
}
|
||||
|
||||
uint64_t rocksdb_flushjobinfo_file_number(const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.file_number;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_flushjobinfo_oldest_blob_file_number(
|
||||
const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.oldest_blob_file_number;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_flushjobinfo_thread_id(const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.thread_id;
|
||||
}
|
||||
|
||||
int rocksdb_flushjobinfo_job_id(const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.job_id;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_flushjobinfo_triggered_writes_slowdown(
|
||||
const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.triggered_writes_slowdown;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_flushjobinfo_triggered_writes_stop(
|
||||
const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.triggered_writes_stop;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_flushjobinfo_smallest_seqno(
|
||||
const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.smallest_seqno;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_flushjobinfo_largest_seqno(
|
||||
const rocksdb_flushjobinfo_t* info) {
|
||||
return info->rep.largest_seqno;
|
||||
}
|
||||
|
||||
uint32_t rocksdb_flushjobinfo_flush_reason(const rocksdb_flushjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.flush_reason);
|
||||
}
|
||||
|
||||
uint32_t rocksdb_flushjobinfo_blob_compression_type(
|
||||
const rocksdb_flushjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.blob_compression_type);
|
||||
}
|
||||
|
||||
/* CompactionJobInfo */
|
||||
|
||||
uint32_t rocksdb_compactionjobinfo_cf_id(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.cf_id;
|
||||
}
|
||||
|
||||
const char* rocksdb_compactionjobinfo_cf_name(
|
||||
const rocksdb_compactionjobinfo_t* info, size_t* size) {
|
||||
*size = info->rep.cf_name.size();
|
||||
return info->rep.cf_name.data();
|
||||
}
|
||||
|
||||
void rocksdb_compactionjobinfo_status(const rocksdb_compactionjobinfo_t* info,
|
||||
char** errptr) {
|
||||
SaveError(errptr, info->rep.status);
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_thread_id(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.thread_id;
|
||||
}
|
||||
|
||||
int rocksdb_compactionjobinfo_job_id(const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.job_id;
|
||||
}
|
||||
|
||||
int rocksdb_compactionjobinfo_num_l0_files(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.num_l0_files;
|
||||
}
|
||||
|
||||
int rocksdb_compactionjobinfo_base_input_level(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.base_input_level;
|
||||
}
|
||||
|
||||
int rocksdb_compactionjobinfo_output_level(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.output_level;
|
||||
}
|
||||
|
||||
uint32_t rocksdb_compactionjobinfo_compaction_reason(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.compaction_reason);
|
||||
}
|
||||
|
||||
uint32_t rocksdb_compactionjobinfo_compression(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.compression);
|
||||
}
|
||||
|
||||
uint32_t rocksdb_compactionjobinfo_blob_compression_type(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.blob_compression_type);
|
||||
}
|
||||
|
||||
unsigned char rocksdb_compactionjobinfo_aborted(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.aborted;
|
||||
}
|
||||
|
||||
/* SubcompactionJobInfo */
|
||||
|
||||
uint32_t rocksdb_subcompactionjobinfo_cf_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return info->rep.cf_id;
|
||||
}
|
||||
|
||||
const char* rocksdb_subcompactionjobinfo_cf_name(
|
||||
const rocksdb_subcompactionjobinfo_t* info, size_t* size) {
|
||||
*size = info->rep.cf_name.size();
|
||||
return info->rep.cf_name.data();
|
||||
}
|
||||
|
||||
void rocksdb_subcompactionjobinfo_status(
|
||||
const rocksdb_subcompactionjobinfo_t* info, char** errptr) {
|
||||
SaveError(errptr, info->rep.status);
|
||||
}
|
||||
|
||||
uint64_t rocksdb_subcompactionjobinfo_thread_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return info->rep.thread_id;
|
||||
}
|
||||
|
||||
int rocksdb_subcompactionjobinfo_job_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return info->rep.job_id;
|
||||
}
|
||||
|
||||
int rocksdb_subcompactionjobinfo_subcompaction_job_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return info->rep.subcompaction_job_id;
|
||||
}
|
||||
|
||||
int rocksdb_subcompactionjobinfo_base_input_level(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return info->rep.base_input_level;
|
||||
}
|
||||
|
||||
int rocksdb_subcompactionjobinfo_output_level(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return info->rep.output_level;
|
||||
}
|
||||
|
||||
uint32_t rocksdb_subcompactionjobinfo_compaction_reason(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.compaction_reason);
|
||||
}
|
||||
|
||||
uint32_t rocksdb_subcompactionjobinfo_compression(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.compression);
|
||||
}
|
||||
|
||||
uint32_t rocksdb_subcompactionjobinfo_blob_compression_type(
|
||||
const rocksdb_subcompactionjobinfo_t* info) {
|
||||
return static_cast<uint32_t>(info->rep.blob_compression_type);
|
||||
}
|
||||
|
||||
/* ExternalFileIngestionInfo */
|
||||
|
||||
const char* rocksdb_externalfileingestioninfo_cf_name(
|
||||
const rocksdb_externalfileingestioninfo_t* info, size_t* size) {
|
||||
*size = info->rep.cf_name.size();
|
||||
return info->rep.cf_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_externalfileingestioninfo_external_file_path(
|
||||
const rocksdb_externalfileingestioninfo_t* info, size_t* size) {
|
||||
*size = info->rep.external_file_path.size();
|
||||
return info->rep.external_file_path.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_externalfileingestioninfo_internal_file_path(
|
||||
const rocksdb_externalfileingestioninfo_t* info, size_t* size) {
|
||||
*size = info->rep.internal_file_path.size();
|
||||
return info->rep.internal_file_path.data();
|
||||
}
|
||||
|
||||
uint64_t rocksdb_externalfileingestioninfo_global_seqno(
|
||||
const rocksdb_externalfileingestioninfo_t* info) {
|
||||
return info->rep.global_seqno;
|
||||
}
|
||||
|
||||
/* MemTableInfo */
|
||||
|
||||
const char* rocksdb_memtableinfo_cf_name(const rocksdb_memtableinfo_t* info,
|
||||
size_t* size) {
|
||||
*size = info->rep.cf_name.size();
|
||||
return info->rep.cf_name.data();
|
||||
}
|
||||
|
||||
uint64_t rocksdb_memtableinfo_first_seqno(const rocksdb_memtableinfo_t* info) {
|
||||
return info->rep.first_seqno;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_memtableinfo_earliest_seqno(
|
||||
const rocksdb_memtableinfo_t* info) {
|
||||
return info->rep.earliest_seqno;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_memtableinfo_num_entries(const rocksdb_memtableinfo_t* info) {
|
||||
return info->rep.num_entries;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_memtableinfo_num_deletes(const rocksdb_memtableinfo_t* info) {
|
||||
return info->rep.num_deletes;
|
||||
}
|
||||
|
||||
const char* rocksdb_memtableinfo_newest_udt(const rocksdb_memtableinfo_t* info,
|
||||
size_t* size) {
|
||||
*size = info->rep.newest_udt.size();
|
||||
return info->rep.newest_udt.data();
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/auto_simple_bindings.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Sources:
|
||||
// - include/rocksdb/listener.h
|
||||
// - tools/c_api_gen/auto_simple_bindings_blocklist.json
|
||||
// - include/rocksdb/c.h
|
||||
// - tools/c_api_gen/c_base.cc
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/auto_simple_bindings.py
|
||||
|
||||
// Output group: Auto-discovered JobInfo metadata simple
|
||||
|
||||
/* FlushJobInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_flushjobinfo_cf_id(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_flushjobinfo_cf_name(
|
||||
const rocksdb_flushjobinfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_flushjobinfo_file_path(
|
||||
const rocksdb_flushjobinfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_flushjobinfo_file_number(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_flushjobinfo_oldest_blob_file_number(
|
||||
const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_flushjobinfo_thread_id(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_flushjobinfo_job_id(
|
||||
const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_flushjobinfo_triggered_writes_slowdown(
|
||||
const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_flushjobinfo_triggered_writes_stop(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_flushjobinfo_smallest_seqno(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_flushjobinfo_largest_seqno(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_flushjobinfo_flush_reason(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_flushjobinfo_blob_compression_type(const rocksdb_flushjobinfo_t* info);
|
||||
|
||||
/* CompactionJobInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_compactionjobinfo_cf_id(const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_compactionjobinfo_cf_name(
|
||||
const rocksdb_compactionjobinfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_compactionjobinfo_status(
|
||||
const rocksdb_compactionjobinfo_t* info, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compactionjobinfo_thread_id(const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_compactionjobinfo_job_id(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_compactionjobinfo_num_l0_files(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_compactionjobinfo_base_input_level(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_compactionjobinfo_output_level(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t rocksdb_compactionjobinfo_compaction_reason(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_compactionjobinfo_compression(const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_compactionjobinfo_blob_compression_type(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_compactionjobinfo_aborted(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
/* SubcompactionJobInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_subcompactionjobinfo_cf_id(const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_subcompactionjobinfo_cf_name(
|
||||
const rocksdb_subcompactionjobinfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_subcompactionjobinfo_status(
|
||||
const rocksdb_subcompactionjobinfo_t* info, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_subcompactionjobinfo_thread_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_subcompactionjobinfo_job_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int
|
||||
rocksdb_subcompactionjobinfo_subcompaction_job_id(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_subcompactionjobinfo_base_input_level(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_subcompactionjobinfo_output_level(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_subcompactionjobinfo_compaction_reason(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t rocksdb_subcompactionjobinfo_compression(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint32_t
|
||||
rocksdb_subcompactionjobinfo_blob_compression_type(
|
||||
const rocksdb_subcompactionjobinfo_t* info);
|
||||
|
||||
/* ExternalFileIngestionInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_externalfileingestioninfo_cf_name(
|
||||
const rocksdb_externalfileingestioninfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_externalfileingestioninfo_external_file_path(
|
||||
const rocksdb_externalfileingestioninfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_externalfileingestioninfo_internal_file_path(
|
||||
const rocksdb_externalfileingestioninfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_externalfileingestioninfo_global_seqno(
|
||||
const rocksdb_externalfileingestioninfo_t* info);
|
||||
|
||||
/* MemTableInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_memtableinfo_cf_name(
|
||||
const rocksdb_memtableinfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_memtableinfo_first_seqno(const rocksdb_memtableinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_memtableinfo_earliest_seqno(const rocksdb_memtableinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_memtableinfo_num_entries(const rocksdb_memtableinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_memtableinfo_num_deletes(const rocksdb_memtableinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_memtableinfo_newest_udt(
|
||||
const rocksdb_memtableinfo_t* info, size_t* size);
|
||||
@@ -0,0 +1,84 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'JobInfo metadata simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_jobinfo_metadata_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_jobinfo_metadata_subset.cc.inc
|
||||
|
||||
/* JobInfo metadata simple */
|
||||
|
||||
size_t rocksdb_compactionjobinfo_input_files_count(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.input_files.size();
|
||||
}
|
||||
|
||||
size_t rocksdb_compactionjobinfo_output_files_count(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.output_files.size();
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_elapsed_micros(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.elapsed_micros;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_num_corrupt_keys(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.num_corrupt_keys;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_input_records(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.num_input_records;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_output_records(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.num_output_records;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_total_input_bytes(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.total_input_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compactionjobinfo_total_output_bytes(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.total_output_bytes;
|
||||
}
|
||||
|
||||
size_t rocksdb_compactionjobinfo_num_input_files(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.num_input_files;
|
||||
}
|
||||
|
||||
size_t rocksdb_compactionjobinfo_num_input_files_at_output_level(
|
||||
const rocksdb_compactionjobinfo_t* info) {
|
||||
return info->rep.stats.num_input_files_at_output_level;
|
||||
}
|
||||
|
||||
const char* rocksdb_writestallinfo_cf_name(const rocksdb_writestallinfo_t* info,
|
||||
size_t* size) {
|
||||
*size = info->rep.cf_name.size();
|
||||
return info->rep.cf_name.data();
|
||||
}
|
||||
|
||||
const rocksdb_writestallcondition_t* rocksdb_writestallinfo_cur(
|
||||
const rocksdb_writestallinfo_t* info) {
|
||||
return reinterpret_cast<const rocksdb_writestallcondition_t*>(
|
||||
&info->rep.condition.cur);
|
||||
}
|
||||
|
||||
const rocksdb_writestallcondition_t* rocksdb_writestallinfo_prev(
|
||||
const rocksdb_writestallinfo_t* info) {
|
||||
return reinterpret_cast<const rocksdb_writestallcondition_t*>(
|
||||
&info->rep.condition.prev);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'JobInfo metadata simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_jobinfo_metadata_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_jobinfo_metadata_subset.cc.inc
|
||||
|
||||
/* JobInfo metadata simple */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t rocksdb_compactionjobinfo_input_files_count(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t rocksdb_compactionjobinfo_output_files_count(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compactionjobinfo_elapsed_micros(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compactionjobinfo_num_corrupt_keys(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compactionjobinfo_input_records(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compactionjobinfo_output_records(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compactionjobinfo_total_input_bytes(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compactionjobinfo_total_output_bytes(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t rocksdb_compactionjobinfo_num_input_files(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_compactionjobinfo_num_input_files_at_output_level(
|
||||
const rocksdb_compactionjobinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_writestallinfo_cf_name(
|
||||
const rocksdb_writestallinfo_t* info, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const rocksdb_writestallcondition_t*
|
||||
rocksdb_writestallinfo_cur(const rocksdb_writestallinfo_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const rocksdb_writestallcondition_t*
|
||||
rocksdb_writestallinfo_prev(const rocksdb_writestallinfo_t* info);
|
||||
@@ -0,0 +1,501 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/auto_simple_bindings.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Sources:
|
||||
// - include/rocksdb/compaction_job_stats.h
|
||||
// - include/rocksdb/listener.h
|
||||
// - include/rocksdb/table_properties.h
|
||||
// - tools/c_api_gen/auto_simple_bindings_blocklist.json
|
||||
// - include/rocksdb/c.h
|
||||
// - tools/c_api_gen/c_base.cc
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/auto_simple_bindings.py
|
||||
|
||||
// Output group: Auto-discovered metadata view structs simple
|
||||
|
||||
/* TableProperties */
|
||||
|
||||
uint64_t rocksdb_table_properties_orig_file_number(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.orig_file_number;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_data_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.data_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_uncompressed_data_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.uncompressed_data_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_index_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.index_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_index_partitions(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.index_partitions;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_top_level_index_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.top_level_index_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_index_key_is_user_key(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.index_key_is_user_key;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_index_value_is_delta_encoded(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.index_value_is_delta_encoded;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_udi_is_primary_index(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.udi_is_primary_index;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_filter_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.filter_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_raw_key_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.raw_key_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_raw_value_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.raw_value_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_data_blocks(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_data_blocks;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_data_blocks_compression_rejected(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_data_blocks_compression_rejected;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_data_blocks_compression_bypassed(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_data_blocks_compression_bypassed;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_uniform_blocks(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_uniform_blocks;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_entries(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_entries;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_filter_entries(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_filter_entries;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_deletions(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_deletions;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_merge_operands(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_merge_operands;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_num_range_deletions(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.num_range_deletions;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_format_version(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.format_version;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_fixed_key_len(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.fixed_key_len;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_column_family_id(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.column_family_id;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_creation_time(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.creation_time;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_oldest_key_time(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.oldest_key_time;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_newest_key_time(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.newest_key_time;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_file_creation_time(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.file_creation_time;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_slow_compression_estimated_data_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.slow_compression_estimated_data_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_fast_compression_estimated_data_size(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.fast_compression_estimated_data_size;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_external_sst_file_global_seqno_offset(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.external_sst_file_global_seqno_offset;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_tail_start_offset(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.tail_start_offset;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_user_defined_timestamps_persisted(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.user_defined_timestamps_persisted;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_key_largest_seqno(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.key_largest_seqno;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_key_smallest_seqno(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.key_smallest_seqno;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_data_block_restart_interval(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.data_block_restart_interval;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_index_block_restart_interval(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.index_block_restart_interval;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_table_properties_separate_key_value_in_data_block(
|
||||
const rocksdb_table_properties_t* props) {
|
||||
return props->rep.separate_key_value_in_data_block;
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_db_id(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.db_id.size();
|
||||
return props->rep.db_id.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_db_session_id(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.db_session_id.size();
|
||||
return props->rep.db_session_id.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_db_host_id(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.db_host_id.size();
|
||||
return props->rep.db_host_id.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_column_family_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.column_family_name.size();
|
||||
return props->rep.column_family_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_filter_policy_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.filter_policy_name.size();
|
||||
return props->rep.filter_policy_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_comparator_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.comparator_name.size();
|
||||
return props->rep.comparator_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_merge_operator_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.merge_operator_name.size();
|
||||
return props->rep.merge_operator_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_prefix_extractor_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.prefix_extractor_name.size();
|
||||
return props->rep.prefix_extractor_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_property_collectors_names(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.property_collectors_names.size();
|
||||
return props->rep.property_collectors_names.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_compression_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.compression_name.size();
|
||||
return props->rep.compression_name.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_compression_options(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.compression_options.size();
|
||||
return props->rep.compression_options.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_table_properties_seqno_to_time_mapping(
|
||||
const rocksdb_table_properties_t* props, size_t* size) {
|
||||
*size = props->rep.seqno_to_time_mapping.size();
|
||||
return props->rep.seqno_to_time_mapping.data();
|
||||
}
|
||||
|
||||
/* CompactionJobStats */
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_elapsed_micros(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.elapsed_micros;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_cpu_micros(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.cpu_micros;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_compaction_job_stats_has_accurate_num_input_records(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.has_accurate_num_input_records;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_input_records(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_input_records;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_blobs_read(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_blobs_read;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_input_files(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_input_files;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_input_files_trivially_moved(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_input_files_trivially_moved;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_input_files_at_output_level(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_input_files_at_output_level;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_filtered_input_files(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_filtered_input_files;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_filtered_input_files_at_output_level(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_filtered_input_files_at_output_level;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_output_records(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_output_records;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_output_files(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_output_files;
|
||||
}
|
||||
|
||||
size_t rocksdb_compaction_job_stats_num_output_files_blob(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_output_files_blob;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_compaction_job_stats_is_full_compaction(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.is_full_compaction;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_compaction_job_stats_is_manual_compaction(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.is_manual_compaction;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_compaction_job_stats_is_remote_compaction(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.is_remote_compaction;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_input_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_input_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_blob_bytes_read(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_blob_bytes_read;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_output_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_output_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_output_bytes_blob(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_output_bytes_blob;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_skipped_input_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_skipped_input_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_records_replaced(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_records_replaced;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_input_raw_key_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_input_raw_key_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_total_input_raw_value_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.total_input_raw_value_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_input_deletion_records(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_input_deletion_records;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_expired_deletion_records(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_expired_deletion_records;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_corrupt_keys(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_corrupt_keys;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_file_write_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.file_write_nanos;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_file_range_sync_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.file_range_sync_nanos;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_file_fsync_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.file_fsync_nanos;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_file_prepare_write_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.file_prepare_write_nanos;
|
||||
}
|
||||
|
||||
const char* rocksdb_compaction_job_stats_smallest_output_key_prefix(
|
||||
const rocksdb_compaction_job_stats_t* stats, size_t* size) {
|
||||
*size = stats->rep.smallest_output_key_prefix.size();
|
||||
return stats->rep.smallest_output_key_prefix.data();
|
||||
}
|
||||
|
||||
const char* rocksdb_compaction_job_stats_largest_output_key_prefix(
|
||||
const rocksdb_compaction_job_stats_t* stats, size_t* size) {
|
||||
*size = stats->rep.largest_output_key_prefix.size();
|
||||
return stats->rep.largest_output_key_prefix.data();
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_single_del_fallthru(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_single_del_fallthru;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_job_stats_num_single_del_mismatch(
|
||||
const rocksdb_compaction_job_stats_t* stats) {
|
||||
return stats->rep.num_single_del_mismatch;
|
||||
}
|
||||
|
||||
/* CompactionFileInfo */
|
||||
|
||||
int rocksdb_compaction_file_info_level(
|
||||
const rocksdb_compaction_file_info_t* info) {
|
||||
return info->rep.level;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_file_info_file_number(
|
||||
const rocksdb_compaction_file_info_t* info) {
|
||||
return info->rep.file_number;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_compaction_file_info_oldest_blob_file_number(
|
||||
const rocksdb_compaction_file_info_t* info) {
|
||||
return info->rep.oldest_blob_file_number;
|
||||
}
|
||||
|
||||
/* BlobFileAdditionInfo */
|
||||
|
||||
uint64_t rocksdb_blob_file_addition_info_total_blob_count(
|
||||
const rocksdb_blob_file_addition_info_t* info) {
|
||||
return info->rep.total_blob_count;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_blob_file_addition_info_total_blob_bytes(
|
||||
const rocksdb_blob_file_addition_info_t* info) {
|
||||
return info->rep.total_blob_bytes;
|
||||
}
|
||||
|
||||
/* BlobFileGarbageInfo */
|
||||
|
||||
uint64_t rocksdb_blob_file_garbage_info_garbage_blob_count(
|
||||
const rocksdb_blob_file_garbage_info_t* info) {
|
||||
return info->rep.garbage_blob_count;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_blob_file_garbage_info_garbage_blob_bytes(
|
||||
const rocksdb_blob_file_garbage_info_t* info) {
|
||||
return info->rep.garbage_blob_bytes;
|
||||
}
|
||||
@@ -0,0 +1,361 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/auto_simple_bindings.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Sources:
|
||||
// - include/rocksdb/compaction_job_stats.h
|
||||
// - include/rocksdb/listener.h
|
||||
// - include/rocksdb/table_properties.h
|
||||
// - tools/c_api_gen/auto_simple_bindings_blocklist.json
|
||||
// - include/rocksdb/c.h
|
||||
// - tools/c_api_gen/c_base.cc
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/auto_simple_bindings.py
|
||||
|
||||
// Output group: Auto-discovered metadata view structs simple
|
||||
|
||||
/* TableProperties */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_orig_file_number(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_data_size(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_uncompressed_data_size(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_index_size(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_index_partitions(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_top_level_index_size(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_index_key_is_user_key(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_index_value_is_delta_encoded(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_udi_is_primary_index(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_filter_size(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_raw_key_size(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_raw_value_size(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_num_data_blocks(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_num_data_blocks_compression_rejected(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_num_data_blocks_compression_bypassed(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_num_uniform_blocks(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_num_entries(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_num_filter_entries(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_num_deletions(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_num_merge_operands(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_num_range_deletions(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_format_version(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_fixed_key_len(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_column_family_id(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_creation_time(const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_oldest_key_time(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_newest_key_time(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_file_creation_time(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_slow_compression_estimated_data_size(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_fast_compression_estimated_data_size(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_external_sst_file_global_seqno_offset(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_tail_start_offset(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_user_defined_timestamps_persisted(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_key_largest_seqno(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_table_properties_key_smallest_seqno(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_data_block_restart_interval(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_index_block_restart_interval(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_table_properties_separate_key_value_in_data_block(
|
||||
const rocksdb_table_properties_t* props);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_table_properties_db_id(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_table_properties_db_session_id(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_table_properties_db_host_id(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_column_family_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_filter_policy_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char* rocksdb_table_properties_comparator_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_merge_operator_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_prefix_extractor_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_property_collectors_names(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_compression_name(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_compression_options(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_table_properties_seqno_to_time_mapping(
|
||||
const rocksdb_table_properties_t* props, size_t* size);
|
||||
|
||||
/* CompactionJobStats */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compaction_job_stats_elapsed_micros(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compaction_job_stats_cpu_micros(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_compaction_job_stats_has_accurate_num_input_records(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_input_records(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compaction_job_stats_num_blobs_read(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t rocksdb_compaction_job_stats_num_input_files(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_compaction_job_stats_num_input_files_trivially_moved(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_compaction_job_stats_num_input_files_at_output_level(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_compaction_job_stats_num_filtered_input_files(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_compaction_job_stats_num_filtered_input_files_at_output_level(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_output_records(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t rocksdb_compaction_job_stats_num_output_files(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_compaction_job_stats_num_output_files_blob(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_compaction_job_stats_is_full_compaction(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_compaction_job_stats_is_manual_compaction(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_compaction_job_stats_is_remote_compaction(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_input_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_blob_bytes_read(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_output_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_output_bytes_blob(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_skipped_input_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_records_replaced(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_input_raw_key_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_total_input_raw_value_bytes(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_input_deletion_records(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_expired_deletion_records(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_corrupt_keys(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_file_write_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_file_range_sync_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_file_fsync_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_file_prepare_write_nanos(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_compaction_job_stats_smallest_output_key_prefix(
|
||||
const rocksdb_compaction_job_stats_t* stats, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API const char*
|
||||
rocksdb_compaction_job_stats_largest_output_key_prefix(
|
||||
const rocksdb_compaction_job_stats_t* stats, size_t* size);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_single_del_fallthru(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_job_stats_num_single_del_mismatch(
|
||||
const rocksdb_compaction_job_stats_t* stats);
|
||||
|
||||
/* CompactionFileInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_compaction_file_info_level(
|
||||
const rocksdb_compaction_file_info_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_compaction_file_info_file_number(
|
||||
const rocksdb_compaction_file_info_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_compaction_file_info_oldest_blob_file_number(
|
||||
const rocksdb_compaction_file_info_t* info);
|
||||
|
||||
/* BlobFileAdditionInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_blob_file_addition_info_total_blob_count(
|
||||
const rocksdb_blob_file_addition_info_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_blob_file_addition_info_total_blob_bytes(
|
||||
const rocksdb_blob_file_addition_info_t* info);
|
||||
|
||||
/* BlobFileGarbageInfo */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_blob_file_garbage_info_garbage_blob_count(
|
||||
const rocksdb_blob_file_garbage_info_t* info);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_blob_file_garbage_info_garbage_blob_bytes(
|
||||
const rocksdb_blob_file_garbage_info_t* info);
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,84 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'Options simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_options_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_options_subset.cc.inc
|
||||
|
||||
/* Options simple */
|
||||
|
||||
void rocksdb_options_set_compression_options_zstd_max_train_bytes(
|
||||
rocksdb_options_t* opt, int zstd_max_train_bytes) {
|
||||
opt->rep.compression_opts.zstd_max_train_bytes = zstd_max_train_bytes;
|
||||
}
|
||||
|
||||
int rocksdb_options_get_compression_options_zstd_max_train_bytes(
|
||||
rocksdb_options_t* opt) {
|
||||
return opt->rep.compression_opts.zstd_max_train_bytes;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_compression_options_use_zstd_dict_trainer(
|
||||
rocksdb_options_t* opt, unsigned char use_zstd_dict_trainer) {
|
||||
opt->rep.compression_opts.use_zstd_dict_trainer = use_zstd_dict_trainer;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_options_get_compression_options_use_zstd_dict_trainer(
|
||||
rocksdb_options_t* opt) {
|
||||
return opt->rep.compression_opts.use_zstd_dict_trainer;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_compression_options_parallel_threads(
|
||||
rocksdb_options_t* opt, int value) {
|
||||
opt->rep.compression_opts.parallel_threads = value;
|
||||
}
|
||||
|
||||
int rocksdb_options_get_compression_options_parallel_threads(
|
||||
rocksdb_options_t* opt) {
|
||||
return opt->rep.compression_opts.parallel_threads;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_compression_options_max_dict_buffer_bytes(
|
||||
rocksdb_options_t* opt, uint64_t max_dict_buffer_bytes) {
|
||||
opt->rep.compression_opts.max_dict_buffer_bytes = max_dict_buffer_bytes;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_options_get_compression_options_max_dict_buffer_bytes(
|
||||
rocksdb_options_t* opt) {
|
||||
return opt->rep.compression_opts.max_dict_buffer_bytes;
|
||||
}
|
||||
|
||||
unsigned char
|
||||
rocksdb_options_get_bottommost_compression_options_use_zstd_dict_trainer(
|
||||
rocksdb_options_t* opt) {
|
||||
return opt->rep.bottommost_compression_opts.use_zstd_dict_trainer;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_use_fsync(rocksdb_options_t* opt, int use_fsync) {
|
||||
opt->rep.use_fsync = use_fsync;
|
||||
}
|
||||
|
||||
int rocksdb_options_get_use_fsync(rocksdb_options_t* opt) {
|
||||
return opt->rep.use_fsync;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_disable_auto_compactions(rocksdb_options_t* opt,
|
||||
int disable) {
|
||||
opt->rep.disable_auto_compactions = disable;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_optimize_filters_for_hits(rocksdb_options_t* opt,
|
||||
int v) {
|
||||
opt->rep.optimize_filters_for_hits = v;
|
||||
}
|
||||
|
||||
void rocksdb_options_set_report_bg_io_stats(rocksdb_options_t* opt, int v) {
|
||||
opt->rep.report_bg_io_stats = v;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'Options simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_options_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_options_subset.cc.inc
|
||||
|
||||
/* Options simple */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_options_set_compression_options_zstd_max_train_bytes(
|
||||
rocksdb_options_t* opt, int zstd_max_train_bytes);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int
|
||||
rocksdb_options_get_compression_options_zstd_max_train_bytes(
|
||||
rocksdb_options_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_options_set_compression_options_use_zstd_dict_trainer(
|
||||
rocksdb_options_t* opt, unsigned char use_zstd_dict_trainer);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_options_get_compression_options_use_zstd_dict_trainer(
|
||||
rocksdb_options_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_options_set_compression_options_parallel_threads(rocksdb_options_t* opt,
|
||||
int value);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int
|
||||
rocksdb_options_get_compression_options_parallel_threads(
|
||||
rocksdb_options_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_options_set_compression_options_max_dict_buffer_bytes(
|
||||
rocksdb_options_t* opt, uint64_t max_dict_buffer_bytes);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_options_get_compression_options_max_dict_buffer_bytes(
|
||||
rocksdb_options_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_options_get_bottommost_compression_options_use_zstd_dict_trainer(
|
||||
rocksdb_options_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_use_fsync(
|
||||
rocksdb_options_t* opt, int use_fsync);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_options_get_use_fsync(
|
||||
rocksdb_options_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_disable_auto_compactions(
|
||||
rocksdb_options_t* opt, int disable);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_optimize_filters_for_hits(
|
||||
rocksdb_options_t* opt, int v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_report_bg_io_stats(
|
||||
rocksdb_options_t* opt, int v);
|
||||
@@ -0,0 +1,236 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/auto_simple_bindings.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Sources:
|
||||
// - include/rocksdb/options.h
|
||||
// - tools/c_api_gen/auto_simple_bindings_blocklist.json
|
||||
// - include/rocksdb/c.h
|
||||
// - tools/c_api_gen/c_base.cc
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/auto_simple_bindings.py
|
||||
|
||||
// Output group: Auto-discovered ReadOptions simple
|
||||
|
||||
/* ReadOptions */
|
||||
|
||||
void rocksdb_readoptions_set_deadline(rocksdb_readoptions_t* opt,
|
||||
uint64_t microseconds) {
|
||||
opt->rep.deadline = std::chrono::microseconds(microseconds);
|
||||
}
|
||||
|
||||
uint64_t rocksdb_readoptions_get_deadline(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.deadline.count();
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_io_timeout(rocksdb_readoptions_t* opt,
|
||||
uint64_t microseconds) {
|
||||
opt->rep.io_timeout = std::chrono::microseconds(microseconds);
|
||||
}
|
||||
|
||||
uint64_t rocksdb_readoptions_get_io_timeout(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.io_timeout.count();
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_read_tier(rocksdb_readoptions_t* opt, int v) {
|
||||
opt->rep.read_tier = static_cast<decltype(opt->rep.read_tier)>(v);
|
||||
}
|
||||
|
||||
int rocksdb_readoptions_get_read_tier(rocksdb_readoptions_t* opt) {
|
||||
return static_cast<int>(opt->rep.read_tier);
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_rate_limiter_priority(rocksdb_readoptions_t* opt,
|
||||
int v) {
|
||||
opt->rep.rate_limiter_priority =
|
||||
static_cast<decltype(opt->rep.rate_limiter_priority)>(v);
|
||||
}
|
||||
|
||||
int rocksdb_readoptions_get_rate_limiter_priority(rocksdb_readoptions_t* opt) {
|
||||
return static_cast<int>(opt->rep.rate_limiter_priority);
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_value_size_soft_limit(rocksdb_readoptions_t* opt,
|
||||
uint64_t v) {
|
||||
opt->rep.value_size_soft_limit = v;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_readoptions_get_value_size_soft_limit(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.value_size_soft_limit;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_verify_checksums(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.verify_checksums = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_verify_checksums(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.verify_checksums;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_fill_cache(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.fill_cache = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_fill_cache(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.fill_cache;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_ignore_range_deletions(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.ignore_range_deletions = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_ignore_range_deletions(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.ignore_range_deletions;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_async_io(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.async_io = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_async_io(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.async_io;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_optimize_multiget_for_io(
|
||||
rocksdb_readoptions_t* opt, unsigned char v) {
|
||||
opt->rep.optimize_multiget_for_io = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_optimize_multiget_for_io(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.optimize_multiget_for_io;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_readahead_size(rocksdb_readoptions_t* opt,
|
||||
size_t v) {
|
||||
opt->rep.readahead_size = v;
|
||||
}
|
||||
|
||||
size_t rocksdb_readoptions_get_readahead_size(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.readahead_size;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_max_skippable_internal_keys(
|
||||
rocksdb_readoptions_t* opt, uint64_t v) {
|
||||
opt->rep.max_skippable_internal_keys = v;
|
||||
}
|
||||
|
||||
uint64_t rocksdb_readoptions_get_max_skippable_internal_keys(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.max_skippable_internal_keys;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_tailing(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.tailing = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_tailing(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.tailing;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_total_order_seek(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.total_order_seek = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_total_order_seek(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.total_order_seek;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_auto_prefix_mode(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.auto_prefix_mode = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_auto_prefix_mode(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.auto_prefix_mode;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_prefix_same_as_start(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.prefix_same_as_start = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_prefix_same_as_start(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.prefix_same_as_start;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_pin_data(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.pin_data = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_pin_data(rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.pin_data;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_adaptive_readahead(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.adaptive_readahead = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_adaptive_readahead(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.adaptive_readahead;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_background_purge_on_iterator_cleanup(
|
||||
rocksdb_readoptions_t* opt, unsigned char v) {
|
||||
opt->rep.background_purge_on_iterator_cleanup = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_background_purge_on_iterator_cleanup(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.background_purge_on_iterator_cleanup;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_auto_readahead_size(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.auto_readahead_size = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_auto_readahead_size(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.auto_readahead_size;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_allow_unprepared_value(rocksdb_readoptions_t* opt,
|
||||
unsigned char v) {
|
||||
opt->rep.allow_unprepared_value = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_allow_unprepared_value(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.allow_unprepared_value;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_auto_refresh_iterator_with_snapshot(
|
||||
rocksdb_readoptions_t* opt, unsigned char v) {
|
||||
opt->rep.auto_refresh_iterator_with_snapshot = v;
|
||||
}
|
||||
|
||||
unsigned char rocksdb_readoptions_get_auto_refresh_iterator_with_snapshot(
|
||||
rocksdb_readoptions_t* opt) {
|
||||
return opt->rep.auto_refresh_iterator_with_snapshot;
|
||||
}
|
||||
|
||||
void rocksdb_readoptions_set_io_activity(rocksdb_readoptions_t* opt, int v) {
|
||||
opt->rep.io_activity = static_cast<decltype(opt->rep.io_activity)>(v);
|
||||
}
|
||||
|
||||
int rocksdb_readoptions_get_io_activity(rocksdb_readoptions_t* opt) {
|
||||
return static_cast<int>(opt->rep.io_activity);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/auto_simple_bindings.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Sources:
|
||||
// - include/rocksdb/options.h
|
||||
// - tools/c_api_gen/auto_simple_bindings_blocklist.json
|
||||
// - include/rocksdb/c.h
|
||||
// - tools/c_api_gen/c_base.cc
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/auto_simple_bindings.py
|
||||
|
||||
// Output group: Auto-discovered ReadOptions simple
|
||||
|
||||
/* ReadOptions */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_deadline(
|
||||
rocksdb_readoptions_t* opt, uint64_t microseconds);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_readoptions_get_deadline(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_io_timeout(
|
||||
rocksdb_readoptions_t* opt, uint64_t microseconds);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_readoptions_get_io_timeout(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_read_tier(
|
||||
rocksdb_readoptions_t* opt, int v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_readoptions_get_read_tier(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_rate_limiter_priority(
|
||||
rocksdb_readoptions_t* opt, int v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_readoptions_get_rate_limiter_priority(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_value_size_soft_limit(
|
||||
rocksdb_readoptions_t* opt, uint64_t v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_readoptions_get_value_size_soft_limit(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_verify_checksums(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_verify_checksums(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_fill_cache(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_readoptions_get_fill_cache(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_ignore_range_deletions(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_ignore_range_deletions(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_async_io(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_readoptions_get_async_io(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_readoptions_set_optimize_multiget_for_io(rocksdb_readoptions_t* opt,
|
||||
unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_optimize_multiget_for_io(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_readahead_size(
|
||||
rocksdb_readoptions_t* opt, size_t v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API size_t
|
||||
rocksdb_readoptions_get_readahead_size(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_readoptions_set_max_skippable_internal_keys(rocksdb_readoptions_t* opt,
|
||||
uint64_t v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API uint64_t
|
||||
rocksdb_readoptions_get_max_skippable_internal_keys(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_tailing(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_readoptions_get_tailing(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_total_order_seek(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_total_order_seek(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_auto_prefix_mode(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_auto_prefix_mode(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_prefix_same_as_start(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_prefix_same_as_start(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_pin_data(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_readoptions_get_pin_data(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_adaptive_readahead(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_adaptive_readahead(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_readoptions_set_background_purge_on_iterator_cleanup(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_background_purge_on_iterator_cleanup(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_auto_readahead_size(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_auto_readahead_size(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_allow_unprepared_value(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_allow_unprepared_value(rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void
|
||||
rocksdb_readoptions_set_auto_refresh_iterator_with_snapshot(
|
||||
rocksdb_readoptions_t* opt, unsigned char v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API unsigned char
|
||||
rocksdb_readoptions_get_auto_refresh_iterator_with_snapshot(
|
||||
rocksdb_readoptions_t* opt);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_io_activity(
|
||||
rocksdb_readoptions_t* opt, int v);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API int rocksdb_readoptions_get_io_activity(
|
||||
rocksdb_readoptions_t* opt);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,371 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'DB data operations'
|
||||
// --section 'WriteBatch' --section 'Transaction'
|
||||
// --section 'TransactionDB simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_subset.cc.inc
|
||||
|
||||
/* DB data operations */
|
||||
|
||||
void rocksdb_put(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr,
|
||||
db->rep->Put(options->rep, Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_put_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* val,
|
||||
size_t vallen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Put(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, column_family->rep,
|
||||
Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_merge(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* val,
|
||||
size_t vallen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Merge(options->rep, Slice(key, keylen),
|
||||
Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_merge_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* val,
|
||||
size_t vallen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Merge(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_write(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr) {
|
||||
SaveError(errptr, db->rep->Write(options->rep, &batch->rep));
|
||||
}
|
||||
|
||||
void rocksdb_put_with_ts(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->Put(options->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_put_cf_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr,
|
||||
db->rep->Put(options->rep, column_family->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_cf_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, const char* ts,
|
||||
size_t tslen, char** errptr) {
|
||||
SaveError(errptr, db->rep->Delete(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete(rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->SingleDelete(options->rep, Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete_cf(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen, char** errptr) {
|
||||
SaveError(errptr, db->rep->SingleDelete(options->rep, column_family->rep,
|
||||
Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete_with_ts(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t keylen,
|
||||
const char* ts, size_t tslen, char** errptr) {
|
||||
SaveError(errptr, db->rep->SingleDelete(options->rep, Slice(key, keylen),
|
||||
Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_singledelete_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr) {
|
||||
SaveError(errptr,
|
||||
db->rep->SingleDelete(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(ts, tslen)));
|
||||
}
|
||||
|
||||
void rocksdb_delete_range_cf(rocksdb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* start_key, size_t start_key_len,
|
||||
const char* end_key, size_t end_key_len,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->DeleteRange(options->rep, column_family->rep,
|
||||
Slice(start_key, start_key_len),
|
||||
Slice(end_key, end_key_len)));
|
||||
}
|
||||
|
||||
void rocksdb_flush(rocksdb_t* db, const rocksdb_flushoptions_t* options,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->Flush(options->rep));
|
||||
}
|
||||
|
||||
void rocksdb_flush_cf(rocksdb_t* db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
char** errptr) {
|
||||
SaveError(errptr, db->rep->Flush(options->rep, column_family->rep));
|
||||
}
|
||||
|
||||
void rocksdb_flush_wal(rocksdb_t* db, unsigned char sync, char** errptr) {
|
||||
SaveError(errptr, db->rep->FlushWAL(sync));
|
||||
}
|
||||
|
||||
void rocksdb_pause_background_work(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->PauseBackgroundWork());
|
||||
}
|
||||
|
||||
void rocksdb_continue_background_work(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->ContinueBackgroundWork());
|
||||
}
|
||||
|
||||
void rocksdb_disable_file_deletions(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->DisableFileDeletions());
|
||||
}
|
||||
|
||||
void rocksdb_enable_file_deletions(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->EnableFileDeletions());
|
||||
}
|
||||
|
||||
void rocksdb_verify_checksum(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->VerifyChecksum());
|
||||
}
|
||||
|
||||
void rocksdb_verify_file_checksums(rocksdb_t* db, char** errptr) {
|
||||
SaveError(errptr, db->rep->VerifyFileChecksums(ReadOptions()));
|
||||
}
|
||||
|
||||
void rocksdb_destroy_db(const rocksdb_options_t* options, const char* name,
|
||||
char** errptr) {
|
||||
SaveError(errptr, DestroyDB(name, options->rep));
|
||||
}
|
||||
|
||||
void rocksdb_repair_db(const rocksdb_options_t* options, const char* name,
|
||||
char** errptr) {
|
||||
SaveError(errptr, RepairDB(name, options->rep));
|
||||
}
|
||||
|
||||
/* WriteBatch */
|
||||
|
||||
void rocksdb_writebatch_clear(rocksdb_writebatch_t* b) { b->rep.Clear(); }
|
||||
|
||||
void rocksdb_writebatch_put(rocksdb_writebatch_t* b, const char* key,
|
||||
size_t klen, const char* val, size_t vlen) {
|
||||
b->rep.Put(Slice(key, klen), Slice(val, vlen));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_put_cf(rocksdb_writebatch_t* b,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen) {
|
||||
b->rep.Put(column_family->rep, Slice(key, klen), Slice(val, vlen));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_delete(rocksdb_writebatch_t* b, const char* key,
|
||||
size_t klen) {
|
||||
b->rep.Delete(Slice(key, klen));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_put_log_data(rocksdb_writebatch_t* b, const char* blob,
|
||||
size_t len) {
|
||||
b->rep.PutLogData(Slice(blob, len));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_set_save_point(rocksdb_writebatch_t* b) {
|
||||
b->rep.SetSavePoint();
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_rollback_to_save_point(rocksdb_writebatch_t* b,
|
||||
char** errptr) {
|
||||
SaveError(errptr, b->rep.RollbackToSavePoint());
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_pop_save_point(rocksdb_writebatch_t* b, char** errptr) {
|
||||
SaveError(errptr, b->rep.PopSavePoint());
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_verify_checksum(rocksdb_writebatch_t* b,
|
||||
char** errptr) {
|
||||
SaveError(errptr, b->rep.VerifyChecksum());
|
||||
}
|
||||
|
||||
/* Transaction */
|
||||
|
||||
void rocksdb_transaction_put(rocksdb_transaction_t* txn, const char* key,
|
||||
size_t klen, const char* val, size_t vlen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn->rep->Put(Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_put_cf(rocksdb_transaction_t* txn,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Put(column_family->rep, Slice(key, klen),
|
||||
Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_merge(rocksdb_transaction_t* txn, const char* key,
|
||||
size_t klen, const char* val, size_t vlen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn->rep->Merge(Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_merge_cf(rocksdb_transaction_t* txn,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Merge(column_family->rep, Slice(key, klen),
|
||||
Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_delete(rocksdb_transaction_t* txn, const char* key,
|
||||
size_t klen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Delete(Slice(key, klen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_delete_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Delete(column_family->rep, Slice(key, klen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_commit(rocksdb_transaction_t* txn, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Commit());
|
||||
}
|
||||
|
||||
void rocksdb_transaction_rollback(rocksdb_transaction_t* txn, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Rollback());
|
||||
}
|
||||
|
||||
void rocksdb_transaction_put_log_data(rocksdb_transaction_t* txn,
|
||||
const char* blob, size_t len) {
|
||||
txn->rep->PutLogData(Slice(blob, len));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_set_savepoint(rocksdb_transaction_t* txn) {
|
||||
txn->rep->SetSavePoint();
|
||||
}
|
||||
|
||||
void rocksdb_transaction_rollback_to_savepoint(rocksdb_transaction_t* txn,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn->rep->RollbackToSavePoint());
|
||||
}
|
||||
|
||||
/* TransactionDB simple */
|
||||
|
||||
void rocksdb_transactiondb_put(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr,
|
||||
txn_db->rep->Put(options->rep, Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_put_cf(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen,
|
||||
const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Put(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_write(rocksdb_transactiondb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr) {
|
||||
SaveError(errptr, db->rep->Write(options->rep, &batch->rep));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_merge(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Merge(options->rep, Slice(key, klen),
|
||||
Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_merge_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key, size_t klen,
|
||||
const char* val, size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Merge(options->rep, column_family->rep,
|
||||
Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_delete(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Delete(options->rep, Slice(key, klen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_delete_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Delete(options->rep, column_family->rep,
|
||||
Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_flush_wal(rocksdb_transactiondb_t* txn_db,
|
||||
unsigned char sync, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->FlushWAL(sync));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_flush(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_flushoptions_t* options,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Flush(options->rep));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_flush_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Flush(options->rep, column_family->rep));
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'DB data operations'
|
||||
// --section 'WriteBatch' --section 'Transaction'
|
||||
// --section 'TransactionDB simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_subset.cc.inc
|
||||
|
||||
/* DB data operations */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_merge(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_merge_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_write(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_put_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, const char* val, size_t vallen,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_singledelete_cf_with_ts(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* ts, size_t tslen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_delete_range_cf(
|
||||
rocksdb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* start_key,
|
||||
size_t start_key_len, const char* end_key, size_t end_key_len,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_flush(
|
||||
rocksdb_t* db, const rocksdb_flushoptions_t* options, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_flush_cf(
|
||||
rocksdb_t* db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_flush_wal(rocksdb_t* db,
|
||||
unsigned char sync,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_pause_background_work(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_continue_background_work(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_enable_file_deletions(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_verify_checksum(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_verify_file_checksums(rocksdb_t* db,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_destroy_db(
|
||||
const rocksdb_options_t* options, const char* name, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_repair_db(
|
||||
const rocksdb_options_t* options, const char* name, char** errptr);
|
||||
|
||||
/* WriteBatch */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_clear(
|
||||
rocksdb_writebatch_t* b);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put(rocksdb_writebatch_t* b,
|
||||
const char* key,
|
||||
size_t klen,
|
||||
const char* val,
|
||||
size_t vlen);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_cf(
|
||||
rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val, size_t vlen);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_delete(
|
||||
rocksdb_writebatch_t* b, const char* key, size_t klen);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_log_data(
|
||||
rocksdb_writebatch_t* b, const char* blob, size_t len);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_set_save_point(
|
||||
rocksdb_writebatch_t* b);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_rollback_to_save_point(
|
||||
rocksdb_writebatch_t* b, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_pop_save_point(
|
||||
rocksdb_writebatch_t* b, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_verify_checksum(
|
||||
rocksdb_writebatch_t* b, char** errptr);
|
||||
|
||||
/* Transaction */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put(
|
||||
rocksdb_transaction_t* txn, const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_merge(
|
||||
rocksdb_transaction_t* txn, const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_merge_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_delete(
|
||||
rocksdb_transaction_t* txn, const char* key, size_t klen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_delete_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_commit(
|
||||
rocksdb_transaction_t* txn, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback(
|
||||
rocksdb_transaction_t* txn, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put_log_data(
|
||||
rocksdb_transaction_t* txn, const char* blob, size_t len);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_set_savepoint(
|
||||
rocksdb_transaction_t* txn);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback_to_savepoint(
|
||||
rocksdb_transaction_t* txn, char** errptr);
|
||||
|
||||
/* TransactionDB simple */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_put(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_put_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_write(
|
||||
rocksdb_transactiondb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_merge(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_merge_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key, size_t klen,
|
||||
const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_delete(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_delete_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush_wal(
|
||||
rocksdb_transactiondb_t* txn_db, unsigned char sync, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, char** errptr);
|
||||
@@ -0,0 +1,77 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'Transaction'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_transaction_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_transaction_subset.cc.inc
|
||||
|
||||
/* Transaction */
|
||||
|
||||
void rocksdb_transaction_put(rocksdb_transaction_t* txn, const char* key,
|
||||
size_t klen, const char* val, size_t vlen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn->rep->Put(Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_put_cf(rocksdb_transaction_t* txn,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Put(column_family->rep, Slice(key, klen),
|
||||
Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_merge(rocksdb_transaction_t* txn, const char* key,
|
||||
size_t klen, const char* val, size_t vlen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn->rep->Merge(Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_merge_cf(rocksdb_transaction_t* txn,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Merge(column_family->rep, Slice(key, klen),
|
||||
Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_delete(rocksdb_transaction_t* txn, const char* key,
|
||||
size_t klen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Delete(Slice(key, klen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_delete_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Delete(column_family->rep, Slice(key, klen)));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_commit(rocksdb_transaction_t* txn, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Commit());
|
||||
}
|
||||
|
||||
void rocksdb_transaction_rollback(rocksdb_transaction_t* txn, char** errptr) {
|
||||
SaveError(errptr, txn->rep->Rollback());
|
||||
}
|
||||
|
||||
void rocksdb_transaction_put_log_data(rocksdb_transaction_t* txn,
|
||||
const char* blob, size_t len) {
|
||||
txn->rep->PutLogData(Slice(blob, len));
|
||||
}
|
||||
|
||||
void rocksdb_transaction_set_savepoint(rocksdb_transaction_t* txn) {
|
||||
txn->rep->SetSavePoint();
|
||||
}
|
||||
|
||||
void rocksdb_transaction_rollback_to_savepoint(rocksdb_transaction_t* txn,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn->rep->RollbackToSavePoint());
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'Transaction'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_transaction_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_transaction_subset.cc.inc
|
||||
|
||||
/* Transaction */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put(
|
||||
rocksdb_transaction_t* txn, const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_merge(
|
||||
rocksdb_transaction_t* txn, const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_merge_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_delete(
|
||||
rocksdb_transaction_t* txn, const char* key, size_t klen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_delete_cf(
|
||||
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_commit(
|
||||
rocksdb_transaction_t* txn, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback(
|
||||
rocksdb_transaction_t* txn, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put_log_data(
|
||||
rocksdb_transaction_t* txn, const char* blob, size_t len);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_set_savepoint(
|
||||
rocksdb_transaction_t* txn);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback_to_savepoint(
|
||||
rocksdb_transaction_t* txn, char** errptr);
|
||||
@@ -0,0 +1,87 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'TransactionDB simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_transactiondb_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_transactiondb_subset.cc.inc
|
||||
|
||||
/* TransactionDB simple */
|
||||
|
||||
void rocksdb_transactiondb_put(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr,
|
||||
txn_db->rep->Put(options->rep, Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_put_cf(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t keylen,
|
||||
const char* val, size_t vallen,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Put(options->rep, column_family->rep,
|
||||
Slice(key, keylen), Slice(val, vallen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_write(rocksdb_transactiondb_t* db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr) {
|
||||
SaveError(errptr, db->rep->Write(options->rep, &batch->rep));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_merge(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Merge(options->rep, Slice(key, klen),
|
||||
Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_merge_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key, size_t klen,
|
||||
const char* val, size_t vlen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Merge(options->rep, column_family->rep,
|
||||
Slice(key, klen), Slice(val, vlen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_delete(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Delete(options->rep, Slice(key, klen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_delete_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Delete(options->rep, column_family->rep,
|
||||
Slice(key, keylen)));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_flush_wal(rocksdb_transactiondb_t* txn_db,
|
||||
unsigned char sync, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->FlushWAL(sync));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_flush(rocksdb_transactiondb_t* txn_db,
|
||||
const rocksdb_flushoptions_t* options,
|
||||
char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Flush(options->rep));
|
||||
}
|
||||
|
||||
void rocksdb_transactiondb_flush_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, char** errptr) {
|
||||
SaveError(errptr, txn_db->rep->Flush(options->rep, column_family->rep));
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'TransactionDB simple'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_transactiondb_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_transactiondb_subset.cc.inc
|
||||
|
||||
/* TransactionDB simple */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_put(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_put_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, const char* val, size_t vallen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_write(
|
||||
rocksdb_transactiondb_t* db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_writebatch_t* batch, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_merge(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_merge_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key, size_t klen,
|
||||
const char* val, size_t vlen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_delete(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
const char* key, size_t klen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_delete_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, const char* key,
|
||||
size_t keylen, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush_wal(
|
||||
rocksdb_transactiondb_t* txn_db, unsigned char sync, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options,
|
||||
char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush_cf(
|
||||
rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options,
|
||||
rocksdb_column_family_handle_t* column_family, char** errptr);
|
||||
@@ -0,0 +1,58 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'WriteBatch'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_writebatch_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_writebatch_subset.cc.inc
|
||||
|
||||
/* WriteBatch */
|
||||
|
||||
void rocksdb_writebatch_clear(rocksdb_writebatch_t* b) { b->rep.Clear(); }
|
||||
|
||||
void rocksdb_writebatch_put(rocksdb_writebatch_t* b, const char* key,
|
||||
size_t klen, const char* val, size_t vlen) {
|
||||
b->rep.Put(Slice(key, klen), Slice(val, vlen));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_put_cf(rocksdb_writebatch_t* b,
|
||||
rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val,
|
||||
size_t vlen) {
|
||||
b->rep.Put(column_family->rep, Slice(key, klen), Slice(val, vlen));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_delete(rocksdb_writebatch_t* b, const char* key,
|
||||
size_t klen) {
|
||||
b->rep.Delete(Slice(key, klen));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_put_log_data(rocksdb_writebatch_t* b, const char* blob,
|
||||
size_t len) {
|
||||
b->rep.PutLogData(Slice(blob, len));
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_set_save_point(rocksdb_writebatch_t* b) {
|
||||
b->rep.SetSavePoint();
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_rollback_to_save_point(rocksdb_writebatch_t* b,
|
||||
char** errptr) {
|
||||
SaveError(errptr, b->rep.RollbackToSavePoint());
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_pop_save_point(rocksdb_writebatch_t* b, char** errptr) {
|
||||
SaveError(errptr, b->rep.PopSavePoint());
|
||||
}
|
||||
|
||||
void rocksdb_writebatch_verify_checksum(rocksdb_writebatch_t* b,
|
||||
char** errptr) {
|
||||
SaveError(errptr, b->rep.VerifyChecksum());
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// @generated
|
||||
// -----------------------------------------------------------------------------
|
||||
// Auto-generated by tools/c_api_gen/generate_c_api.py.
|
||||
// DO NOT EDIT THIS FILE DIRECTLY.
|
||||
// Source: tools/c_api_gen/spec.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// To regenerate this file:
|
||||
// python3 tools/c_api_gen/generate_c_api.py
|
||||
// --spec tools/c_api_gen/spec.json --section 'WriteBatch'
|
||||
// --header-out
|
||||
// c_api_gen/c_generated_writebatch_subset.h.inc
|
||||
// --source-out
|
||||
// c_api_gen/c_generated_writebatch_subset.cc.inc
|
||||
|
||||
/* WriteBatch */
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_clear(
|
||||
rocksdb_writebatch_t* b);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put(rocksdb_writebatch_t* b,
|
||||
const char* key,
|
||||
size_t klen,
|
||||
const char* val,
|
||||
size_t vlen);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_cf(
|
||||
rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family,
|
||||
const char* key, size_t klen, const char* val, size_t vlen);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_delete(
|
||||
rocksdb_writebatch_t* b, const char* key, size_t klen);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_log_data(
|
||||
rocksdb_writebatch_t* b, const char* blob, size_t len);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_set_save_point(
|
||||
rocksdb_writebatch_t* b);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_rollback_to_save_point(
|
||||
rocksdb_writebatch_t* b, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_pop_save_point(
|
||||
rocksdb_writebatch_t* b, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_verify_checksum(
|
||||
rocksdb_writebatch_t* b, char** errptr);
|
||||
Vendored
+18
@@ -127,6 +127,24 @@ class OffsetableCacheKey : private CacheKey {
|
||||
return CacheKey(file_num_etc64_, offset_etc64_ ^ offset);
|
||||
}
|
||||
|
||||
// Construct a CacheKey for a record located at byte `offset` within a file in
|
||||
// which every distinct cached region is at least 5 bytes long. The low two
|
||||
// offset bits are dropped, which is collision-free under that >= 5-byte (>= 4
|
||||
// would suffice) guarantee and lets different kinds of records in the same
|
||||
// file share a single keyspace without colliding.
|
||||
//
|
||||
// This is the canonical cache-key scheme for byte-offset records that carry
|
||||
// the block-based "min 5 byte" guarantee: block-based SST blocks (see
|
||||
// BlockBasedTable::GetCacheKey) and SimpleGen2Blob records (which always
|
||||
// include a >= 5-byte trailer; see db/blob/blob_gen2_format.h). Because both
|
||||
// use this same function, an SST's data blocks and its embedded blob records
|
||||
// never collide even when the block cache and blob cache are the same cache.
|
||||
// Keeping a single implementation here avoids a divergence bug that would
|
||||
// silently alias the two keyspaces.
|
||||
inline CacheKey WithOffsetForMinSizeRecord(uint64_t offset) const {
|
||||
return WithOffset(offset >> 2);
|
||||
}
|
||||
|
||||
// The "common prefix" is a shared prefix for all the returned CacheKeys.
|
||||
// It is specific to the file but the same for all offsets within the file.
|
||||
static constexpr size_t kCommonPrefixSize = 8;
|
||||
|
||||
Vendored
+1
-1
@@ -3108,7 +3108,7 @@ AutoHyperClockTable::HandleImpl* AutoHyperClockTable::Lookup(
|
||||
HandleImpl* const arr = array_.Get();
|
||||
NextWithShift next_with_shift = arr[home].head_next_with_shift.LoadRelaxed();
|
||||
for (size_t i = 0; !next_with_shift.IsEnd() && i < 10; ++i) {
|
||||
HandleImpl* h = &arr[next_with_shift.IsEnd()];
|
||||
HandleImpl* h = &arr[next_with_shift.GetNext()];
|
||||
// Attempt cheap key match without acquiring a read ref. This could give a
|
||||
// false positive, which is re-checked after acquiring read ref, or false
|
||||
// negative, which is re-checked in the full Lookup. Also, this is a
|
||||
|
||||
+50
-27
@@ -46,7 +46,7 @@ This document provides guidance on how to add new options to RocksDB's public AP
|
||||
|
||||
## Pattern 1: Adding a Standard Column Family Option
|
||||
|
||||
Example reference: commit `94e65a2e0b4f817aa4bfa4c96cdf867e7980d7bc` (memtable_veirfy_per_key_checksum_on_seek)
|
||||
Example reference: commit `94e65a2e0b4f817aa4bfa4c96cdf867e7980d7bc` (memtable_verify_per_key_checksum_on_seek)
|
||||
|
||||
### Step 1: Define the Option in Public Header
|
||||
|
||||
@@ -63,7 +63,7 @@ Add the option with documentation in `AdvancedColumnFamilyOptions` struct:
|
||||
// operation.
|
||||
// This option depends on memtable_protection_bytes_per_key to be non zero.
|
||||
// If memtable_protection_bytes_per_key is zero, no validation is performed.
|
||||
bool memtable_veirfy_per_key_checksum_on_seek = false;
|
||||
bool memtable_verify_per_key_checksum_on_seek = false;
|
||||
```
|
||||
|
||||
### Step 2: Add to Internal Options Structs
|
||||
@@ -74,14 +74,14 @@ Add to `MutableCFOptions` struct (or `ImmutableCFOptions` for immutable options)
|
||||
|
||||
```cpp
|
||||
// In MutableCFOptions constructor from Options:
|
||||
memtable_veirfy_per_key_checksum_on_seek(
|
||||
options.memtable_veirfy_per_key_checksum_on_seek),
|
||||
memtable_verify_per_key_checksum_on_seek(
|
||||
options.memtable_verify_per_key_checksum_on_seek),
|
||||
|
||||
// In MutableCFOptions default constructor:
|
||||
memtable_veirfy_per_key_checksum_on_seek(false),
|
||||
memtable_verify_per_key_checksum_on_seek(false),
|
||||
|
||||
// In MutableCFOptions struct member declarations:
|
||||
bool memtable_veirfy_per_key_checksum_on_seek;
|
||||
bool memtable_verify_per_key_checksum_on_seek;
|
||||
```
|
||||
|
||||
### Step 3: Register for Serialization/Deserialization
|
||||
@@ -91,9 +91,9 @@ bool memtable_veirfy_per_key_checksum_on_seek;
|
||||
Add to the options type info map for serialization:
|
||||
|
||||
```cpp
|
||||
{"memtable_veirfy_per_key_checksum_on_seek",
|
||||
{"memtable_verify_per_key_checksum_on_seek",
|
||||
{offsetof(struct MutableCFOptions,
|
||||
memtable_veirfy_per_key_checksum_on_seek),
|
||||
memtable_verify_per_key_checksum_on_seek),
|
||||
OptionType::kBoolean, OptionVerificationType::kNormal,
|
||||
OptionTypeFlags::kMutable}},
|
||||
```
|
||||
@@ -101,8 +101,8 @@ Add to the options type info map for serialization:
|
||||
Add logging in `MutableCFOptions::Dump()`:
|
||||
|
||||
```cpp
|
||||
ROCKS_LOG_INFO(log, "memtable_veirfy_per_key_checksum_on_seek: %d",
|
||||
memtable_veirfy_per_key_checksum_on_seek);
|
||||
ROCKS_LOG_INFO(log, "memtable_verify_per_key_checksum_on_seek: %d",
|
||||
memtable_verify_per_key_checksum_on_seek);
|
||||
```
|
||||
|
||||
### Step 4: Update Options Helper
|
||||
@@ -112,8 +112,8 @@ ROCKS_LOG_INFO(log, "memtable_veirfy_per_key_checksum_on_seek: %d",
|
||||
Add to `UpdateColumnFamilyOptions()`:
|
||||
|
||||
```cpp
|
||||
cf_opts->memtable_veirfy_per_key_checksum_on_seek =
|
||||
moptions.memtable_veirfy_per_key_checksum_on_seek;
|
||||
cf_opts->memtable_verify_per_key_checksum_on_seek =
|
||||
moptions.memtable_verify_per_key_checksum_on_seek;
|
||||
```
|
||||
|
||||
### Step 5: Add to Options Settable Test
|
||||
@@ -123,7 +123,7 @@ cf_opts->memtable_veirfy_per_key_checksum_on_seek =
|
||||
Add to the test string in `ColumnFamilyOptionsAllFieldsSettable`:
|
||||
|
||||
```cpp
|
||||
"memtable_veirfy_per_key_checksum_on_seek=1;"
|
||||
"memtable_verify_per_key_checksum_on_seek=1;"
|
||||
```
|
||||
|
||||
### Step 6: Add db_stress Support
|
||||
@@ -131,23 +131,23 @@ Add to the test string in `ColumnFamilyOptionsAllFieldsSettable`:
|
||||
**File: `db_stress_tool/db_stress_common.h`**
|
||||
|
||||
```cpp
|
||||
DECLARE_bool(memtable_veirfy_per_key_checksum_on_seek);
|
||||
DECLARE_bool(memtable_verify_per_key_checksum_on_seek);
|
||||
```
|
||||
|
||||
**File: `db_stress_tool/db_stress_gflags.cc`**
|
||||
|
||||
```cpp
|
||||
DEFINE_bool(
|
||||
memtable_veirfy_per_key_checksum_on_seek,
|
||||
ROCKSDB_NAMESPACE::Options().memtable_veirfy_per_key_checksum_on_seek,
|
||||
"Sets CF option memtable_veirfy_per_key_checksum_on_seek.");
|
||||
memtable_verify_per_key_checksum_on_seek,
|
||||
ROCKSDB_NAMESPACE::Options().memtable_verify_per_key_checksum_on_seek,
|
||||
"Sets CF option memtable_verify_per_key_checksum_on_seek.");
|
||||
```
|
||||
|
||||
**File: `db_stress_tool/db_stress_test_base.cc`**
|
||||
|
||||
```cpp
|
||||
options.memtable_veirfy_per_key_checksum_on_seek =
|
||||
FLAGS_memtable_veirfy_per_key_checksum_on_seek;
|
||||
options.memtable_verify_per_key_checksum_on_seek =
|
||||
FLAGS_memtable_verify_per_key_checksum_on_seek;
|
||||
```
|
||||
|
||||
### Step 7: Add db_bench Support
|
||||
@@ -156,12 +156,12 @@ options.memtable_veirfy_per_key_checksum_on_seek =
|
||||
|
||||
```cpp
|
||||
// Flag definition (near related flags):
|
||||
DEFINE_bool(memtable_veirfy_per_key_checksum_on_seek, false,
|
||||
"Sets CF option memtable_veirfy_per_key_checksum_on_seek");
|
||||
DEFINE_bool(memtable_verify_per_key_checksum_on_seek, false,
|
||||
"Sets CF option memtable_verify_per_key_checksum_on_seek");
|
||||
|
||||
// Apply flag to options (in InitializeOptionsFromFlags or similar):
|
||||
options.memtable_veirfy_per_key_checksum_on_seek =
|
||||
FLAGS_memtable_veirfy_per_key_checksum_on_seek;
|
||||
options.memtable_verify_per_key_checksum_on_seek =
|
||||
FLAGS_memtable_verify_per_key_checksum_on_seek;
|
||||
```
|
||||
|
||||
### Step 8: Add Crash Test Support
|
||||
@@ -169,7 +169,7 @@ options.memtable_veirfy_per_key_checksum_on_seek =
|
||||
**File: `tools/db_crashtest.py`**
|
||||
|
||||
```python
|
||||
"memtable_veirfy_per_key_checksum_on_seek": lambda: random.choice([0] * 7 + [1]),
|
||||
"memtable_verify_per_key_checksum_on_seek": lambda: random.choice([0] * 7 + [1]),
|
||||
```
|
||||
|
||||
Also add constraint handling in `finalize_and_sanitize()` if needed:
|
||||
@@ -177,7 +177,7 @@ Also add constraint handling in `finalize_and_sanitize()` if needed:
|
||||
```python
|
||||
# only skip list memtable representation supports paranoid memory checks
|
||||
if dest_params.get("memtablerep") != "skip_list":
|
||||
dest_params["memtable_veirfy_per_key_checksum_on_seek"] = 0
|
||||
dest_params["memtable_verify_per_key_checksum_on_seek"] = 0
|
||||
```
|
||||
|
||||
### Step 9: Add Release Note
|
||||
@@ -185,7 +185,7 @@ if dest_params.get("memtablerep") != "skip_list":
|
||||
**File: `unreleased_history/new_features/<descriptive_name>.md`**
|
||||
|
||||
```markdown
|
||||
A new flag memtable_veirfy_per_key_checksum_on_seek is added to AdvancedColumnFamilyOptions. When it is enabled, it will validate key checksum along the binary search path on skiplist based memtable during seek operation.
|
||||
A new flag memtable_verify_per_key_checksum_on_seek is added to AdvancedColumnFamilyOptions. When it is enabled, it will validate key checksum along the binary search path on skiplist based memtable during seek operation.
|
||||
```
|
||||
|
||||
---
|
||||
@@ -421,6 +421,30 @@ Example reference: commit `429b36c22d76403d275dd0e6877b08d4cea2bc90` (block_alig
|
||||
|
||||
If an option already exists but needs C API support:
|
||||
|
||||
**First decide whether the option is auto-managed.**
|
||||
|
||||
Many simple option fields are no longer maintained by hand in
|
||||
`include/rocksdb/c.h` and `db/c.cc`. Before adding a manual wrapper:
|
||||
|
||||
- Check whether the option belongs to a family handled by
|
||||
`tools/c_api_gen/auto_simple_bindings.py`.
|
||||
- If it is a simple scalar/enum/string field in an auto-managed family, run
|
||||
`python3 tools/c_api_gen/regen_all.py` and let the generator add the C API.
|
||||
- After regenerating, run
|
||||
`python3 tools/c_api_gen/verify_generated_up_to_date.py` to confirm the
|
||||
checked-in generated fragments stay stable.
|
||||
- Do not edit generated `.inc` files under `c_api_gen/` by hand.
|
||||
- If the new field is not ready for C API support yet, add an entry to
|
||||
`tools/c_api_gen/auto_simple_bindings_blocklist.json` with
|
||||
`"policy": "deferred"` and a concrete reason so the build stays intentional
|
||||
rather than silently drifting.
|
||||
- If the field needs custom ownership, callback, vector, or nested-struct
|
||||
marshalling, keep it manual or move it into `tools/c_api_gen/spec.json`
|
||||
depending on the API shape.
|
||||
|
||||
If the option is not auto-managed, or the C API really is a custom/manual case,
|
||||
the traditional hand-written pattern still applies:
|
||||
|
||||
**File: `db/c.cc`**
|
||||
|
||||
```cpp
|
||||
@@ -509,4 +533,3 @@ Common option types used in serialization:
|
||||
- [ ] unreleased_history markdown file
|
||||
- [ ] Java API (for BlockBasedTableOptions)
|
||||
- [ ] C API (if needed)
|
||||
|
||||
|
||||
@@ -168,9 +168,18 @@ Status YourNewAPI(const YourAPIOptions& /*options*/,
|
||||
|
||||
### Step 5: Add C API Bindings
|
||||
|
||||
**Header:** `include/rocksdb/c.h`
|
||||
> **Important:** `include/rocksdb/c.h` and `db/c.cc` are `@generated` and must
|
||||
> NOT be edited by hand — your changes would be overwritten on the next
|
||||
> regeneration. Choose the right path first (see "Before writing C API code by
|
||||
> hand" below). For hand-written (manual) wrappers, edit the source templates
|
||||
> `tools/c_api_gen/c_base.h` (declarations) and `tools/c_api_gen/c_base.cc`
|
||||
> (implementations), then run `python3 tools/c_api_gen/regen_all.py` to produce
|
||||
> `c.h` / `c.cc`. The snippets below show the *declaration* and *implementation*
|
||||
> you would add to those templates.
|
||||
|
||||
\`\`\`c
|
||||
**Header (declaration → `tools/c_api_gen/c_base.h`):**
|
||||
|
||||
```c
|
||||
// Basic version
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_your_new_api(
|
||||
rocksdb_t* db,
|
||||
@@ -191,7 +200,7 @@ extern ROCKSDB_LIBRARY_API void rocksdb_your_new_api_opt(
|
||||
char** errptr);
|
||||
\`\`\`
|
||||
|
||||
**Implementation:** `db/c.cc`
|
||||
**Implementation (→ `tools/c_api_gen/c_base.cc`):**
|
||||
|
||||
\`\`\`cpp
|
||||
void rocksdb_your_new_api(rocksdb_t* db, const char* start_key,
|
||||
@@ -217,6 +226,38 @@ void rocksdb_your_new_api_cf(rocksdb_t* db,
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
**Before writing C API code by hand, choose the right path:**
|
||||
|
||||
- **Auto-managed simple struct fields:** If you added a new field to a managed
|
||||
public struct such as `ReadOptions`, selected option structs, or managed
|
||||
metadata structs, first check `tools/c_api_gen/auto_simple_bindings.py`.
|
||||
Simple scalar/enum/string fields should be regenerated with
|
||||
`python3 tools/c_api_gen/regen_all.py` rather than hand-editing
|
||||
`include/rocksdb/c.h` / `db/c.cc`.
|
||||
After regenerating, run
|
||||
`python3 tools/c_api_gen/verify_generated_up_to_date.py` to confirm the
|
||||
checked-in generated fragments are stable.
|
||||
- **Spec-driven wrappers:** If the API is still mechanically generated but needs
|
||||
an explicit C shape, naming, or `Status`/`char** errptr` policy, add it to
|
||||
`tools/c_api_gen/spec.json`.
|
||||
- **Fully manual wrappers:** If the API uses callbacks, ownership transfer,
|
||||
vectors/maps, open flows, or otherwise irregular marshalling, keep the C API
|
||||
hand-written.
|
||||
|
||||
**Temporary deferral for auto-managed families:**
|
||||
|
||||
If a new field lands in an auto-managed family but the C API shape is not ready
|
||||
yet, add a checked-in entry to
|
||||
`tools/c_api_gen/auto_simple_bindings_blocklist.json` with:
|
||||
|
||||
- `policy: "manual"` when the field is intentionally outside simple auto-gen
|
||||
- `policy: "deferred"` when the field should be revisited later
|
||||
- a concrete `reason`
|
||||
- `tracking_issue` when available
|
||||
|
||||
If a field in an auto-managed family is not supported by the generator and is
|
||||
not covered by the blocklist, regeneration should fail. That is intentional.
|
||||
|
||||
**If you have options, also add:**
|
||||
|
||||
\`\`\`cpp
|
||||
@@ -482,8 +523,8 @@ public class YourAPIOptionsTest {
|
||||
| StackableDB | `include/rocksdb/utilities/stackable_db.h` | ✓ |
|
||||
| Secondary DB | `db/db_impl/db_impl_secondary.h` | If not supported |
|
||||
| Compacted DB | `db/db_impl/compacted_db_impl.h` | If not supported |
|
||||
| C API Header | `include/rocksdb/c.h` | ✓ |
|
||||
| C API Implementation | `db/c.cc` | ✓ |
|
||||
| C API Header (manual wrappers) | `tools/c_api_gen/c_base.h` → regen → `include/rocksdb/c.h` (`@generated`) | ✓ |
|
||||
| C API Implementation (manual wrappers) | `tools/c_api_gen/c_base.cc` → regen → `db/c.cc` (`@generated`) | ✓ |
|
||||
| Java API | `java/src/main/java/org/rocksdb/RocksDB.java` | ✓ |
|
||||
| Java Options | `java/src/main/java/org/rocksdb/YourAPIOptions.java` | If needed |
|
||||
| JNI Implementation | `java/rocksjni/rocksjni.cc` | ✓ |
|
||||
|
||||
@@ -44,10 +44,6 @@ if(@WITH_NUMA@)
|
||||
find_dependency(NUMA)
|
||||
endif()
|
||||
|
||||
if(@WITH_TBB@)
|
||||
find_dependency(TBB)
|
||||
endif()
|
||||
|
||||
find_dependency(Threads)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/RocksDBTargets.cmake")
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# - Find TBB
|
||||
# Find the Thread Building Blocks library and includes
|
||||
#
|
||||
# TBB_INCLUDE_DIRS - where to find tbb.h, etc.
|
||||
# TBB_LIBRARIES - List of libraries when using TBB.
|
||||
# TBB_FOUND - True if TBB found.
|
||||
|
||||
if(NOT DEFINED TBB_ROOT_DIR)
|
||||
set(TBB_ROOT_DIR "$ENV{TBBROOT}")
|
||||
endif()
|
||||
|
||||
find_path(TBB_INCLUDE_DIRS
|
||||
NAMES tbb/tbb.h
|
||||
HINTS ${TBB_ROOT_DIR}/include)
|
||||
|
||||
find_library(TBB_LIBRARIES
|
||||
NAMES tbb
|
||||
HINTS ${TBB_ROOT_DIR}/lib ENV LIBRARY_PATH)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(TBB DEFAULT_MSG TBB_LIBRARIES TBB_INCLUDE_DIRS)
|
||||
|
||||
mark_as_advanced(
|
||||
TBB_LIBRARIES
|
||||
TBB_INCLUDE_DIRS)
|
||||
|
||||
if(TBB_FOUND AND NOT (TARGET TBB::TBB))
|
||||
add_library (TBB::TBB UNKNOWN IMPORTED)
|
||||
set_target_properties(TBB::TBB
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION ${TBB_LIBRARIES}
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS})
|
||||
endif()
|
||||
+132
-26
@@ -30,13 +30,78 @@ inline static SequenceNumber GetSeqNum(const DBImpl* db, const Snapshot* s) {
|
||||
Status ArenaWrappedDBIter::GetProperty(std::string prop_name,
|
||||
std::string* prop) {
|
||||
if (prop_name == "rocksdb.iterator.super-version-number") {
|
||||
if (!internal_iter_initialized_) {
|
||||
*prop = std::to_string(sv_number_);
|
||||
return Status::OK();
|
||||
}
|
||||
// First try to pass the value returned from inner iterator.
|
||||
if (!db_iter_->GetProperty(prop_name, prop).ok()) {
|
||||
*prop = std::to_string(sv_number_);
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
return db_iter_->GetProperty(prop_name, prop);
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return db_iter_->status();
|
||||
}
|
||||
return db_iter_->GetProperty(std::move(prop_name), prop);
|
||||
}
|
||||
|
||||
void ArenaWrappedDBIter::CleanupDeferredSuperVersion() {
|
||||
if (deferred_sv_ != nullptr) {
|
||||
assert(db_impl_ != nullptr);
|
||||
db_impl_->CleanupIteratorSuperVersion(
|
||||
deferred_sv_, read_options_.background_purge_on_iterator_cleanup);
|
||||
deferred_sv_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ArenaWrappedDBIter::DestroyDBIter() {
|
||||
db_iter_->~DBIter();
|
||||
CleanupDeferredSuperVersion();
|
||||
}
|
||||
|
||||
void ArenaWrappedDBIter::ColumnFamilyDataUnrefDeleter::operator()(
|
||||
ColumnFamilyData* cfd) const {
|
||||
if (cfd == nullptr) {
|
||||
return;
|
||||
}
|
||||
assert(db_impl != nullptr);
|
||||
|
||||
InstrumentedMutexLock lock(db_impl->mutex());
|
||||
cfd->UnrefAndTryDelete();
|
||||
}
|
||||
|
||||
void ArenaWrappedDBIter::DestroyDBIterAndArena() {
|
||||
DestroyDBIter();
|
||||
arena_.~Arena();
|
||||
}
|
||||
|
||||
Status ArenaWrappedDBIter::EnsureInternalIteratorInitialized(
|
||||
const MultiScanArgs* scan_opts) {
|
||||
if (internal_iter_initialized_) {
|
||||
return Status::OK();
|
||||
}
|
||||
if (db_impl_ == nullptr || deferred_cfd_ == nullptr ||
|
||||
deferred_sv_ == nullptr) {
|
||||
Status s = Status::InvalidArgument(
|
||||
"Internal iterator cannot be initialized without deferred DB state");
|
||||
db_iter_->set_status(s);
|
||||
db_iter_->set_valid(false);
|
||||
return s;
|
||||
}
|
||||
|
||||
const MultiScanArgs* pruning_scan_opts =
|
||||
scan_opts != nullptr && scan_opts->HasBoundedScanRanges() ? scan_opts
|
||||
: nullptr;
|
||||
child_read_options_ = read_options_;
|
||||
child_read_options_.snapshot = nullptr;
|
||||
InternalIterator* internal_iter = db_impl_->NewInternalIterator(
|
||||
child_read_options_, deferred_cfd_, deferred_sv_, &arena_, sequence_,
|
||||
/*allow_unprepared_value=*/true, this, pruning_scan_opts);
|
||||
deferred_cfd_ = nullptr;
|
||||
deferred_sv_ = nullptr;
|
||||
SetIterUnderDBIterImpl(internal_iter);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void ArenaWrappedDBIter::Init(
|
||||
@@ -44,18 +109,26 @@ void ArenaWrappedDBIter::Init(
|
||||
const MutableCFOptions& mutable_cf_options, const Version* version,
|
||||
const SequenceNumber& sequence, uint64_t version_number,
|
||||
ReadCallback* read_callback, ColumnFamilyHandleImpl* cfh,
|
||||
bool expose_blob_index, bool allow_refresh, ReadOnlyMemTable* active_mem) {
|
||||
bool expose_blob_index, bool allow_refresh, ReadOnlyMemTable* active_mem,
|
||||
DBImpl* db_impl, ColumnFamilyData* cfd) {
|
||||
read_options_ = read_options;
|
||||
child_read_options_ = read_options;
|
||||
if (!CheckFSFeatureSupport(env->GetFileSystem().get(),
|
||||
FSSupportedOps::kAsyncIO)) {
|
||||
read_options_.async_io = false;
|
||||
}
|
||||
read_options_.total_order_seek |= ioptions.prefix_seek_opt_in_only;
|
||||
|
||||
db_iter_ = DBIter::NewIter(
|
||||
env, read_options_, ioptions, mutable_cf_options,
|
||||
ioptions.user_comparator, /*internal_iter=*/nullptr, version, sequence,
|
||||
read_callback, active_mem, cfh, expose_blob_index, &arena_);
|
||||
if (cfh != nullptr) {
|
||||
db_impl = cfh->db();
|
||||
cfd = cfh->cfd();
|
||||
}
|
||||
|
||||
db_iter_ = DBIter::NewIter(env, read_options_, ioptions, mutable_cf_options,
|
||||
ioptions.user_comparator,
|
||||
/*internal_iter=*/nullptr, version, sequence,
|
||||
read_callback, active_mem, /*cfh=*/nullptr,
|
||||
expose_blob_index, &arena_, db_impl, cfd);
|
||||
|
||||
sv_number_ = version_number;
|
||||
allow_refresh_ = allow_refresh;
|
||||
@@ -65,13 +138,13 @@ void ArenaWrappedDBIter::Init(
|
||||
|
||||
void ArenaWrappedDBIter::MaybeAutoRefresh(bool is_seek,
|
||||
DBIter::Direction direction) {
|
||||
if (cfh_ != nullptr && read_options_.snapshot != nullptr && allow_refresh_ &&
|
||||
read_options_.auto_refresh_iterator_with_snapshot) {
|
||||
if (cfd_ref_ != nullptr && read_options_.snapshot != nullptr &&
|
||||
allow_refresh_ && read_options_.auto_refresh_iterator_with_snapshot) {
|
||||
// The intent here is to capture the superversion number change
|
||||
// reasonably soon from the time it actually happened. As such,
|
||||
// we're fine with weaker synchronization / ordering guarantees
|
||||
// provided by relaxed atomic (in favor of less CPU / mem overhead).
|
||||
uint64_t cur_sv_number = cfh_->cfd()->GetSuperVersionNumberRelaxed();
|
||||
uint64_t cur_sv_number = cfd_ref_->GetSuperVersionNumberRelaxed();
|
||||
if ((sv_number_ != cur_sv_number) && status().ok()) {
|
||||
// Changing iterators' direction is pretty heavy-weight operation and
|
||||
// could have unintended consequences when it comes to prefix seek.
|
||||
@@ -150,13 +223,13 @@ void ArenaWrappedDBIter::DoRefresh(const Snapshot* snapshot,
|
||||
// present in the error log, but won't be reflected in the iterator status.
|
||||
// This is by design as we expect compaction to clean up those obsolete files
|
||||
// eventually.
|
||||
db_iter_->~DBIter();
|
||||
|
||||
arena_.~Arena();
|
||||
DestroyDBIterAndArena();
|
||||
new (&arena_) Arena();
|
||||
|
||||
auto cfd = cfh_->cfd();
|
||||
auto db_impl = cfh_->db();
|
||||
auto cfd = cfd_ref_.get();
|
||||
auto db_impl = db_impl_;
|
||||
assert(cfd != nullptr);
|
||||
assert(db_impl != nullptr);
|
||||
|
||||
SuperVersion* sv = cfd->GetReferencedSuperVersion(db_impl);
|
||||
assert(sv->version_number >= sv_number);
|
||||
@@ -164,23 +237,27 @@ void ArenaWrappedDBIter::DoRefresh(const Snapshot* snapshot,
|
||||
if (read_callback_) {
|
||||
read_callback_->Refresh(read_seq);
|
||||
}
|
||||
// TODO: Preserve Prepare() scan options across Refresh() so a refreshed
|
||||
// MultiScan iterator can rebuild the same pruned tree.
|
||||
Init(env, read_options_, cfd->ioptions(), sv->mutable_cf_options, sv->current,
|
||||
read_seq, sv->version_number, read_callback_, cfh_, expose_blob_index_,
|
||||
allow_refresh_, allow_mark_memtable_for_flush_ ? sv->mem : nullptr);
|
||||
read_seq, sv->version_number, read_callback_, nullptr,
|
||||
expose_blob_index_, allow_refresh_,
|
||||
allow_mark_memtable_for_flush_ ? sv->mem : nullptr, db_impl, cfd);
|
||||
|
||||
InternalIterator* internal_iter = db_impl->NewInternalIterator(
|
||||
read_options_, cfd, sv, &arena_, read_seq,
|
||||
/* allow_unprepared_value */ true, /* db_iter */ this);
|
||||
SetIterUnderDBIter(internal_iter);
|
||||
internal_iter_initialized_ = true;
|
||||
}
|
||||
|
||||
Status ArenaWrappedDBIter::Refresh(const Snapshot* snapshot) {
|
||||
if (cfh_ == nullptr || !allow_refresh_) {
|
||||
if (cfd_ref_ == nullptr || db_impl_ == nullptr || !allow_refresh_) {
|
||||
return Status::NotSupported("Creating renew iterator is not allowed.");
|
||||
}
|
||||
assert(db_iter_ != nullptr);
|
||||
auto cfd = cfh_->cfd();
|
||||
auto db_impl = cfh_->db();
|
||||
auto cfd = cfd_ref_.get();
|
||||
auto db_impl = db_impl_;
|
||||
|
||||
// TODO(yiwu): For last_seq_same_as_publish_seq_==false, this is not the
|
||||
// correct behavior. Will be corrected automatically when we take a snapshot
|
||||
@@ -193,6 +270,13 @@ Status ArenaWrappedDBIter::Refresh(const Snapshot* snapshot) {
|
||||
TEST_SYNC_POINT("ArenaWrappedDBIter::Refresh:1");
|
||||
TEST_SYNC_POINT("ArenaWrappedDBIter::Refresh:2");
|
||||
|
||||
if (!internal_iter_initialized_) {
|
||||
Status s = EnsureInternalIteratorInitialized(nullptr);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (sv_number_ != cur_sv_number) {
|
||||
DoRefresh(snapshot, cur_sv_number);
|
||||
@@ -250,25 +334,47 @@ Status ArenaWrappedDBIter::Refresh(const Snapshot* snapshot) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void ArenaWrappedDBIter::Prepare(const MultiScanArgs& scan_opts) {
|
||||
if (prepare_called_) {
|
||||
db_iter_->set_status(Status::InvalidArgument(
|
||||
"Prepare called more than once on the same iterator"));
|
||||
db_iter_->set_valid(false);
|
||||
return;
|
||||
}
|
||||
prepare_called_ = true;
|
||||
|
||||
Status s = db_iter_->SetScanOptionsForPrepare(scan_opts);
|
||||
if (!s.ok()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const MultiScanArgs* pruning_scan_opts =
|
||||
scan_opts.HasBoundedScanRanges() ? &scan_opts : nullptr;
|
||||
s = EnsureInternalIteratorInitialized(pruning_scan_opts);
|
||||
if (!s.ok()) {
|
||||
return;
|
||||
}
|
||||
|
||||
db_iter_->PrepareInternalChildren();
|
||||
}
|
||||
|
||||
ArenaWrappedDBIter* NewArenaWrappedDbIterator(
|
||||
Env* env, const ReadOptions& read_options, ColumnFamilyHandleImpl* cfh,
|
||||
SuperVersion* sv, const SequenceNumber& sequence,
|
||||
ReadCallback* read_callback, DBImpl* db_impl, bool expose_blob_index,
|
||||
bool allow_refresh, bool allow_mark_memtable_for_flush) {
|
||||
ArenaWrappedDBIter* db_iter = new ArenaWrappedDBIter();
|
||||
ColumnFamilyData* cfd = cfh->cfd();
|
||||
db_iter->Init(env, read_options, cfh->cfd()->ioptions(),
|
||||
sv->mutable_cf_options, sv->current, sequence,
|
||||
sv->version_number, read_callback, cfh, expose_blob_index,
|
||||
allow_refresh,
|
||||
allow_mark_memtable_for_flush ? sv->mem : nullptr);
|
||||
if (cfh != nullptr && allow_refresh) {
|
||||
db_iter->StoreRefreshInfo(cfh, read_callback, expose_blob_index);
|
||||
if (allow_refresh && cfd != nullptr) {
|
||||
db_iter->StoreRefreshInfo(read_callback, expose_blob_index);
|
||||
}
|
||||
|
||||
InternalIterator* internal_iter = db_impl->NewInternalIterator(
|
||||
db_iter->GetReadOptions(), cfh->cfd(), sv, db_iter->GetArena(), sequence,
|
||||
/*allow_unprepared_value=*/true, db_iter);
|
||||
db_iter->SetIterUnderDBIter(internal_iter);
|
||||
db_iter->StoreDeferredInitInfo(db_impl, cfd, sv, sequence,
|
||||
allow_mark_memtable_for_flush);
|
||||
|
||||
return db_iter;
|
||||
}
|
||||
|
||||
+74
-17
@@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "db/db_impl/db_impl.h"
|
||||
@@ -33,10 +34,17 @@ class Version;
|
||||
// When using the class's Iterator interface, the behavior is exactly
|
||||
// the same as the inner DBIter.
|
||||
class ArenaWrappedDBIter : public Iterator {
|
||||
struct ColumnFamilyDataUnrefDeleter {
|
||||
DBImpl* db_impl = nullptr;
|
||||
void operator()(ColumnFamilyData* cfd) const;
|
||||
};
|
||||
using ColumnFamilyDataRef =
|
||||
std::unique_ptr<ColumnFamilyData, ColumnFamilyDataUnrefDeleter>;
|
||||
|
||||
public:
|
||||
~ArenaWrappedDBIter() override {
|
||||
if (db_iter_ != nullptr) {
|
||||
db_iter_->~DBIter();
|
||||
DestroyDBIter();
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
@@ -51,7 +59,7 @@ class ArenaWrappedDBIter : public Iterator {
|
||||
// Set the internal iterator wrapped inside the DB Iterator. Usually it is
|
||||
// a merging iterator.
|
||||
virtual void SetIterUnderDBIter(InternalIterator* iter) {
|
||||
db_iter_->SetIter(iter);
|
||||
SetIterUnderDBIterImpl(iter);
|
||||
}
|
||||
|
||||
void SetMemtableRangetombstoneIter(
|
||||
@@ -60,26 +68,48 @@ class ArenaWrappedDBIter : public Iterator {
|
||||
}
|
||||
|
||||
bool Valid() const override { return db_iter_->Valid(); }
|
||||
void SeekToFirst() override { db_iter_->SeekToFirst(); }
|
||||
void SeekToLast() override { db_iter_->SeekToLast(); }
|
||||
void SeekToFirst() override {
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return;
|
||||
}
|
||||
db_iter_->SeekToFirst();
|
||||
}
|
||||
void SeekToLast() override {
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return;
|
||||
}
|
||||
db_iter_->SeekToLast();
|
||||
}
|
||||
// 'target' does not contain timestamp, even if user timestamp feature is
|
||||
// enabled.
|
||||
void Seek(const Slice& target) override {
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return;
|
||||
}
|
||||
MaybeAutoRefresh(true /* is_seek */, DBIter::kForward);
|
||||
db_iter_->Seek(target);
|
||||
}
|
||||
|
||||
void SeekForPrev(const Slice& target) override {
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return;
|
||||
}
|
||||
MaybeAutoRefresh(true /* is_seek */, DBIter::kReverse);
|
||||
db_iter_->SeekForPrev(target);
|
||||
}
|
||||
|
||||
void Next() override {
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return;
|
||||
}
|
||||
db_iter_->Next();
|
||||
MaybeAutoRefresh(false /* is_seek */, DBIter::kForward);
|
||||
}
|
||||
|
||||
void Prev() override {
|
||||
if (!EnsureInternalIteratorInitialized(nullptr).ok()) {
|
||||
return;
|
||||
}
|
||||
db_iter_->Prev();
|
||||
MaybeAutoRefresh(false /* is_seek */, DBIter::kReverse);
|
||||
}
|
||||
@@ -96,12 +126,13 @@ class ArenaWrappedDBIter : public Iterator {
|
||||
Status Refresh() override;
|
||||
Status Refresh(const Snapshot*) override;
|
||||
|
||||
bool PrepareValue() override { return db_iter_->PrepareValue(); }
|
||||
|
||||
void Prepare(const MultiScanArgs& scan_opts) override {
|
||||
db_iter_->Prepare(scan_opts);
|
||||
bool PrepareValue() override {
|
||||
return EnsureInternalIteratorInitialized(nullptr).ok() &&
|
||||
db_iter_->PrepareValue();
|
||||
}
|
||||
|
||||
void Prepare(const MultiScanArgs& scan_opts) override;
|
||||
|
||||
// FIXME: we could just pass SV in for mutable cf option, version and version
|
||||
// number, but this is used by SstFileReader which does not have a SV.
|
||||
void Init(Env* env, const ReadOptions& read_options,
|
||||
@@ -110,27 +141,53 @@ class ArenaWrappedDBIter : public Iterator {
|
||||
const SequenceNumber& sequence, uint64_t version_number,
|
||||
ReadCallback* read_callback, ColumnFamilyHandleImpl* cfh,
|
||||
bool expose_blob_index, bool allow_refresh,
|
||||
ReadOnlyMemTable* active_mem);
|
||||
ReadOnlyMemTable* active_mem, DBImpl* db_impl = nullptr,
|
||||
ColumnFamilyData* cfd = nullptr);
|
||||
|
||||
// Store some parameters so we can refresh the iterator at a later point
|
||||
// with these same params
|
||||
void StoreRefreshInfo(ColumnFamilyHandleImpl* cfh,
|
||||
ReadCallback* read_callback, bool expose_blob_index) {
|
||||
cfh_ = cfh;
|
||||
// Store parameters used only by explicit/auto-refresh.
|
||||
void StoreRefreshInfo(ReadCallback* read_callback, bool expose_blob_index) {
|
||||
read_callback_ = read_callback;
|
||||
expose_blob_index_ = expose_blob_index;
|
||||
}
|
||||
|
||||
void StoreDeferredInitInfo(DBImpl* db_impl, ColumnFamilyData* cfd,
|
||||
SuperVersion* sv, const SequenceNumber& sequence,
|
||||
bool allow_mark_memtable_for_flush) {
|
||||
assert(cfd != nullptr);
|
||||
db_impl_ = db_impl;
|
||||
cfd->Ref();
|
||||
cfd_ref_ = ColumnFamilyDataRef(cfd, ColumnFamilyDataUnrefDeleter{db_impl});
|
||||
deferred_cfd_ = cfd;
|
||||
deferred_sv_ = sv;
|
||||
sequence_ = sequence;
|
||||
allow_mark_memtable_for_flush_ = allow_mark_memtable_for_flush;
|
||||
}
|
||||
|
||||
private:
|
||||
Status EnsureInternalIteratorInitialized(const MultiScanArgs* scan_opts);
|
||||
void SetIterUnderDBIterImpl(InternalIterator* iter) {
|
||||
db_iter_->SetIter(iter);
|
||||
internal_iter_initialized_ = true;
|
||||
}
|
||||
void CleanupDeferredSuperVersion();
|
||||
void DestroyDBIter();
|
||||
void DestroyDBIterAndArena();
|
||||
void DoRefresh(const Snapshot* snapshot, uint64_t sv_number);
|
||||
void MaybeAutoRefresh(bool is_seek, DBIter::Direction direction);
|
||||
|
||||
DBIter* db_iter_ = nullptr;
|
||||
Arena arena_;
|
||||
uint64_t sv_number_;
|
||||
ColumnFamilyHandleImpl* cfh_ = nullptr;
|
||||
uint64_t sv_number_ = 0;
|
||||
DBImpl* db_impl_ = nullptr;
|
||||
ColumnFamilyDataRef cfd_ref_{nullptr, ColumnFamilyDataUnrefDeleter{}};
|
||||
ColumnFamilyData* deferred_cfd_ = nullptr;
|
||||
SuperVersion* deferred_sv_ = nullptr;
|
||||
SequenceNumber sequence_ = kMaxSequenceNumber;
|
||||
bool internal_iter_initialized_ = false;
|
||||
bool prepare_called_ = false;
|
||||
ReadOptions read_options_;
|
||||
ReadCallback* read_callback_;
|
||||
ReadOptions child_read_options_;
|
||||
ReadCallback* read_callback_ = nullptr;
|
||||
bool expose_blob_index_ = false;
|
||||
bool allow_refresh_ = true;
|
||||
bool allow_mark_memtable_for_flush_ = true;
|
||||
|
||||
@@ -11,6 +11,24 @@
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
// WARNING: This value is == kCurrentFileBlobIndexFileNumber.
|
||||
// Use this name only where file number zero means "no valid blob file" or
|
||||
// "current file" is not understood/supported.
|
||||
constexpr uint64_t kInvalidBlobFileNumber = 0;
|
||||
|
||||
// WARNING: This value is == kInvalidBlobFileNumber.
|
||||
// Use this name only for BlobIndex references to the same physical file as what
|
||||
// is currently being read; generic blob-file metadata must treat zero as
|
||||
// invalid. (Using a distinct value like 1 was found to be more problematic,
|
||||
// e.g. because of legacy "stackable" blob implementation.)
|
||||
//
|
||||
// This "zero is invalid unless you are the embedded reader/writer" contract is
|
||||
// enforced by integrity checks that reject file number zero on generic paths;
|
||||
// see FileMetaData::UpdateBoundaries (write/output path) and Version::GetBlob /
|
||||
// Version::MultiGetBlob (read path). Same-file references must be resolved (by
|
||||
// EmbeddedBlobResolvingIterator) before they reach those paths. Do not weaken
|
||||
// those checks -- they catch leaks/corruption closer to the root cause.
|
||||
constexpr uint64_t kCurrentFileBlobIndexFileNumber = kInvalidBlobFileNumber;
|
||||
static_assert(kCurrentFileBlobIndexFileNumber == kInvalidBlobFileNumber);
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "logging/logging.h"
|
||||
#include "options/cf_options.h"
|
||||
#include "options/options_helper.h"
|
||||
#include "rocksdb/file_system.h"
|
||||
#include "rocksdb/slice.h"
|
||||
#include "rocksdb/status.h"
|
||||
#include "test_util/sync_point.h"
|
||||
@@ -200,6 +201,8 @@ Status BlobFileBuilder::OpenBlobFileIfNeeded() {
|
||||
{
|
||||
assert(file_options_);
|
||||
fo_copy = *file_options_;
|
||||
fo_copy.open_contract = FileOpenContract::kNoReopenForWrite |
|
||||
FileOpenContract::kNoReadersWhileOpenForWrite;
|
||||
fo_copy.write_hint = write_hint_;
|
||||
Status s = NewWritableFile(fs_, blob_file_path, &file, fo_copy);
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ Status BlobFileCache::OpenBlobFileReaderUncached(
|
||||
Statistics* const statistics = immutable_options_->stats;
|
||||
RecordTick(statistics, NO_FILE_OPENS);
|
||||
|
||||
assert(file_options_);
|
||||
Status s = BlobFileReader::Create(
|
||||
*immutable_options_, read_options, *file_options_, column_family_id_,
|
||||
blob_file_read_hist_, blob_file_number, io_tracer_,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "file/read_write_util.h"
|
||||
#include "file/writable_file_writer.h"
|
||||
#include "logging/logging.h"
|
||||
#include "rocksdb/file_system.h"
|
||||
#include "util/aligned_buffer.h"
|
||||
#include "util/compression.h"
|
||||
#include "util/mutexlock.h"
|
||||
@@ -199,7 +200,9 @@ Status BlobFilePartitionManager::OpenNewBlobFile(Partition* partition,
|
||||
}
|
||||
|
||||
std::unique_ptr<FSWritableFile> file;
|
||||
Status s = NewWritableFile(fs_, blob_file_path, &file, file_options_);
|
||||
FileOptions writer_file_options = file_options_;
|
||||
writer_file_options.open_contract = FileOpenContract::kNoReopenForWrite;
|
||||
Status s = NewWritableFile(fs_, blob_file_path, &file, writer_file_options);
|
||||
if (!s.ok()) {
|
||||
RemoveFilePartitionMapping(blob_file_number);
|
||||
return s;
|
||||
@@ -208,7 +211,7 @@ Status BlobFilePartitionManager::OpenNewBlobFile(Partition* partition,
|
||||
const bool perform_data_verification =
|
||||
checksum_handoff_file_types_.Contains(FileType::kBlobFile);
|
||||
auto file_writer = std::make_unique<WritableFileWriter>(
|
||||
std::move(file), blob_file_path, file_options_, clock_, io_tracer_,
|
||||
std::move(file), blob_file_path, writer_file_options, clock_, io_tracer_,
|
||||
statistics_, Histograms::BLOB_DB_BLOB_FILE_WRITE_MICROS, listeners_,
|
||||
file_checksum_gen_factory_, perform_data_verification);
|
||||
|
||||
|
||||
+35
-31
@@ -12,6 +12,7 @@
|
||||
#include "db/blob/blob_log_format.h"
|
||||
#include "file/file_prefetch_buffer.h"
|
||||
#include "file/filename.h"
|
||||
#include "file/read_write_util.h"
|
||||
#include "monitoring/statistics_impl.h"
|
||||
#include "options/cf_options.h"
|
||||
#include "rocksdb/file_system.h"
|
||||
@@ -20,6 +21,7 @@
|
||||
#include "table/format.h"
|
||||
#include "table/multiget_context.h"
|
||||
#include "test_util/sync_point.h"
|
||||
#include "util/aligned_buffer.h"
|
||||
#include "util/compression.h"
|
||||
#include "util/stop_watch.h"
|
||||
|
||||
@@ -105,24 +107,6 @@ Status BlobFileReader::OpenFile(
|
||||
|
||||
constexpr IODebugContext* dbg = nullptr;
|
||||
|
||||
{
|
||||
TEST_SYNC_POINT("BlobFileReader::OpenFile:GetFileSize");
|
||||
|
||||
const Status s =
|
||||
fs->GetFileSize(blob_file_path, IOOptions(), file_size, dbg);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip_footer_size_check &&
|
||||
*file_size < BlobLogHeader::kSize + BlobLogFooter::kSize) {
|
||||
return Status::Corruption("Malformed blob file");
|
||||
}
|
||||
if (skip_footer_size_check && *file_size < BlobLogHeader::kSize) {
|
||||
return Status::Corruption("Malformed blob file");
|
||||
}
|
||||
|
||||
std::unique_ptr<FSRandomAccessFile> file;
|
||||
FileOptions reader_file_opts = file_opts;
|
||||
|
||||
@@ -142,6 +126,24 @@ Status BlobFileReader::OpenFile(
|
||||
|
||||
assert(file);
|
||||
|
||||
{
|
||||
Status s = GetFileSizeFromOpenFileOrPath(
|
||||
file.get(), fs, blob_file_path, file_size, dbg,
|
||||
FileSizeFallback::kNotSupportedOnly,
|
||||
[]() { TEST_SYNC_POINT("BlobFileReader::OpenFile:GetFileSize"); });
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip_footer_size_check &&
|
||||
*file_size < BlobLogHeader::kSize + BlobLogFooter::kSize) {
|
||||
return Status::Corruption("Malformed blob file");
|
||||
}
|
||||
if (skip_footer_size_check && *file_size < BlobLogHeader::kSize) {
|
||||
return Status::Corruption("Malformed blob file");
|
||||
}
|
||||
|
||||
if (immutable_options.advise_random_on_open) {
|
||||
file->Hint(FSRandomAccessFile::kRandom);
|
||||
}
|
||||
@@ -165,7 +167,7 @@ Status BlobFileReader::ReadHeader(const RandomAccessFileReader* file_reader,
|
||||
|
||||
Slice header_slice;
|
||||
Buffer buf;
|
||||
AlignedBuf aligned_buf;
|
||||
AlignedBuffer direct_io_buffer;
|
||||
|
||||
{
|
||||
TEST_SYNC_POINT("BlobFileReader::ReadHeader:ReadFromFile");
|
||||
@@ -175,7 +177,7 @@ Status BlobFileReader::ReadHeader(const RandomAccessFileReader* file_reader,
|
||||
|
||||
const Status s =
|
||||
ReadFromFile(file_reader, read_options, read_offset, read_size,
|
||||
statistics, &header_slice, &buf, &aligned_buf);
|
||||
statistics, &header_slice, &buf, &direct_io_buffer);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
@@ -216,7 +218,7 @@ Status BlobFileReader::ReadFooter(const RandomAccessFileReader* file_reader,
|
||||
|
||||
Slice footer_slice;
|
||||
Buffer buf;
|
||||
AlignedBuf aligned_buf;
|
||||
AlignedBuffer direct_io_buffer;
|
||||
|
||||
{
|
||||
TEST_SYNC_POINT("BlobFileReader::ReadFooter:ReadFromFile");
|
||||
@@ -226,7 +228,7 @@ Status BlobFileReader::ReadFooter(const RandomAccessFileReader* file_reader,
|
||||
|
||||
const Status s =
|
||||
ReadFromFile(file_reader, read_options, read_offset, read_size,
|
||||
statistics, &footer_slice, &buf, &aligned_buf);
|
||||
statistics, &footer_slice, &buf, &direct_io_buffer);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
@@ -257,10 +259,11 @@ Status BlobFileReader::ReadFromFile(const RandomAccessFileReader* file_reader,
|
||||
const ReadOptions& read_options,
|
||||
uint64_t read_offset, size_t read_size,
|
||||
Statistics* statistics, Slice* slice,
|
||||
Buffer* buf, AlignedBuf* aligned_buf) {
|
||||
Buffer* buf,
|
||||
AlignedBuffer* direct_io_buffer) {
|
||||
assert(slice);
|
||||
assert(buf);
|
||||
assert(aligned_buf);
|
||||
assert(direct_io_buffer);
|
||||
|
||||
assert(file_reader);
|
||||
|
||||
@@ -277,15 +280,15 @@ Status BlobFileReader::ReadFromFile(const RandomAccessFileReader* file_reader,
|
||||
|
||||
if (file_reader->use_direct_io()) {
|
||||
constexpr char* scratch = nullptr;
|
||||
AlignedBufferAllocationContext direct_io_context{direct_io_buffer};
|
||||
|
||||
s = file_reader->Read(io_options, read_offset, read_size, slice, scratch,
|
||||
aligned_buf, &dbg);
|
||||
&direct_io_context, &dbg);
|
||||
} else {
|
||||
buf->reset(new char[read_size]);
|
||||
constexpr AlignedBuf* aligned_scratch = nullptr;
|
||||
|
||||
s = file_reader->Read(io_options, read_offset, read_size, slice, buf->get(),
|
||||
aligned_scratch, &dbg);
|
||||
nullptr, &dbg);
|
||||
}
|
||||
|
||||
if (!s.ok()) {
|
||||
@@ -349,7 +352,7 @@ Status BlobFileReader::GetBlob(
|
||||
|
||||
Slice record_slice;
|
||||
Buffer buf;
|
||||
AlignedBuf aligned_buf;
|
||||
AlignedBuffer direct_io_buffer;
|
||||
|
||||
bool prefetched = false;
|
||||
|
||||
@@ -379,7 +382,7 @@ Status BlobFileReader::GetBlob(
|
||||
const Status s =
|
||||
ReadFromFile(file_reader_.get(), read_options, record_offset,
|
||||
static_cast<size_t>(record_size), statistics_,
|
||||
&record_slice, &buf, &aligned_buf);
|
||||
&record_slice, &buf, &direct_io_buffer);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
@@ -477,7 +480,7 @@ void BlobFileReader::MultiGetBlob(
|
||||
}
|
||||
|
||||
Buffer buf;
|
||||
AlignedBuf aligned_buf;
|
||||
AlignedBuffer direct_io_buffer;
|
||||
|
||||
Status s;
|
||||
bool direct_io = file_reader_->use_direct_io();
|
||||
@@ -500,8 +503,9 @@ void BlobFileReader::MultiGetBlob(
|
||||
IODebugContext dbg;
|
||||
s = file_reader_->PrepareIOOptions(read_options, opts, &dbg);
|
||||
if (s.ok()) {
|
||||
AlignedBufferAllocationContext direct_io_context{&direct_io_buffer};
|
||||
s = file_reader_->MultiRead(opts, read_reqs.data(), read_reqs.size(),
|
||||
direct_io ? &aligned_buf : nullptr, &dbg);
|
||||
&direct_io_context, &dbg);
|
||||
}
|
||||
if (!s.ok()) {
|
||||
for (auto& req : read_reqs) {
|
||||
|
||||
@@ -108,7 +108,7 @@ class BlobFileReader {
|
||||
const ReadOptions& read_options,
|
||||
uint64_t read_offset, size_t read_size,
|
||||
Statistics* statistics, Slice* slice, Buffer* buf,
|
||||
AlignedBuf* aligned_buf);
|
||||
AlignedBuffer* direct_io_buffer);
|
||||
|
||||
static Status VerifyBlob(const Slice& record_slice, const Slice& user_key,
|
||||
uint64_t value_size);
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "db/blob/blob_contents.h"
|
||||
#include "db/blob/blob_log_format.h"
|
||||
#include "db/blob/blob_log_writer.h"
|
||||
#include "env/composite_env_wrapper.h"
|
||||
#include "env/mock_env.h"
|
||||
#include "file/filename.h"
|
||||
#include "file/read_write_util.h"
|
||||
@@ -136,6 +138,167 @@ class BlobFileReaderTest : public testing::Test {
|
||||
std::unique_ptr<Env> mock_env_;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns a stale path-level size for one target blob file while leaving the
|
||||
// opened file handle untouched. This lets the test verify
|
||||
// BlobFileReader::Create prefers the opened handle's size when the path stat
|
||||
// lags behind.
|
||||
class StalePathSizeFileSystem : public FileSystemWrapper {
|
||||
public:
|
||||
static const char* kClassName() { return "StalePathSizeFileSystem"; }
|
||||
|
||||
StalePathSizeFileSystem(const std::shared_ptr<FileSystem>& target,
|
||||
std::string stale_path)
|
||||
: FileSystemWrapper(target), stale_path_(std::move(stale_path)) {}
|
||||
|
||||
const char* Name() const override { return kClassName(); }
|
||||
|
||||
IOStatus GetFileSize(const std::string& fname, const IOOptions& options,
|
||||
uint64_t* file_size, IODebugContext* dbg) override {
|
||||
if (fname == stale_path_) {
|
||||
*file_size = 0;
|
||||
return IOStatus::OK();
|
||||
}
|
||||
return FileSystemWrapper::GetFileSize(fname, options, file_size, dbg);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string stale_path_;
|
||||
};
|
||||
|
||||
// Makes opened blob file handles fail GetFileSize() with a hard error so the
|
||||
// reader path can verify that such errors are propagated directly.
|
||||
class FailingOpenFileSizeRandomAccessFile
|
||||
: public FSRandomAccessFileOwnerWrapper {
|
||||
public:
|
||||
explicit FailingOpenFileSizeRandomAccessFile(
|
||||
std::unique_ptr<FSRandomAccessFile>&& target)
|
||||
: FSRandomAccessFileOwnerWrapper(std::move(target)) {}
|
||||
|
||||
IOStatus GetFileSize(uint64_t* /*result*/) override {
|
||||
return IOStatus::IOError("open file size failed");
|
||||
}
|
||||
};
|
||||
|
||||
// Makes opened blob file handles report GetFileSize() as unsupported so the
|
||||
// reader path exercises its path-level fallback logic.
|
||||
class NotSupportedOpenFileSizeRandomAccessFile
|
||||
: public FSRandomAccessFileOwnerWrapper {
|
||||
public:
|
||||
explicit NotSupportedOpenFileSizeRandomAccessFile(
|
||||
std::unique_ptr<FSRandomAccessFile>&& target)
|
||||
: FSRandomAccessFileOwnerWrapper(std::move(target)) {}
|
||||
|
||||
IOStatus GetFileSize(uint64_t* /*result*/) override {
|
||||
return IOStatus::NotSupported("open file size not supported");
|
||||
}
|
||||
};
|
||||
|
||||
class OpenFileSizeFileSystem : public FileSystemWrapper {
|
||||
public:
|
||||
OpenFileSizeFileSystem(const std::shared_ptr<FileSystem>& target,
|
||||
std::string target_path)
|
||||
: FileSystemWrapper(target), target_path_(std::move(target_path)) {}
|
||||
|
||||
IOStatus NewRandomAccessFile(const std::string& fname,
|
||||
const FileOptions& options,
|
||||
std::unique_ptr<FSRandomAccessFile>* result,
|
||||
IODebugContext* dbg) override {
|
||||
std::unique_ptr<FSRandomAccessFile> file;
|
||||
IOStatus s =
|
||||
FileSystemWrapper::NewRandomAccessFile(fname, options, &file, dbg);
|
||||
if (!s.ok()) {
|
||||
return IOStatus(std::move(s));
|
||||
}
|
||||
if (fname == target_path_) {
|
||||
*result = WrapTargetFile(std::move(file));
|
||||
} else {
|
||||
*result = std::move(file);
|
||||
}
|
||||
return IOStatus::OK();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<FSRandomAccessFile> WrapTargetFile(
|
||||
std::unique_ptr<FSRandomAccessFile>&& file) = 0;
|
||||
|
||||
private:
|
||||
const std::string target_path_;
|
||||
};
|
||||
|
||||
// Wraps the target blob file in FailingOpenFileSizeRandomAccessFile while
|
||||
// leaving all other files alone.
|
||||
class FailingOpenFileSizeFileSystem : public OpenFileSizeFileSystem {
|
||||
public:
|
||||
static const char* kClassName() { return "FailingOpenFileSizeFileSystem"; }
|
||||
|
||||
FailingOpenFileSizeFileSystem(const std::shared_ptr<FileSystem>& target,
|
||||
std::string target_path)
|
||||
: OpenFileSizeFileSystem(target, std::move(target_path)) {}
|
||||
|
||||
const char* Name() const override { return kClassName(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<FSRandomAccessFile> WrapTargetFile(
|
||||
std::unique_ptr<FSRandomAccessFile>&& file) override {
|
||||
return std::unique_ptr<FSRandomAccessFile>(
|
||||
new FailingOpenFileSizeRandomAccessFile(std::move(file)));
|
||||
}
|
||||
};
|
||||
|
||||
// Wraps the target blob file in NotSupportedOpenFileSizeRandomAccessFile while
|
||||
// leaving all other files alone.
|
||||
class NotSupportedOpenFileSizeFileSystem : public OpenFileSizeFileSystem {
|
||||
public:
|
||||
static const char* kClassName() {
|
||||
return "NotSupportedOpenFileSizeFileSystem";
|
||||
}
|
||||
|
||||
NotSupportedOpenFileSizeFileSystem(const std::shared_ptr<FileSystem>& target,
|
||||
std::string target_path)
|
||||
: OpenFileSizeFileSystem(target, std::move(target_path)) {}
|
||||
|
||||
const char* Name() const override { return kClassName(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<FSRandomAccessFile> WrapTargetFile(
|
||||
std::unique_ptr<FSRandomAccessFile>&& file) override {
|
||||
return std::unique_ptr<FSRandomAccessFile>(
|
||||
new NotSupportedOpenFileSizeRandomAccessFile(std::move(file)));
|
||||
}
|
||||
};
|
||||
|
||||
// Forces the target blob file onto the NotSupported open-handle-size branch and
|
||||
// then fails the fallback path-level GetFileSize() call.
|
||||
class FailingFallbackPathSizeFileSystem
|
||||
: public NotSupportedOpenFileSizeFileSystem {
|
||||
public:
|
||||
static const char* kClassName() {
|
||||
return "FailingFallbackPathSizeFileSystem";
|
||||
}
|
||||
|
||||
FailingFallbackPathSizeFileSystem(const std::shared_ptr<FileSystem>& target,
|
||||
std::string target_path)
|
||||
: NotSupportedOpenFileSizeFileSystem(target, target_path),
|
||||
target_path_(std::move(target_path)) {}
|
||||
|
||||
const char* Name() const override { return kClassName(); }
|
||||
|
||||
IOStatus GetFileSize(const std::string& fname, const IOOptions& options,
|
||||
uint64_t* file_size, IODebugContext* dbg) override {
|
||||
if (fname == target_path_) {
|
||||
return IOStatus::IOError("fallback path size failed");
|
||||
}
|
||||
return FileSystemWrapper::GetFileSize(fname, options, file_size, dbg);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string target_path_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(BlobFileReaderTest, CreateReaderAndGetBlob) {
|
||||
Options options;
|
||||
options.env = mock_env_.get();
|
||||
@@ -428,6 +591,211 @@ TEST_F(BlobFileReaderTest, CreateReaderAndGetBlob) {
|
||||
}
|
||||
}
|
||||
|
||||
// Verifies Create() prefers the file size reported by the opened handle over a
|
||||
// stale path-level size query by returning a readable reader even when the path
|
||||
// stat intentionally reports 0 for the blob file.
|
||||
TEST_F(BlobFileReaderTest, CreateReaderUsesOpenedFileSizeWhenPathSizeIsStale) {
|
||||
const std::string db_path = test::PerThreadDBPath(
|
||||
mock_env_.get(),
|
||||
"BlobFileReaderTest_CreateReaderUsesOpenedFileSizeWhenPathSizeIsStale");
|
||||
|
||||
constexpr uint64_t blob_file_number = 1;
|
||||
const std::string blob_file_path = BlobFileName(db_path, blob_file_number);
|
||||
|
||||
auto stale_size_fs = std::make_shared<StalePathSizeFileSystem>(
|
||||
mock_env_->GetFileSystem(), blob_file_path);
|
||||
CompositeEnvWrapper stale_size_env(mock_env_.get(), stale_size_fs);
|
||||
|
||||
Options options;
|
||||
options.env = &stale_size_env;
|
||||
options.cf_paths.emplace_back(db_path, 0);
|
||||
options.enable_blob_files = true;
|
||||
|
||||
ImmutableOptions immutable_options(options);
|
||||
|
||||
constexpr uint32_t column_family_id = 1;
|
||||
constexpr bool has_ttl = false;
|
||||
constexpr ExpirationRange expiration_range;
|
||||
constexpr char key[] = "key";
|
||||
constexpr char blob[] = "blob";
|
||||
|
||||
uint64_t blob_offset = 0;
|
||||
uint64_t blob_size = 0;
|
||||
WriteBlobFile(immutable_options, column_family_id, has_ttl, expiration_range,
|
||||
expiration_range, blob_file_number, key, blob, kNoCompression,
|
||||
&blob_offset, &blob_size);
|
||||
|
||||
std::unique_ptr<BlobFileReader> reader;
|
||||
ReadOptions read_options;
|
||||
read_options.verify_checksums = false;
|
||||
ASSERT_OK(BlobFileReader::Create(
|
||||
immutable_options, read_options, FileOptions(), column_family_id,
|
||||
/*blob_file_read_hist=*/nullptr, blob_file_number, nullptr /*IOTracer*/,
|
||||
&reader));
|
||||
ASSERT_NE(reader, nullptr);
|
||||
|
||||
std::unique_ptr<BlobContents> value;
|
||||
uint64_t bytes_read = 0;
|
||||
ASSERT_OK(reader->GetBlob(read_options, key, blob_offset, blob_size,
|
||||
kNoCompression,
|
||||
/*prefetch_buffer=*/nullptr,
|
||||
/*allocator=*/nullptr, &value, &bytes_read));
|
||||
ASSERT_NE(value, nullptr);
|
||||
ASSERT_EQ(value->data(), Slice(blob));
|
||||
ASSERT_EQ(bytes_read, blob_size);
|
||||
}
|
||||
|
||||
// Verifies Create() falls back to the path-level GetFileSize() call when the
|
||||
// opened file handle reports that size queries are unsupported.
|
||||
TEST_F(BlobFileReaderTest,
|
||||
CreateReaderFallsBackToPathSizeWhenOpenedFileSizeNotSupported) {
|
||||
const std::string db_path = test::PerThreadDBPath(
|
||||
mock_env_.get(),
|
||||
"BlobFileReaderTest_"
|
||||
"CreateReaderFallsBackToPathSizeWhenOpenedFileSizeNotSupported");
|
||||
|
||||
constexpr uint64_t blob_file_number = 1;
|
||||
const std::string blob_file_path = BlobFileName(db_path, blob_file_number);
|
||||
|
||||
auto not_supported_open_file_size_fs =
|
||||
std::make_shared<NotSupportedOpenFileSizeFileSystem>(
|
||||
mock_env_->GetFileSystem(), blob_file_path);
|
||||
CompositeEnvWrapper not_supported_open_file_size_env(
|
||||
mock_env_.get(), not_supported_open_file_size_fs);
|
||||
|
||||
Options options;
|
||||
options.env = ¬_supported_open_file_size_env;
|
||||
options.cf_paths.emplace_back(db_path, 0);
|
||||
options.enable_blob_files = true;
|
||||
|
||||
ImmutableOptions immutable_options(options);
|
||||
|
||||
constexpr uint32_t column_family_id = 1;
|
||||
constexpr bool has_ttl = false;
|
||||
constexpr ExpirationRange expiration_range;
|
||||
constexpr char key[] = "key";
|
||||
constexpr char blob[] = "blob";
|
||||
|
||||
uint64_t blob_offset = 0;
|
||||
uint64_t blob_size = 0;
|
||||
WriteBlobFile(immutable_options, column_family_id, has_ttl, expiration_range,
|
||||
expiration_range, blob_file_number, key, blob, kNoCompression,
|
||||
&blob_offset, &blob_size);
|
||||
|
||||
std::unique_ptr<BlobFileReader> reader;
|
||||
ReadOptions read_options;
|
||||
read_options.verify_checksums = false;
|
||||
ASSERT_OK(BlobFileReader::Create(
|
||||
immutable_options, read_options, FileOptions(), column_family_id,
|
||||
/*blob_file_read_hist=*/nullptr, blob_file_number, nullptr /*IOTracer*/,
|
||||
&reader));
|
||||
ASSERT_NE(reader, nullptr);
|
||||
|
||||
std::unique_ptr<BlobContents> value;
|
||||
uint64_t bytes_read = 0;
|
||||
ASSERT_OK(reader->GetBlob(read_options, key, blob_offset, blob_size,
|
||||
kNoCompression,
|
||||
/*prefetch_buffer=*/nullptr,
|
||||
/*allocator=*/nullptr, &value, &bytes_read));
|
||||
ASSERT_NE(value, nullptr);
|
||||
ASSERT_EQ(value->data(), Slice(blob));
|
||||
ASSERT_EQ(bytes_read, blob_size);
|
||||
}
|
||||
|
||||
// Verifies Create() propagates a real error from the opened file handle's
|
||||
// GetFileSize() rather than masking it with any path-level fallback.
|
||||
TEST_F(BlobFileReaderTest, CreateReaderPropagatesOpenedFileSizeError) {
|
||||
const std::string db_path = test::PerThreadDBPath(
|
||||
mock_env_.get(),
|
||||
"BlobFileReaderTest_CreateReaderPropagatesOpenedFileSizeError");
|
||||
|
||||
constexpr uint64_t blob_file_number = 1;
|
||||
const std::string blob_file_path = BlobFileName(db_path, blob_file_number);
|
||||
|
||||
auto failing_open_file_size_fs =
|
||||
std::make_shared<FailingOpenFileSizeFileSystem>(
|
||||
mock_env_->GetFileSystem(), blob_file_path);
|
||||
CompositeEnvWrapper failing_open_file_size_env(mock_env_.get(),
|
||||
failing_open_file_size_fs);
|
||||
|
||||
Options options;
|
||||
options.env = &failing_open_file_size_env;
|
||||
options.cf_paths.emplace_back(db_path, 0);
|
||||
options.enable_blob_files = true;
|
||||
|
||||
ImmutableOptions immutable_options(options);
|
||||
|
||||
constexpr uint32_t column_family_id = 1;
|
||||
constexpr bool has_ttl = false;
|
||||
constexpr ExpirationRange expiration_range;
|
||||
constexpr char key[] = "key";
|
||||
constexpr char blob[] = "blob";
|
||||
|
||||
uint64_t blob_offset = 0;
|
||||
uint64_t blob_size = 0;
|
||||
WriteBlobFile(immutable_options, column_family_id, has_ttl, expiration_range,
|
||||
expiration_range, blob_file_number, key, blob, kNoCompression,
|
||||
&blob_offset, &blob_size);
|
||||
|
||||
std::unique_ptr<BlobFileReader> reader;
|
||||
ReadOptions read_options;
|
||||
Status s = BlobFileReader::Create(
|
||||
immutable_options, read_options, FileOptions(), column_family_id,
|
||||
/*blob_file_read_hist=*/nullptr, blob_file_number, nullptr /*IOTracer*/,
|
||||
&reader);
|
||||
ASSERT_TRUE(s.IsIOError());
|
||||
ASSERT_EQ(reader, nullptr);
|
||||
}
|
||||
|
||||
// Verifies Create() also propagates errors from the path-level fallback size
|
||||
// query when the opened file handle only reports NotSupported for GetFileSize.
|
||||
TEST_F(
|
||||
BlobFileReaderTest,
|
||||
CreateReaderPropagatesFallbackPathSizeErrorWhenOpenedFileSizeNotSupported) {
|
||||
const std::string db_path =
|
||||
test::PerThreadDBPath(mock_env_.get(),
|
||||
"BlobFileReaderTest_"
|
||||
"CreateReaderPropagatesFallbackPathSizeErrorWhenOpe"
|
||||
"nedFileSizeNotSupported");
|
||||
|
||||
constexpr uint64_t blob_file_number = 1;
|
||||
const std::string blob_file_path = BlobFileName(db_path, blob_file_number);
|
||||
|
||||
auto failing_fallback_path_size_fs =
|
||||
std::make_shared<FailingFallbackPathSizeFileSystem>(
|
||||
mock_env_->GetFileSystem(), blob_file_path);
|
||||
CompositeEnvWrapper failing_fallback_path_size_env(
|
||||
mock_env_.get(), failing_fallback_path_size_fs);
|
||||
|
||||
Options options;
|
||||
options.env = &failing_fallback_path_size_env;
|
||||
options.cf_paths.emplace_back(db_path, 0);
|
||||
options.enable_blob_files = true;
|
||||
|
||||
ImmutableOptions immutable_options(options);
|
||||
|
||||
constexpr uint32_t column_family_id = 1;
|
||||
constexpr bool has_ttl = false;
|
||||
constexpr ExpirationRange expiration_range;
|
||||
constexpr char key[] = "key";
|
||||
constexpr char blob[] = "blob";
|
||||
|
||||
uint64_t blob_offset = 0;
|
||||
uint64_t blob_size = 0;
|
||||
WriteBlobFile(immutable_options, column_family_id, has_ttl, expiration_range,
|
||||
expiration_range, blob_file_number, key, blob, kNoCompression,
|
||||
&blob_offset, &blob_size);
|
||||
|
||||
std::unique_ptr<BlobFileReader> reader;
|
||||
ReadOptions read_options;
|
||||
Status s = BlobFileReader::Create(
|
||||
immutable_options, read_options, FileOptions(), column_family_id,
|
||||
/*blob_file_read_hist=*/nullptr, blob_file_number, nullptr /*IOTracer*/,
|
||||
&reader);
|
||||
ASSERT_TRUE(s.IsIOError());
|
||||
ASSERT_EQ(reader, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(BlobFileReaderTest, Malformed) {
|
||||
// Write a blob file consisting of nothing but a header, and make sure we
|
||||
// detect the error when we open it for reading
|
||||
@@ -849,7 +1217,6 @@ class BlobFileReaderIOErrorTest
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BlobFileReaderTest, BlobFileReaderIOErrorTest,
|
||||
::testing::ValuesIn(std::vector<std::string>{
|
||||
"BlobFileReader::OpenFile:GetFileSize",
|
||||
"BlobFileReader::OpenFile:NewRandomAccessFile",
|
||||
"BlobFileReader::ReadHeader:ReadFromFile",
|
||||
"BlobFileReader::ReadFooter:ReadFromFile",
|
||||
|
||||
@@ -32,6 +32,9 @@ Status BlobGarbageMeter::GetBlobReferenceDetails(const ParsedInternalKey& ikey,
|
||||
if (blob_index.IsInlined() || blob_index.HasTTL()) {
|
||||
return Status::Corruption("Unexpected TTL/inlined blob index");
|
||||
}
|
||||
if (blob_index.IsSameFile()) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
*blob_file_number = blob_index.file_number();
|
||||
*bytes =
|
||||
@@ -125,7 +128,9 @@ Status BlobGarbageMeter::ProcessEntityBlobReferences(
|
||||
!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
if (file_number != kInvalidBlobFileNumber) {
|
||||
AddFlow(file_number, blob_bytes, is_inflow);
|
||||
}
|
||||
return Status::OK();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,6 +151,24 @@ TEST(BlobGarbageMeterTest, PlainValue) {
|
||||
ASSERT_TRUE(blob_garbage_meter.flows().empty());
|
||||
}
|
||||
|
||||
TEST(BlobGarbageMeterTest, SameFileBlobIndex) {
|
||||
constexpr char user_key[] = "user_key";
|
||||
constexpr SequenceNumber seq = 123;
|
||||
|
||||
const InternalKey key(user_key, seq, kTypeBlobIndex);
|
||||
const Slice key_slice = key.Encode();
|
||||
|
||||
std::string value;
|
||||
BlobIndex::EncodeBlob(&value, kCurrentFileBlobIndexFileNumber,
|
||||
/*offset=*/123, /*size=*/456, kNoCompression);
|
||||
|
||||
BlobGarbageMeter blob_garbage_meter;
|
||||
|
||||
ASSERT_OK(blob_garbage_meter.ProcessInFlow(key_slice, value));
|
||||
ASSERT_OK(blob_garbage_meter.ProcessOutFlow(key_slice, value));
|
||||
ASSERT_TRUE(blob_garbage_meter.flows().empty());
|
||||
}
|
||||
|
||||
TEST(BlobGarbageMeterTest, CorruptInternalKey) {
|
||||
constexpr char corrupt_key[] = "i_am_corrupt";
|
||||
const Slice key_slice(corrupt_key);
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
// 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).
|
||||
|
||||
#include "db/blob/blob_gen2_format.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "file/random_access_file_reader.h"
|
||||
#include "file/writable_file_writer.h"
|
||||
#include "rocksdb/options.h"
|
||||
#include "rocksdb/slice.h"
|
||||
#include "table/format.h"
|
||||
#include "util/cast_util.h"
|
||||
#include "util/coding.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
Status ReadAndVerifySimpleGen2BlobRecord(
|
||||
const ReadOptions& read_options, RandomAccessFileReader* file,
|
||||
uint64_t record_offset, size_t payload_size, size_t record_size,
|
||||
ChecksumType checksum_type, uint32_t base_context_checksum,
|
||||
CompressionType expected_compression, char* buf) {
|
||||
assert(file != nullptr);
|
||||
assert(buf != nullptr);
|
||||
assert(record_size == payload_size + kSimpleGen2BlobTrailerSize);
|
||||
|
||||
Slice result;
|
||||
IOOptions opts;
|
||||
IODebugContext dbg;
|
||||
Status s = file->PrepareIOOptions(read_options, opts, &dbg);
|
||||
if (s.ok()) {
|
||||
s = file->Read(opts, record_offset, record_size, &result, buf, nullptr,
|
||||
&dbg);
|
||||
}
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
if (result.size() != record_size) {
|
||||
return Status::Corruption("Could not read complete blob record");
|
||||
}
|
||||
// With mmap reads the data lands outside `buf`; copy it in so the caller can
|
||||
// rely on `buf` owning the bytes (this is the only copy on the mmap path).
|
||||
// TODO: fix this extra memcpy in the mmap case
|
||||
if (result.data() != buf) {
|
||||
memcpy(buf, result.data(), record_size);
|
||||
}
|
||||
|
||||
const char* record = buf;
|
||||
const CompressionType compression =
|
||||
static_cast<CompressionType>(record[payload_size]);
|
||||
if (compression != expected_compression) {
|
||||
return Status::Corruption(
|
||||
"Blob record compression does not match blob index");
|
||||
}
|
||||
|
||||
if (read_options.verify_checksums) {
|
||||
uint32_t stored = DecodeFixed32(record + payload_size + 1);
|
||||
stored -= ChecksumModifierForContext(base_context_checksum, record_offset);
|
||||
const uint32_t computed = ComputeBuiltinChecksumWithLastByte(
|
||||
checksum_type, record, payload_size, record[payload_size]);
|
||||
if (stored != computed) {
|
||||
return Status::Corruption("Blob record checksum mismatch in " +
|
||||
file->file_name() + " offset " +
|
||||
std::to_string(record_offset) + " size " +
|
||||
std::to_string(payload_size));
|
||||
}
|
||||
}
|
||||
|
||||
if (compression != kNoCompression) {
|
||||
return Status::Corruption("Blob record compression is not supported");
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
IOStatus WriteSimpleGen2BlobRecord(WritableFileWriter* file,
|
||||
const WriteOptions& write_options,
|
||||
ChecksumType checksum_type,
|
||||
uint32_t base_context_checksum,
|
||||
uint64_t record_offset, const Slice& payload,
|
||||
CompressionType compression) {
|
||||
assert(file != nullptr);
|
||||
// Placeholder for future embedded blob compression support; only
|
||||
// uncompressed payloads are currently written.
|
||||
assert(compression == kNoCompression);
|
||||
|
||||
std::array<char, kSimpleGen2BlobTrailerSize> trailer;
|
||||
trailer[0] = lossless_cast<char>(compression);
|
||||
uint32_t checksum = ComputeBuiltinChecksumWithLastByte(
|
||||
checksum_type, payload.data(), payload.size(), /*last_byte=*/trailer[0]);
|
||||
checksum += ChecksumModifierForContext(base_context_checksum, record_offset);
|
||||
EncodeFixed32(trailer.data() + 1, checksum);
|
||||
|
||||
IOOptions opts;
|
||||
IOStatus io_s = WritableFileWriter::PrepareIOOptions(write_options, opts);
|
||||
if (!io_s.ok()) {
|
||||
return io_s;
|
||||
}
|
||||
if (!payload.empty()) {
|
||||
io_s = file->Append(opts, payload);
|
||||
if (!io_s.ok()) {
|
||||
return io_s;
|
||||
}
|
||||
}
|
||||
return file->Append(opts, Slice(trailer.data(), trailer.size()));
|
||||
}
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
@@ -0,0 +1,92 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
// 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).
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "cache/cache_key.h"
|
||||
#include "rocksdb/compression_type.h"
|
||||
#include "rocksdb/io_status.h"
|
||||
#include "rocksdb/rocksdb_namespace.h"
|
||||
#include "rocksdb/status.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
struct ReadOptions;
|
||||
struct WriteOptions;
|
||||
class RandomAccessFileReader;
|
||||
class WritableFileWriter;
|
||||
class Slice;
|
||||
enum ChecksumType : char;
|
||||
|
||||
// "SimpleGen2Blob" is the second-generation on-disk format for a blob payload
|
||||
// referenced by a same-file / context-relative blob index. A record is just the
|
||||
// payload bytes followed by a small block-style trailer:
|
||||
//
|
||||
// <payload bytes> <1-byte compression marker> <4-byte checksum>
|
||||
//
|
||||
// The checksum is a builtin block checksum over (payload + compression marker),
|
||||
// context-modified by the record's absolute file offset (see
|
||||
// ChecksumModifierForContext / ComputeBuiltinChecksumWithLastByte in
|
||||
// table/format.h) so that an identical payload at a different offset gets a
|
||||
// different stored checksum. Payloads are currently uncompressed only.
|
||||
//
|
||||
// This format is deliberately decoupled from any particular file type: the same
|
||||
// record shape is read out of SST files (embedded blobs) and is intended to be
|
||||
// reused by other blob-bearing files. The only file-type-specific inputs are
|
||||
// the byte source (a RandomAccessFileReader) and the checksum context (checksum
|
||||
// type + base context checksum), both passed in by the caller.
|
||||
inline constexpr size_t kSimpleGen2BlobTrailerSize = 5;
|
||||
|
||||
// Cache key for the SimpleGen2Blob record at byte `record_offset` within a file
|
||||
// whose base cache key is `base_cache_key`. Delegates to the shared
|
||||
// OffsetableCacheKey::WithOffsetForMinSizeRecord scheme -- the exact same
|
||||
// scheme block-based SST data blocks use via BlockBasedTable::GetCacheKey --
|
||||
// which is valid because a SimpleGen2Blob record always carries a >= 5-byte
|
||||
// trailer. As a result the cache key is collision-free with the file's data
|
||||
// blocks even when the blob cache and block cache are the same cache, with no
|
||||
// separately maintained algorithm to drift out of sync.
|
||||
inline CacheKey GetSimpleGen2BlobCacheKey(
|
||||
const OffsetableCacheKey& base_cache_key, uint64_t record_offset) {
|
||||
return base_cache_key.WithOffsetForMinSizeRecord(record_offset);
|
||||
}
|
||||
|
||||
// Reads a SimpleGen2Blob record of `record_size` bytes (which must equal
|
||||
// `payload_size + kSimpleGen2BlobTrailerSize`) from `file` at `record_offset`
|
||||
// into `buf` (capacity >= record_size) and verifies its compression marker and,
|
||||
// when read_options.verify_checksums is set, its context-modified checksum.
|
||||
//
|
||||
// `checksum_type` and `base_context_checksum` are the file's checksum context
|
||||
// (e.g. from the SST footer). `expected_compression` is the compression type
|
||||
// the caller expects the record to carry (from the blob index); it must match
|
||||
// the record's marker, and currently must be kNoCompression.
|
||||
//
|
||||
// On success, buf[0, payload_size) holds the verified, uncompressed payload
|
||||
// (the trailer remains at the tail of `buf` and can be ignored).
|
||||
Status ReadAndVerifySimpleGen2BlobRecord(
|
||||
const ReadOptions& read_options, RandomAccessFileReader* file,
|
||||
uint64_t record_offset, size_t payload_size, size_t record_size,
|
||||
ChecksumType checksum_type, uint32_t base_context_checksum,
|
||||
CompressionType expected_compression, char* buf);
|
||||
|
||||
// Writes a SimpleGen2Blob record for `payload` at the current end of `file`,
|
||||
// which the caller asserts is byte offset `record_offset`. Appends the payload
|
||||
// bytes followed by the 5-byte trailer (compression marker + context-modified
|
||||
// builtin checksum), mirroring ReadAndVerifySimpleGen2BlobRecord so the on-disk
|
||||
// record format lives in one module.
|
||||
//
|
||||
// `checksum_type` and `base_context_checksum` are the file's checksum context
|
||||
// (e.g. from the SST footer). `compression` is the payload's compression type,
|
||||
// which currently must be kNoCompression.
|
||||
IOStatus WriteSimpleGen2BlobRecord(WritableFileWriter* file,
|
||||
const WriteOptions& write_options,
|
||||
ChecksumType checksum_type,
|
||||
uint32_t base_context_checksum,
|
||||
uint64_t record_offset, const Slice& payload,
|
||||
CompressionType compression);
|
||||
|
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
+16
-2
@@ -7,6 +7,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "db/blob/blob_constants.h"
|
||||
#include "rocksdb/compression_type.h"
|
||||
#include "util/coding.h"
|
||||
#include "util/compression.h"
|
||||
@@ -57,6 +58,14 @@ class BlobIndex {
|
||||
|
||||
bool IsInlined() const { return type_ == Type::kInlinedTTL; }
|
||||
|
||||
// True for a blob record stored in the same physical file as the table entry.
|
||||
// Only embedded-blob SST reader/writer paths should interpret file number
|
||||
// zero this way; generic blob metadata treats it as invalid.
|
||||
bool IsSameFile() const {
|
||||
return (type_ == Type::kBlob || type_ == Type::kBlobTTL) &&
|
||||
file_number_ == kCurrentFileBlobIndexFileNumber;
|
||||
}
|
||||
|
||||
bool HasTTL() const {
|
||||
return type_ == Type::kInlinedTTL || type_ == Type::kBlobTTL;
|
||||
}
|
||||
@@ -125,8 +134,13 @@ class BlobIndex {
|
||||
if (IsInlined()) {
|
||||
oss << "[inlined blob] value:" << value_.ToString(output_hex);
|
||||
} else {
|
||||
oss << "[blob ref] file:" << file_number_ << " offset:" << offset_
|
||||
<< " size:" << size_
|
||||
oss << "[blob ref] file:";
|
||||
if (IsSameFile()) {
|
||||
oss << "same";
|
||||
} else {
|
||||
oss << file_number_;
|
||||
}
|
||||
oss << " offset:" << offset_ << " size:" << size_
|
||||
<< " compression: " << CompressionTypeToString(compression_);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,10 @@
|
||||
#include "cache/charged_cache.h"
|
||||
#include "db/blob/blob_contents.h"
|
||||
#include "db/blob/blob_file_reader.h"
|
||||
#include "db/blob/blob_gen2_format.h"
|
||||
#include "db/blob/blob_log_format.h"
|
||||
#include "file/random_access_file_reader.h"
|
||||
#include "memory/memory_allocator_impl.h"
|
||||
#include "monitoring/statistics_impl.h"
|
||||
#include "options/cf_options.h"
|
||||
#include "table/get_context.h"
|
||||
@@ -74,6 +77,7 @@ Status BlobSource::GetBlobFromCache(
|
||||
assert(cached_blob->GetValue());
|
||||
|
||||
PERF_COUNTER_ADD(blob_cache_hit_count, 1);
|
||||
PERF_COUNTER_ADD(blob_cache_read_byte, cached_blob->GetValue()->size());
|
||||
RecordTick(statistics_, BLOB_DB_CACHE_HIT);
|
||||
RecordTick(statistics_, BLOB_DB_CACHE_BYTES_READ,
|
||||
cached_blob->GetValue()->size());
|
||||
@@ -304,6 +308,96 @@ Status BlobSource::GetBlob(const ReadOptions& read_options,
|
||||
return s;
|
||||
}
|
||||
|
||||
Status BlobSource::GetSimpleGen2Blob(
|
||||
const ReadOptions& read_options, const OffsetableCacheKey& base_cache_key,
|
||||
RandomAccessFileReader* file, uint64_t record_offset, uint64_t payload_size,
|
||||
ChecksumType checksum_type, uint32_t base_context_checksum,
|
||||
CompressionType expected_compression, PinnableSlice* value,
|
||||
uint64_t* bytes_read) {
|
||||
assert(value);
|
||||
assert(file);
|
||||
|
||||
const uint64_t record_size = payload_size + kSimpleGen2BlobTrailerSize;
|
||||
|
||||
// The cache key is derived from the SimpleGen2Blob format (shared scheme with
|
||||
// block-based SST blocks); see GetSimpleGen2BlobCacheKey.
|
||||
const CacheKey cache_key =
|
||||
GetSimpleGen2BlobCacheKey(base_cache_key, record_offset);
|
||||
|
||||
Status s;
|
||||
|
||||
CacheHandleGuard<BlobContents> blob_handle;
|
||||
|
||||
// First, try to get the blob from the cache.
|
||||
if (blob_cache_) {
|
||||
Slice key = cache_key.AsSlice();
|
||||
s = GetBlobFromCache(key, &blob_handle);
|
||||
if (s.ok()) {
|
||||
PinCachedBlob(&blob_handle, value);
|
||||
|
||||
// For consistency, the on-disk record size is assigned to bytes_read on
|
||||
// both cache hits and misses.
|
||||
if (bytes_read) {
|
||||
*bytes_read = record_size;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
assert(blob_handle.IsEmpty());
|
||||
|
||||
const bool no_io = read_options.read_tier == kBlockCacheTier;
|
||||
if (no_io) {
|
||||
return Status::Incomplete("Cannot read blob(s): no disk I/O allowed");
|
||||
}
|
||||
|
||||
// Cache miss (or no cache configured). Read the record into a buffer
|
||||
// allocated from the blob cache's memory allocator when we intend to insert
|
||||
// it, exposing the uncompressed payload as BlobContents (the trailer just
|
||||
// sits unused at the tail of the buffer).
|
||||
MemoryAllocator* const allocator = (blob_cache_ && read_options.fill_cache)
|
||||
? blob_cache_.get()->memory_allocator()
|
||||
: nullptr;
|
||||
|
||||
CacheAllocationPtr buf =
|
||||
AllocateBlock(static_cast<size_t>(record_size), allocator);
|
||||
s = ReadAndVerifySimpleGen2BlobRecord(
|
||||
read_options, file, record_offset, static_cast<size_t>(payload_size),
|
||||
static_cast<size_t>(record_size), checksum_type, base_context_checksum,
|
||||
expected_compression, buf.get());
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::unique_ptr<BlobContents> blob_contents(
|
||||
new BlobContents(std::move(buf), static_cast<size_t>(payload_size)));
|
||||
|
||||
// Record the per-read statistics (mirrors BlobFileReader::GetBlob).
|
||||
RecordTick(statistics_, BLOB_DB_BLOB_FILE_BYTES_READ, record_size);
|
||||
PERF_COUNTER_ADD(blob_read_count, 1);
|
||||
PERF_COUNTER_ADD(blob_read_byte, record_size);
|
||||
if (bytes_read) {
|
||||
*bytes_read = record_size;
|
||||
}
|
||||
|
||||
if (blob_cache_ && read_options.fill_cache) {
|
||||
// If filling cache is allowed and a cache is configured, try to put the
|
||||
// blob into the cache.
|
||||
Slice key = cache_key.AsSlice();
|
||||
s = PutBlobIntoCache(key, &blob_contents, &blob_handle);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
PinCachedBlob(&blob_handle, value);
|
||||
} else {
|
||||
PinOwnedBlob(&blob_contents, value);
|
||||
}
|
||||
|
||||
assert(s.ok());
|
||||
return s;
|
||||
}
|
||||
|
||||
void BlobSource::MultiGetBlob(const ReadOptions& read_options,
|
||||
autovector<BlobFileReadRequests>& blob_reqs,
|
||||
uint64_t* bytes_read) {
|
||||
|
||||
@@ -25,6 +25,8 @@ struct MutableCFOptions;
|
||||
class Status;
|
||||
class FilePrefetchBuffer;
|
||||
class Slice;
|
||||
class RandomAccessFileReader;
|
||||
enum ChecksumType : char;
|
||||
|
||||
// BlobSource is a class that provides universal access to blobs, regardless of
|
||||
// whether they are in the blob cache, secondary cache, or (remote) storage.
|
||||
@@ -59,6 +61,41 @@ class BlobSource {
|
||||
FilePrefetchBuffer* prefetch_buffer, PinnableSlice* value,
|
||||
uint64_t* bytes_read);
|
||||
|
||||
// Reads a SimpleGen2Blob payload (see db/blob/blob_gen2_format.h) through the
|
||||
// blob value cache and BLOB_DB_* statistics. This is the counterpart to
|
||||
// GetBlob() for the second-generation blob record format, which is read
|
||||
// directly from a RandomAccessFileReader rather than from a traditional blob
|
||||
// file.
|
||||
//
|
||||
// The cache key is derived from the SimpleGen2Blob format itself, not chosen
|
||||
// by the caller: it is GetSimpleGen2BlobCacheKey(base_cache_key,
|
||||
// record_offset), the same offset scheme block-based SST blocks use. The
|
||||
// caller supplies only its file's `base_cache_key` (db_id / db_session_id /
|
||||
// file_number). This keeps blob records collision-free with the file's data
|
||||
// blocks even when the blob cache and block cache are the same cache.
|
||||
//
|
||||
// `file`, `record_offset`, `payload_size`, `checksum_type`,
|
||||
// `base_context_checksum`, and `expected_compression` are the inputs to the
|
||||
// SimpleGen2Blob reader used on a cache miss (see
|
||||
// ReadAndVerifySimpleGen2BlobRecord). The on-disk record size (payload +
|
||||
// trailer) is reported via `*bytes_read` (when non-null) and the
|
||||
// BLOB_DB_BLOB_FILE_BYTES_READ / blob_read_byte counters, consistently on
|
||||
// both cache hits and misses.
|
||||
//
|
||||
// On a cache hit, pins the cached value into `*value` (no copy). On a miss,
|
||||
// reads + verifies the record into a cache-allocator buffer, records the
|
||||
// per-read stats, inserts it into the cache (when configured and fill_cache
|
||||
// is set), and pins it into `*value`. If blob_cache_ is not configured, the
|
||||
// record is still read and read stats recorded, just without a cache
|
||||
// lookup/insert.
|
||||
Status GetSimpleGen2Blob(const ReadOptions& read_options,
|
||||
const OffsetableCacheKey& base_cache_key,
|
||||
RandomAccessFileReader* file, uint64_t record_offset,
|
||||
uint64_t payload_size, ChecksumType checksum_type,
|
||||
uint32_t base_context_checksum,
|
||||
CompressionType expected_compression,
|
||||
PinnableSlice* value, uint64_t* bytes_read);
|
||||
|
||||
// Read multiple blobs from the underlying cache or blob file(s).
|
||||
//
|
||||
// If successful, returns ok and sets "result" in the elements of "blob_reqs"
|
||||
|
||||
@@ -229,6 +229,7 @@ TEST_F(BlobSourceTest, GetBlobsFromCache) {
|
||||
// Retrieved the blob cache num_blobs * 3 times via TEST_BlobInCache,
|
||||
// GetBlob, and TEST_BlobInCache.
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count, 0);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte, 0);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count, num_blobs);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte, total_bytes);
|
||||
ASSERT_GE((int)get_perf_context()->blob_checksum_time, 0);
|
||||
@@ -262,6 +263,8 @@ TEST_F(BlobSourceTest, GetBlobsFromCache) {
|
||||
blob_bytes += blob_sizes[i];
|
||||
total_bytes += bytes_read;
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count, i);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte,
|
||||
blob_bytes - blob_sizes[i]);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count, i + 1);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte, total_bytes);
|
||||
|
||||
@@ -269,11 +272,13 @@ TEST_F(BlobSourceTest, GetBlobsFromCache) {
|
||||
blob_offsets[i]));
|
||||
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count, i + 1);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte, blob_bytes);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count, i + 1);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte, total_bytes);
|
||||
}
|
||||
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count, num_blobs);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte, blob_bytes);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count, num_blobs);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte, total_bytes);
|
||||
|
||||
@@ -312,6 +317,7 @@ TEST_F(BlobSourceTest, GetBlobsFromCache) {
|
||||
// Retrieved the blob cache num_blobs * 3 times via TEST_BlobInCache,
|
||||
// GetBlob, and TEST_BlobInCache.
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count, num_blobs * 3);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte, blob_bytes * 3);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count, 0); // without i/o
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte, 0); // without i/o
|
||||
|
||||
@@ -690,6 +696,8 @@ TEST_F(BlobSourceTest, MultiGetBlobsFromMultiFiles) {
|
||||
// TEST_BlobInCache.
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count,
|
||||
num_blobs * blob_files);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte,
|
||||
blob_value_bytes * blob_files);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count,
|
||||
num_blobs * blob_files); // blocking i/o
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte,
|
||||
@@ -750,6 +758,8 @@ TEST_F(BlobSourceTest, MultiGetBlobsFromMultiFiles) {
|
||||
// via MultiGetBlob and TEST_BlobInCache.
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_hit_count,
|
||||
num_blobs * blob_files * 2);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_cache_read_byte,
|
||||
blob_value_bytes * blob_files * 2);
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_count,
|
||||
0); // blocking i/o
|
||||
ASSERT_EQ((int)get_perf_context()->blob_read_byte,
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "cache/compressed_secondary_cache.h"
|
||||
@@ -26,10 +29,12 @@
|
||||
#include "db/db_test_util.h"
|
||||
#include "db/db_with_timestamp_test_util.h"
|
||||
#include "db/wide/wide_column_test_util.h"
|
||||
#include "env/composite_env_wrapper.h"
|
||||
#include "file/filename.h"
|
||||
#include "file/random_access_file_reader.h"
|
||||
#include "port/stack_trace.h"
|
||||
#include "rocksdb/convenience.h"
|
||||
#include "rocksdb/file_system.h"
|
||||
#include "rocksdb/trace_reader_writer.h"
|
||||
#include "rocksdb/trace_record.h"
|
||||
#include "rocksdb/utilities/replayer.h"
|
||||
@@ -101,6 +106,206 @@ class RecordingBlobDirectWritePartitionStrategy
|
||||
std::vector<Call> calls_;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
// Matches BlobDB file names so the test filesystem can special-case only active
|
||||
// blob files without changing unrelated file opens.
|
||||
bool IsBlobFilePath(const std::string& fname) {
|
||||
const size_t basename_pos = fname.find_last_of("/\\");
|
||||
const std::string basename = basename_pos == std::string::npos
|
||||
? fname
|
||||
: fname.substr(basename_pos + 1);
|
||||
uint64_t file_number = 0;
|
||||
FileType file_type = kWalFile;
|
||||
return ParseFileName(basename, &file_number, &file_type) &&
|
||||
file_type == kBlobFile;
|
||||
}
|
||||
|
||||
// Keeps track of when an active blob file stops being writer-visible so the
|
||||
// test filesystem can model current-size visibility only while the file remains
|
||||
// active.
|
||||
class ActiveBlobVisibilityWritableFile : public FSWritableFileOwnerWrapper {
|
||||
public:
|
||||
ActiveBlobVisibilityWritableFile(std::unique_ptr<FSWritableFile>&& target,
|
||||
std::function<void()> on_close)
|
||||
: FSWritableFileOwnerWrapper(std::move(target)),
|
||||
on_close_(std::move(on_close)) {}
|
||||
|
||||
~ActiveBlobVisibilityWritableFile() override { DeactivateOnce(); }
|
||||
|
||||
IOStatus Close(const IOOptions& options, IODebugContext* dbg) override {
|
||||
IOStatus s = target()->Close(options, dbg);
|
||||
DeactivateOnce();
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
void DeactivateOnce() {
|
||||
if (on_close_) {
|
||||
on_close_();
|
||||
on_close_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void()> on_close_;
|
||||
};
|
||||
|
||||
// Simulates a remote readable file whose GetFileSize() either exposes the live
|
||||
// on-disk size for default-contract active blobs or hides it for
|
||||
// append-only-no-readers files.
|
||||
class ActiveBlobVisibilityRandomAccessFile
|
||||
: public FSRandomAccessFileOwnerWrapper {
|
||||
public:
|
||||
ActiveBlobVisibilityRandomAccessFile(
|
||||
std::unique_ptr<FSRandomAccessFile>&& target, bool expose_current_size,
|
||||
std::shared_ptr<FileSystem> underlying_fs, std::string fname)
|
||||
: FSRandomAccessFileOwnerWrapper(std::move(target)),
|
||||
expose_current_size_(expose_current_size),
|
||||
underlying_fs_(std::move(underlying_fs)),
|
||||
fname_(std::move(fname)) {}
|
||||
|
||||
IOStatus GetFileSize(uint64_t* result) override {
|
||||
if (!expose_current_size_) {
|
||||
*result = 0;
|
||||
return IOStatus::OK();
|
||||
}
|
||||
// Delegate to the underlying FS path-level GetFileSize (bypassing the
|
||||
// wrapper that reports 0 for active blobs) to simulate a remote FS that
|
||||
// exposes the current file size through the open handle.
|
||||
return underlying_fs_->GetFileSize(fname_, IOOptions(), result,
|
||||
/*dbg=*/nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
const bool expose_current_size_;
|
||||
std::shared_ptr<FileSystem> underlying_fs_;
|
||||
std::string fname_;
|
||||
};
|
||||
|
||||
// Models a remote filesystem where active direct-write blobs are only
|
||||
// reader-visible when the writer does not promise no concurrent readers.
|
||||
class RemoteBlobVisibilityFileSystem : public FileSystemWrapper {
|
||||
public:
|
||||
explicit RemoteBlobVisibilityFileSystem(const std::shared_ptr<FileSystem>& fs)
|
||||
: FileSystemWrapper(fs) {}
|
||||
|
||||
static const char* kClassName() { return "RemoteBlobVisibilityFileSystem"; }
|
||||
const char* Name() const override { return kClassName(); }
|
||||
|
||||
IOStatus NewWritableFile(const std::string& fname, const FileOptions& opts,
|
||||
std::unique_ptr<FSWritableFile>* result,
|
||||
IODebugContext* dbg) override {
|
||||
std::unique_ptr<FSWritableFile> file;
|
||||
IOStatus s = target()->NewWritableFile(fname, opts, &file, dbg);
|
||||
if (!s.ok() || !IsBlobFilePath(fname)) {
|
||||
*result = std::move(file);
|
||||
return IOStatus(std::move(s));
|
||||
}
|
||||
|
||||
const bool has_no_reopen_for_write_contract = HasFileOpenContract(
|
||||
opts.open_contract, FileOpenContract::kNoReopenForWrite);
|
||||
const bool has_no_readers_while_open_for_write_contract =
|
||||
HasFileOpenContract(opts.open_contract,
|
||||
FileOpenContract::kNoReadersWhileOpenForWrite);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
saw_no_reopen_for_write_writer_contract_ |=
|
||||
has_no_reopen_for_write_contract;
|
||||
saw_no_readers_while_open_for_write_writer_contract_ |=
|
||||
has_no_readers_while_open_for_write_contract;
|
||||
if (!has_no_readers_while_open_for_write_contract) {
|
||||
active_blob_paths_.insert(fname);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_no_readers_while_open_for_write_contract) {
|
||||
*result = std::move(file);
|
||||
return IOStatus::OK();
|
||||
}
|
||||
|
||||
result->reset(new ActiveBlobVisibilityWritableFile(
|
||||
std::move(file), [this, tracked_path = std::string(fname)]() {
|
||||
DeactivateBlobPath(tracked_path);
|
||||
}));
|
||||
return IOStatus::OK();
|
||||
}
|
||||
|
||||
IOStatus NewRandomAccessFile(const std::string& fname,
|
||||
const FileOptions& opts,
|
||||
std::unique_ptr<FSRandomAccessFile>* result,
|
||||
IODebugContext* dbg) override {
|
||||
std::unique_ptr<FSRandomAccessFile> file;
|
||||
IOStatus s = target()->NewRandomAccessFile(fname, opts, &file, dbg);
|
||||
if (!s.ok() || !IsBlobFilePath(fname)) {
|
||||
*result = std::move(file);
|
||||
return IOStatus(std::move(s));
|
||||
}
|
||||
|
||||
const bool has_no_readers_while_open_for_write_contract =
|
||||
HasFileOpenContract(opts.open_contract,
|
||||
FileOpenContract::kNoReadersWhileOpenForWrite);
|
||||
const bool active_blob = IsActiveBlobPath(fname);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
saw_no_readers_while_open_for_write_reader_contract_ |=
|
||||
has_no_readers_while_open_for_write_contract;
|
||||
}
|
||||
|
||||
if (!active_blob) {
|
||||
*result = std::move(file);
|
||||
return IOStatus::OK();
|
||||
}
|
||||
|
||||
result->reset(new ActiveBlobVisibilityRandomAccessFile(
|
||||
std::move(file), !has_no_readers_while_open_for_write_contract, target_,
|
||||
fname));
|
||||
return IOStatus::OK();
|
||||
}
|
||||
|
||||
IOStatus GetFileSize(const std::string& fname, const IOOptions& options,
|
||||
uint64_t* file_size, IODebugContext* dbg) override {
|
||||
if (IsActiveBlobPath(fname)) {
|
||||
*file_size = 0;
|
||||
return IOStatus::OK();
|
||||
}
|
||||
return target()->GetFileSize(fname, options, file_size, dbg);
|
||||
}
|
||||
|
||||
bool SawNoReopenForWriteWriterContract() const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
return saw_no_reopen_for_write_writer_contract_;
|
||||
}
|
||||
|
||||
bool SawNoReadersWhileOpenForWriteWriterContract() const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
return saw_no_readers_while_open_for_write_writer_contract_;
|
||||
}
|
||||
|
||||
bool SawNoReadersWhileOpenForWriteReaderContract() const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
return saw_no_readers_while_open_for_write_reader_contract_;
|
||||
}
|
||||
|
||||
private:
|
||||
void DeactivateBlobPath(const std::string& fname) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
active_blob_paths_.erase(fname);
|
||||
}
|
||||
|
||||
bool IsActiveBlobPath(const std::string& fname) const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
return active_blob_paths_.find(fname) != active_blob_paths_.end();
|
||||
}
|
||||
|
||||
mutable std::mutex mu_;
|
||||
bool saw_no_reopen_for_write_writer_contract_ = false;
|
||||
bool saw_no_readers_while_open_for_write_writer_contract_ = false;
|
||||
bool saw_no_readers_while_open_for_write_reader_contract_ = false;
|
||||
std::unordered_set<std::string> active_blob_paths_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
class DBBlobDirectWriteTest : public DBTestBase {
|
||||
protected:
|
||||
DBBlobDirectWriteTest()
|
||||
@@ -816,6 +1021,30 @@ TEST_F(DBBlobDirectWriteTest, DirectWriteImmutableMemtableRead) {
|
||||
verify_reads();
|
||||
}
|
||||
|
||||
// Verifies active blob direct-write files promise no write reopen without also
|
||||
// promising no concurrent readers.
|
||||
TEST_F(DBBlobDirectWriteTest, DirectWriteUsesReadableContractForRemoteFile) {
|
||||
auto remote_fs =
|
||||
std::make_shared<RemoteBlobVisibilityFileSystem>(env_->GetFileSystem());
|
||||
std::unique_ptr<Env> remote_env(new CompositeEnvWrapper(env_, remote_fs));
|
||||
|
||||
Options options = GetDirectWriteOptions();
|
||||
options.env = remote_env.get();
|
||||
Reopen(options);
|
||||
|
||||
const std::string key = "remote_blob_key";
|
||||
const std::string value(128, 'w');
|
||||
|
||||
ASSERT_OK(Put(key, value));
|
||||
ASSERT_TRUE(remote_fs->SawNoReopenForWriteWriterContract());
|
||||
ASSERT_FALSE(remote_fs->SawNoReadersWhileOpenForWriteWriterContract());
|
||||
|
||||
ASSERT_EQ(Get(key), value);
|
||||
ASSERT_FALSE(remote_fs->SawNoReadersWhileOpenForWriteReaderContract());
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
TEST_F(DBBlobDirectWriteTest, DirectWriteRefreshesReaderAfterFlush) {
|
||||
Options options = GetDirectWriteOptions();
|
||||
options.blob_direct_write_partitions = 1;
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#include "file/filename.h"
|
||||
#include "port/port.h"
|
||||
#include "port/stack_trace.h"
|
||||
#include "rocksdb/perf_context.h"
|
||||
#include "rocksdb/sst_file_writer.h"
|
||||
#include "rocksdb/table.h"
|
||||
#include "util/string_util.h"
|
||||
#include "utilities/merge_operators.h"
|
||||
|
||||
@@ -41,6 +44,18 @@ void CorruptPinnedBlobIndexOnCleanup(void* arg1, void* /*arg2*/) {
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(BlobIndexTest, SameFileBlobIndex) {
|
||||
std::string encoded;
|
||||
BlobIndex::EncodeBlob(&encoded, kCurrentFileBlobIndexFileNumber,
|
||||
/*offset=*/123, /*size=*/456, kNoCompression);
|
||||
|
||||
BlobIndex blob_index;
|
||||
ASSERT_OK(blob_index.DecodeFrom(encoded));
|
||||
EXPECT_TRUE(blob_index.IsSameFile());
|
||||
EXPECT_EQ(blob_index.file_number(), kCurrentFileBlobIndexFileNumber);
|
||||
EXPECT_NE(blob_index.DebugString(false).find("file:same"), std::string::npos);
|
||||
}
|
||||
|
||||
// kTypeBlobIndex is a value type used by BlobDB only. The base rocksdb
|
||||
// should accept the value type on write, and report not supported value
|
||||
// for reads, unless caller request for it explicitly. The base rocksdb
|
||||
@@ -330,6 +345,436 @@ TEST_F(DBBlobIndexTest, ReadOnlyGetImplReturnsBlobIndexWhenRequested) {
|
||||
ASSERT_TRUE(is_blob_index);
|
||||
}
|
||||
|
||||
// Regression test for a same-file (embedded) BlobIndex being exposed
|
||||
// unresolved through an iterator. With index_type=kBinarySearchWithFirstKey
|
||||
// and allow_unprepared_value (the default for DB iterators), the block-based
|
||||
// table iterator can sit in the is_at_first_key_from_index_ state and return
|
||||
// the raw kTypeBlobIndex internal key from the index, while value() resolves
|
||||
// the same-file blob to its plain payload. DBIter then reads the stale
|
||||
// kTypeBlobIndex type and routes the already-resolved plain value through the
|
||||
// blob-index path, corrupting/misreading it.
|
||||
//
|
||||
// Forcing one entry per data block makes every embedded blob the first key of
|
||||
// a block, reliably triggering the deferred-first-key state on both SeekToFirst
|
||||
// and forward block transitions.
|
||||
TEST_F(DBBlobIndexTest, EmbeddedBlobIteratorWithFirstKeyIndex) {
|
||||
Options options = GetTestOptions();
|
||||
options.create_if_missing = true;
|
||||
BlockBasedTableOptions bbto;
|
||||
bbto.index_type =
|
||||
BlockBasedTableOptions::IndexType::kBinarySearchWithFirstKey;
|
||||
// Soft limit of 1 byte starts a new data block after every entry.
|
||||
bbto.block_size = 1;
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
|
||||
DestroyAndReopen(options);
|
||||
|
||||
// Build an embedded-blob SST whose large values are stored as same-file blob
|
||||
// records (table entries become same-file BlobIndex references).
|
||||
const std::string sst_path = dbname_ + "/embedded_first_key.sst";
|
||||
SstFileWriterEmbeddedBlobOptions embedded_blob_options;
|
||||
embedded_blob_options.min_blob_size = 8;
|
||||
|
||||
const std::string big1(1024, 'x');
|
||||
const std::string big2(1024, 'y');
|
||||
const std::string big3(1024, 'z');
|
||||
|
||||
SstFileWriter writer(EnvOptions(), options);
|
||||
ASSERT_OK(writer.OpenWithEmbeddedBlobs(sst_path, embedded_blob_options));
|
||||
ASSERT_OK(writer.Put("k1", big1));
|
||||
ASSERT_OK(writer.Put("k2", big2));
|
||||
ASSERT_OK(writer.Put("k3", big3));
|
||||
ASSERT_OK(writer.Finish());
|
||||
|
||||
ASSERT_OK(db_->IngestExternalFile({sst_path}, IngestExternalFileOptions()));
|
||||
|
||||
// Point lookups resolve same-file blobs before exposing them, so Get works.
|
||||
ASSERT_EQ(Get("k1"), big1);
|
||||
ASSERT_EQ(Get("k2"), big2);
|
||||
ASSERT_EQ(Get("k3"), big3);
|
||||
|
||||
// Iterator path: the bug manifests here.
|
||||
std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
|
||||
iter->SeekToFirst();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k1");
|
||||
EXPECT_EQ(iter->value(), big1);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k2");
|
||||
EXPECT_EQ(iter->value(), big2);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k3");
|
||||
EXPECT_EQ(iter->value(), big3);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_FALSE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
|
||||
// Seek directly to a block whose first key is an embedded blob.
|
||||
iter->Seek("k2");
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k2");
|
||||
EXPECT_EQ(iter->value(), big2);
|
||||
}
|
||||
|
||||
// Backward iteration (Prev / SeekForPrev) over an embedded-blob SST must work,
|
||||
// including for wide-column entities whose same-file blob columns are resolved
|
||||
// into an iterator-owned buffer. DBIter requires the underlying iterator's
|
||||
// value to be pinned for backward iteration; EmbeddedBlobResolvingIterator
|
||||
// therefore pins resolved values -- both whole-value blob payloads and rebuilt
|
||||
// wide-column values -- and hands their cleanup to the PinnedIteratorsManager
|
||||
// across repositioning. Before that, backward iteration over the wide-column
|
||||
// entity returned NotSupported (or tripped the IsValuePinned() assertion).
|
||||
TEST_F(DBBlobIndexTest, EmbeddedBlobBackwardIteration) {
|
||||
Options options = GetTestOptions();
|
||||
options.create_if_missing = true;
|
||||
DestroyAndReopen(options);
|
||||
|
||||
const std::string sst_path = dbname_ + "/embedded_backward.sst";
|
||||
SstFileWriterEmbeddedBlobOptions embedded_blob_options;
|
||||
embedded_blob_options.min_blob_size = 8;
|
||||
|
||||
// Whole-value same-file blobs.
|
||||
const std::string big1(1024, 'x');
|
||||
const std::string big3(1024, 'z');
|
||||
// Wide-column entity: a small (inline) default column plus a large
|
||||
// (embedded, same-file blob) non-default column -- the mixed wide-column
|
||||
// path whose resolved value lands in an iterator-owned buffer.
|
||||
const std::string k2_default(2, 'd');
|
||||
const std::string k2_big_col(1024, 'c');
|
||||
const WideColumns k2_columns{{kDefaultWideColumnName, k2_default},
|
||||
{"big", k2_big_col}};
|
||||
|
||||
SstFileWriter writer(EnvOptions(), options);
|
||||
ASSERT_OK(writer.OpenWithEmbeddedBlobs(sst_path, embedded_blob_options));
|
||||
ASSERT_OK(writer.Put("k1", big1));
|
||||
ASSERT_OK(writer.PutEntity("k2", k2_columns));
|
||||
ASSERT_OK(writer.Put("k3", big3));
|
||||
ASSERT_OK(writer.Finish());
|
||||
|
||||
ASSERT_OK(db_->IngestExternalFile({sst_path}, IngestExternalFileOptions()));
|
||||
|
||||
std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
|
||||
|
||||
// Backward scan via SeekToLast + Prev.
|
||||
iter->SeekToLast();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k3");
|
||||
EXPECT_EQ(iter->value(), big3);
|
||||
|
||||
iter->Prev();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k2");
|
||||
EXPECT_EQ(iter->value(), k2_default);
|
||||
EXPECT_EQ(iter->columns(), k2_columns);
|
||||
|
||||
iter->Prev();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k1");
|
||||
EXPECT_EQ(iter->value(), big1);
|
||||
|
||||
iter->Prev();
|
||||
ASSERT_FALSE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
|
||||
// SeekForPrev directly onto the wide-column entity, then step back.
|
||||
iter->SeekForPrev("k2");
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k2");
|
||||
EXPECT_EQ(iter->value(), k2_default);
|
||||
EXPECT_EQ(iter->columns(), k2_columns);
|
||||
|
||||
iter->Prev();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k1");
|
||||
EXPECT_EQ(iter->value(), big1);
|
||||
}
|
||||
|
||||
// Regression test for T277566778. If resolving a same-file ("embedded") blob
|
||||
// fails during compaction (e.g. a blob-region read fault), the error must be
|
||||
// surfaced as-is. It must NOT be masked by feeding the raw, unresolved
|
||||
// same-file BlobIndex downstream, where FileMetaData::UpdateBoundaries would
|
||||
// (correctly) reject file number 0 and report a misleading "Invalid blob file
|
||||
// number" corruption. The EmbeddedBlobResolvingIterator must not expose an
|
||||
// unresolved same-file value on error: for eager (compaction) callers it
|
||||
// resolves during positioning so the error is visible via status()/Valid()
|
||||
// before value().
|
||||
TEST_F(DBBlobIndexTest, EmbeddedBlobResolveErrorDuringCompactionNotMasked) {
|
||||
Options options = GetTestOptions();
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
DestroyAndReopen(options);
|
||||
|
||||
const std::string sst_path = dbname_ + "/embedded_resolve_err.sst";
|
||||
SstFileWriterEmbeddedBlobOptions embedded_blob_options;
|
||||
embedded_blob_options.min_blob_size = 8;
|
||||
|
||||
// Wide-column entity with a large (embedded, same-file blob) column: the
|
||||
// mixed path whose resolution reads the blob region during compaction.
|
||||
const std::string big_col(1024, 'c');
|
||||
const WideColumns columns{{kDefaultWideColumnName, "d"}, {"big", big_col}};
|
||||
|
||||
SstFileWriter writer(EnvOptions(), options);
|
||||
ASSERT_OK(writer.OpenWithEmbeddedBlobs(sst_path, embedded_blob_options));
|
||||
ASSERT_OK(writer.PutEntity("k2", columns));
|
||||
ASSERT_OK(writer.Finish());
|
||||
ASSERT_OK(db_->IngestExternalFile({sst_path}, IngestExternalFileOptions()));
|
||||
|
||||
// Add keys straddling the entity so a real compaction (not a trivial move)
|
||||
// reads and resolves the embedded entity.
|
||||
ASSERT_OK(Put("k1", "v1"));
|
||||
ASSERT_OK(Put("k3", "v3"));
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
// Inject a resolution failure only during the compaction below, simulating a
|
||||
// blob-region read fault.
|
||||
const Status kInjected = Status::IOError("injected embedded blob read error");
|
||||
SyncPoint::GetInstance()->SetCallBack(
|
||||
"BlockBasedTable::MaybeResolveEmbeddedValue:InjectError",
|
||||
[&](void* arg) { *static_cast<Status*>(arg) = kInjected; });
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
const Status s = db_->CompactRange(CompactRangeOptions(), nullptr, nullptr);
|
||||
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
|
||||
// The compaction must fail with the injected read error, NOT a masked
|
||||
// "Invalid blob file number" corruption.
|
||||
ASSERT_NOK(s);
|
||||
EXPECT_TRUE(s.IsIOError()) << s.ToString();
|
||||
EXPECT_EQ(s.ToString().find("Invalid blob file number"), std::string::npos)
|
||||
<< s.ToString();
|
||||
}
|
||||
|
||||
// Regression test for T277310719, the whole-value (kTypeBlobIndex) sibling of
|
||||
// the wide-column-entity case above (T277566778). Both share one root cause: on
|
||||
// a blob-region resolution error during compaction, the
|
||||
// EmbeddedBlobResolvingIterator must not fall back to exposing the raw,
|
||||
// unresolved same-file value.
|
||||
//
|
||||
// The whole-value variant is more dangerous than the entity variant because it
|
||||
// escapes the FileMetaData::UpdateBoundaries tripwire: ResolveKeyType()
|
||||
// rewrites the key type kTypeBlobIndex -> kTypeValue (no I/O, always succeeds),
|
||||
// so on a masked resolution error the emitted entry is {kTypeValue, raw
|
||||
// BlobIndex bytes}. UpdateBoundaries only scans kTypeBlobIndex/entity types, so
|
||||
// unlike the entity variant it does NOT reject it -- the masked error slips
|
||||
// through, a corrupt {kTypeValue, BlobIndex} record is written to the
|
||||
// compaction output, and a later point lookup reads those raw BlobIndex bytes
|
||||
// back as the value (in db_stress this surfaced as the
|
||||
// ExpectedValue::IsValueBaseValid assertion, not "Invalid blob file number").
|
||||
// The eager (compaction) resolver must surface the error via status()/Valid()
|
||||
// before value() is consumed.
|
||||
TEST_F(DBBlobIndexTest,
|
||||
EmbeddedBlobResolveErrorWholeValueDuringCompactionNotMasked) {
|
||||
Options options = GetTestOptions();
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
DestroyAndReopen(options);
|
||||
|
||||
const std::string sst_path = dbname_ + "/embedded_resolve_err_wholevalue.sst";
|
||||
SstFileWriterEmbeddedBlobOptions embedded_blob_options;
|
||||
embedded_blob_options.min_blob_size = 8;
|
||||
|
||||
// A large whole value is stored as a same-file blob, so the table entry
|
||||
// becomes a same-file (file number 0) BlobIndex (kTypeBlobIndex) -- the
|
||||
// whole-value path whose resolution reads the blob region during compaction.
|
||||
const std::string big_val(1024, 'b');
|
||||
|
||||
SstFileWriter writer(EnvOptions(), options);
|
||||
ASSERT_OK(writer.OpenWithEmbeddedBlobs(sst_path, embedded_blob_options));
|
||||
ASSERT_OK(writer.Put("k2", big_val));
|
||||
ASSERT_OK(writer.Finish());
|
||||
ASSERT_OK(db_->IngestExternalFile({sst_path}, IngestExternalFileOptions()));
|
||||
|
||||
// Add keys straddling the embedded blob so a real compaction (not a trivial
|
||||
// move) reads and resolves it.
|
||||
ASSERT_OK(Put("k1", "v1"));
|
||||
ASSERT_OK(Put("k3", "v3"));
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
// Inject a resolution failure only during the compaction below, simulating a
|
||||
// blob-region read fault.
|
||||
const Status kInjected = Status::IOError("injected embedded blob read error");
|
||||
SyncPoint::GetInstance()->SetCallBack(
|
||||
"BlockBasedTable::MaybeResolveEmbeddedValue:InjectError",
|
||||
[&](void* arg) { *static_cast<Status*>(arg) = kInjected; });
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
const Status s = db_->CompactRange(CompactRangeOptions(), nullptr, nullptr);
|
||||
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
|
||||
// The compaction must fail with the injected read error. Before the fix it
|
||||
// instead succeeded (masking the error) and persisted a {kTypeValue, raw
|
||||
// BlobIndex} record; it must not do that, and it must not report a misleading
|
||||
// "Invalid blob file number" corruption either.
|
||||
ASSERT_NOK(s);
|
||||
EXPECT_TRUE(s.IsIOError()) << s.ToString();
|
||||
EXPECT_EQ(s.ToString().find("Invalid blob file number"), std::string::npos)
|
||||
<< s.ToString();
|
||||
}
|
||||
|
||||
// When a blob cache is configured, same-file ("embedded") blob reads should go
|
||||
// through BlobSource: the first read misses + inserts + does a disk read, and
|
||||
// the second read of the same blob is served from the blob cache. This holds on
|
||||
// both the Get() and the iterator paths.
|
||||
TEST_F(DBBlobIndexTest, EmbeddedBlobBlobCacheHitMiss) {
|
||||
Options options = GetTestOptions();
|
||||
options.create_if_missing = true;
|
||||
options.statistics = CreateDBStatistics();
|
||||
|
||||
LRUCacheOptions co;
|
||||
co.capacity = 8 << 20;
|
||||
options.blob_cache = NewLRUCache(co);
|
||||
|
||||
DestroyAndReopen(options);
|
||||
|
||||
const std::string sst_path = dbname_ + "/embedded_cache.sst";
|
||||
SstFileWriterEmbeddedBlobOptions embedded_blob_options;
|
||||
embedded_blob_options.min_blob_size = 8;
|
||||
|
||||
const std::string big1(1024, 'x');
|
||||
const std::string big2(1024, 'y');
|
||||
|
||||
SstFileWriter writer(EnvOptions(), options);
|
||||
ASSERT_OK(writer.OpenWithEmbeddedBlobs(sst_path, embedded_blob_options));
|
||||
ASSERT_OK(writer.Put("k1", big1));
|
||||
ASSERT_OK(writer.Put("k2", big2));
|
||||
ASSERT_OK(writer.Finish());
|
||||
|
||||
ASSERT_OK(db_->IngestExternalFile({sst_path}, IngestExternalFileOptions()));
|
||||
|
||||
Statistics* const stats = options.statistics.get();
|
||||
|
||||
// First Get: blob cache miss -> disk read -> cache insert.
|
||||
ASSERT_OK(stats->Reset());
|
||||
get_perf_context()->Reset();
|
||||
SetPerfLevel(kEnableCount);
|
||||
ASSERT_EQ(Get("k1"), big1);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_MISS), 1);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_HIT), 0);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_ADD), 1);
|
||||
EXPECT_GT(stats->getTickerCount(BLOB_DB_BLOB_FILE_BYTES_READ), 0);
|
||||
EXPECT_EQ(get_perf_context()->blob_read_count, 1);
|
||||
|
||||
// Second Get of the same key: blob cache hit, no disk read, no insert.
|
||||
ASSERT_OK(stats->Reset());
|
||||
get_perf_context()->Reset();
|
||||
ASSERT_EQ(Get("k1"), big1);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_HIT), 1);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_MISS), 0);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_ADD), 0);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_BLOB_FILE_BYTES_READ), 0);
|
||||
EXPECT_EQ(get_perf_context()->blob_read_count, 0);
|
||||
EXPECT_EQ(get_perf_context()->blob_cache_hit_count, 1);
|
||||
|
||||
// Iterator path: first read of a fresh key misses + inserts.
|
||||
ASSERT_OK(stats->Reset());
|
||||
{
|
||||
std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
|
||||
iter->Seek("k2");
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->value(), big2);
|
||||
}
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_MISS), 1);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_ADD), 1);
|
||||
|
||||
// Iterator path: second read of the same key hits the blob cache.
|
||||
ASSERT_OK(stats->Reset());
|
||||
{
|
||||
std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
|
||||
iter->Seek("k2");
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->value(), big2);
|
||||
}
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_HIT), 1);
|
||||
EXPECT_EQ(stats->getTickerCount(BLOB_DB_CACHE_ADD), 0);
|
||||
|
||||
SetPerfLevel(kDisable);
|
||||
}
|
||||
|
||||
// With the blob cache and block cache pointing at the same Cache, the SST-like
|
||||
// cache-key scheme (offset >> 2 on the SST's base key) keeps embedded blob
|
||||
// records disjoint from the SST's data blocks. Reading embedded blobs must not
|
||||
// alias or evict data blocks, and values must remain correct.
|
||||
TEST_F(DBBlobIndexTest, EmbeddedBlobSharedBlockAndBlobCache) {
|
||||
Options options = GetTestOptions();
|
||||
options.create_if_missing = true;
|
||||
options.statistics = CreateDBStatistics();
|
||||
|
||||
LRUCacheOptions co;
|
||||
co.capacity = 16 << 20;
|
||||
auto shared_cache = NewLRUCache(co);
|
||||
options.blob_cache = shared_cache;
|
||||
|
||||
BlockBasedTableOptions bbto;
|
||||
bbto.block_cache = shared_cache;
|
||||
bbto.cache_index_and_filter_blocks = true;
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
|
||||
|
||||
DestroyAndReopen(options);
|
||||
|
||||
const std::string sst_path = dbname_ + "/embedded_shared.sst";
|
||||
SstFileWriterEmbeddedBlobOptions embedded_blob_options;
|
||||
embedded_blob_options.min_blob_size = 8;
|
||||
|
||||
const std::string big1(1024, 'x');
|
||||
const std::string big2(1024, 'y');
|
||||
|
||||
SstFileWriter writer(EnvOptions(), options);
|
||||
ASSERT_OK(writer.OpenWithEmbeddedBlobs(sst_path, embedded_blob_options));
|
||||
ASSERT_OK(writer.Put("k1", big1));
|
||||
ASSERT_OK(writer.Put("k2", big2));
|
||||
ASSERT_OK(writer.Finish());
|
||||
|
||||
ASSERT_OK(db_->IngestExternalFile({sst_path}, IngestExternalFileOptions()));
|
||||
|
||||
Statistics* const stats = options.statistics.get();
|
||||
|
||||
// Values are correct with a shared cache, and re-reads hit both the block
|
||||
// cache (data blocks) and the blob cache (embedded payloads) independently.
|
||||
ASSERT_EQ(Get("k1"), big1);
|
||||
ASSERT_EQ(Get("k2"), big2);
|
||||
ASSERT_EQ(Get("k1"), big1);
|
||||
ASSERT_EQ(Get("k2"), big2);
|
||||
EXPECT_GT(stats->getTickerCount(BLOB_DB_CACHE_HIT), 0);
|
||||
EXPECT_GT(stats->getTickerCount(BLOCK_CACHE_HIT), 0);
|
||||
|
||||
// Iterator yields correct values too.
|
||||
std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
|
||||
iter->SeekToFirst();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k1");
|
||||
EXPECT_EQ(iter->value(), big1);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
EXPECT_EQ(iter->key(), "k2");
|
||||
EXPECT_EQ(iter->value(), big2);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_FALSE(iter->Valid());
|
||||
ASSERT_OK(iter->status());
|
||||
}
|
||||
|
||||
class PlainBlobValueFilterV3 : public CompactionFilter {
|
||||
public:
|
||||
PlainBlobValueFilterV3(std::atomic<int>* filter_call_count,
|
||||
|
||||
@@ -179,6 +179,8 @@ Status BuildTable(
|
||||
TEST_SYNC_POINT_CALLBACK("BuildTable:create_file", &use_direct_writes);
|
||||
#endif // !NDEBUG
|
||||
FileOptions fo_copy = file_options;
|
||||
fo_copy.open_contract = FileOpenContract::kNoReopenForWrite |
|
||||
FileOpenContract::kNoReadersWhileOpenForWrite;
|
||||
fo_copy.write_hint = write_hint;
|
||||
IOStatus io_s = NewWritableFile(fs, fname, &file, fo_copy);
|
||||
assert(s.ok());
|
||||
|
||||
+1928
-20
File diff suppressed because it is too large
Load Diff
@@ -678,6 +678,9 @@ ColumnFamilyData::ColumnFamilyData(
|
||||
internal_stats_->GetBlobFileReadHist(), io_tracer));
|
||||
blob_source_.reset(new BlobSource(ioptions_, mutable_cf_options_, db_id,
|
||||
db_session_id, blob_file_cache_.get()));
|
||||
// Let the table cache route same-file ("embedded") blob reads through the
|
||||
// blob value cache + stats. Both objects share this CFD's lifetime.
|
||||
table_cache_->SetBlobSource(blob_source_.get());
|
||||
|
||||
if (ioptions_.compaction_style == kCompactionStyleLevel) {
|
||||
compaction_picker_.reset(
|
||||
|
||||
@@ -454,6 +454,18 @@ class Compaction {
|
||||
return notify_on_compaction_completion_;
|
||||
}
|
||||
|
||||
// Called by DBImpl::NotifyOnCompactionPreCommit to ensure the
|
||||
// OnCompactionPreCommit listener callback fires at most once per
|
||||
// compaction lifecycle, even though the notify helper is invoked at multiple
|
||||
// potential ReleaseCompactionFiles() sites for safety.
|
||||
void SetNotifyOnCompactionPreCommitCalled() {
|
||||
notify_on_compaction_pre_commit_called_ = true;
|
||||
}
|
||||
|
||||
bool WasNotifyOnCompactionPreCommitCalled() const {
|
||||
return notify_on_compaction_pre_commit_called_;
|
||||
}
|
||||
|
||||
static constexpr int kInvalidLevel = -1;
|
||||
|
||||
// Evaluate proximal output level. If the compaction supports
|
||||
@@ -626,6 +638,12 @@ class Compaction {
|
||||
// begin.
|
||||
bool notify_on_compaction_completion_;
|
||||
|
||||
// Tracks whether OnCompactionPreCommit has already fired for this
|
||||
// compaction. The notify helper is called from multiple potential
|
||||
// ReleaseCompactionFiles() call sites; this flag guarantees that listeners
|
||||
// observe the callback exactly once per compaction.
|
||||
bool notify_on_compaction_pre_commit_called_ = false;
|
||||
|
||||
// Enable/disable GC collection for blobs during compaction.
|
||||
bool enable_blob_garbage_collection_;
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@ CompactionJob::CompactionJob(
|
||||
fs_(db_options.fs, io_tracer),
|
||||
file_options_for_read_(
|
||||
fs_->OptimizeForCompactionTableRead(file_options, db_options_)),
|
||||
file_options_for_compaction_input_read_(file_options_for_read_),
|
||||
versions_(versions),
|
||||
shutting_down_(shutting_down),
|
||||
manual_compaction_canceled_(manual_compaction_canceled),
|
||||
@@ -203,6 +204,11 @@ CompactionJob::CompactionJob(
|
||||
assert(job_context);
|
||||
assert(job_context->snapshot_context_initialized);
|
||||
|
||||
if (db_options_.use_direct_io_for_compaction_reads &&
|
||||
!db_options_.use_direct_reads) {
|
||||
file_options_for_compaction_input_read_.use_direct_reads = true;
|
||||
}
|
||||
|
||||
const auto* cfd = compact_->compaction->column_family_data();
|
||||
ThreadStatusUtil::SetEnableTracking(db_options_.enable_thread_tracking);
|
||||
ThreadStatusUtil::SetColumnFamily(cfd);
|
||||
@@ -1536,10 +1542,20 @@ InternalIterator* CompactionJob::CreateInputIterator(
|
||||
|
||||
// Although the v2 aggregator is what the level iterator(s) know about,
|
||||
// the AddTombstones calls will be propagated down to the v1 aggregator.
|
||||
const bool open_ephemeral_table_reader =
|
||||
db_options_.use_direct_io_for_compaction_reads &&
|
||||
!db_options_.use_direct_reads;
|
||||
FileOptions& input_file_options =
|
||||
open_ephemeral_table_reader ? file_options_for_compaction_input_read_
|
||||
: file_options_for_read_;
|
||||
TEST_SYNC_POINT_CALLBACK(
|
||||
"CompactionJob::CreateInputIterator:InputFileOptions",
|
||||
&input_file_options);
|
||||
iterators.raw_input =
|
||||
std::unique_ptr<InternalIterator>(versions_->MakeInputIterator(
|
||||
read_options, sub_compact->compaction, sub_compact->RangeDelAgg(),
|
||||
file_options_for_read_, boundaries.start, boundaries.end));
|
||||
input_file_options, boundaries.start, boundaries.end,
|
||||
open_ephemeral_table_reader));
|
||||
InternalIterator* input = iterators.raw_input.get();
|
||||
|
||||
if (boundaries.start.has_value() || boundaries.end.has_value()) {
|
||||
@@ -2065,10 +2081,18 @@ Status CompactionJob::FinishCompactionOutputFile(
|
||||
std::pair<SequenceNumber, SequenceNumber> keep_seqno_range{
|
||||
0, kMaxSequenceNumber};
|
||||
if (sub_compact->compaction->SupportsPerKeyPlacement()) {
|
||||
// Point entries are routed to proximal output only when their seqno is
|
||||
// strictly greater than `proximal_after_seqno_`. Range tombstones use a
|
||||
// [lower, upper) filter, so split them at the next seqno to preserve the
|
||||
// same boundary.
|
||||
SequenceNumber range_del_split_seqno = proximal_after_seqno_;
|
||||
if (range_del_split_seqno < kMaxSequenceNumber) {
|
||||
range_del_split_seqno++;
|
||||
}
|
||||
if (outputs.IsProximalLevel()) {
|
||||
keep_seqno_range.first = proximal_after_seqno_;
|
||||
keep_seqno_range.first = range_del_split_seqno;
|
||||
} else {
|
||||
keep_seqno_range.second = proximal_after_seqno_;
|
||||
keep_seqno_range.second = range_del_split_seqno;
|
||||
}
|
||||
}
|
||||
CompactionIterationStats range_del_out_stats;
|
||||
@@ -2462,6 +2486,8 @@ Status CompactionJob::OpenCompactionOutputFile(SubcompactionState* sub_compact,
|
||||
auto temperature =
|
||||
sub_compact->compaction->GetOutputTemperature(outputs.IsProximalLevel());
|
||||
fo_copy.temperature = temperature;
|
||||
fo_copy.open_contract = FileOpenContract::kNoReopenForWrite |
|
||||
FileOpenContract::kNoReadersWhileOpenForWrite;
|
||||
fo_copy.write_hint = write_hint_;
|
||||
|
||||
Status s;
|
||||
|
||||
@@ -462,6 +462,8 @@ class CompactionJob {
|
||||
FileSystemPtr fs_;
|
||||
// env_option optimized for compaction table reads
|
||||
FileOptions file_options_for_read_;
|
||||
// file_options_for_read_ plus compaction-input-only overrides.
|
||||
FileOptions file_options_for_compaction_input_read_;
|
||||
VersionSet* versions_;
|
||||
const std::atomic<bool>* shutting_down_;
|
||||
const std::atomic<bool>& manual_compaction_canceled_;
|
||||
|
||||
@@ -189,14 +189,24 @@ CompactionJob::ProcessKeyValueCompactionWithCompactionService(
|
||||
return compaction_status;
|
||||
}
|
||||
|
||||
// CompactionServiceJobStatus::kSuccess was returned, but somehow we failed to
|
||||
// read the result. Consider this as an installation failure
|
||||
if (!s.ok()) {
|
||||
sub_compact->status = s;
|
||||
// Wait() returned kSuccess, but the primary host could not deserialize the
|
||||
// remote result before importing any output files into this DB. The remote
|
||||
// output is still isolated in the service-managed staging directory, so it
|
||||
// is safe to fall back to local compaction for the same job and notify the
|
||||
// service via OnInstallation(kUseLocal).
|
||||
assert(sub_compact->status.ok());
|
||||
assert(sub_compact->GetMutableCompactionOutputs().empty());
|
||||
assert(sub_compact->GetMutableProximalOutputs().empty());
|
||||
ROCKS_LOG_WARN(db_options_.info_log,
|
||||
"[%s] [JOB %d] Failed to parse remote compaction result "
|
||||
"(%s), falling back to local compaction",
|
||||
compaction->column_family_data()->GetName().c_str(), job_id_,
|
||||
s.ToString().c_str());
|
||||
compaction_result.status.PermitUncheckedError();
|
||||
db_options_.compaction_service->OnInstallation(
|
||||
response.scheduled_job_id, CompactionServiceJobStatus::kFailure);
|
||||
return CompactionServiceJobStatus::kFailure;
|
||||
response.scheduled_job_id, CompactionServiceJobStatus::kUseLocal);
|
||||
return CompactionServiceJobStatus::kUseLocal;
|
||||
}
|
||||
sub_compact->status = compaction_result.status;
|
||||
|
||||
@@ -421,6 +431,14 @@ Status CompactionServiceCompactionJob::Run() {
|
||||
// Please note that input stats will be updated by primary host when all
|
||||
// subcompactions are finished
|
||||
UpdateCompactionJobOutputStatsFromInternalStats(status, internal_stats_);
|
||||
// Whole-file filtering changes which keys are fed to the iterator, so the
|
||||
// iterator-based input record count should not be treated as exact.
|
||||
for (size_t level = 1; level < c->num_input_levels(); ++level) {
|
||||
if (!c->filtered_input_levels(level).empty()) {
|
||||
compaction_result_->stats.has_accurate_num_input_records = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// and set fields that are not propagated as part of the update
|
||||
compaction_result_->stats.is_manual_compaction = c->is_manual_compaction();
|
||||
compaction_result_->stats.is_full_compaction = c->is_full_compaction();
|
||||
@@ -641,6 +659,10 @@ static std::unordered_map<std::string, OptionTypeInfo>
|
||||
{"cpu_micros",
|
||||
{offsetof(struct CompactionJobStats, cpu_micros), OptionType::kUInt64T,
|
||||
OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
|
||||
{"has_accurate_num_input_records",
|
||||
{offsetof(struct CompactionJobStats, has_accurate_num_input_records),
|
||||
OptionType::kBoolean, OptionVerificationType::kNormal,
|
||||
OptionTypeFlags::kNone}},
|
||||
{"num_input_records",
|
||||
{offsetof(struct CompactionJobStats, num_input_records),
|
||||
OptionType::kUInt64T, OptionVerificationType::kNormal,
|
||||
|
||||
@@ -127,6 +127,7 @@ class MyTestCompactionService : public CompactionService {
|
||||
|
||||
void OnInstallation(const std::string& /*scheduled_job_id*/,
|
||||
CompactionServiceJobStatus status) override {
|
||||
installation_callback_count_.fetch_add(1);
|
||||
final_updated_status_ = status;
|
||||
}
|
||||
|
||||
@@ -167,6 +168,8 @@ class MyTestCompactionService : public CompactionService {
|
||||
return final_updated_status_.load();
|
||||
}
|
||||
|
||||
int GetOnInstallationCount() { return installation_callback_count_.load(); }
|
||||
|
||||
protected:
|
||||
InstrumentedMutex mutex_;
|
||||
const std::string db_path_;
|
||||
@@ -195,6 +198,7 @@ class MyTestCompactionService : public CompactionService {
|
||||
std::vector<std::shared_ptr<EventListener>> listeners_;
|
||||
std::vector<std::shared_ptr<TablePropertiesCollectorFactory>>
|
||||
table_properties_collector_factories_;
|
||||
std::atomic_int installation_callback_count_{0};
|
||||
std::atomic<CompactionServiceJobStatus> final_updated_status_{
|
||||
CompactionServiceJobStatus::kUseLocal};
|
||||
|
||||
@@ -607,6 +611,101 @@ TEST_F(CompactionServiceTest, StandaloneDeleteRangeTombstoneOptimization) {
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
}
|
||||
|
||||
TEST_F(CompactionServiceTest,
|
||||
StandaloneDeleteRangeTombstoneMakesInputCountInaccurate) {
|
||||
Options options = CurrentOptions();
|
||||
options.compaction_style = CompactionStyle::kCompactionStyleUniversal;
|
||||
options.compaction_verify_record_count = true;
|
||||
ReopenWithCompactionService(&options);
|
||||
|
||||
std::vector<std::string> files;
|
||||
{
|
||||
SstFileWriter sst_file_writer(EnvOptions(), options);
|
||||
std::string file1 = dbname_ + "file1.sst";
|
||||
ASSERT_OK(sst_file_writer.Open(file1));
|
||||
ASSERT_OK(sst_file_writer.Put("a", "a1"));
|
||||
ASSERT_OK(sst_file_writer.Put("b", "b1"));
|
||||
ExternalSstFileInfo file1_info;
|
||||
ASSERT_OK(sst_file_writer.Finish(&file1_info));
|
||||
files.push_back(std::move(file1));
|
||||
|
||||
std::string file2 = dbname_ + "file2.sst";
|
||||
ASSERT_OK(sst_file_writer.Open(file2));
|
||||
ASSERT_OK(sst_file_writer.Put("x", "x1"));
|
||||
ASSERT_OK(sst_file_writer.Put("y", "y1"));
|
||||
ExternalSstFileInfo file2_info;
|
||||
ASSERT_OK(sst_file_writer.Finish(&file2_info));
|
||||
files.push_back(std::move(file2));
|
||||
}
|
||||
|
||||
IngestExternalFileOptions ifo;
|
||||
ASSERT_OK(db_->IngestExternalFile(files, ifo));
|
||||
ASSERT_EQ(Get("a"), "a1");
|
||||
ASSERT_EQ(Get("b"), "b1");
|
||||
ASSERT_EQ(Get("x"), "x1");
|
||||
ASSERT_EQ(Get("y"), "y1");
|
||||
ASSERT_EQ(2, NumTableFilesAtLevel(6));
|
||||
|
||||
auto my_cs = GetCompactionService();
|
||||
uint64_t comp_num = my_cs->GetCompactionNum();
|
||||
|
||||
size_t num_files_after_filtered = 0;
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"VersionSet::MakeInputIterator:NewCompactionMergingIterator",
|
||||
[&](void* arg) {
|
||||
num_files_after_filtered = *static_cast<size_t*>(arg);
|
||||
});
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
{
|
||||
// The standalone range tombstone can fully cover the old versioned files,
|
||||
// so universal compaction may filter those files before iteration.
|
||||
files.clear();
|
||||
SstFileWriter sst_file_writer(EnvOptions(), options);
|
||||
std::string file2 = dbname_ + "file2.sst";
|
||||
ASSERT_OK(sst_file_writer.Open(file2));
|
||||
ASSERT_OK(sst_file_writer.DeleteRange("a", "z"));
|
||||
ExternalSstFileInfo file2_info;
|
||||
ASSERT_OK(sst_file_writer.Finish(&file2_info));
|
||||
files.push_back(std::move(file2));
|
||||
|
||||
std::string file3 = dbname_ + "file3.sst";
|
||||
ASSERT_OK(sst_file_writer.Open(file3));
|
||||
ASSERT_OK(sst_file_writer.Put("a", "a2"));
|
||||
ASSERT_OK(sst_file_writer.Put("b", "b2"));
|
||||
ExternalSstFileInfo file3_info;
|
||||
ASSERT_OK(sst_file_writer.Finish(&file3_info));
|
||||
files.push_back(std::move(file3));
|
||||
|
||||
std::string file4 = dbname_ + "file4.sst";
|
||||
ASSERT_OK(sst_file_writer.Open(file4));
|
||||
ASSERT_OK(sst_file_writer.Put("x", "x2"));
|
||||
ASSERT_OK(sst_file_writer.Put("y", "y2"));
|
||||
ExternalSstFileInfo file4_info;
|
||||
ASSERT_OK(sst_file_writer.Finish(&file4_info));
|
||||
files.push_back(std::move(file4));
|
||||
}
|
||||
|
||||
ASSERT_OK(db_->IngestExternalFile(files, ifo));
|
||||
ASSERT_OK(db_->WaitForCompact(WaitForCompactOptions()));
|
||||
ASSERT_GE(my_cs->GetCompactionNum(), comp_num + 1);
|
||||
|
||||
CompactionServiceResult result;
|
||||
my_cs->GetResult(&result);
|
||||
ASSERT_OK(result.status);
|
||||
ASSERT_TRUE(result.stats.is_remote_compaction);
|
||||
ASSERT_FALSE(result.stats.has_accurate_num_input_records);
|
||||
ASSERT_EQ(1, num_files_after_filtered);
|
||||
|
||||
ASSERT_EQ(Get("a"), "a2");
|
||||
ASSERT_EQ(Get("b"), "b2");
|
||||
ASSERT_EQ(Get("x"), "x2");
|
||||
ASSERT_EQ(Get("y"), "y2");
|
||||
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
}
|
||||
|
||||
TEST_F(CompactionServiceTest, CompactionOutputFileIOError) {
|
||||
Options options = CurrentOptions();
|
||||
options.disable_auto_compactions = true;
|
||||
@@ -939,6 +1038,37 @@ TEST_F(CompactionServiceTest, VerifyInputRecordCount) {
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
}
|
||||
|
||||
TEST_F(CompactionServiceTest, InaccurateInputRecordCount) {
|
||||
Options options = CurrentOptions();
|
||||
options.disable_auto_compactions = true;
|
||||
ReopenWithCompactionService(&options);
|
||||
GenerateTestData();
|
||||
|
||||
auto my_cs = GetCompactionService();
|
||||
|
||||
std::string start_str = Key(15);
|
||||
std::string end_str = Key(45);
|
||||
Slice start(start_str);
|
||||
Slice end(end_str);
|
||||
uint64_t comp_num = my_cs->GetCompactionNum();
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"CompactionServiceCompactionJob::Run:0", [&](void* arg) {
|
||||
CompactionServiceResult* compaction_result =
|
||||
*(static_cast<CompactionServiceResult**>(arg));
|
||||
ASSERT_TRUE(compaction_result != nullptr);
|
||||
compaction_result->stats.has_accurate_num_input_records = false;
|
||||
compaction_result->stats.num_input_records = 0;
|
||||
});
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), &start, &end));
|
||||
ASSERT_GE(my_cs->GetCompactionNum(), comp_num + 1);
|
||||
|
||||
SyncPoint::GetInstance()->DisableProcessing();
|
||||
SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
}
|
||||
|
||||
TEST_F(CompactionServiceTest, EmptyResult) {
|
||||
Options options = CurrentOptions();
|
||||
options.disable_auto_compactions = true;
|
||||
@@ -1281,6 +1411,10 @@ TEST_F(CompactionServiceTest, TruncatedOutput) {
|
||||
|
||||
TEST_F(CompactionServiceTest, CustomFileChecksum) {
|
||||
Options options = CurrentOptions();
|
||||
// Pin compression so the auto-compacted LSM shape (and thus whether the
|
||||
// manual CompactRange below schedules a remote compaction) doesn't depend on
|
||||
// the default compression type. kNoCompression is always available.
|
||||
options.compression = kNoCompression;
|
||||
options.file_checksum_gen_factory = GetFileChecksumGenCrc32cFactory();
|
||||
ReopenWithCompactionService(&options);
|
||||
GenerateTestData();
|
||||
@@ -1448,7 +1582,7 @@ TEST_F(CompactionServiceTest, FailedToStart) {
|
||||
ASSERT_TRUE(s.IsIncomplete());
|
||||
}
|
||||
|
||||
TEST_F(CompactionServiceTest, InvalidResult) {
|
||||
TEST_F(CompactionServiceTest, InvalidResultFallsBackToLocal) {
|
||||
Options options = CurrentOptions();
|
||||
options.disable_auto_compactions = true;
|
||||
ReopenWithCompactionService(&options);
|
||||
@@ -1456,15 +1590,22 @@ TEST_F(CompactionServiceTest, InvalidResult) {
|
||||
GenerateTestData();
|
||||
|
||||
auto my_cs = GetCompactionService();
|
||||
ASSERT_EQ(0, my_cs->GetOnInstallationCount());
|
||||
my_cs->OverrideWaitResult("Invalid Str");
|
||||
int compaction_num_before = my_cs->GetCompactionNum();
|
||||
|
||||
std::string start_str = Key(15);
|
||||
std::string end_str = Key(45);
|
||||
Slice start(start_str);
|
||||
Slice end(end_str);
|
||||
// The remote result is malformed before any installation starts, so the
|
||||
// primary should recover by rerunning the compaction locally for this job.
|
||||
Status s = db_->CompactRange(CompactRangeOptions(), &start, &end);
|
||||
ASSERT_FALSE(s.ok());
|
||||
ASSERT_EQ(CompactionServiceJobStatus::kFailure,
|
||||
ASSERT_OK(s);
|
||||
ASSERT_GE(my_cs->GetCompactionNum(), compaction_num_before + 1);
|
||||
VerifyTestData();
|
||||
ASSERT_EQ(1, my_cs->GetOnInstallationCount());
|
||||
ASSERT_EQ(CompactionServiceJobStatus::kUseLocal,
|
||||
my_cs->GetFinalCompactionServiceJobStatus());
|
||||
}
|
||||
|
||||
|
||||
@@ -2897,6 +2897,61 @@ TEST_P(PrecludeLastLevelTest, RangeDelsCauseFileEndpointsToOverlap) {
|
||||
Close();
|
||||
}
|
||||
|
||||
TEST_F(PrecludeLastLevelTestBase,
|
||||
RangeDelAtProximalSeqnoBoundaryStaysInLastLevel) {
|
||||
constexpr int kNumLevels = 7;
|
||||
|
||||
Options options = CurrentOptions();
|
||||
options.env = mock_env_.get();
|
||||
options.num_levels = kNumLevels;
|
||||
options.disable_auto_compactions = true;
|
||||
DestroyAndReopen(options);
|
||||
Defer close_db([&] { Close(); });
|
||||
|
||||
ASSERT_OK(Put(Key(2), "old"));
|
||||
ASSERT_OK(Put(Key(12), "old"));
|
||||
ManagedSnapshot snapshot(db_.get());
|
||||
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(), Key(2),
|
||||
Key(12)));
|
||||
ASSERT_OK(Flush());
|
||||
MoveFilesToLevel(6);
|
||||
|
||||
const int l5_file_keys[][2] = {{0, 4}, {5, 9}};
|
||||
for (const auto& l5_file : l5_file_keys) {
|
||||
ASSERT_OK(Put(Key(l5_file[0]), "hot"));
|
||||
ASSERT_OK(Put(Key(l5_file[1]), "hot"));
|
||||
ASSERT_OK(Flush());
|
||||
MoveFilesToLevel(5);
|
||||
}
|
||||
ASSERT_EQ("0,0,0,0,0,2,1", FilesPerLevel());
|
||||
|
||||
SyncPoint::GetInstance()->SetCallBack(
|
||||
"CompactionJob::PrepareTimes():preclude_last_level_min_seqno",
|
||||
[](void* arg) { *static_cast<SequenceNumber*>(arg) = 0; });
|
||||
SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
ASSERT_OK(db_->SetOptions({{"preclude_last_level_data_seconds", "10000"}}));
|
||||
|
||||
auto l5_files = GetLevelFileMetadatas(5);
|
||||
auto l6_files = GetLevelFileMetadatas(6);
|
||||
ASSERT_EQ(2, l5_files.size());
|
||||
ASSERT_EQ(1, l6_files.size());
|
||||
|
||||
ASSERT_OK(db_->CompactFiles(CompactionOptions(),
|
||||
{MakeTableFileName(l5_files[1]->fd.GetNumber()),
|
||||
MakeTableFileName(l6_files[0]->fd.GetNumber())},
|
||||
6));
|
||||
|
||||
uint64_t l6_range_deletions = 0;
|
||||
for (auto* f : GetLevelFileMetadatas(5)) {
|
||||
ASSERT_EQ(0, f->num_range_deletions);
|
||||
}
|
||||
for (auto* f : GetLevelFileMetadatas(6)) {
|
||||
l6_range_deletions += f->num_range_deletions;
|
||||
}
|
||||
ASSERT_GT(l6_range_deletions, 0);
|
||||
}
|
||||
|
||||
// Tests DBIter::GetProperty("rocksdb.iterator.write-time") return a data's
|
||||
// approximate write unix time.
|
||||
class IteratorWriteTimeTest
|
||||
|
||||
+109
-4
@@ -761,6 +761,111 @@ TEST_F(DBBasicTest, ReuseManifestOnOpenFullStackComposition) {
|
||||
EXPECT_EQ("v", Get("k"));
|
||||
}
|
||||
|
||||
// Regression test for WAL recovery while publishing a fresh MANIFEST. The test
|
||||
// stores SSTs in a separate DB path, injects failure after CURRENT points at
|
||||
// the new MANIFEST, and simulates crash cleanup; the recovered SST must survive
|
||||
// because the synced MANIFEST references it.
|
||||
TEST_F(DBBasicTest, RecoverySstDirSyncedBeforeFreshManifestPublish) {
|
||||
auto fault_fs = std::make_shared<FaultInjectionTestFS>(env_->GetFileSystem());
|
||||
std::unique_ptr<Env> fault_env(NewCompositeEnv(fault_fs));
|
||||
|
||||
Options options = CurrentOptions();
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.env = fault_env.get();
|
||||
options.reuse_manifest_on_open = false;
|
||||
options.db_paths.emplace_back(dbname_ + "_2", 1ULL << 30);
|
||||
|
||||
DestroyAndReopen(options);
|
||||
ASSERT_OK(Put("base", "value"));
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
ASSERT_OK(Put("recovered", "value"));
|
||||
ASSERT_OK(db_->FlushWAL(true));
|
||||
Close();
|
||||
|
||||
fault_fs->ResetState();
|
||||
|
||||
std::atomic<bool> fail_after_current_publish{true};
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"VersionSet::ProcessManifestWrites:AfterSetCurrentFile", [&](void* arg) {
|
||||
if (fail_after_current_publish.exchange(false)) {
|
||||
ASSERT_NE(nullptr, arg);
|
||||
IOStatus* io_s = static_cast<IOStatus*>(arg);
|
||||
ASSERT_OK(*io_s);
|
||||
*io_s = IOStatus::IOError("injected current publish aftermath");
|
||||
}
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
Status s = TryReopen(options);
|
||||
ASSERT_TRUE(s.IsIOError()) << s.ToString();
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
|
||||
ASSERT_OK(fault_fs->DeleteFilesCreatedAfterLastDirSync(IOOptions(), nullptr));
|
||||
|
||||
s = TryReopen(options);
|
||||
ASSERT_OK(s);
|
||||
ASSERT_EQ("value", Get("base"));
|
||||
ASSERT_EQ("value", Get("recovered"));
|
||||
Close();
|
||||
}
|
||||
|
||||
// Regression test for WAL recovery while appending to a reused MANIFEST. The
|
||||
// first reopen forces recovery to create an SST and then fail after MANIFEST
|
||||
// sync. The simulated crash cleanup deletes files without a prior directory
|
||||
// sync; the recovered SST must survive because the synced MANIFEST references
|
||||
// it.
|
||||
TEST_F(DBBasicTest,
|
||||
ReuseManifestOnOpenSyncsRecoverySstDirBeforeManifestAppend) {
|
||||
auto fault_fs = std::make_shared<FaultInjectionTestFS>(env_->GetFileSystem());
|
||||
std::unique_ptr<Env> fault_env(NewCompositeEnv(fault_fs));
|
||||
|
||||
Options options = CurrentOptions();
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.env = fault_env.get();
|
||||
options.reuse_manifest_on_open = true;
|
||||
|
||||
DestroyAndReopen(options);
|
||||
ASSERT_OK(Put("base", "value"));
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
ASSERT_OK(Put("recovered", "value"));
|
||||
ASSERT_OK(db_->FlushWAL(true));
|
||||
Close();
|
||||
|
||||
fault_fs->ResetState();
|
||||
|
||||
std::atomic<bool> fail_after_manifest_sync{true};
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"VersionSet::ProcessManifestWrites:AfterSyncManifest", [&](void* arg) {
|
||||
if (fail_after_manifest_sync.exchange(false)) {
|
||||
ASSERT_NE(nullptr, arg);
|
||||
IOStatus* io_s = static_cast<IOStatus*>(arg);
|
||||
ASSERT_OK(*io_s);
|
||||
*io_s = IOStatus::IOError("injected manifest sync aftermath");
|
||||
}
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
Status s = TryReopen(options);
|
||||
ASSERT_TRUE(s.IsIOError()) << s.ToString();
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
|
||||
ASSERT_OK(fault_fs->DeleteFilesCreatedAfterLastDirSync(IOOptions(), nullptr));
|
||||
|
||||
s = TryReopen(options);
|
||||
ASSERT_OK(s);
|
||||
ASSERT_EQ("value", Get("base"));
|
||||
ASSERT_EQ("value", Get("recovered"));
|
||||
Close();
|
||||
}
|
||||
|
||||
// Direct unit test for WritableFileWriter's initial_file_size parameter:
|
||||
// verifies the visible size accessors report the existing on-disk size
|
||||
// immediately, rather than the constructor's zero default.
|
||||
@@ -5354,9 +5459,9 @@ class DBBasicTestMultiGet : public DBTestBase {
|
||||
std::vector<std::string> cf_names_;
|
||||
};
|
||||
|
||||
class DBBasicTestWithParallelIO : public DBBasicTestMultiGet,
|
||||
public testing::WithParamInterface<
|
||||
std::tuple<bool, bool, bool, uint32_t>> {
|
||||
class DBBasicTestWithParallelIO : public testing::WithParamInterface<
|
||||
std::tuple<bool, bool, bool, uint32_t>>,
|
||||
public DBBasicTestMultiGet {
|
||||
public:
|
||||
DBBasicTestWithParallelIO()
|
||||
: DBBasicTestMultiGet("/db_basic_test_with_parallel_io", 1,
|
||||
@@ -6226,7 +6331,7 @@ TEST_F(DBBasicTest, DisallowMemtableWrite) {
|
||||
Options options_disallow = options_allow;
|
||||
options_disallow.disallow_memtable_writes = true;
|
||||
options_disallow.paranoid_memory_checks = true;
|
||||
options_disallow.memtable_veirfy_per_key_checksum_on_seek = true;
|
||||
options_disallow.memtable_verify_per_key_checksum_on_seek = true;
|
||||
|
||||
DestroyAndReopen(options_allow);
|
||||
// CFs allowing and disallowing memtable write
|
||||
|
||||
@@ -1482,10 +1482,13 @@ TEST_P(DBBlockCacheTypeTest, AddRedundantStats) {
|
||||
// Access just data, forcing redundant load+insert
|
||||
ReadOptions read_options;
|
||||
std::unique_ptr<Iterator> iter{db_->NewIterator(read_options)};
|
||||
ASSERT_OK(iter->Refresh());
|
||||
|
||||
cache->SetNthLookupNotFound(1);
|
||||
iter->SeekToFirst();
|
||||
ASSERT_TRUE(iter->Valid());
|
||||
ASSERT_EQ(iter->key(), "bar");
|
||||
ASSERT_EQ(iter->value(), "value");
|
||||
|
||||
EXPECT_EQ(2, TestGetTickerCount(options, BLOCK_CACHE_INDEX_ADD));
|
||||
EXPECT_EQ(2, TestGetTickerCount(options, BLOCK_CACHE_FILTER_ADD));
|
||||
|
||||
@@ -2022,7 +2022,11 @@ TEST_F(DBBloomFilterTest, MutableFilterPolicy) {
|
||||
double expected_bpk = 10.0;
|
||||
// Other configs to try
|
||||
std::vector<std::pair<std::string, double>> configs = {
|
||||
{"ribbonfilter:10:-1", 7.0}, {"bloomfilter:5", 5.0}, {"nullptr", 0.0}};
|
||||
{"ribbonfilter:10:-1", 7.0},
|
||||
{"bloomfilter:5", 5.0},
|
||||
{"nullptr", 0.0},
|
||||
// As serialized in OPTIONS file
|
||||
{"{id=ribbonfilter:12:-1;bloom_before_level=-1;}", 8.4}};
|
||||
|
||||
table_options.cache_index_and_filter_blocks = true;
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
|
||||
@@ -427,6 +427,38 @@ TEST_F(DBCompactionAbortTest, AbortAutomaticCompaction) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DBCompactionAbortTest, AbortScheduledAutomaticCompactionBeforePick) {
|
||||
// The goal is to cover an automatic compaction that has been scheduled, but
|
||||
// aborts before the worker picks and removes a column family from the
|
||||
// compaction queue. This pins the scheduler bookkeeping invariant that
|
||||
// ResumeAllCompactions() must be able to schedule that still-queued work.
|
||||
constexpr int kCompactionTrigger = 4;
|
||||
constexpr int kNumL0Files = kCompactionTrigger + 1;
|
||||
Options options = GetOptionsWithStats();
|
||||
options.level0_file_num_compaction_trigger = kCompactionTrigger;
|
||||
options.max_background_compactions = 1;
|
||||
options.max_subcompactions = 1;
|
||||
options.disable_auto_compactions = false;
|
||||
Reopen(options);
|
||||
|
||||
SyncPointAbortHelper helper("BackgroundCallCompaction:0");
|
||||
helper.Setup(dbfull());
|
||||
|
||||
PopulateData(/*num_files=*/kNumL0Files, /*keys_per_file=*/100,
|
||||
/*value_size=*/1000);
|
||||
helper.CleanupAndWait();
|
||||
|
||||
const uint64_t compact_write_bytes_before_resume =
|
||||
stats_->getTickerCount(COMPACT_WRITE_BYTES);
|
||||
dbfull()->ResumeAllCompactions();
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
ASSERT_GT(stats_->getTickerCount(COMPACT_WRITE_BYTES),
|
||||
compact_write_bytes_before_resume);
|
||||
ASSERT_LT(NumTableFilesAtLevel(0), kNumL0Files);
|
||||
VerifyDataIntegrity(/*num_keys=*/100);
|
||||
}
|
||||
|
||||
TEST_F(DBCompactionAbortTest, AbortAndVerifyNoOutputFiles) {
|
||||
Options options = CurrentOptions();
|
||||
options.level0_file_num_compaction_trigger = 4;
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "compaction/compaction_picker_universal.h"
|
||||
#include "db/blob/blob_index.h"
|
||||
#include "db/db_test_util.h"
|
||||
#include "db/dbformat.h"
|
||||
#include "db/table_cache.h"
|
||||
#include "env/mock_env.h"
|
||||
#include "file/filename.h"
|
||||
#include "port/port.h"
|
||||
@@ -6651,6 +6653,572 @@ TEST_P(DBCompactionDirectIOTest, DirectIO) {
|
||||
INSTANTIATE_TEST_CASE_P(DBCompactionDirectIOTest, DBCompactionDirectIOTest,
|
||||
testing::Bool());
|
||||
|
||||
// With use_direct_io_for_compaction_reads OFF, compaction reads must stay
|
||||
// buffered: neither the compaction-input FileOptions nor a kernel O_DIRECT
|
||||
// open should fire. Runs on every platform (the sync points just don't fire
|
||||
// where O_DIRECT isn't reachable). Pairs with
|
||||
// UseDirectIoForCompactionReadsEndToEnd for the on case.
|
||||
TEST_F(DBCompactionTest, UseDirectIoForCompactionReadsOffStaysBuffered) {
|
||||
Options options = CurrentOptions();
|
||||
Destroy(options);
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.use_direct_reads = false;
|
||||
options.use_direct_io_for_compaction_reads = false;
|
||||
options.use_direct_io_for_flush_and_compaction = false;
|
||||
|
||||
std::atomic<bool> observed_direct_compaction_read{false};
|
||||
std::atomic<int> observed_callbacks{0};
|
||||
std::atomic<int> observed_odirect_opens{0};
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"CompactionJob::CreateInputIterator:InputFileOptions", [&](void* arg) {
|
||||
const auto* fo = static_cast<const FileOptions*>(arg);
|
||||
observed_callbacks.fetch_add(1, std::memory_order_relaxed);
|
||||
if (fo->use_direct_reads) {
|
||||
observed_direct_compaction_read.store(true,
|
||||
std::memory_order_relaxed);
|
||||
}
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"NewRandomAccessFile:O_DIRECT", [&](void* /*arg*/) {
|
||||
observed_odirect_opens.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
ASSERT_OK(TryReopen(options));
|
||||
|
||||
const std::string value(4096, 'v');
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
ASSERT_GT(observed_callbacks.load(), 0);
|
||||
ASSERT_FALSE(observed_direct_compaction_read.load());
|
||||
ASSERT_EQ(0, observed_odirect_opens.load());
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
Destroy(options);
|
||||
}
|
||||
|
||||
TEST_F(DBCompactionTest,
|
||||
UseDirectIoForCompactionReadsUsesBoundedEphemeralReaders) {
|
||||
auto fs = std::make_shared<MockFileSystem>(Env::Default()->GetSystemClock(),
|
||||
/*supports_direct_io=*/true);
|
||||
std::unique_ptr<Env> mock_env = NewCompositeEnv(fs);
|
||||
|
||||
Options options = CurrentOptions();
|
||||
options.env = mock_env.get();
|
||||
Destroy(options);
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.use_direct_reads = false;
|
||||
options.use_direct_io_for_compaction_reads = true;
|
||||
options.use_direct_io_for_flush_and_compaction = false;
|
||||
options.max_subcompactions = 3;
|
||||
options.statistics = CreateDBStatistics();
|
||||
|
||||
BlockBasedTableOptions table_options;
|
||||
table_options.block_cache = NewLRUCache(64 << 20);
|
||||
table_options.cache_index_and_filter_blocks = true;
|
||||
table_options.pin_l0_filter_and_index_blocks_in_cache = true;
|
||||
table_options.filter_policy.reset(NewBloomFilterPolicy(10));
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
|
||||
std::atomic<int> fresh_reader_opens{0};
|
||||
std::atomic<int> malformed_fresh_reader_options{0};
|
||||
std::atomic<int> avoid_shared_metadata_cache_opens{0};
|
||||
std::atomic<int> shared_metadata_cache_uses{0};
|
||||
std::atomic<size_t> input_iterator_file_bound{0};
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"TableCache::FindTable:FreshTableReader", [&](void* arg) {
|
||||
const auto* open_options = static_cast<TableCacheOpenOptions*>(arg);
|
||||
fresh_reader_opens.fetch_add(1, std::memory_order_relaxed);
|
||||
if (!open_options->open_ephemeral_table_reader ||
|
||||
!open_options->avoid_shared_metadata_cache ||
|
||||
!open_options->skip_filters) {
|
||||
malformed_fresh_reader_options.fetch_add(1,
|
||||
std::memory_order_relaxed);
|
||||
}
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"BlockBasedTable::PrefetchIndexAndFilterBlocks:SharedMetadataCache",
|
||||
[&](void* arg) {
|
||||
const auto* context = static_cast<std::pair<bool, bool>*>(arg);
|
||||
const bool avoid_shared_metadata_cache = context->first;
|
||||
const bool use_cache = context->second;
|
||||
if (avoid_shared_metadata_cache) {
|
||||
avoid_shared_metadata_cache_opens.fetch_add(
|
||||
1, std::memory_order_relaxed);
|
||||
if (use_cache) {
|
||||
shared_metadata_cache_uses.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"VersionSet::MakeInputIterator:NewCompactionMergingIterator",
|
||||
[&](void* arg) {
|
||||
input_iterator_file_bound.fetch_add(*static_cast<size_t*>(arg),
|
||||
std::memory_order_relaxed);
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
ASSERT_OK(TryReopen(options));
|
||||
|
||||
const std::string value(4096, 'v');
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
ASSERT_GT(fresh_reader_opens.load(), 0);
|
||||
EXPECT_EQ(0, malformed_fresh_reader_options.load());
|
||||
ASSERT_GT(avoid_shared_metadata_cache_opens.load(), 0);
|
||||
EXPECT_EQ(0, shared_metadata_cache_uses.load());
|
||||
ASSERT_GT(input_iterator_file_bound.load(), 0);
|
||||
EXPECT_LE(static_cast<size_t>(fresh_reader_opens.load()),
|
||||
input_iterator_file_bound.load());
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
Destroy(options);
|
||||
}
|
||||
|
||||
// End-to-end check that use_direct_io_for_compaction_reads opens compaction
|
||||
// inputs with O_DIRECT while use_direct_reads stays off (user reads buffered).
|
||||
// The NewRandomAccessFile:O_DIRECT sync point in env/fs_posix.cc fires once
|
||||
// per fresh open with the O_DIRECT flag, so this proves the kernel path, not
|
||||
// just the FileOptions. Only runs on platforms that take the O_DIRECT path.
|
||||
#if !defined(OS_MACOSX) && !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && \
|
||||
!defined(OS_WIN)
|
||||
TEST_F(DBCompactionTest, UseDirectIoForCompactionReadsEndToEnd) {
|
||||
if (!IsDirectIOSupported()) {
|
||||
ROCKSDB_GTEST_BYPASS("Direct IO not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
Options options = CurrentOptions();
|
||||
Destroy(options);
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
// User reads stay buffered, compaction reads should switch to O_DIRECT.
|
||||
options.use_direct_reads = false;
|
||||
options.use_direct_io_for_compaction_reads = true;
|
||||
// Isolate the read-side change; leave the compaction write path buffered.
|
||||
options.use_direct_io_for_flush_and_compaction = false;
|
||||
|
||||
// Sync-point callbacks fire on compaction threads while the test thread
|
||||
// reads these counters, so use atomics to avoid a data race.
|
||||
std::atomic<int> observed_run_starts{0};
|
||||
std::atomic<int> observed_odirect_opens{0};
|
||||
std::atomic<bool> observed_direct_compaction_read{false};
|
||||
std::atomic<int> observed_callbacks{0};
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency({});
|
||||
// Plumbing-level probe: the compaction-input FileOptions should carry
|
||||
// use_direct_reads = true when the new flag is enabled.
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"CompactionJob::CreateInputIterator:InputFileOptions", [&](void* arg) {
|
||||
const auto* fo = static_cast<const FileOptions*>(arg);
|
||||
observed_callbacks.fetch_add(1, std::memory_order_relaxed);
|
||||
if (fo != nullptr && fo->use_direct_reads) {
|
||||
observed_direct_compaction_read.store(true,
|
||||
std::memory_order_relaxed);
|
||||
}
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"CompactionJob::Run():Start", [&](void* /*arg*/) {
|
||||
observed_run_starts.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
// Kernel-level probe: this fires only when open() is issued with O_DIRECT,
|
||||
// proving we change the actual cache mode, not just the FileOptions struct.
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"NewRandomAccessFile:O_DIRECT", [&](void* /*arg*/) {
|
||||
observed_odirect_opens.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
Status s = TryReopen(options);
|
||||
if (s.IsNotSupported() || s.IsInvalidArgument()) {
|
||||
ROCKSDB_GTEST_BYPASS(
|
||||
"Direct IO reads not supported in this test environment");
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
return;
|
||||
}
|
||||
ASSERT_OK(s);
|
||||
|
||||
// Produce two L0 files with OVERLAPPING key ranges so that CompactRange has
|
||||
// actual merge work to do (otherwise RocksDB performs a trivial file move
|
||||
// and never constructs a CompactionJob).
|
||||
const std::string value(4096, 'v');
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
// User reads should still go through the buffered path. Confirm that the
|
||||
// option does not silently flip use_direct_reads for user reads.
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
std::string actual;
|
||||
ASSERT_OK(db_->Get(ReadOptions(), Key(i), &actual));
|
||||
ASSERT_EQ(value, actual);
|
||||
}
|
||||
|
||||
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
||||
// Wait for compaction to complete and CompactionJob to be constructed.
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
// Confirm the compaction actually ran; otherwise the missing sync-point hits
|
||||
// would be a test-setup problem, not an option regression.
|
||||
ASSERT_GT(observed_run_starts.load(), 0)
|
||||
<< "CompactionJob::Run():Start never fired; CompactRange did not "
|
||||
"schedule a compaction.";
|
||||
ASSERT_GT(observed_callbacks.load(), 0);
|
||||
ASSERT_TRUE(observed_direct_compaction_read.load());
|
||||
// At least one compaction-input open went through O_DIRECT. Without the
|
||||
// TableCache bypass this would be zero, since compaction would reuse the
|
||||
// buffered handles cached for user reads.
|
||||
EXPECT_GT(observed_odirect_opens.load(), 0)
|
||||
<< "no compaction-input opens went through O_DIRECT; "
|
||||
"observed_odirect_opens="
|
||||
<< observed_odirect_opens.load();
|
||||
|
||||
// Quick sanity sweep after compaction to confirm data is intact.
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
std::string actual;
|
||||
ASSERT_OK(db_->Get(ReadOptions(), Key(i), &actual));
|
||||
ASSERT_EQ(value, actual);
|
||||
}
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
Destroy(options);
|
||||
}
|
||||
|
||||
// Exercise the LevelIterator bypass path (L1+ compactions) with range
|
||||
// tombstones, where the ephemeral TableReader's lifetime is coupled to the
|
||||
// range_tombstone_iter the file iterator returns. The end-to-end test above
|
||||
// only makes two L0 files, which take the direct NewIterator path and never
|
||||
// hit LevelIterator. Here we build L1/L2 with tombstones and compact L1->L2 so
|
||||
// LevelIterator::NewFileIterator drives the bypass; a wrong reader/iterator
|
||||
// lifetime would crash or trip sanitizers as LevelIterator switches files.
|
||||
// Correctness is checked by computing the expected state of every key and
|
||||
// asserting Get() matches: wave-2 puts beat wave-1, and each key's most-recent
|
||||
// covering tombstone shadows older puts.
|
||||
TEST_F(DBCompactionTest,
|
||||
UseDirectIoForCompactionReadsLevelIteratorWithTombstones) {
|
||||
if (!IsDirectIOSupported()) {
|
||||
ROCKSDB_GTEST_BYPASS("Direct IO not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
Options options = CurrentOptions();
|
||||
Destroy(options);
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.use_direct_reads = false;
|
||||
options.use_direct_io_for_compaction_reads = true;
|
||||
options.use_direct_io_for_flush_and_compaction = false;
|
||||
// Small files / small level base so we can pack data into L1 and L2 with
|
||||
// a few flushes and CompactRange calls instead of needing millions of keys.
|
||||
options.write_buffer_size = 64 * 1024;
|
||||
options.target_file_size_base = 64 * 1024;
|
||||
options.max_bytes_for_level_base = 256 * 1024;
|
||||
options.level0_file_num_compaction_trigger = 100; // never auto-trigger
|
||||
|
||||
std::atomic<int> observed_odirect_opens{0};
|
||||
std::atomic<int> observed_run_starts{0};
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"NewRandomAccessFile:O_DIRECT", [&](void* /*arg*/) {
|
||||
observed_odirect_opens.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
||||
"CompactionJob::Run():Start", [&](void* /*arg*/) {
|
||||
observed_run_starts.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
||||
|
||||
Status s = TryReopen(options);
|
||||
if (s.IsNotSupported() || s.IsInvalidArgument()) {
|
||||
ROCKSDB_GTEST_BYPASS(
|
||||
"Direct IO reads not supported in this test environment");
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
return;
|
||||
}
|
||||
ASSERT_OK(s);
|
||||
|
||||
// Use distinguishable values per wave so we can verify which wave's put
|
||||
// won the merge for each key, not just "some put won".
|
||||
const std::string wave1_value(1024, '1');
|
||||
const std::string wave2_value(1024, '2');
|
||||
|
||||
auto write_batch = [&](int begin, int end, const std::string& value,
|
||||
bool with_range_tombstone) {
|
||||
for (int i = begin; i < end; ++i) {
|
||||
ASSERT_OK(Put(Key(i), value));
|
||||
}
|
||||
if (with_range_tombstone) {
|
||||
// Drop a slice in the middle of the just-written range. The
|
||||
// DeleteRange follows the puts in this batch, so its sequence number
|
||||
// is higher and it shadows the puts on [del_lo, del_hi) within this
|
||||
// SST.
|
||||
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(),
|
||||
Key(begin + (end - begin) / 4),
|
||||
Key(begin + 3 * (end - begin) / 4)));
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
};
|
||||
|
||||
// Wave 1: four flushed SSTs covering [0, 800), each with a tombstone
|
||||
// covering the middle half of its own range. Then compact down so the
|
||||
// next phase exercises LevelIterator over L1+ files.
|
||||
constexpr int kWave1Begin = 0;
|
||||
constexpr int kWave1End = 800;
|
||||
constexpr int kWave1BatchSize = 200;
|
||||
for (int batch_begin = kWave1Begin; batch_begin < kWave1End;
|
||||
batch_begin += kWave1BatchSize) {
|
||||
write_batch(batch_begin, batch_begin + kWave1BatchSize, wave1_value,
|
||||
/*with_range_tombstone=*/true);
|
||||
}
|
||||
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
// Wave 2: two more flushed SSTs at L0 that overlap wave 1, each with their
|
||||
// own range tombstone. The puts in wave 2 have higher seqno than wave 1,
|
||||
// so they win when not tombstoned.
|
||||
struct Wave2Range {
|
||||
int begin;
|
||||
int end;
|
||||
};
|
||||
const Wave2Range wave2_ranges[] = {{50, 250}, {350, 550}};
|
||||
for (const auto& r : wave2_ranges) {
|
||||
write_batch(r.begin, r.end, wave2_value, /*with_range_tombstone=*/true);
|
||||
}
|
||||
|
||||
const int run_starts_before = observed_run_starts.load();
|
||||
const int odirect_before = observed_odirect_opens.load();
|
||||
|
||||
// Compact everything together, forcing a LevelIterator over the lower-level
|
||||
// files on the bypass path. Wrong ephemeral reader / tombstone-iter
|
||||
// lifetimes should trip sanitizers here.
|
||||
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
ASSERT_GT(observed_run_starts.load(), run_starts_before)
|
||||
<< "expected at least one compaction to run during the L1+ phase";
|
||||
EXPECT_GT(observed_odirect_opens.load(), odirect_before)
|
||||
<< "no compaction-input opens went through O_DIRECT during L1+ "
|
||||
"compaction; LevelIterator bypass path may be broken";
|
||||
|
||||
// Compute the precise expected state per key from the test parameters.
|
||||
// For each k in the wave-1 range:
|
||||
// - If k is inside a wave-2 batch: wave-2 wins. NotFound iff k is in
|
||||
// that batch's tombstone range; otherwise present with wave2_value.
|
||||
// - Else: wave 1 wins. NotFound iff k is in its batch's tombstone
|
||||
// range; otherwise present with wave1_value.
|
||||
enum class Expectation { kAbsent, kWave1Value, kWave2Value };
|
||||
auto classify = [&](int k) -> Expectation {
|
||||
// Wave 2 first (it shadows wave 1 wherever it covers).
|
||||
for (const auto& r : wave2_ranges) {
|
||||
if (k >= r.begin && k < r.end) {
|
||||
const int width = r.end - r.begin;
|
||||
const int del_lo = r.begin + width / 4;
|
||||
const int del_hi = r.begin + 3 * width / 4;
|
||||
if (k >= del_lo && k < del_hi) {
|
||||
return Expectation::kAbsent;
|
||||
}
|
||||
return Expectation::kWave2Value;
|
||||
}
|
||||
}
|
||||
// Fall back to wave 1.
|
||||
const int batch = (k - kWave1Begin) / kWave1BatchSize;
|
||||
const int batch_begin = kWave1Begin + batch * kWave1BatchSize;
|
||||
const int del_lo = batch_begin + kWave1BatchSize / 4;
|
||||
const int del_hi = batch_begin + 3 * kWave1BatchSize / 4;
|
||||
if (k >= del_lo && k < del_hi) {
|
||||
return Expectation::kAbsent;
|
||||
}
|
||||
return Expectation::kWave1Value;
|
||||
};
|
||||
|
||||
int present_w1 = 0;
|
||||
int present_w2 = 0;
|
||||
int absent = 0;
|
||||
std::string actual;
|
||||
for (int k = kWave1Begin; k < kWave1End; ++k) {
|
||||
const Status get_s = db_->Get(ReadOptions(), Key(k), &actual);
|
||||
const Expectation exp = classify(k);
|
||||
switch (exp) {
|
||||
case Expectation::kAbsent:
|
||||
EXPECT_TRUE(get_s.IsNotFound())
|
||||
<< "key " << k << " expected NotFound (covered by tombstone); "
|
||||
<< "got status=" << get_s.ToString()
|
||||
<< " value_len=" << (get_s.ok() ? actual.size() : 0);
|
||||
++absent;
|
||||
break;
|
||||
case Expectation::kWave1Value:
|
||||
ASSERT_OK(get_s) << "key " << k << " expected wave-1 value";
|
||||
EXPECT_EQ(wave1_value, actual)
|
||||
<< "key " << k << " expected wave-1 value but got a different one";
|
||||
++present_w1;
|
||||
break;
|
||||
case Expectation::kWave2Value:
|
||||
ASSERT_OK(get_s) << "key " << k << " expected wave-2 value";
|
||||
EXPECT_EQ(wave2_value, actual)
|
||||
<< "key " << k << " expected wave-2 value but got a different one";
|
||||
++present_w2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// All three buckets should be non-empty, so the test really exercises both
|
||||
// tombstone paths and the wave-2-wins path. A zero here means the setup
|
||||
// drifted and the setup (not these checks) should be fixed.
|
||||
EXPECT_GT(present_w1, 0);
|
||||
EXPECT_GT(present_w2, 0);
|
||||
EXPECT_GT(absent, 0);
|
||||
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
||||
Destroy(options);
|
||||
}
|
||||
|
||||
// With the option enabled, run reader threads against the live DB while manual
|
||||
// compactions run in the background. Each compaction-input file is open through
|
||||
// an ephemeral O_DIRECT handle while the shared TableCache still serves user
|
||||
// reads through a buffered handle, so the same SST is open in two cache modes
|
||||
// at once. This stresses that coexistence under TSAN/ASAN/UBSAN; it asserts
|
||||
// reads stay consistent and final values match the last writes, not anything
|
||||
// about timing.
|
||||
TEST_F(DBCompactionTest, UseDirectIoForCompactionReadsConcurrentReadStress) {
|
||||
if (!IsDirectIOSupported()) {
|
||||
ROCKSDB_GTEST_BYPASS("Direct IO not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
Options options = CurrentOptions();
|
||||
Destroy(options);
|
||||
options.create_if_missing = true;
|
||||
options.disable_auto_compactions = true;
|
||||
options.use_direct_reads = false;
|
||||
options.use_direct_io_for_compaction_reads = true;
|
||||
options.use_direct_io_for_flush_and_compaction = false;
|
||||
options.write_buffer_size = 64 * 1024;
|
||||
options.target_file_size_base = 64 * 1024;
|
||||
options.max_bytes_for_level_base = 256 * 1024;
|
||||
options.level0_file_num_compaction_trigger = 100; // never auto-trigger
|
||||
|
||||
Status s = TryReopen(options);
|
||||
if (s.IsNotSupported() || s.IsInvalidArgument()) {
|
||||
ROCKSDB_GTEST_BYPASS(
|
||||
"Direct IO reads not supported in this test environment");
|
||||
return;
|
||||
}
|
||||
ASSERT_OK(s);
|
||||
|
||||
constexpr int kNumKeys = 512;
|
||||
constexpr int kValueSize = 256;
|
||||
const std::string base_value(kValueSize, 'b');
|
||||
|
||||
// Initial population, flushed into a few L0 SSTs.
|
||||
for (int i = 0; i < kNumKeys; ++i) {
|
||||
ASSERT_OK(Put(Key(i), base_value));
|
||||
if (i > 0 && i % 128 == 0) {
|
||||
ASSERT_OK(Flush());
|
||||
}
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
|
||||
std::atomic<bool> stop{false};
|
||||
std::atomic<int64_t> reads_observed{0};
|
||||
std::atomic<int64_t> read_errors{0};
|
||||
|
||||
// Reader threads loop until stop is set, recording any status that isn't OK
|
||||
// or NotFound. The point is to surface Corruption/IOError/use-after-free, so
|
||||
// the main thread can fail the test.
|
||||
constexpr int kNumReaders = 4;
|
||||
std::vector<port::Thread> readers;
|
||||
readers.reserve(kNumReaders);
|
||||
for (int t = 0; t < kNumReaders; ++t) {
|
||||
readers.emplace_back([&, t]() {
|
||||
std::string value;
|
||||
while (!stop.load(std::memory_order_acquire)) {
|
||||
const int k =
|
||||
(t * 7919 +
|
||||
static_cast<int>(reads_observed.load(std::memory_order_relaxed))) %
|
||||
kNumKeys;
|
||||
Status read_s = db_->Get(ReadOptions(), Key(k), &value);
|
||||
if (!read_s.ok() && !read_s.IsNotFound()) {
|
||||
read_errors.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
reads_observed.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Drive a few rounds of writes and compactions on the main thread while
|
||||
// the readers hammer Get(). Each round overwrites every key with a
|
||||
// round-tagged value and then compacts.
|
||||
constexpr int kRounds = 4;
|
||||
std::string last_value = base_value;
|
||||
for (int round = 0; round < kRounds; ++round) {
|
||||
const std::string round_value(kValueSize,
|
||||
static_cast<char>('A' + (round % 26)));
|
||||
for (int i = 0; i < kNumKeys; ++i) {
|
||||
ASSERT_OK(Put(Key(i), round_value));
|
||||
if (i > 0 && i % 64 == 0) {
|
||||
ASSERT_OK(Flush());
|
||||
}
|
||||
}
|
||||
ASSERT_OK(Flush());
|
||||
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
last_value = round_value;
|
||||
}
|
||||
|
||||
stop.store(true, std::memory_order_release);
|
||||
for (auto& reader : readers) {
|
||||
reader.join();
|
||||
}
|
||||
|
||||
// Every key must now hold the final round's value. Catches wholesale
|
||||
// corruption the sampling readers might miss, and confirms compaction
|
||||
// finished under the bypass path.
|
||||
std::string value;
|
||||
for (int i = 0; i < kNumKeys; ++i) {
|
||||
ASSERT_OK(db_->Get(ReadOptions(), Key(i), &value));
|
||||
EXPECT_EQ(last_value, value);
|
||||
}
|
||||
EXPECT_GT(reads_observed.load(), 0)
|
||||
<< "reader threads never observed a single read; test was a no-op";
|
||||
EXPECT_EQ(0, read_errors.load())
|
||||
<< "concurrent reads against compaction with bypass-path saw "
|
||||
<< read_errors.load() << " non-OK/non-NotFound status returns";
|
||||
|
||||
Destroy(options);
|
||||
}
|
||||
#endif // !defined(OS_MACOSX) && !defined(OS_OPENBSD) && ...
|
||||
|
||||
class CompactionPriTest : public DBTestBase,
|
||||
public testing::WithParamInterface<uint32_t> {
|
||||
public:
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
class DBTest2 : public DBTestBase {
|
||||
public:
|
||||
DBTest2() : DBTestBase("db_test2", /*env_do_fsync=*/true) {}
|
||||
DBTest2() : DBTestBase("db_etc2_test", /*env_do_fsync=*/true) {}
|
||||
};
|
||||
|
||||
TEST_F(DBTest2, OpenForReadOnly) {
|
||||
@@ -330,6 +330,8 @@ class DBTestSharedWriteBufferAcrossCFs
|
||||
|
||||
TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
|
||||
Options options = CurrentOptions();
|
||||
options.statistics = CreateDBStatistics();
|
||||
options.statistics->set_stats_level(StatsLevel::kAll);
|
||||
options.arena_block_size = 4096;
|
||||
auto flush_listener = std::make_shared<FlushCounterListener>();
|
||||
options.listeners.push_back(flush_listener);
|
||||
@@ -497,6 +499,29 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
|
||||
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
|
||||
static_cast<uint64_t>(2));
|
||||
}
|
||||
const uint64_t wbm_flushes =
|
||||
TestGetTickerCount(options, FLUSH_REASON_WRITE_BUFFER_MANAGER);
|
||||
ASSERT_GT(wbm_flushes, 0);
|
||||
EXPECT_EQ(0, TestGetTickerCount(options, FLUSH_REASON_WRITE_BUFFER_FULL));
|
||||
|
||||
HistogramData all_memtable_memory;
|
||||
options.statistics->histogramData(FLUSH_MEMTABLE_MEMORY_BYTES,
|
||||
&all_memtable_memory);
|
||||
EXPECT_GE(all_memtable_memory.count, wbm_flushes);
|
||||
EXPECT_GT(all_memtable_memory.sum, 0);
|
||||
|
||||
HistogramData all_memtable_data_size;
|
||||
options.statistics->histogramData(FLUSH_MEMTABLE_TOTAL_DATA_SIZE,
|
||||
&all_memtable_data_size);
|
||||
EXPECT_GE(all_memtable_data_size.count, wbm_flushes);
|
||||
EXPECT_GT(all_memtable_data_size.sum, 0);
|
||||
|
||||
HistogramData wbm_memtable_memory;
|
||||
options.statistics->histogramData(
|
||||
FLUSH_WRITE_BUFFER_MANAGER_MEMTABLE_MEMORY_BYTES, &wbm_memtable_memory);
|
||||
EXPECT_EQ(wbm_flushes, wbm_memtable_memory.count);
|
||||
EXPECT_GT(wbm_memtable_memory.sum, 0);
|
||||
|
||||
if (cost_cache_) {
|
||||
ASSERT_GE(cache->GetUsage(), 256 * 1024);
|
||||
Close();
|
||||
+253
-34
@@ -1,9 +1,12 @@
|
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
// 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).
|
||||
|
||||
#include "db/db_test_util.h"
|
||||
#include "rocksdb/convenience.h"
|
||||
#include "rocksdb/metadata.h"
|
||||
#include "rocksdb/sst_file_writer.h"
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
@@ -43,50 +46,98 @@ TEST_F(DBEtc3Test, AutoTuneManifestSize) {
|
||||
ASSERT_EQ(DBOptions{}.max_manifest_space_amp_pct, 500);
|
||||
|
||||
Options options = CurrentOptions();
|
||||
ASSERT_OK(db_->SetOptions({{"level0_file_num_compaction_trigger", "20"}}));
|
||||
// Test setup: create many flushed files. Keep level compaction semantics so
|
||||
// DeleteFilesInRanges can remove non-L0 files, but prevent automatic
|
||||
// compactions and write stalls from adding unrelated behavior.
|
||||
options.disable_auto_compactions = true;
|
||||
options.level0_slowdown_writes_trigger = 100;
|
||||
options.level0_stop_writes_trigger = 200;
|
||||
|
||||
// Use large column family names to essentially control the amount of payload
|
||||
// data needed for the manifest file. Drop manifest entries don't include the
|
||||
// CF name so are small.
|
||||
// Test strategy: use large column family names to control the rough amount
|
||||
// of payload added to the MANIFEST. Drop manifest entries do not include the
|
||||
// CF name, so they are small.
|
||||
//
|
||||
// Most CF helper calls piggy-back a background manifest write so the main
|
||||
// auto-tuning phases continue to test the unrelaxed background threshold
|
||||
// even though CF manipulation itself is foreground. Phase-specific foreground
|
||||
// checks disable that piggy-backed background write.
|
||||
uint64_t prev_manifest_num = 0, cur_manifest_num = 0;
|
||||
std::deque<ColumnFamilyHandle*> handles;
|
||||
int counter = 5;
|
||||
auto AddCfFn = [&]() {
|
||||
auto UpdateManifestNumsFrom = [&](uint64_t before_manifest_num) {
|
||||
prev_manifest_num = before_manifest_num;
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
};
|
||||
auto BackgroundManifestWriteFn = [&]() {
|
||||
uint64_t before_manifest_num = cur_manifest_num;
|
||||
ASSERT_OK(Put("x", std::to_string(counter++)));
|
||||
ASSERT_OK(Flush());
|
||||
UpdateManifestNumsFrom(before_manifest_num);
|
||||
};
|
||||
auto AddCfFn = [&](bool include_background_manifest_write = true) {
|
||||
uint64_t before_manifest_num = cur_manifest_num;
|
||||
std::string name = "cf" + std::to_string(counter++);
|
||||
name.resize(1000, 'a');
|
||||
ASSERT_OK(db_->CreateColumnFamily(options, name, &handles.emplace_back()));
|
||||
prev_manifest_num = cur_manifest_num;
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
if (include_background_manifest_write) {
|
||||
BackgroundManifestWriteFn();
|
||||
}
|
||||
UpdateManifestNumsFrom(before_manifest_num);
|
||||
};
|
||||
auto DropCfFn = [&]() {
|
||||
auto DropCfFn = [&](bool include_background_manifest_write = true) {
|
||||
uint64_t before_manifest_num = cur_manifest_num;
|
||||
ASSERT_OK(db_->DropColumnFamily(handles.front()));
|
||||
ASSERT_OK(db_->DestroyColumnFamilyHandle(handles.front()));
|
||||
handles.pop_front();
|
||||
prev_manifest_num = cur_manifest_num;
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
};
|
||||
auto TrivialManifestWriteFn = [&]() {
|
||||
ASSERT_OK(Put("x", std::to_string(counter++)));
|
||||
ASSERT_OK(Flush());
|
||||
prev_manifest_num = cur_manifest_num;
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
if (include_background_manifest_write) {
|
||||
BackgroundManifestWriteFn();
|
||||
}
|
||||
UpdateManifestNumsFrom(before_manifest_num);
|
||||
};
|
||||
|
||||
// ---- Phase 1: foreground threshold relaxation is bounded ----
|
||||
//
|
||||
// Foreground operations should only get about 25% extra headroom, not an
|
||||
// unbounded threshold. With 1000-byte CF names and a 3000-byte normal limit,
|
||||
// the relaxed limit should allow the first four foreground-only CF additions
|
||||
// but require rotation on the fifth.
|
||||
options.max_manifest_file_size = 3000;
|
||||
options.max_manifest_space_amp_pct = 0;
|
||||
DestroyAndReopen(options);
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
prev_manifest_num = cur_manifest_num;
|
||||
for (int i = 1; i <= 4; ++i) {
|
||||
AddCfFn(/*include_background_manifest_write=*/false);
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
}
|
||||
AddCfFn(/*include_background_manifest_write=*/false);
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
while (!handles.empty()) {
|
||||
ASSERT_OK(db_->DestroyColumnFamilyHandle(handles.front()));
|
||||
handles.pop_front();
|
||||
}
|
||||
|
||||
// ---- Phase 2: no auto-tuning means frequent rotation ----
|
||||
//
|
||||
options.max_manifest_file_size = 1000000;
|
||||
options.max_manifest_space_amp_pct = 0; // no auto-tuning yet
|
||||
DestroyAndReopen(options);
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
prev_manifest_num = cur_manifest_num;
|
||||
|
||||
// With the generous (minimum) maximum manifest size, should not be rotated
|
||||
// With the generous minimum manifest size, should not be rotated.
|
||||
AddCfFn();
|
||||
AddCfFn();
|
||||
AddCfFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// Change options for small max and (still) no auto-tuning
|
||||
// Lower the minimum while still disabling auto-tuning.
|
||||
ASSERT_OK(db_->SetDBOptions({{"max_manifest_file_size", "3000"}}));
|
||||
|
||||
// Takes effect on the next manifest write
|
||||
TrivialManifestWriteFn();
|
||||
BackgroundManifestWriteFn();
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// Now we have to rewrite the whole manifest on each write because the
|
||||
@@ -97,28 +148,31 @@ TEST_F(DBEtc3Test, AutoTuneManifestSize) {
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
AddCfFn();
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
TrivialManifestWriteFn();
|
||||
BackgroundManifestWriteFn();
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// ---- Phase 3: auto-tuning raises the background threshold ----
|
||||
//
|
||||
// Enabling auto-tuning should fix this, immediately for next manifest writes.
|
||||
// This will allow up to double-ish the size of the compacted manifest,
|
||||
// which last should have been 4000 + some bytes.
|
||||
// This will allow up to roughly double the size of the compacted manifest,
|
||||
// which now includes CF entries plus the piggy-backed background writes.
|
||||
ASSERT_EQ(handles.size(), 4U);
|
||||
ASSERT_OK(db_->SetDBOptions({{"max_manifest_space_amp_pct", "105"}}));
|
||||
ASSERT_OK(db_->SetDBOptions({{"max_manifest_space_amp_pct", "95"}}));
|
||||
|
||||
// After 9 CF names should be enough to rotate the manifest
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
// Auto-tuning lets several more CF names accumulate in the MANIFEST before
|
||||
// the piggy-backed background write crosses the threshold.
|
||||
for (int i = 1; i <= 3; ++i) {
|
||||
if ((i % 2) == 1) {
|
||||
DropCfFn();
|
||||
}
|
||||
AddCfFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
}
|
||||
TrivialManifestWriteFn();
|
||||
AddCfFn();
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// We now have a different last compacted manifest size, should be
|
||||
// able to go beyond 9 CFs named in manifest this time.
|
||||
// We now have a different last compacted manifest size, so the next
|
||||
// threshold should be based on the newly compacted MANIFEST.
|
||||
ASSERT_EQ(handles.size(), 6U);
|
||||
|
||||
DropCfFn();
|
||||
@@ -128,11 +182,10 @@ TEST_F(DBEtc3Test, AutoTuneManifestSize) {
|
||||
AddCfFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
}
|
||||
// We've written 10 named CFs to the manifest. We should be able to
|
||||
// dynamically change the auto-tuning still based on the last "compacted"
|
||||
// manifest size of 7000 + some bytes.
|
||||
// We should be able to dynamically change the auto-tuning still based on
|
||||
// the last "compacted" manifest size.
|
||||
ASSERT_OK(db_->SetDBOptions({{"max_manifest_space_amp_pct", "51"}}));
|
||||
TrivialManifestWriteFn();
|
||||
BackgroundManifestWriteFn();
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
// And the "compacted" manifest size has reset again, so should be changed
|
||||
// again sooner.
|
||||
@@ -141,13 +194,179 @@ TEST_F(DBEtc3Test, AutoTuneManifestSize) {
|
||||
AddCfFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
}
|
||||
// Enough for manifest change
|
||||
AddCfFn();
|
||||
|
||||
// ---- Phase 4: foreground operations use relaxed threshold ----
|
||||
//
|
||||
// The current MANIFEST is now large enough for the next background manifest
|
||||
// write to rotate it, but still small enough for foreground operations to use
|
||||
// their 25% extra headroom. Assert that each foreground operation stays on
|
||||
// the same MANIFEST, then verify the next background write rotates.
|
||||
const std::string external_files_dir = dbname_ + "/external_files";
|
||||
ASSERT_OK(env_->CreateDirIfMissing(external_files_dir));
|
||||
auto WriteExternalSstFile = [&](const std::string& file_name,
|
||||
const std::string& key,
|
||||
const std::string& value) {
|
||||
const std::string file_path = external_files_dir + "/" + file_name;
|
||||
Status ignored = env_->DeleteFile(file_path);
|
||||
ignored.PermitUncheckedError();
|
||||
|
||||
SstFileWriter sst_file_writer(EnvOptions(), options);
|
||||
ASSERT_OK(sst_file_writer.Open(file_path));
|
||||
ASSERT_OK(sst_file_writer.Put(key, value));
|
||||
ASSERT_OK(sst_file_writer.Finish());
|
||||
};
|
||||
auto IngestExternalFileForegroundManifestWriteFn =
|
||||
[&](std::string* ingested_key) {
|
||||
uint64_t before_manifest_num = cur_manifest_num;
|
||||
const std::string key = "z" + std::to_string(counter++);
|
||||
const std::string value = "v" + std::to_string(counter++);
|
||||
const std::string file_name =
|
||||
"ingest_" + std::to_string(counter++) + ".sst";
|
||||
const std::string file_path = external_files_dir + "/" + file_name;
|
||||
WriteExternalSstFile(file_name, key, value);
|
||||
|
||||
ASSERT_OK(
|
||||
db_->IngestExternalFile({file_path}, IngestExternalFileOptions()));
|
||||
ASSERT_EQ(value, Get(key));
|
||||
*ingested_key = key;
|
||||
Status ignored = env_->DeleteFile(file_path);
|
||||
ignored.PermitUncheckedError();
|
||||
UpdateManifestNumsFrom(before_manifest_num);
|
||||
};
|
||||
auto CreateColumnFamilyWithImportForegroundManifestWriteFn = [&]() {
|
||||
uint64_t before_manifest_num = cur_manifest_num;
|
||||
const std::string cf_name = "import_cf" + std::to_string(counter++);
|
||||
const std::string key = "import" + std::to_string(counter++);
|
||||
const std::string value = "v" + std::to_string(counter++);
|
||||
const std::string file_name =
|
||||
"import_" + std::to_string(counter++) + ".sst";
|
||||
const std::string file_path = external_files_dir + "/" + file_name;
|
||||
WriteExternalSstFile(file_name, key, value);
|
||||
|
||||
LiveFileMetaData file_metadata;
|
||||
file_metadata.name = file_name;
|
||||
file_metadata.db_path = external_files_dir;
|
||||
file_metadata.smallest_seqno = 0;
|
||||
file_metadata.largest_seqno = 0;
|
||||
file_metadata.level = 0;
|
||||
ExportImportFilesMetaData metadata;
|
||||
metadata.files.push_back(file_metadata);
|
||||
metadata.db_comparator_name = options.comparator->Name();
|
||||
|
||||
ColumnFamilyHandle* import_handle = nullptr;
|
||||
ASSERT_OK(db_->CreateColumnFamilyWithImport(options, cf_name,
|
||||
ImportColumnFamilyOptions(),
|
||||
metadata, &import_handle));
|
||||
ASSERT_NE(import_handle, nullptr);
|
||||
handles.push_back(import_handle);
|
||||
|
||||
std::string result;
|
||||
ASSERT_OK(db_->Get(ReadOptions(), import_handle, key, &result));
|
||||
ASSERT_EQ(value, result);
|
||||
Status ignored = env_->DeleteFile(file_path);
|
||||
ignored.PermitUncheckedError();
|
||||
UpdateManifestNumsFrom(before_manifest_num);
|
||||
};
|
||||
auto DeleteFilesInRangesForegroundManifestWriteFn =
|
||||
[&](const std::string& key) {
|
||||
uint64_t before_manifest_num = cur_manifest_num;
|
||||
const std::string limit = key + "\xff";
|
||||
std::vector<RangeOpt> ranges;
|
||||
ranges.emplace_back(key, limit);
|
||||
ASSERT_OK(DeleteFilesInRanges(db_.get(), db_->DefaultColumnFamily(),
|
||||
ranges.data(), ranges.size(),
|
||||
/*include_end=*/false));
|
||||
|
||||
std::string result;
|
||||
ASSERT_TRUE(db_->Get(ReadOptions(), key, &result).IsNotFound());
|
||||
UpdateManifestNumsFrom(before_manifest_num);
|
||||
};
|
||||
|
||||
// Column family manipulation.
|
||||
AddCfFn(/*include_background_manifest_write=*/false);
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// SetOptions should not write to the MANIFEST. If that regresses, the write
|
||||
// should be treated as a background write and rotate here.
|
||||
{
|
||||
ASSERT_OK(db_->SetOptions({{"level0_slowdown_writes_trigger", "101"}}));
|
||||
UpdateManifestNumsFrom(cur_manifest_num);
|
||||
}
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// External file ingestion.
|
||||
std::string ingested_key;
|
||||
IngestExternalFileForegroundManifestWriteFn(&ingested_key);
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// Imported column family creation.
|
||||
CreateColumnFamilyWithImportForegroundManifestWriteFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// Physical file deletion by range.
|
||||
DeleteFilesInRangesForegroundManifestWriteFn(ingested_key);
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// Background flush.
|
||||
BackgroundManifestWriteFn();
|
||||
ASSERT_LT(prev_manifest_num, cur_manifest_num);
|
||||
|
||||
// ---- Phase 5: persisted compacted manifest size survives close/reopen ----
|
||||
// Close with CFs still live. Reopen with reuse_manifest_on_open so the
|
||||
// manifest is NOT rewritten from scratch. The persisted compacted size
|
||||
// should be loaded and used for auto-tuning.
|
||||
// At this point we have 8 CF handles plus default.
|
||||
ASSERT_EQ(handles.size(), 8U);
|
||||
|
||||
// Collect CF names for reopen, then release handles (Close needs this)
|
||||
std::vector<std::string> cf_names = {"default"};
|
||||
for (auto* h : handles) {
|
||||
cf_names.push_back(h->GetName());
|
||||
}
|
||||
for (auto* h : handles) {
|
||||
ASSERT_OK(db_->DestroyColumnFamilyHandle(h));
|
||||
}
|
||||
handles.clear();
|
||||
|
||||
Close();
|
||||
// Use a max_manifest_file_size below the reused manifest size. Auto-tuning
|
||||
// with the persisted compacted size at 200% amp keeps the tuned threshold
|
||||
// high enough. Without persistence, the threshold would be
|
||||
// max(max_manifest_file_size, 0 * anything) = max_manifest_file_size.
|
||||
//
|
||||
// With max_manifest_file_size set to 3000, missing persisted compacted size
|
||||
// would keep tuned = 3000 and the first AddCf would rotate because the
|
||||
// reused manifest is already larger. With persisted compacted size loaded,
|
||||
// the tuned threshold is based on the compacted size, so no rotation until
|
||||
// the manifest grows well beyond the minimum.
|
||||
options.max_manifest_file_size = 3000;
|
||||
options.max_manifest_space_amp_pct = 200;
|
||||
options.reuse_manifest_on_open = true;
|
||||
uint64_t manifest_num_before_reopen = cur_manifest_num;
|
||||
ReopenWithColumnFamilies(cf_names, options);
|
||||
cur_manifest_num = dbfull()->TEST_Current_Manifest_FileNo();
|
||||
|
||||
// With persistence: the manifest file number should NOT have changed
|
||||
// during reopen, because the persisted compacted size keeps the tuned
|
||||
// threshold high enough. Without persistence, last_compacted = 0, so
|
||||
// tuned = max_manifest_file_size = 3000, and the first LogAndApply
|
||||
// during Open rotates the manifest because it is already larger than 3000.
|
||||
ASSERT_EQ(manifest_num_before_reopen, cur_manifest_num);
|
||||
|
||||
// Adding CFs should still not trigger rotation because the tuned threshold
|
||||
// from the persisted compacted size exceeds the current manifest size.
|
||||
for (int i = 1; i <= 4; ++i) {
|
||||
AddCfFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
}
|
||||
for (int i = 1; i <= 4; ++i) {
|
||||
AddCfFn();
|
||||
ASSERT_EQ(prev_manifest_num, cur_manifest_num);
|
||||
}
|
||||
|
||||
// Wrap up
|
||||
while (!handles.empty()) {
|
||||
DropCfFn();
|
||||
DropCfFn(/*include_background_manifest_write=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -473,6 +473,61 @@ TEST_F(DBFlushTest, StatisticsGarbageBasic) {
|
||||
Close();
|
||||
}
|
||||
|
||||
TEST_F(DBFlushTest, FlushReasonStatsWriteBufferFull) {
|
||||
Options options = CurrentOptions();
|
||||
options.statistics = CreateDBStatistics();
|
||||
options.statistics->set_stats_level(StatsLevel::kAll);
|
||||
options.create_if_missing = true;
|
||||
options.compression = kNoCompression;
|
||||
options.disable_auto_compactions = true;
|
||||
options.avoid_flush_during_shutdown = true;
|
||||
options.write_buffer_size = 16 * 1024;
|
||||
options.max_write_buffer_number = 8;
|
||||
|
||||
auto flush_listener = std::make_shared<FlushCounterListener>();
|
||||
flush_listener->expected_flush_reason = FlushReason::kWriteBufferFull;
|
||||
options.listeners.push_back(flush_listener);
|
||||
|
||||
ASSERT_OK(TryReopen(options));
|
||||
|
||||
WriteOptions write_options;
|
||||
write_options.disableWAL = true;
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
ASSERT_OK(Put(Key(i), DummyString(10 * 1024), write_options));
|
||||
}
|
||||
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
||||
ASSERT_OK(dbfull()->TEST_WaitForBackgroundWork());
|
||||
|
||||
const uint64_t write_buffer_full_flushes =
|
||||
TestGetTickerCount(options, FLUSH_REASON_WRITE_BUFFER_FULL);
|
||||
ASSERT_GT(write_buffer_full_flushes, 0);
|
||||
EXPECT_EQ(0, TestGetTickerCount(options, FLUSH_REASON_WRITE_BUFFER_MANAGER));
|
||||
|
||||
HistogramData all_memtable_memory;
|
||||
options.statistics->histogramData(FLUSH_MEMTABLE_MEMORY_BYTES,
|
||||
&all_memtable_memory);
|
||||
EXPECT_GE(all_memtable_memory.count, write_buffer_full_flushes);
|
||||
EXPECT_GT(all_memtable_memory.sum, 0);
|
||||
|
||||
HistogramData all_memtable_data_size;
|
||||
options.statistics->histogramData(FLUSH_MEMTABLE_TOTAL_DATA_SIZE,
|
||||
&all_memtable_data_size);
|
||||
EXPECT_GE(all_memtable_data_size.count, write_buffer_full_flushes);
|
||||
EXPECT_GT(all_memtable_data_size.sum, 0);
|
||||
|
||||
HistogramData write_buffer_full_memtable_memory;
|
||||
options.statistics->histogramData(
|
||||
FLUSH_WRITE_BUFFER_FULL_MEMTABLE_MEMORY_BYTES,
|
||||
&write_buffer_full_memtable_memory);
|
||||
EXPECT_EQ(write_buffer_full_flushes, write_buffer_full_memtable_memory.count);
|
||||
EXPECT_GT(write_buffer_full_memtable_memory.sum, 0);
|
||||
|
||||
HistogramData wbm_memtable_memory;
|
||||
options.statistics->histogramData(
|
||||
FLUSH_WRITE_BUFFER_MANAGER_MEMTABLE_MEMORY_BYTES, &wbm_memtable_memory);
|
||||
EXPECT_EQ(0, wbm_memtable_memory.count);
|
||||
}
|
||||
|
||||
TEST_F(DBFlushTest, StatisticsGarbageInsertAndDeletes) {
|
||||
Options options = CurrentOptions();
|
||||
options.statistics = CreateDBStatistics();
|
||||
@@ -2747,6 +2802,8 @@ TEST_P(DBAtomicFlushTest, ManualAtomicFlush) {
|
||||
Options options = CurrentOptions();
|
||||
options.create_if_missing = true;
|
||||
options.atomic_flush = GetParam();
|
||||
options.statistics = CreateDBStatistics();
|
||||
options.statistics->set_stats_level(StatsLevel::kAll);
|
||||
options.write_buffer_size = (static_cast<size_t>(64) << 20);
|
||||
auto flush_listener = std::make_shared<FlushCounterListener>();
|
||||
flush_listener->expected_flush_reason = FlushReason::kManualFlush;
|
||||
@@ -2773,6 +2830,16 @@ TEST_P(DBAtomicFlushTest, ManualAtomicFlush) {
|
||||
}
|
||||
ASSERT_OK(Flush(cf_ids));
|
||||
|
||||
EXPECT_EQ(options.atomic_flush ? 1 : 0,
|
||||
TestGetTickerCount(options, ATOMIC_FLUSH_REQUEST_REASON_OTHER));
|
||||
EXPECT_EQ(0, TestGetTickerCount(
|
||||
options, ATOMIC_FLUSH_REQUEST_REASON_WRITE_BUFFER_FULL));
|
||||
EXPECT_EQ(0, TestGetTickerCount(
|
||||
options, ATOMIC_FLUSH_REQUEST_REASON_WRITE_BUFFER_MANAGER));
|
||||
EXPECT_EQ(0, TestGetTickerCount(
|
||||
options,
|
||||
ATOMIC_FLUSH_REQUEST_REASON_MEMTABLE_MAX_RANGE_DELETIONS));
|
||||
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto cfh = static_cast<ColumnFamilyHandleImpl*>(handles_[i]);
|
||||
ASSERT_EQ(0, cfh->cfd()->imm()->NumNotFlushed());
|
||||
|
||||
+481
-128
@@ -102,6 +102,7 @@
|
||||
#include "table/get_context.h"
|
||||
#include "table/merging_iterator.h"
|
||||
#include "table/multiget_context.h"
|
||||
#include "table/prepared_file_info.h"
|
||||
#include "table/sst_file_dumper.h"
|
||||
#include "table/table_builder.h"
|
||||
#include "table/two_level_iterator.h"
|
||||
@@ -175,6 +176,7 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname,
|
||||
const bool seq_per_batch, const bool batch_per_txn,
|
||||
bool read_only)
|
||||
: dbname_(dbname),
|
||||
read_only_(read_only),
|
||||
own_info_log_(options.info_log == nullptr),
|
||||
initial_db_options_(SanitizeOptions(dbname, options, read_only,
|
||||
&init_logger_creation_s_)),
|
||||
@@ -332,12 +334,21 @@ Status DBImpl::ResumeImpl(DBRecoverContext context) {
|
||||
// FetchAddLastAllocatedSequence() before writes complete, but only
|
||||
// published via SetLastSequence() after success. If we're recovering from
|
||||
// an error, there may be allocated-but-not-published sequence numbers.
|
||||
// We must sync last_sequence_ with last_allocated_sequence_ before creating
|
||||
// any new memtables/WALs, otherwise the new WAL could start with a sequence
|
||||
// number lower than what was already written, causing "sequence number
|
||||
// going backwards" corruption on subsequent recovery.
|
||||
if (immutable_db_options_.two_write_queues) {
|
||||
// Start recovery from a published sequence number that covers writers which
|
||||
// were already in flight. Recovery flushes repeat this sync at the actual
|
||||
// memtable-switch fence, after FlushAllColumnFamilies() has dropped and
|
||||
// re-acquired the DB mutex.
|
||||
if (two_write_queues_) {
|
||||
WriteThread::Writer w;
|
||||
write_thread_.EnterUnbatched(&w, &mutex_);
|
||||
WriteThread::Writer nonmem_w;
|
||||
nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_);
|
||||
WaitForPendingWrites();
|
||||
|
||||
versions_->SyncLastSequenceWithAllocated();
|
||||
|
||||
nonmem_write_thread_.ExitUnbatched(&nonmem_w);
|
||||
write_thread_.ExitUnbatched(&w);
|
||||
}
|
||||
|
||||
TEST_SYNC_POINT("DBImpl::ResumeImpl:AfterSyncSeq");
|
||||
@@ -495,6 +506,21 @@ void DBImpl::WaitForAsyncFileOpen() {
|
||||
}
|
||||
}
|
||||
|
||||
void DBImpl::NotifyOnDBShutdownBegin() {
|
||||
mutex_.AssertHeld();
|
||||
if (shutdown_notification_sent_ || immutable_db_options_.listeners.empty()) {
|
||||
return;
|
||||
}
|
||||
shutdown_notification_sent_ = true;
|
||||
|
||||
// release lock while notifying events
|
||||
mutex_.Unlock();
|
||||
for (const auto& listener : immutable_db_options_.listeners) {
|
||||
listener->OnDBShutdownBegin(this);
|
||||
}
|
||||
mutex_.Lock();
|
||||
}
|
||||
|
||||
// Will lock the mutex_, will wait for completion if wait is true
|
||||
void DBImpl::CancelAllBackgroundWork(bool wait) {
|
||||
ROCKS_LOG_INFO(immutable_db_options_.info_log,
|
||||
@@ -541,6 +567,9 @@ void DBImpl::CancelAllBackgroundWork(bool wait) {
|
||||
immutable_db_options_.compaction_service->CancelAwaitingJobs();
|
||||
}
|
||||
|
||||
if (!already_shutting_down) {
|
||||
NotifyOnDBShutdownBegin();
|
||||
}
|
||||
shutting_down_.store(true, std::memory_order_release);
|
||||
bg_cv_.SignalAll();
|
||||
if (!wait) {
|
||||
@@ -653,7 +682,8 @@ void DBImpl::UnregisterBlobDirectWriteColumnFamily() {
|
||||
Status DBImpl::MaybeWriteWalMarkersToManifestOnClose() {
|
||||
mutex_.AssertHeld();
|
||||
if (!mutable_db_options_.optimize_manifest_for_recovery ||
|
||||
!opened_successfully_ || versions_ == nullptr || logs_.empty()) {
|
||||
!opened_successfully_ || read_only_ || versions_ == nullptr ||
|
||||
logs_.empty()) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@@ -789,16 +819,35 @@ Status DBImpl::CloseHelper() {
|
||||
bg_flush_scheduled_ || bg_purge_scheduled_ ||
|
||||
bg_pressure_callback_in_progress_ ||
|
||||
bg_async_file_open_state_ == AsyncFileOpenState::kScheduled ||
|
||||
async_wal_precreate_state_ == AsyncWALPrecreateState::kScheduled ||
|
||||
pending_purge_obsolete_files_ ||
|
||||
error_handler_.IsRecoveryInProgress()) {
|
||||
TEST_SYNC_POINT("DBImpl::~DBImpl:WaitJob");
|
||||
bg_cv_.Wait();
|
||||
}
|
||||
|
||||
// Release any opened-but-unpublished WAL writer after the in-flight worker
|
||||
// has published its result. Clear the DB-owned async slot while holding
|
||||
// mutex_, but destroy the detached writer after dropping mutex_ because
|
||||
// log::Writer / WritableFileWriter destruction can flush and close the file.
|
||||
// The file itself can be left behind as an empty future WAL; recovery already
|
||||
// tolerates it and marks its file number used if observed.
|
||||
UnpublishedWAL unused_async_wal = std::move(async_wal_precreate_wal_);
|
||||
async_wal_precreate_state_ = AsyncWALPrecreateState::kNotScheduled;
|
||||
if (unused_async_wal.writer) {
|
||||
mutex_.Unlock();
|
||||
unused_async_wal.Reset();
|
||||
mutex_.Lock();
|
||||
}
|
||||
|
||||
// Ensure subclasses don't forget to schedule async file opening
|
||||
assert(!immutable_db_options_.open_files_async || !opened_successfully_ ||
|
||||
bg_async_file_open_state_ != AsyncFileOpenState::kNotScheduled);
|
||||
|
||||
// No FileIngestionHandle from PrepareFileIngestion() may still be
|
||||
// outstanding
|
||||
assert(num_outstanding_prepared_ingestions_.load() == 0);
|
||||
|
||||
TEST_SYNC_POINT_CALLBACK("DBImpl::CloseHelper:PendingPurgeFinished",
|
||||
&files_grabbed_for_purge_);
|
||||
EraseThreadStatusDbInfo();
|
||||
@@ -820,6 +869,8 @@ Status DBImpl::CloseHelper() {
|
||||
if (default_cf_handle_ != nullptr || persist_stats_cf_handle_ != nullptr) {
|
||||
// we need to delete handle outside of lock because it does its own locking
|
||||
mutex_.Unlock();
|
||||
TEST_SYNC_POINT("DBImpl::CloseHelper:CFHandleCleanupUnlocked");
|
||||
TEST_SYNC_POINT("DBImpl::CloseHelper:CFHandleCleanupAllowed");
|
||||
if (default_cf_handle_) {
|
||||
delete default_cf_handle_;
|
||||
default_cf_handle_ = nullptr;
|
||||
@@ -840,7 +891,7 @@ Status DBImpl::CloseHelper() {
|
||||
// manifest file), it is not able to identify live files correctly. As a
|
||||
// result, all "live" files can get deleted by accident. However, corrupted
|
||||
// manifest is recoverable by RepairDB().
|
||||
if (opened_successfully_) {
|
||||
if (opened_successfully_ && !read_only_) {
|
||||
JobContext job_context(next_job_id_.fetch_add(1));
|
||||
FindObsoleteFiles(&job_context, true);
|
||||
|
||||
@@ -887,25 +938,6 @@ Status DBImpl::CloseHelper() {
|
||||
logs_.clear();
|
||||
}
|
||||
|
||||
// Table cache may have table handles holding blocks from the block cache.
|
||||
// We need to release them before the block cache is destroyed. The block
|
||||
// cache may be destroyed inside versions_.reset(), when column family data
|
||||
// list is destroyed, so leaving handles in table cache after
|
||||
// versions_.reset() may cause issues. Here we clean all unreferenced handles
|
||||
// in table cache, and (for certain builds/conditions) assert that no obsolete
|
||||
// files are hanging around unreferenced (leak) in the table/blob file cache.
|
||||
// Now we assume all user queries have finished, so only version set itself
|
||||
// can possibly hold the blocks from block cache. After releasing unreferenced
|
||||
// handles here, only handles held by version set left and inside
|
||||
// versions_.reset(), we will release them. There, we need to make sure every
|
||||
// time a handle is released, we erase it from the cache too. By doing that,
|
||||
// we can guarantee that after versions_.reset(), table cache is empty
|
||||
// so the cache can be safely destroyed.
|
||||
#ifndef NDEBUG
|
||||
TEST_VerifyNoObsoleteFilesCached(/*db_mutex_already_held=*/true);
|
||||
#endif // !NDEBUG
|
||||
table_cache_->EraseUnRefEntries();
|
||||
|
||||
for (auto& txn_entry : recovered_transactions_) {
|
||||
delete txn_entry.second;
|
||||
}
|
||||
@@ -931,6 +963,42 @@ Status DBImpl::CloseHelper() {
|
||||
}
|
||||
}
|
||||
|
||||
// Drain obsolete-file purge work started AFTER the early CloseHelper wait
|
||||
// near the top of this method. A late SuperVersion cleanup -- a dropped
|
||||
// column family handle, or an in-flight iterator/Get whose ReadOptions or
|
||||
// immutable_db_options_.avoid_unnecessary_blocking_io selected background
|
||||
// purge -- can run in one of the mutex-unlocked windows above and enter the
|
||||
// FindObsoleteFiles() -> PurgeObsoleteFiles(..., true) handoff. During that
|
||||
// handoff pending_purge_obsolete_files_ is already nonzero, but
|
||||
// bg_purge_scheduled_ may still be zero until SchedulePurge() runs at the end
|
||||
// of PurgeObsoleteFiles(). Wait for both states while mutex_/this are still
|
||||
// alive; bg_cv_.Wait() releases mutex_ so pending and scheduled purges can
|
||||
// finish and signal.
|
||||
TEST_SYNC_POINT("DBImpl::CloseHelper:BeforeFinalPurgeDrain");
|
||||
while (pending_purge_obsolete_files_ || bg_purge_scheduled_) {
|
||||
TEST_SYNC_POINT("DBImpl::CloseHelper:FinalPurgeDrainWait");
|
||||
bg_cv_.Wait();
|
||||
}
|
||||
|
||||
// Table cache may have table handles holding blocks from the block cache.
|
||||
// We need to release them before the block cache is destroyed. The block
|
||||
// cache may be destroyed inside versions_.reset(), when column family data
|
||||
// list is destroyed, so leaving handles in table cache after
|
||||
// versions_.reset() may cause issues. Here we clean all unreferenced handles
|
||||
// in table cache, and (for certain builds/conditions) assert that no obsolete
|
||||
// files are hanging around unreferenced (leak) in the table/blob file cache.
|
||||
// Now we assume all user queries have finished, and close-time purge work has
|
||||
// settled, so only version set itself can possibly hold the blocks from block
|
||||
// cache. After releasing unreferenced handles here, only handles held by
|
||||
// version set left and inside versions_.reset(), we will release them. There,
|
||||
// we need to make sure every time a handle is released, we erase it from the
|
||||
// cache too. By doing that, we can guarantee that after versions_.reset(),
|
||||
// table cache is empty so the cache can be safely destroyed.
|
||||
#ifndef NDEBUG
|
||||
TEST_VerifyNoObsoleteFilesCached(/*db_mutex_already_held=*/true);
|
||||
#endif // !NDEBUG
|
||||
table_cache_->EraseUnRefEntries();
|
||||
|
||||
versions_.reset();
|
||||
mutex_.Unlock();
|
||||
if (db_lock_ != nullptr) {
|
||||
@@ -1809,6 +1877,8 @@ Status DBImpl::SetDBOptions(
|
||||
// TODO(xiez): clarify why apply optimize for read to write options
|
||||
file_options_for_compaction_ = fs_->OptimizeForCompactionTableRead(
|
||||
file_options_for_compaction_, immutable_db_options_);
|
||||
TEST_SYNC_POINT_CALLBACK("DBImpl::SetDBOptions:FileOptionsForCompaction",
|
||||
&file_options_for_compaction_);
|
||||
if (wal_other_option_changed || wal_size_option_changed) {
|
||||
WriteThread::Writer w;
|
||||
write_thread_.EnterUnbatched(&w, &mutex_);
|
||||
@@ -2440,30 +2510,8 @@ struct SuperVersionHandle {
|
||||
static void CleanupSuperVersionHandle(void* arg1, void* /*arg2*/) {
|
||||
SuperVersionHandle* sv_handle = static_cast<SuperVersionHandle*>(arg1);
|
||||
|
||||
if (sv_handle->super_version->Unref()) {
|
||||
// Job id == 0 means that this is not our background process, but rather
|
||||
// user thread
|
||||
JobContext job_context(0);
|
||||
|
||||
sv_handle->mu->Lock();
|
||||
sv_handle->super_version->Cleanup();
|
||||
sv_handle->db->FindObsoleteFiles(&job_context, false, true);
|
||||
if (sv_handle->background_purge) {
|
||||
sv_handle->db->ScheduleBgLogWriterClose(&job_context);
|
||||
sv_handle->db->AddSuperVersionsToFreeQueue(sv_handle->super_version);
|
||||
sv_handle->db->SchedulePurge();
|
||||
}
|
||||
sv_handle->mu->Unlock();
|
||||
|
||||
if (!sv_handle->background_purge) {
|
||||
delete sv_handle->super_version;
|
||||
}
|
||||
if (job_context.HaveSomethingToDelete()) {
|
||||
sv_handle->db->PurgeObsoleteFiles(job_context,
|
||||
sv_handle->db->CleanupIteratorSuperVersion(sv_handle->super_version,
|
||||
sv_handle->background_purge);
|
||||
}
|
||||
job_context.Clean();
|
||||
}
|
||||
|
||||
delete sv_handle;
|
||||
}
|
||||
@@ -2485,7 +2533,8 @@ static void CleanupGetMergeOperandsState(void* arg1, void* /*arg2*/) {
|
||||
InternalIterator* DBImpl::NewInternalIterator(
|
||||
const ReadOptions& read_options, ColumnFamilyData* cfd,
|
||||
SuperVersion* super_version, Arena* arena, SequenceNumber sequence,
|
||||
bool allow_unprepared_value, ArenaWrappedDBIter* db_iter) {
|
||||
bool allow_unprepared_value, ArenaWrappedDBIter* db_iter,
|
||||
const MultiScanArgs* scan_opts) {
|
||||
InternalIterator* internal_iter;
|
||||
assert(arena != nullptr);
|
||||
auto prefix_extractor =
|
||||
@@ -2497,47 +2546,62 @@ InternalIterator* DBImpl::NewInternalIterator(
|
||||
// here, and no unit test cares about the value provided here.
|
||||
!read_options.total_order_seek && prefix_extractor != nullptr,
|
||||
read_options.iterate_upper_bound);
|
||||
Status s;
|
||||
const Comparator* user_comparator = cfd->user_comparator();
|
||||
const bool mem_intersects =
|
||||
!super_version->mem->IsEmpty() &&
|
||||
MultiScanIntersectsMemTable(super_version->mem, read_options,
|
||||
super_version->GetSeqnoToTimeMapping(),
|
||||
prefix_extractor, scan_opts, user_comparator);
|
||||
if (scan_opts == nullptr || mem_intersects) {
|
||||
// Collect iterator for mutable memtable
|
||||
auto mem_iter = super_version->mem->NewIterator(
|
||||
read_options, super_version->GetSeqnoToTimeMapping(), arena,
|
||||
super_version->mutable_cf_options.prefix_extractor.get(),
|
||||
/*for_flush=*/false);
|
||||
Status s;
|
||||
if (!read_options.ignore_range_deletions) {
|
||||
std::unique_ptr<TruncatedRangeDelIterator> mem_tombstone_iter;
|
||||
auto range_del_iter = super_version->mem->NewRangeTombstoneIterator(
|
||||
read_options, sequence, false /* immutable_memtable */);
|
||||
if (range_del_iter == nullptr || range_del_iter->empty()) {
|
||||
delete range_del_iter;
|
||||
} else {
|
||||
std::unique_ptr<FragmentedRangeTombstoneIterator> range_del_iter(
|
||||
super_version->mem->NewRangeTombstoneIterator(
|
||||
read_options, sequence, false /* immutable_memtable */));
|
||||
if (range_del_iter != nullptr && !range_del_iter->empty()) {
|
||||
mem_tombstone_iter = std::make_unique<TruncatedRangeDelIterator>(
|
||||
std::unique_ptr<FragmentedRangeTombstoneIterator>(range_del_iter),
|
||||
&cfd->ioptions().internal_comparator, nullptr /* smallest */,
|
||||
nullptr /* largest */);
|
||||
std::move(range_del_iter), &cfd->ioptions().internal_comparator,
|
||||
nullptr /* smallest */, nullptr /* largest */);
|
||||
}
|
||||
merge_iter_builder.AddPointAndTombstoneIterator(
|
||||
mem_iter, std::move(mem_tombstone_iter));
|
||||
} else {
|
||||
merge_iter_builder.AddIterator(mem_iter);
|
||||
}
|
||||
} else if (scan_opts != nullptr) {
|
||||
merge_iter_builder.SetMemtablePruned(true);
|
||||
}
|
||||
|
||||
// Collect all needed child iterators for immutable memtables
|
||||
if (s.ok()) {
|
||||
if (s.ok() &&
|
||||
(scan_opts == nullptr || super_version->imm->GetTotalNumEntries() > 0)) {
|
||||
// Collect all needed child iterators for immutable memtables. When scan
|
||||
// ranges are provided, AddIterators prunes each immutable memtable
|
||||
// individually.
|
||||
super_version->imm->AddIterators(
|
||||
read_options, super_version->GetSeqnoToTimeMapping(),
|
||||
super_version->mutable_cf_options.prefix_extractor.get(),
|
||||
&merge_iter_builder, !read_options.ignore_range_deletions);
|
||||
&merge_iter_builder, !read_options.ignore_range_deletions, sequence,
|
||||
scan_opts, user_comparator);
|
||||
}
|
||||
TEST_SYNC_POINT_CALLBACK("DBImpl::NewInternalIterator:StatusCallback", &s);
|
||||
if (s.ok()) {
|
||||
// Collect iterators for files in L0 - Ln
|
||||
if (read_options.read_tier != kMemtableTier) {
|
||||
super_version->current->AddIterators(read_options, file_options_,
|
||||
&merge_iter_builder,
|
||||
allow_unprepared_value);
|
||||
super_version->current->AddIterators(
|
||||
read_options, file_options_, &merge_iter_builder,
|
||||
allow_unprepared_value, sequence, scan_opts);
|
||||
}
|
||||
internal_iter = merge_iter_builder.Finish(
|
||||
read_options.ignore_range_deletions ? nullptr : db_iter);
|
||||
if (internal_iter == nullptr) {
|
||||
internal_iter = NewEmptyInternalIterator<Slice>(arena);
|
||||
}
|
||||
SuperVersionHandle* cleanup = new SuperVersionHandle(
|
||||
this, &mutex_, super_version,
|
||||
read_options.background_purge_on_iterator_cleanup ||
|
||||
@@ -2551,6 +2615,35 @@ InternalIterator* DBImpl::NewInternalIterator(
|
||||
return NewErrorInternalIterator<Slice>(s, arena);
|
||||
}
|
||||
|
||||
void DBImpl::CleanupIteratorSuperVersion(SuperVersion* super_version,
|
||||
bool background_purge) {
|
||||
background_purge =
|
||||
background_purge || immutable_db_options_.avoid_unnecessary_blocking_io;
|
||||
if (super_version->Unref()) {
|
||||
// Job id == 0 means that this is not our background process, but rather
|
||||
// user thread
|
||||
JobContext job_context(0);
|
||||
|
||||
mutex_.Lock();
|
||||
super_version->Cleanup();
|
||||
FindObsoleteFiles(&job_context, false, true);
|
||||
if (background_purge) {
|
||||
ScheduleBgLogWriterClose(&job_context);
|
||||
AddSuperVersionsToFreeQueue(super_version);
|
||||
SchedulePurge();
|
||||
}
|
||||
mutex_.Unlock();
|
||||
|
||||
if (!background_purge) {
|
||||
delete super_version;
|
||||
}
|
||||
if (job_context.HaveSomethingToDelete()) {
|
||||
PurgeObsoleteFiles(job_context, background_purge);
|
||||
}
|
||||
job_context.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
ColumnFamilyHandle* DBImpl::DefaultColumnFamily() const {
|
||||
return default_cf_handle_;
|
||||
}
|
||||
@@ -5820,6 +5913,7 @@ Status DBImpl::DeleteFilesInRanges(ColumnFamilyHandle* column_family,
|
||||
}
|
||||
|
||||
VersionEdit edit;
|
||||
edit.MarkForegroundOperation();
|
||||
std::set<FileMetaData*> deleted_files;
|
||||
JobContext job_context(next_job_id_.fetch_add(1), true);
|
||||
{
|
||||
@@ -5917,6 +6011,79 @@ Status DBImpl::GetLiveFilesChecksumInfo(FileChecksumList* checksum_list) {
|
||||
return versions_->GetLiveFilesChecksumInfo(checksum_list);
|
||||
}
|
||||
|
||||
Status DBImpl::GetPreparedFileInfoForExternalSstIngestion(
|
||||
const std::string& file_path,
|
||||
std::shared_ptr<const PreparedFileInfo>* file_info) {
|
||||
if (file_info == nullptr) {
|
||||
return Status::InvalidArgument("file_info must not be null");
|
||||
}
|
||||
file_info->reset();
|
||||
|
||||
const size_t file_name_pos = file_path.find_last_of("/\\");
|
||||
const std::string file_name = file_name_pos == std::string::npos
|
||||
? file_path
|
||||
: file_path.substr(file_name_pos + 1);
|
||||
uint64_t file_number = 0;
|
||||
FileType file_type;
|
||||
if (!ParseFileName(file_name, &file_number, &file_type) ||
|
||||
file_type != kTableFile || file_number == 0) {
|
||||
return Status::InvalidArgument("Invalid table file name: " + file_path);
|
||||
}
|
||||
|
||||
int file_level = -1;
|
||||
FileMetaData* file_meta = nullptr;
|
||||
ColumnFamilyData* file_cfd = nullptr;
|
||||
Version* file_version = nullptr;
|
||||
std::shared_ptr<const TableProperties> table_properties;
|
||||
ReadOptions read_options;
|
||||
|
||||
{
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
Status s = versions_->GetMetadataForFile(file_number, &file_level,
|
||||
&file_meta, &file_cfd);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
const std::string expected_file_path = TableFileName(
|
||||
file_cfd->ioptions().cf_paths, file_number, file_meta->fd.GetPathId());
|
||||
if (file_path != expected_file_path) {
|
||||
return Status::InvalidArgument("Path does not match live table file: " +
|
||||
file_path);
|
||||
}
|
||||
|
||||
file_cfd->Ref();
|
||||
file_version = file_cfd->current();
|
||||
file_version->Ref();
|
||||
}
|
||||
const Defer cleanup_refs([&]() {
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
file_version->Unref();
|
||||
file_cfd->UnrefAndTryDelete();
|
||||
});
|
||||
|
||||
Status s = file_cfd->table_cache()->GetTableProperties(
|
||||
file_options_, read_options, file_cfd->internal_comparator(), *file_meta,
|
||||
&table_properties, file_version->GetMutableCFOptions(),
|
||||
false /* no_io */);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
assert(table_properties != nullptr);
|
||||
|
||||
auto prepared_file_info = std::make_shared<PreparedFileInfo>();
|
||||
prepared_file_info->file_size = file_meta->fd.GetFileSize();
|
||||
prepared_file_info->smallest = file_meta->smallest;
|
||||
prepared_file_info->largest = file_meta->largest;
|
||||
prepared_file_info->table_properties = *table_properties;
|
||||
prepared_file_info->table_properties.key_largest_seqno =
|
||||
file_meta->fd.largest_seqno;
|
||||
prepared_file_info->table_properties.key_smallest_seqno =
|
||||
file_meta->fd.smallest_seqno;
|
||||
*file_info = std::move(prepared_file_info);
|
||||
return s;
|
||||
}
|
||||
|
||||
void DBImpl::GetColumnFamilyMetaData(ColumnFamilyHandle* column_family,
|
||||
ColumnFamilyMetaData* cf_meta) {
|
||||
assert(column_family);
|
||||
@@ -6639,11 +6806,76 @@ Status DBImpl::IngestExternalFile(
|
||||
return IngestExternalFiles({arg});
|
||||
}
|
||||
|
||||
Status DBImpl::IngestExternalFiles(
|
||||
const std::vector<IngestExternalFileArg>& args) {
|
||||
PERF_TIMER_GUARD(file_ingestion_nanos);
|
||||
// TODO: plumb Env::IOActivity, Env::IOPriority
|
||||
const WriteOptions write_options;
|
||||
class FileIngestionHandleImpl : public FileIngestionHandle {
|
||||
public:
|
||||
explicit FileIngestionHandleImpl(DBImpl* db) : db_(db) {}
|
||||
~FileIngestionHandleImpl() override;
|
||||
|
||||
FileIngestionHandleImpl(const FileIngestionHandleImpl&) = delete;
|
||||
FileIngestionHandleImpl& operator=(const FileIngestionHandleImpl&) = delete;
|
||||
FileIngestionHandleImpl(FileIngestionHandleImpl&&) = delete;
|
||||
FileIngestionHandleImpl& operator=(FileIngestionHandleImpl&&) = delete;
|
||||
|
||||
Status Abort() override;
|
||||
|
||||
DBImpl* const db_;
|
||||
std::vector<ExternalSstFileIngestionJob> jobs_;
|
||||
std::unique_ptr<std::list<uint64_t>::iterator> pending_output_elem_;
|
||||
bool fill_cache_ = true;
|
||||
// Set true once committed or aborted, so the destructor does not roll back.
|
||||
bool consumed_ = false;
|
||||
};
|
||||
|
||||
FileIngestionHandleImpl::~FileIngestionHandleImpl() {
|
||||
if (consumed_ || db_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Dropped without commit or abort: roll back as a safety net.
|
||||
db_->RollbackPreparedFileIngestion(this);
|
||||
ROCKS_LOG_WARN(
|
||||
db_->immutable_db_options_.info_log,
|
||||
"[%zu CF(s)] File ingestion handle destroyed without commit or "
|
||||
"abort; prepared files were rolled back.",
|
||||
jobs_.size());
|
||||
}
|
||||
|
||||
void DBImpl::RollbackPreparedFileIngestion(FileIngestionHandleImpl* const h) {
|
||||
// Delete the staged internal files and release the reserved file numbers /
|
||||
// pending-output protection, leaving the DB unchanged.
|
||||
const Status rollback_status = Status::Incomplete("file ingestion aborted");
|
||||
for (auto& job : h->jobs_) {
|
||||
job.Cleanup(rollback_status);
|
||||
}
|
||||
{
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
ReleaseFileNumberFromPendingOutputs(h->pending_output_elem_);
|
||||
}
|
||||
h->consumed_ = true;
|
||||
num_outstanding_prepared_ingestions_.fetch_sub(1);
|
||||
}
|
||||
|
||||
Status FileIngestionHandleImpl::Abort() {
|
||||
if (consumed_) {
|
||||
return Status::InvalidArgument(
|
||||
"file ingestion handle has already been committed or aborted");
|
||||
}
|
||||
db_->RollbackPreparedFileIngestion(this);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status DBImpl::PrepareFileIngestion(
|
||||
const std::vector<IngestExternalFileArg>& args,
|
||||
std::unique_ptr<FileIngestionHandle>* handle) {
|
||||
if (handle == nullptr) {
|
||||
return Status::InvalidArgument("file ingestion handle output is null");
|
||||
}
|
||||
handle->reset();
|
||||
// Recorded as INGEST_EXTERNAL_FILE_PREPARE_TIME on success below.
|
||||
const bool record_ingest_micros =
|
||||
stats_ != nullptr &&
|
||||
stats_->get_stats_level() > StatsLevel::kExceptTimers;
|
||||
const uint64_t prepare_start_micros =
|
||||
record_ingest_micros ? immutable_db_options_.clock->NowMicros() : 0;
|
||||
|
||||
if (args.empty()) {
|
||||
return Status::InvalidArgument("ingestion arg list is empty");
|
||||
@@ -6668,6 +6900,17 @@ Status DBImpl::IngestExternalFiles(
|
||||
"external_files[" + std::to_string(i) + "] is empty";
|
||||
return Status::InvalidArgument(err_msg);
|
||||
}
|
||||
if (!args[i].file_infos.empty()) {
|
||||
if (args[i].file_infos.size() != args[i].external_files.size()) {
|
||||
return Status::InvalidArgument("file_infos[" + std::to_string(i) +
|
||||
"] size must match external_files[" +
|
||||
std::to_string(i) + "] size");
|
||||
}
|
||||
if (args[i].options.write_global_seqno) {
|
||||
return Status::InvalidArgument(
|
||||
"write_global_seqno is not supported when file_infos is set");
|
||||
}
|
||||
}
|
||||
if (i && args[i].options.fill_cache != args[i - 1].options.fill_cache) {
|
||||
return Status::InvalidArgument(
|
||||
"fill_cache should be the same across ingestion options.");
|
||||
@@ -6744,6 +6987,7 @@ Status DBImpl::IngestExternalFiles(
|
||||
}
|
||||
|
||||
std::vector<ExternalSstFileIngestionJob> ingestion_jobs;
|
||||
ingestion_jobs.reserve(num_cfs);
|
||||
for (const auto& arg : args) {
|
||||
auto* cfd = static_cast<ColumnFamilyHandleImpl*>(arg.column_family)->cfd();
|
||||
ingestion_jobs.emplace_back(versions_.get(), cfd, immutable_db_options_,
|
||||
@@ -6761,8 +7005,9 @@ Status DBImpl::IngestExternalFiles(
|
||||
this);
|
||||
Status es = ingestion_jobs[i].Prepare(
|
||||
args[i].external_files, args[i].files_checksums,
|
||||
args[i].files_checksum_func_names, args[i].atomic_replace_range,
|
||||
args[i].file_temperature, start_file_number, super_version);
|
||||
args[i].files_checksum_func_names, args[i].file_infos,
|
||||
args[i].atomic_replace_range, args[i].file_temperature,
|
||||
start_file_number, super_version);
|
||||
// capture first error only
|
||||
if (!es.ok() && status.ok()) {
|
||||
status = es;
|
||||
@@ -6777,8 +7022,9 @@ Status DBImpl::IngestExternalFiles(
|
||||
this);
|
||||
Status es = ingestion_jobs[0].Prepare(
|
||||
args[0].external_files, args[0].files_checksums,
|
||||
args[0].files_checksum_func_names, args[0].atomic_replace_range,
|
||||
args[0].file_temperature, next_file_number, super_version);
|
||||
args[0].files_checksum_func_names, args[0].file_infos,
|
||||
args[0].atomic_replace_range, args[0].file_temperature,
|
||||
next_file_number, super_version);
|
||||
if (!es.ok()) {
|
||||
status = es;
|
||||
}
|
||||
@@ -6793,8 +7039,86 @@ Status DBImpl::IngestExternalFiles(
|
||||
return status;
|
||||
}
|
||||
|
||||
auto handle_impl = std::make_unique<FileIngestionHandleImpl>(this);
|
||||
handle_impl->jobs_ = std::move(ingestion_jobs);
|
||||
handle_impl->pending_output_elem_ = std::move(pending_output_elem);
|
||||
handle_impl->fill_cache_ = args[0].options.fill_cache;
|
||||
if (record_ingest_micros) {
|
||||
RecordTimeToHistogram(
|
||||
stats_, INGEST_EXTERNAL_FILE_PREPARE_TIME,
|
||||
immutable_db_options_.clock->NowMicros() - prepare_start_micros);
|
||||
}
|
||||
num_outstanding_prepared_ingestions_.fetch_add(1);
|
||||
*handle = std::move(handle_impl);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status DBImpl::CommitFileIngestionHandles(
|
||||
std::vector<std::unique_ptr<FileIngestionHandle>> handles) {
|
||||
if (handles.empty()) {
|
||||
return Status::InvalidArgument("no file ingestion handles to commit");
|
||||
}
|
||||
// Validate the handles and group their jobs by column family, merging same-CF
|
||||
// jobs into one so each column family commits via a single atomic version
|
||||
// edit and one SuperVersion install.
|
||||
Status status;
|
||||
std::vector<FileIngestionHandleImpl*> hs;
|
||||
hs.reserve(handles.size());
|
||||
std::vector<ExternalSstFileIngestionJob*> ingestion_jobs;
|
||||
const bool fill_cache =
|
||||
static_cast<FileIngestionHandleImpl*>(handles[0].get())->fill_cache_;
|
||||
int max_file_opening_threads = 1;
|
||||
|
||||
{
|
||||
UnorderedMap<ColumnFamilyData*, ExternalSstFileIngestionJob*>
|
||||
primary_job_for_cfd;
|
||||
for (const auto& handle : handles) {
|
||||
assert(handle);
|
||||
auto* h = static_cast<FileIngestionHandleImpl*>(handle.get());
|
||||
assert(h->db_ == this);
|
||||
if (h->consumed_) {
|
||||
status = Status::InvalidArgument(
|
||||
"file ingestion handle has already been committed or aborted");
|
||||
}
|
||||
if (h->fill_cache_ != fill_cache) {
|
||||
status = Status::InvalidArgument(
|
||||
"fill cache arg must be consistent across all handles");
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
hs.push_back(h);
|
||||
for (auto& job : h->jobs_) {
|
||||
max_file_opening_threads =
|
||||
std::max(max_file_opening_threads, job.file_opening_threads());
|
||||
auto [it, inserted] =
|
||||
primary_job_for_cfd.try_emplace(job.GetColumnFamilyData(), &job);
|
||||
if (inserted) {
|
||||
ingestion_jobs.push_back(&job);
|
||||
} else {
|
||||
status = it->second->MergeForSameColumnFamily(&job);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const size_t num_jobs = ingestion_jobs.size();
|
||||
|
||||
// TODO: plumb Env::IOActivity, Env::IOPriority
|
||||
const WriteOptions write_options;
|
||||
// Decided here (not in Prepare) so the histograms reflect the stats level at
|
||||
// commit time; recorded only on success below.
|
||||
const bool record_ingest_micros =
|
||||
stats_ != nullptr &&
|
||||
stats_->get_stats_level() > StatsLevel::kExceptTimers;
|
||||
const uint64_t run_start_micros =
|
||||
record_ingest_micros ? immutable_db_options_.clock->NowMicros() : 0;
|
||||
|
||||
std::vector<SuperVersionContext> sv_ctxs;
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
for (size_t i = 0; i != num_jobs; ++i) {
|
||||
sv_ctxs.emplace_back(true /* create_superversion */);
|
||||
}
|
||||
TEST_SYNC_POINT("DBImpl::IngestExternalFiles:BeforeJobsRun:0");
|
||||
@@ -6805,9 +7129,9 @@ Status DBImpl::IngestExternalFiles(
|
||||
// mutex so the lock-acquisition order is ingest_sst_lock -> DB mutex
|
||||
// throughout. Use readlock so we still allow concurrent ingestions.
|
||||
std::vector<std::unique_ptr<ReadLock>> ingest_read_locks;
|
||||
ingest_read_locks.reserve(num_cfs);
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i].GetColumnFamilyData();
|
||||
ingest_read_locks.reserve(num_jobs);
|
||||
for (auto* job : ingestion_jobs) {
|
||||
auto* cfd = job->GetColumnFamilyData();
|
||||
if (!cfd->IsDropped()) {
|
||||
ingest_read_locks.emplace_back(
|
||||
std::make_unique<ReadLock>(&cfd->GetIngestSstLock()));
|
||||
@@ -6833,14 +7157,14 @@ Status DBImpl::IngestExternalFiles(
|
||||
// So wait here to ensure there is no pending write to memtable.
|
||||
WaitForPendingWrites();
|
||||
|
||||
num_running_ingest_file_ += static_cast<int>(num_cfs);
|
||||
num_running_ingest_file_ += static_cast<int>(num_jobs);
|
||||
TEST_SYNC_POINT("DBImpl::IngestExternalFile:AfterIncIngestFileCounter");
|
||||
TEST_SYNC_POINT("DBImpl::IngestExternalFile:AfterIncIngestFileCounter:2");
|
||||
|
||||
bool at_least_one_cf_need_flush = false;
|
||||
std::vector<bool> need_flush(num_cfs, false);
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i].GetColumnFamilyData();
|
||||
std::vector<bool> need_flush(num_jobs, false);
|
||||
for (size_t i = 0; i != num_jobs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i]->GetColumnFamilyData();
|
||||
if (cfd->IsDropped()) {
|
||||
// TODO (yanqin) investigate whether we should abort ingestion or
|
||||
// proceed with other non-dropped column families.
|
||||
@@ -6849,7 +7173,7 @@ Status DBImpl::IngestExternalFiles(
|
||||
break;
|
||||
}
|
||||
bool tmp = false;
|
||||
status = ingestion_jobs[i].NeedsFlush(&tmp, cfd->GetSuperVersion());
|
||||
status = ingestion_jobs[i]->NeedsFlush(&tmp, cfd->GetSuperVersion());
|
||||
need_flush[i] = tmp;
|
||||
at_least_one_cf_need_flush = (at_least_one_cf_need_flush || tmp);
|
||||
if (!status.ok()) {
|
||||
@@ -6869,11 +7193,11 @@ Status DBImpl::IngestExternalFiles(
|
||||
{} /* provided_candidate_cfds */, true /* entered_write_thread */);
|
||||
mutex_.Lock();
|
||||
} else {
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
for (size_t i = 0; i != num_jobs; ++i) {
|
||||
if (need_flush[i]) {
|
||||
mutex_.Unlock();
|
||||
status =
|
||||
FlushMemTable(ingestion_jobs[i].GetColumnFamilyData(),
|
||||
FlushMemTable(ingestion_jobs[i]->GetColumnFamilyData(),
|
||||
flush_opts, FlushReason::kExternalFileIngestion,
|
||||
true /* entered_write_thread */);
|
||||
mutex_.Lock();
|
||||
@@ -6884,22 +7208,22 @@ Status DBImpl::IngestExternalFiles(
|
||||
}
|
||||
}
|
||||
if (status.ok()) {
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
for (size_t i = 0; i != num_jobs; ++i) {
|
||||
if (immutable_db_options_.atomic_flush || need_flush[i]) {
|
||||
ingestion_jobs[i].SetFlushedBeforeRun();
|
||||
ingestion_jobs[i]->SetFlushedBeforeRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Run ingestion jobs.
|
||||
if (status.ok()) {
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
for (size_t i = 0; i != num_jobs; ++i) {
|
||||
mutex_.AssertHeld();
|
||||
status = ingestion_jobs[i].Run();
|
||||
status = ingestion_jobs[i]->Run();
|
||||
if (!status.ok()) {
|
||||
break;
|
||||
}
|
||||
ingestion_jobs[i].RegisterRange();
|
||||
ingestion_jobs[i]->RegisterRange();
|
||||
}
|
||||
}
|
||||
// Now that Run() has assigned the actual seqno for each ingested file,
|
||||
@@ -6911,9 +7235,9 @@ Status DBImpl::IngestExternalFiles(
|
||||
// next conversion observes the new barrier and refuses any insert
|
||||
// with insert_seq < assigned.
|
||||
if (status.ok()) {
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i].GetColumnFamilyData();
|
||||
SequenceNumber assigned = ingestion_jobs[i].MaxAssignedSequenceNumber();
|
||||
for (auto* job : ingestion_jobs) {
|
||||
auto* cfd = job->GetColumnFamilyData();
|
||||
SequenceNumber assigned = job->MaxAssignedSequenceNumber();
|
||||
if (assigned > 0) {
|
||||
cfd->mem()->BumpIngestSeqnoBarrier(assigned);
|
||||
}
|
||||
@@ -6921,16 +7245,18 @@ Status DBImpl::IngestExternalFiles(
|
||||
}
|
||||
if (status.ok()) {
|
||||
ReadOptions read_options;
|
||||
read_options.fill_cache = args[0].options.fill_cache;
|
||||
read_options.fill_cache = fill_cache;
|
||||
autovector<ColumnFamilyData*> cfds_to_commit;
|
||||
autovector<autovector<VersionEdit*>> edit_lists;
|
||||
uint32_t num_entries = 0;
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i].GetColumnFamilyData();
|
||||
for (auto* job : ingestion_jobs) {
|
||||
auto* cfd = job->GetColumnFamilyData();
|
||||
assert(!cfd->IsDropped());
|
||||
cfds_to_commit.push_back(cfd);
|
||||
autovector<VersionEdit*> edit_list;
|
||||
edit_list.push_back(ingestion_jobs[i].edit());
|
||||
auto* edit = job->edit();
|
||||
edit->MarkForegroundOperation();
|
||||
edit_list.push_back(edit);
|
||||
edit_lists.push_back(edit_list);
|
||||
++num_entries;
|
||||
}
|
||||
@@ -6943,10 +7269,11 @@ Status DBImpl::IngestExternalFiles(
|
||||
}
|
||||
assert(0 == num_entries);
|
||||
}
|
||||
status =
|
||||
versions_->LogAndApply(cfds_to_commit, read_options, write_options,
|
||||
|
||||
edit_lists, &mutex_, directories_.GetDbDir());
|
||||
status = versions_->LogAndApply(
|
||||
cfds_to_commit, read_options, write_options, edit_lists, &mutex_,
|
||||
directories_.GetDbDir(), false /* new_descriptor_log */,
|
||||
nullptr /* new_cf_options */, {} /* manifest_wcbs */, {} /* pre_cb */,
|
||||
max_file_opening_threads);
|
||||
// It is safe to update VersionSet last seqno here after LogAndApply since
|
||||
// LogAndApply persists last sequence number from VersionEdits,
|
||||
// which are from file's largest seqno and not from VersionSet.
|
||||
@@ -6955,11 +7282,10 @@ Status DBImpl::IngestExternalFiles(
|
||||
// mutex when persisting MANIFEST file, and the snapshots taken during
|
||||
// that period will not be stable if VersionSet last seqno is updated
|
||||
// before LogAndApply.
|
||||
SequenceNumber max_assigned_seqno =
|
||||
ingestion_jobs[0].MaxAssignedSequenceNumber();
|
||||
for (size_t i = 1; i != num_cfs; ++i) {
|
||||
max_assigned_seqno = std::max(
|
||||
max_assigned_seqno, ingestion_jobs[i].MaxAssignedSequenceNumber());
|
||||
SequenceNumber max_assigned_seqno = 0;
|
||||
for (auto* job : ingestion_jobs) {
|
||||
max_assigned_seqno =
|
||||
std::max(max_assigned_seqno, job->MaxAssignedSequenceNumber());
|
||||
}
|
||||
if (max_assigned_seqno > 0) {
|
||||
const SequenceNumber last_seqno = versions_->LastSequence();
|
||||
@@ -6971,17 +7297,17 @@ Status DBImpl::IngestExternalFiles(
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& job : ingestion_jobs) {
|
||||
job.UnregisterRange();
|
||||
for (auto* job : ingestion_jobs) {
|
||||
job->UnregisterRange();
|
||||
}
|
||||
|
||||
if (status.ok()) {
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i].GetColumnFamilyData();
|
||||
for (size_t i = 0; i != num_jobs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i]->GetColumnFamilyData();
|
||||
assert(!cfd->IsDropped());
|
||||
InstallSuperVersionAndScheduleWork(cfd, &sv_ctxs[i]);
|
||||
#ifndef NDEBUG
|
||||
if (0 == i && num_cfs > 1) {
|
||||
if (0 == i && num_jobs > 1) {
|
||||
TEST_SYNC_POINT("DBImpl::IngestExternalFiles:InstallSVForFirstCF:0");
|
||||
TEST_SYNC_POINT("DBImpl::IngestExternalFiles:InstallSVForFirstCF:1");
|
||||
}
|
||||
@@ -7006,12 +7332,14 @@ Status DBImpl::IngestExternalFiles(
|
||||
PERF_TIMER_STOP(file_ingestion_blocking_live_writes_nanos);
|
||||
|
||||
if (status.ok()) {
|
||||
for (auto& job : ingestion_jobs) {
|
||||
job.UpdateStats();
|
||||
for (auto* job : ingestion_jobs) {
|
||||
job->UpdateStats();
|
||||
}
|
||||
for (auto* h : hs) {
|
||||
ReleaseFileNumberFromPendingOutputs(h->pending_output_elem_);
|
||||
}
|
||||
}
|
||||
ReleaseFileNumberFromPendingOutputs(pending_output_elem);
|
||||
num_running_ingest_file_ -= static_cast<int>(num_cfs);
|
||||
num_running_ingest_file_ -= static_cast<int>(num_jobs);
|
||||
if (0 == num_running_ingest_file_) {
|
||||
bg_cv_.SignalAll();
|
||||
}
|
||||
@@ -7019,24 +7347,46 @@ Status DBImpl::IngestExternalFiles(
|
||||
}
|
||||
// mutex_ is unlocked here
|
||||
|
||||
// Cleanup
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
sv_ctxs[i].Clean();
|
||||
// This may rollback jobs that have completed successfully. This is
|
||||
// intended for atomicity.
|
||||
ingestion_jobs[i].Cleanup(status);
|
||||
for (auto& sv_ctx : sv_ctxs) {
|
||||
sv_ctx.Clean();
|
||||
}
|
||||
if (status.ok()) {
|
||||
for (size_t i = 0; i != num_cfs; ++i) {
|
||||
auto* cfd = ingestion_jobs[i].GetColumnFamilyData();
|
||||
if (!status.ok()) {
|
||||
// The atomic commit failed; nothing was made visible. The handles are NOT
|
||||
// consumed, so each one's destructor rolls it back
|
||||
return status;
|
||||
}
|
||||
|
||||
for (auto* job : ingestion_jobs) {
|
||||
job->Cleanup(status);
|
||||
auto* cfd = job->GetColumnFamilyData();
|
||||
if (!cfd->IsDropped()) {
|
||||
NotifyOnExternalFileIngested(cfd, ingestion_jobs[i]);
|
||||
NotifyOnExternalFileIngested(cfd, *job);
|
||||
}
|
||||
}
|
||||
for (auto* h : hs) {
|
||||
h->consumed_ = true;
|
||||
num_outstanding_prepared_ingestions_.fetch_sub(1);
|
||||
}
|
||||
// Record commit latency.
|
||||
if (record_ingest_micros) {
|
||||
RecordTimeToHistogram(
|
||||
stats_, INGEST_EXTERNAL_FILE_RUN_TIME,
|
||||
immutable_db_options_.clock->NowMicros() - run_start_micros);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Status DBImpl::IngestExternalFiles(
|
||||
const std::vector<IngestExternalFileArg>& args) {
|
||||
PERF_TIMER_GUARD(file_ingestion_nanos);
|
||||
std::unique_ptr<FileIngestionHandle> handle;
|
||||
Status status = PrepareFileIngestion(args, &handle);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
return CommitFileIngestionHandle(std::move(handle));
|
||||
}
|
||||
|
||||
Status DBImpl::CreateColumnFamilyWithImport(
|
||||
const ColumnFamilyOptions& options, const std::string& column_family_name,
|
||||
const ImportColumnFamilyOptions& import_options,
|
||||
@@ -7078,6 +7428,7 @@ Status DBImpl::CreateColumnFamilyWithImport(
|
||||
|
||||
SuperVersionContext dummy_sv_ctx(/* create_superversion */ true);
|
||||
VersionEdit dummy_edit;
|
||||
dummy_edit.MarkForegroundOperation();
|
||||
uint64_t next_file_number = 0;
|
||||
std::unique_ptr<std::list<uint64_t>::iterator> pending_output_elem;
|
||||
{
|
||||
@@ -7135,9 +7486,10 @@ Status DBImpl::CreateColumnFamilyWithImport(
|
||||
|
||||
// Install job edit [Mutex will be unlocked here]
|
||||
if (status.ok()) {
|
||||
status = versions_->LogAndApply(cfd, read_options, write_options,
|
||||
import_job.edit(), &mutex_,
|
||||
directories_.GetDbDir());
|
||||
auto* edit = import_job.edit();
|
||||
edit->MarkForegroundOperation();
|
||||
status = versions_->LogAndApply(cfd, read_options, write_options, edit,
|
||||
&mutex_, directories_.GetDbDir());
|
||||
if (status.ok()) {
|
||||
InstallSuperVersionForConfigChange(cfd, &sv_context);
|
||||
}
|
||||
@@ -7568,6 +7920,7 @@ Status DBImpl::ReserveFileNumbersBeforeIngestion(
|
||||
// reuse the file number that has already assigned to the internal file,
|
||||
// and this will overwrite the external file. To protect the external
|
||||
// file, we have to make sure the file number will never being reused.
|
||||
dummy_edit.MarkForegroundOperation();
|
||||
s = versions_->LogAndApply(cfd, read_options, write_options, &dummy_edit,
|
||||
&mutex_, directories_.GetDbDir());
|
||||
if (s.ok()) {
|
||||
|
||||
+157
-11
@@ -15,6 +15,8 @@
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -74,6 +76,7 @@ namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
class Arena;
|
||||
class ArenaWrappedDBIter;
|
||||
class FileIngestionHandleImpl;
|
||||
class InMemoryStatsHistoryIterator;
|
||||
class MemTable;
|
||||
class PersistentStatsHistoryIterator;
|
||||
@@ -573,6 +576,10 @@ class DBImpl : public DB {
|
||||
const LiveFilesStorageInfoOptions& opts,
|
||||
std::vector<LiveFileStorageInfo>* files) override;
|
||||
|
||||
Status GetPreparedFileInfoForExternalSstIngestion(
|
||||
const std::string& file_path,
|
||||
std::shared_ptr<const PreparedFileInfo>* file_info) override;
|
||||
|
||||
// Obtains the meta data of the specified column family of the DB.
|
||||
// TODO(yhchiang): output parameter is placed in the end in this codebase.
|
||||
void GetColumnFamilyMetaData(ColumnFamilyHandle* column_family,
|
||||
@@ -602,6 +609,14 @@ class DBImpl : public DB {
|
||||
Status IngestExternalFiles(
|
||||
const std::vector<IngestExternalFileArg>& args) override;
|
||||
|
||||
using DB::PrepareFileIngestion;
|
||||
Status PrepareFileIngestion(
|
||||
const std::vector<IngestExternalFileArg>& args,
|
||||
std::unique_ptr<FileIngestionHandle>* handle) override;
|
||||
|
||||
Status CommitFileIngestionHandles(
|
||||
std::vector<std::unique_ptr<FileIngestionHandle>> handles) override;
|
||||
|
||||
using DB::CreateColumnFamilyWithImport;
|
||||
Status CreateColumnFamilyWithImport(
|
||||
const ColumnFamilyOptions& options, const std::string& column_family_name,
|
||||
@@ -855,12 +870,22 @@ class DBImpl : public DB {
|
||||
// memtable range tombstone iterator used by the underlying merging iterator.
|
||||
// This range tombstone iterator can be refreshed later by db_iter.
|
||||
// @param read_options Must outlive the returned iterator.
|
||||
InternalIterator* NewInternalIterator(const ReadOptions& read_options,
|
||||
ColumnFamilyData* cfd,
|
||||
SuperVersion* super_version,
|
||||
Arena* arena, SequenceNumber sequence,
|
||||
bool allow_unprepared_value,
|
||||
ArenaWrappedDBIter* db_iter = nullptr);
|
||||
// @param sequence The snapshot sequence captured when the DB iterator was
|
||||
// created. Child iterators must use this instead of dereferencing
|
||||
// read_options.snapshot, which may be released before lazy initialization.
|
||||
// @param scan_opts Optional bounded scan ranges used only to prune the
|
||||
// iterator tree during lazy Prepare() initialization.
|
||||
InternalIterator* NewInternalIterator(
|
||||
const ReadOptions& read_options, ColumnFamilyData* cfd,
|
||||
SuperVersion* super_version, Arena* arena, SequenceNumber sequence,
|
||||
bool allow_unprepared_value, ArenaWrappedDBIter* db_iter = nullptr,
|
||||
const MultiScanArgs* scan_opts = nullptr);
|
||||
|
||||
// Release a SuperVersion held by an iterator. This preserves the cleanup
|
||||
// behavior used by materialized internal iterators even when the DB iterator
|
||||
// never needed to lazily build its child iterator tree.
|
||||
void CleanupIteratorSuperVersion(SuperVersion* super_version,
|
||||
bool background_purge);
|
||||
|
||||
LogsWithPrepTracker* logs_with_prep_tracker() {
|
||||
return &logs_with_prep_tracker_;
|
||||
@@ -1190,6 +1215,8 @@ class DBImpl : public DB {
|
||||
|
||||
bool TEST_IsRecoveryInProgress();
|
||||
|
||||
Status TEST_ResumeImpl(DBRecoverContext context);
|
||||
|
||||
// Return the maximum overlapping data (in bytes) at next level for any
|
||||
// file at a level >= 1.
|
||||
uint64_t TEST_MaxNextLevelOverlappingBytes(
|
||||
@@ -1372,6 +1399,7 @@ class DBImpl : public DB {
|
||||
|
||||
protected:
|
||||
const std::string dbname_;
|
||||
const bool read_only_;
|
||||
// TODO(peterd): unify with VersionSet::db_id_
|
||||
std::string db_id_;
|
||||
// db_session_id_ is an identifier that gets reset
|
||||
@@ -1453,6 +1481,13 @@ class DBImpl : public DB {
|
||||
std::atomic<int> next_job_id_ = 1;
|
||||
|
||||
std::atomic<bool> shutting_down_ = false;
|
||||
// Protected by mutex_. This is separate from shutting_down_ because
|
||||
// OnDBShutdownBegin must fire before shutting_down_ is published, and the
|
||||
// notification releases mutex_ while invoking listeners. Marking that the
|
||||
// notification has started prevents a concurrent or reentrant
|
||||
// CancelAllBackgroundWork() call from firing it again during that unlocked
|
||||
// callback window.
|
||||
bool shutdown_notification_sent_ = false;
|
||||
|
||||
// No new background jobs can be queued if true. This is used to prevent new
|
||||
// background jobs from being queued after WaitForCompact() completes waiting
|
||||
@@ -1527,6 +1562,16 @@ class DBImpl : public DB {
|
||||
const Status& st,
|
||||
const CompactionJobStats& job_stats,
|
||||
int job_id);
|
||||
// Fires the OnCompactionPreCommit listener callback. Mirrors
|
||||
// NotifyOnCompactionCompleted but is invoked before ReleaseCompactionFiles()
|
||||
// (i.e. while input files still have being_compacted == true). Idempotent:
|
||||
// safe to call from multiple potential release sites; only fires once per
|
||||
// compaction, and only if NotifyOnCompactionBegin previously fired.
|
||||
void NotifyOnCompactionPreCommit(ColumnFamilyData* cfd, Compaction* c,
|
||||
const Status& st,
|
||||
const CompactionJobStats& job_stats,
|
||||
int job_id);
|
||||
void NotifyOnDBShutdownBegin();
|
||||
void NotifyOnMemTableSealed(ColumnFamilyData* cfd,
|
||||
const MemTableInfo& mem_table_info);
|
||||
|
||||
@@ -1887,6 +1932,7 @@ class DBImpl : public DB {
|
||||
friend class WriteBatchWithIndex;
|
||||
friend class WriteUnpreparedTxnDB;
|
||||
friend class WriteUnpreparedTxn;
|
||||
friend class FileIngestionHandleImpl;
|
||||
|
||||
friend class ForwardIterator;
|
||||
friend struct SuperVersion;
|
||||
@@ -2224,6 +2270,10 @@ class DBImpl : public DB {
|
||||
void ReleaseFileNumberFromPendingOutputs(
|
||||
std::unique_ptr<std::list<uint64_t>::iterator>& v);
|
||||
|
||||
// Rolls back one prepared file ingestion (delete its staged files, release
|
||||
// the reserved file numbers)
|
||||
void RollbackPreparedFileIngestion(FileIngestionHandleImpl* const h);
|
||||
|
||||
// Similar to pending_outputs, preserve OPTIONS file. Used for remote
|
||||
// compaction.
|
||||
std::list<uint64_t>::iterator CaptureOptionsFileNumber();
|
||||
@@ -2435,6 +2485,10 @@ class DBImpl : public DB {
|
||||
const autovector<ColumnFamilyData*>& provided_candidate_cfds = {},
|
||||
bool entered_write_thread = false);
|
||||
|
||||
// REQUIRES: mutex locked and write queues drained up to the recovery flush
|
||||
// fence that is about to switch memtables.
|
||||
void MaybeSyncLastSequenceWithAllocatedForRecovery(FlushReason flush_reason);
|
||||
|
||||
Status RetryFlushesForErrorRecovery(FlushReason flush_reason, bool wait);
|
||||
|
||||
// Wait until flushing this column family won't stall writes
|
||||
@@ -2574,10 +2628,15 @@ class DBImpl : public DB {
|
||||
// Helper function to perform trivial move by updating manifest metadata
|
||||
// without rewriting data files. This is called when IsTrivialMove() is true.
|
||||
// REQUIRES: mutex held
|
||||
// Returns: Status of the trivial move operation
|
||||
Status PerformTrivialMove(Compaction& c, LogBuffer* log_buffer,
|
||||
bool& compaction_released, size_t& moved_files,
|
||||
size_t& moved_bytes);
|
||||
// Populates the Compaction's edit with DeleteFile/AddFile entries for
|
||||
// a trivial move (no data rewriting). Does not commit the edit.
|
||||
void PrepareTrivialMoveEdit(Compaction& c, LogBuffer* log_buffer,
|
||||
size_t& moved_files, size_t& moved_bytes);
|
||||
|
||||
// REQUIRES: mutex held, PrepareTrivialMoveEdit already called
|
||||
// Commits the trivial move by calling LogAndApply on the prepared edit.
|
||||
// Returns: Status of the manifest write
|
||||
Status CommitTrivialMove(Compaction& c, bool& compaction_released);
|
||||
|
||||
// REQUIRES: mutex unlocked
|
||||
void TrackOrUntrackFiles(const std::vector<std::string>& existing_data_files,
|
||||
@@ -2810,7 +2869,68 @@ class DBImpl : public DB {
|
||||
size_t GetWalPreallocateBlockSize(uint64_t write_buffer_size) const;
|
||||
Env::WriteLifeTimeHint CalculateWALWriteHint() { return Env::WLTH_SHORT; }
|
||||
|
||||
IOStatus CreateWAL(const WriteOptions& write_options, uint64_t log_file_num,
|
||||
// Returns true when async WAL precreation is enabled and compatible with the
|
||||
// active WAL strategy. WAL recycling already avoids file creation latency, so
|
||||
// precreation is disabled when recycle_log_file_num is non-zero.
|
||||
bool AsyncWALPrecreateEnabled() const;
|
||||
|
||||
// A WAL file that has a reserved file number and may have an opened writer,
|
||||
// but has not been added to DBImpl's in-memory logical WAL tracking lists
|
||||
// (logs_ and alive_wal_files_).
|
||||
struct UnpublishedWAL {
|
||||
uint64_t log_number = 0;
|
||||
std::unique_ptr<log::Writer> writer;
|
||||
|
||||
UnpublishedWAL() = default;
|
||||
UnpublishedWAL(const UnpublishedWAL&) = delete;
|
||||
UnpublishedWAL& operator=(const UnpublishedWAL&) = delete;
|
||||
|
||||
UnpublishedWAL(UnpublishedWAL&& other) noexcept {
|
||||
*this = std::move(other);
|
||||
}
|
||||
UnpublishedWAL& operator=(UnpublishedWAL&& other) noexcept {
|
||||
if (this != &other) {
|
||||
log_number = other.log_number;
|
||||
writer = std::move(other.writer);
|
||||
other.Reset();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
log_number = 0;
|
||||
writer.reset();
|
||||
}
|
||||
};
|
||||
|
||||
// Reserves the next WAL file number and schedules a HIGH-priority background
|
||||
// task to precreate that WAL file. A precreated WAL is not a logical WAL
|
||||
// until a foreground WAL rotation consumes it.
|
||||
void MaybeScheduleAsyncWALPrecreate(size_t preallocate_block_size);
|
||||
|
||||
// Background task for opening the reserved future WAL and publishing the
|
||||
// result under mutex_.
|
||||
static void BGWorkAsyncWALPrecreate(void* arg);
|
||||
|
||||
// Waits for an in-flight async WAL precreation and returns a prepared WAL if
|
||||
// one is available. If precreation failed, returns an empty WAL and lets the
|
||||
// foreground rotation create the WAL synchronously. Caller must hold mutex_.
|
||||
UnpublishedWAL WaitForAsyncWALPrecreate();
|
||||
|
||||
// Opens and preallocates a WAL writer without writing logical WAL records.
|
||||
// Used by async WAL precreation and by synchronous WAL creation.
|
||||
IOStatus CreateWALWriter(const DBOptions& db_options, uint64_t log_file_num,
|
||||
uint64_t recycle_log_number,
|
||||
size_t preallocate_block_size,
|
||||
UnpublishedWAL* new_wal);
|
||||
|
||||
// Starts an opened WAL file by writing the initial records required before it
|
||||
// can be installed as the current WAL for foreground writes.
|
||||
IOStatus StartWALFile(const WriteOptions& write_options,
|
||||
const PredecessorWALInfo& predecessor_wal_info,
|
||||
log::Writer* new_log);
|
||||
IOStatus CreateWAL(const DBOptions& db_options,
|
||||
const WriteOptions& write_options, uint64_t log_file_num,
|
||||
uint64_t recycle_log_number, size_t preallocate_block_size,
|
||||
const PredecessorWALInfo& predecessor_wal_info,
|
||||
log::Writer** new_log);
|
||||
@@ -3306,6 +3426,28 @@ class DBImpl : public DB {
|
||||
AsyncFileOpenState bg_async_file_open_state_ =
|
||||
AsyncFileOpenState::kNotScheduled;
|
||||
|
||||
// State machine for the single async WAL precreation slot protected by
|
||||
// mutex_. Background precreation failure returns to kNotScheduled; foreground
|
||||
// rotation handles it the same as no prepared WAL and creates one
|
||||
// synchronously. kScheduled owns a reserved file number; kReady owns an
|
||||
// opened writer that has not been started or added to logical WAL tracking.
|
||||
enum class AsyncWALPrecreateState : uint8_t {
|
||||
kNotScheduled = 0, // No WAL precreate work is in-flight or ready.
|
||||
kScheduled, // Background task owns creation of the reserved WAL.
|
||||
kReady, // Reserved WAL writer is open but not logically live.
|
||||
};
|
||||
|
||||
// Protected by mutex_. Tracks at most one background precreated WAL. A
|
||||
// precreated WAL is only reserved empty storage until SwitchMemtable()
|
||||
// consumes it and installs it in DBImpl's in-memory logical WAL tracking
|
||||
// lists (logs_ and alive_wal_files_).
|
||||
AsyncWALPrecreateState async_wal_precreate_state_ =
|
||||
AsyncWALPrecreateState::kNotScheduled;
|
||||
|
||||
// Reserved in-flight/ready precreated WAL. The writer is populated only while
|
||||
// state is kReady.
|
||||
UnpublishedWAL async_wal_precreate_wal_;
|
||||
|
||||
std::deque<ManualCompactionState*> manual_compaction_dequeue_;
|
||||
|
||||
// shall we disable deletion of obsolete files
|
||||
@@ -3355,6 +3497,10 @@ class DBImpl : public DB {
|
||||
// REQUIRES: mutex held
|
||||
int num_running_ingest_file_ = 0;
|
||||
|
||||
// Number of FileIngestionHandle objects produced by PrepareFileIngestion()
|
||||
// that have not been committed or destroyed yet.
|
||||
std::atomic<uint32_t> num_outstanding_prepared_ingestions_{0};
|
||||
|
||||
WalManager wal_manager_;
|
||||
|
||||
// A value of > 0 temporarily disables scheduling of background work
|
||||
|
||||
@@ -35,6 +35,32 @@
|
||||
|
||||
namespace ROCKSDB_NAMESPACE {
|
||||
|
||||
namespace {
|
||||
|
||||
void RecordAtomicFlushRequestReason(Statistics* stats,
|
||||
FlushReason flush_reason) {
|
||||
// Keep this aligned with the existing rocksdb.flush.reason.* counters: they
|
||||
// cover automatic flush triggers used for write-stall debugging. Other
|
||||
// FlushReason values are counted by the catch-all other ticker.
|
||||
switch (flush_reason) {
|
||||
case FlushReason::kWriteBufferFull:
|
||||
RecordTick(stats, ATOMIC_FLUSH_REQUEST_REASON_WRITE_BUFFER_FULL);
|
||||
break;
|
||||
case FlushReason::kWriteBufferManager:
|
||||
RecordTick(stats, ATOMIC_FLUSH_REQUEST_REASON_WRITE_BUFFER_MANAGER);
|
||||
break;
|
||||
case FlushReason::kMemtableMaxRangeDeletions:
|
||||
RecordTick(stats,
|
||||
ATOMIC_FLUSH_REQUEST_REASON_MEMTABLE_MAX_RANGE_DELETIONS);
|
||||
break;
|
||||
default:
|
||||
RecordTick(stats, ATOMIC_FLUSH_REQUEST_REASON_OTHER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool DBImpl::EnoughRoomForCompaction(
|
||||
ColumnFamilyData* cfd, const std::vector<CompactionInputFiles>& inputs,
|
||||
bool* sfm_reserved_compact_space, LogBuffer* log_buffer) {
|
||||
@@ -1581,8 +1607,7 @@ Status DBImpl::CompactFiles(const CompactionOptions& compact_options,
|
||||
return s;
|
||||
}
|
||||
|
||||
Status DBImpl::PerformTrivialMove(Compaction& c, LogBuffer* log_buffer,
|
||||
bool& compaction_released,
|
||||
void DBImpl::PrepareTrivialMoveEdit(Compaction& c, LogBuffer* log_buffer,
|
||||
size_t& moved_files, size_t& moved_bytes) {
|
||||
mutex_.AssertHeld();
|
||||
|
||||
@@ -1616,6 +1641,10 @@ Status DBImpl::PerformTrivialMove(Compaction& c, LogBuffer* log_buffer,
|
||||
}
|
||||
moved_files += c.num_input_files(l);
|
||||
}
|
||||
}
|
||||
|
||||
Status DBImpl::CommitTrivialMove(Compaction& c, bool& compaction_released) {
|
||||
mutex_.AssertHeld();
|
||||
|
||||
// Install the new version
|
||||
const ReadOptions read_options(Env::IOActivity::kCompaction);
|
||||
@@ -1740,8 +1769,8 @@ Status DBImpl::CompactFilesImpl(
|
||||
bool compaction_released = false;
|
||||
size_t moved_files = 0;
|
||||
size_t moved_bytes = 0;
|
||||
Status status = PerformTrivialMove(
|
||||
*c.get(), log_buffer, compaction_released, moved_files, moved_bytes);
|
||||
PrepareTrivialMoveEdit(*c.get(), log_buffer, moved_files, moved_bytes);
|
||||
Status status = CommitTrivialMove(*c.get(), compaction_released);
|
||||
|
||||
if (status.ok()) {
|
||||
InstallSuperVersionAndScheduleWork(
|
||||
@@ -2009,6 +2038,46 @@ void DBImpl::NotifyOnCompactionCompleted(
|
||||
// flush process.
|
||||
}
|
||||
|
||||
void DBImpl::NotifyOnCompactionPreCommit(
|
||||
ColumnFamilyData* cfd, Compaction* c, const Status& st,
|
||||
const CompactionJobStats& compaction_job_stats, const int job_id) {
|
||||
if (immutable_db_options_.listeners.size() == 0U) {
|
||||
return;
|
||||
}
|
||||
mutex_.AssertHeld();
|
||||
if (shutting_down_.load(std::memory_order_acquire)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only fire if OnCompactionBegin has fired for this compaction.
|
||||
if (c->ShouldNotifyOnCompactionCompleted() == false) {
|
||||
return;
|
||||
}
|
||||
// Idempotency: ensure listeners observe at most one
|
||||
// OnCompactionPreCommit per compaction lifecycle, even though the
|
||||
// notify helper is invoked at multiple potential ReleaseCompactionFiles()
|
||||
// sites for safety.
|
||||
if (c->WasNotifyOnCompactionPreCommitCalled()) {
|
||||
return;
|
||||
}
|
||||
c->SetNotifyOnCompactionPreCommitCalled();
|
||||
|
||||
int num_l0_files = cfd->current()->storage_info()->NumLevelFiles(0);
|
||||
// release lock while notifying events
|
||||
mutex_.Unlock();
|
||||
TEST_SYNC_POINT("DBImpl::NotifyOnCompactionPreCommit::UnlockMutex");
|
||||
{
|
||||
CompactionJobInfo info{};
|
||||
info.num_l0_files = num_l0_files;
|
||||
BuildCompactionJobInfo(cfd, c, st, compaction_job_stats, job_id, &info);
|
||||
for (const auto& listener : immutable_db_options_.listeners) {
|
||||
listener->OnCompactionPreCommit(this, info);
|
||||
}
|
||||
info.status.PermitUncheckedError();
|
||||
}
|
||||
mutex_.Lock();
|
||||
}
|
||||
|
||||
// REQUIREMENT: block all background work by calling PauseBackgroundWork()
|
||||
// before calling this function
|
||||
// TODO (hx235): Replace Status::NotSupported() with Status::Aborted() for
|
||||
@@ -2192,6 +2261,8 @@ Status DBImpl::FlushAllColumnFamilies(const FlushOptions& flush_options,
|
||||
Status status;
|
||||
if (immutable_db_options_.atomic_flush || flush_options.force_atomic_flush) {
|
||||
mutex_.Unlock();
|
||||
TEST_SYNC_POINT(
|
||||
"DBImpl::FlushAllColumnFamilies:BeforeAtomicFlushMemTables");
|
||||
status = AtomicFlushMemTables(flush_options, flush_reason);
|
||||
if (status.IsColumnFamilyDropped()) {
|
||||
status = Status::OK();
|
||||
@@ -2203,6 +2274,7 @@ Status DBImpl::FlushAllColumnFamilies(const FlushOptions& flush_options,
|
||||
continue;
|
||||
}
|
||||
mutex_.Unlock();
|
||||
TEST_SYNC_POINT("DBImpl::FlushAllColumnFamilies:BeforeFlushMemTable");
|
||||
status = FlushMemTable(cfd, flush_options, flush_reason);
|
||||
TEST_SYNC_POINT("DBImpl::FlushAllColumnFamilies:1");
|
||||
TEST_SYNC_POINT("DBImpl::FlushAllColumnFamilies:2");
|
||||
@@ -2557,6 +2629,14 @@ void DBImpl::NotifyOnManualFlushScheduled(autovector<ColumnFamilyData*> cfds,
|
||||
}
|
||||
}
|
||||
|
||||
void DBImpl::MaybeSyncLastSequenceWithAllocatedForRecovery(
|
||||
FlushReason flush_reason) {
|
||||
mutex_.AssertHeld();
|
||||
if (two_write_queues_ && IsRecoveryFlush(flush_reason)) {
|
||||
versions_->SyncLastSequenceWithAllocated();
|
||||
}
|
||||
}
|
||||
|
||||
Status DBImpl::FlushMemTable(ColumnFamilyData* cfd,
|
||||
const FlushOptions& flush_options,
|
||||
FlushReason flush_reason,
|
||||
@@ -2596,6 +2676,12 @@ Status DBImpl::FlushMemTable(ColumnFamilyData* cfd,
|
||||
}
|
||||
WaitForPendingWrites();
|
||||
|
||||
// Recovery may have released `mutex_` after the earlier `ResumeImpl()`
|
||||
// sync. Refresh sequence state at the actual memtable-switch fence, after
|
||||
// both write queues are drained and before `SwitchMemtable()` consumes
|
||||
// `LastSequence()`.
|
||||
MaybeSyncLastSequenceWithAllocatedForRecovery(flush_reason);
|
||||
|
||||
if (!cfd->mem()->IsEmpty() || !cached_recoverable_state_empty_.load() ||
|
||||
IsRecoveryFlush(flush_reason)) {
|
||||
s = SwitchMemtable(cfd, &context);
|
||||
@@ -2785,6 +2871,11 @@ Status DBImpl::AtomicFlushMemTables(
|
||||
}
|
||||
WaitForPendingWrites();
|
||||
|
||||
// Keep atomic recovery flushes consistent with the single-CF path: the
|
||||
// sequence sync must happen after both write queues are drained and before
|
||||
// any recovery memtable switch reads `LastSequence()`.
|
||||
MaybeSyncLastSequenceWithAllocatedForRecovery(flush_reason);
|
||||
|
||||
SelectColumnFamiliesForAtomicFlush(&cfds, candidate_cfds, flush_reason);
|
||||
|
||||
// Unref the newly generated candidate cfds (when not provided) in
|
||||
@@ -3180,7 +3271,7 @@ void DBImpl::ResumeAllCompactions() {
|
||||
void DBImpl::MaybeScheduleFlushOrCompaction() {
|
||||
mutex_.AssertHeld();
|
||||
TEST_SYNC_POINT("DBImpl::MaybeScheduleFlushOrCompaction:Start");
|
||||
if (!opened_successfully_) {
|
||||
if (!opened_successfully_ || read_only_) {
|
||||
// Compaction may introduce data race to DB open
|
||||
return;
|
||||
}
|
||||
@@ -3488,6 +3579,7 @@ bool DBImpl::EnqueuePendingFlush(const FlushRequest& flush_req) {
|
||||
}
|
||||
++unscheduled_flushes_;
|
||||
flush_queue_.push_back(flush_req);
|
||||
RecordAtomicFlushRequestReason(stats_, flush_req.flush_reason);
|
||||
enqueued = true;
|
||||
}
|
||||
return enqueued;
|
||||
@@ -4024,6 +4116,13 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
status = Status::ShutdownInProgress();
|
||||
} else if (compaction_aborted_.load(std::memory_order_acquire) > 0) {
|
||||
status = Status::Incomplete(Status::SubCode::kCompactionAborted);
|
||||
if (!is_prepicked) {
|
||||
// This automatic compaction was scheduled from compaction_queue_, but
|
||||
// abort happened before PickCompactionFromQueue() could remove the
|
||||
// queued CF. Restore the unscheduled count so ResumeAllCompactions()
|
||||
// can schedule the still-queued work.
|
||||
unscheduled_compactions_++;
|
||||
}
|
||||
} else if (is_manual &&
|
||||
manual_compaction->canceled.load(std::memory_order_acquire)) {
|
||||
status = Status::Incomplete(Status::SubCode::kManualCompactionPaused);
|
||||
@@ -4031,11 +4130,15 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
} else {
|
||||
status = error_handler_.GetBGError();
|
||||
// If we get here, it means a hard error happened after this compaction
|
||||
// was scheduled by MaybeScheduleFlushOrCompaction(), but before it got
|
||||
// a chance to execute. Since we didn't pop a cfd from the compaction
|
||||
// queue, increment unscheduled_compactions_
|
||||
// was scheduled by MaybeScheduleFlushOrCompaction(), but before it got a
|
||||
// chance to execute. Since non-prepicked work consumed an unscheduled
|
||||
// compaction credit without popping a cfd from the compaction queue,
|
||||
// restore the credit here. Prepicked work was scheduled directly and did
|
||||
// not consume unscheduled_compactions_.
|
||||
if (!is_prepicked) {
|
||||
unscheduled_compactions_++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!status.ok()) {
|
||||
if (is_manual) {
|
||||
@@ -4255,6 +4358,8 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
for (const auto& f : *c->inputs(0)) {
|
||||
c->edit()->DeleteFile(c->level(), f->fd.GetNumber());
|
||||
}
|
||||
NotifyOnCompactionPreCommit(c->column_family_data(), c.get(), status,
|
||||
compaction_job_stats, job_context->job_id);
|
||||
status = versions_->LogAndApply(
|
||||
c->column_family_data(), read_options, write_options, c->edit(),
|
||||
&mutex_, directories_.GetDbDir(),
|
||||
@@ -4473,6 +4578,8 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
++out_file_metadata_it;
|
||||
}
|
||||
|
||||
NotifyOnCompactionPreCommit(c->column_family_data(), c.get(), status,
|
||||
compaction_job_stats, job_context->job_id);
|
||||
status = versions_->LogAndApply(
|
||||
c->column_family_data(), read_options, write_options, c->edit(),
|
||||
&mutex_, directories_.GetDbDir(),
|
||||
@@ -4549,8 +4656,12 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
// Perform the trivial move
|
||||
size_t moved_files = 0;
|
||||
size_t moved_bytes = 0;
|
||||
status = PerformTrivialMove(*c.get(), log_buffer, compaction_released,
|
||||
moved_files, moved_bytes);
|
||||
// Populate the edit first so that CompactionJobInfo has output file
|
||||
// info when OnCompactionPreCommit fires.
|
||||
PrepareTrivialMoveEdit(*c.get(), log_buffer, moved_files, moved_bytes);
|
||||
NotifyOnCompactionPreCommit(c->column_family_data(), c.get(), status,
|
||||
compaction_job_stats, job_context->job_id);
|
||||
status = CommitTrivialMove(*c.get(), compaction_released);
|
||||
io_s = versions_->io_status();
|
||||
InstallSuperVersionAndScheduleWork(
|
||||
c->column_family_data(), job_context->superversion_contexts.data());
|
||||
@@ -4673,6 +4784,10 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
ReleaseOptionsFileNumber(min_options_file_number_elem);
|
||||
}
|
||||
|
||||
// Fire OnCompactionPreCommit before compaction_job.Install runs
|
||||
// ReleaseCompactionFiles in its manifest write callback.
|
||||
NotifyOnCompactionPreCommit(c->column_family_data(), c.get(), status,
|
||||
compaction_job_stats, job_context->job_id);
|
||||
status = compaction_job.Install(&compaction_released);
|
||||
io_s = compaction_job.io_status();
|
||||
if (status.ok()) {
|
||||
@@ -4692,6 +4807,14 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
|
||||
|
||||
if (c != nullptr) {
|
||||
if (!compaction_released) {
|
||||
// Safety net: if any of the paths above did not fire the
|
||||
// OnCompactionPreCommit notification (e.g. status was not OK and
|
||||
// an early-out skipped the LogAndApply / Install), still fire the
|
||||
// notify here while files are about to be released. The notify is
|
||||
// idempotent and is a no-op if it has already fired (or if Begin never
|
||||
// fired).
|
||||
NotifyOnCompactionPreCommit(c->column_family_data(), c.get(), status,
|
||||
compaction_job_stats, job_context->job_id);
|
||||
c->ReleaseCompactionFiles(status);
|
||||
} else {
|
||||
#ifndef NDEBUG
|
||||
|
||||
@@ -35,6 +35,11 @@ Status DBImpl::TEST_SwitchWAL() {
|
||||
return s;
|
||||
}
|
||||
|
||||
Status DBImpl::TEST_ResumeImpl(DBRecoverContext context) {
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
return ResumeImpl(context);
|
||||
}
|
||||
|
||||
uint64_t DBImpl::TEST_MaxNextLevelOverlappingBytes(
|
||||
ColumnFamilyHandle* column_family) {
|
||||
ColumnFamilyData* cfd;
|
||||
|
||||
@@ -833,6 +833,7 @@ void DBImpl::PurgeObsoleteFiles(JobContext& state, bool schedule_only) {
|
||||
}
|
||||
wal_manager_.PurgeObsoleteWALFiles();
|
||||
LogFlush(immutable_db_options_.info_log);
|
||||
TEST_SYNC_POINT("DBImpl::PurgeObsoleteFiles:BeforePendingPurgeFinished");
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
--pending_purge_obsolete_files_;
|
||||
assert(pending_purge_obsolete_files_ >= 0);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user