|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
//
|
|
|
|
// The test uses an array to compare against values written to the database.
|
|
|
|
// Keys written to the array are in 1:1 correspondence to the actual values in
|
|
|
|
// the database according to the formula in the function GenerateValue.
|
|
|
|
|
|
|
|
// Space is reserved in the array from 0 to FLAGS_max_key and values are
|
|
|
|
// randomly written/deleted/read from those positions. During verification we
|
|
|
|
// compare all the positions in the array. To shorten/elongate the running
|
|
|
|
// time, you could change the settings: FLAGS_max_key, FLAGS_ops_per_thread,
|
|
|
|
// (sometimes also FLAGS_threads).
|
|
|
|
//
|
|
|
|
// NOTE that if FLAGS_test_batches_snapshots is set, the test will have
|
|
|
|
// different behavior. See comment of the flag for details.
|
|
|
|
|
|
|
|
#ifdef GFLAGS
|
|
|
|
#pragma once
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <chrono>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <exception>
|
|
|
|
#include <queue>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "db/db_impl/db_impl.h"
|
|
|
|
#include "db/version_set.h"
|
|
|
|
#include "db_stress_tool/db_stress_env_wrapper.h"
|
|
|
|
#include "db_stress_tool/db_stress_listener.h"
|
|
|
|
#include "db_stress_tool/db_stress_shared_state.h"
|
|
|
|
#include "db_stress_tool/db_stress_test_base.h"
|
|
|
|
#include "logging/logging.h"
|
|
|
|
#include "monitoring/histogram.h"
|
|
|
|
#include "options/options_helper.h"
|
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/cache.h"
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/slice.h"
|
|
|
|
#include "rocksdb/slice_transform.h"
|
|
|
|
#include "rocksdb/statistics.h"
|
|
|
|
#include "rocksdb/utilities/backup_engine.h"
|
|
|
|
#include "rocksdb/utilities/checkpoint.h"
|
|
|
|
#include "rocksdb/utilities/db_ttl.h"
|
|
|
|
#include "rocksdb/utilities/debug.h"
|
|
|
|
#include "rocksdb/utilities/options_util.h"
|
|
|
|
#include "rocksdb/utilities/transaction.h"
|
|
|
|
#include "rocksdb/utilities/transaction_db.h"
|
|
|
|
#include "rocksdb/write_batch.h"
|
|
|
|
#include "test_util/testutil.h"
|
|
|
|
#include "util/coding.h"
|
|
|
|
#include "util/compression.h"
|
|
|
|
#include "util/crc32c.h"
|
|
|
|
#include "util/gflags_compat.h"
|
|
|
|
#include "util/mutexlock.h"
|
|
|
|
#include "util/random.h"
|
|
|
|
#include "util/string_util.h"
|
|
|
|
#include "utilities/blob_db/blob_db.h"
|
|
|
|
#include "utilities/merge_operators.h"
|
|
|
|
|
|
|
|
using GFLAGS_NAMESPACE::ParseCommandLineFlags;
|
|
|
|
using GFLAGS_NAMESPACE::RegisterFlagValidator;
|
|
|
|
using GFLAGS_NAMESPACE::SetUsageMessage;
|
|
|
|
|
|
|
|
DECLARE_uint64(seed);
|
|
|
|
DECLARE_bool(read_only);
|
|
|
|
DECLARE_int64(max_key);
|
|
|
|
DECLARE_double(hot_key_alpha);
|
|
|
|
DECLARE_int32(max_key_len);
|
|
|
|
DECLARE_string(key_len_percent_dist);
|
|
|
|
DECLARE_int32(key_window_scale_factor);
|
|
|
|
DECLARE_int32(column_families);
|
|
|
|
DECLARE_string(options_file);
|
|
|
|
DECLARE_int64(active_width);
|
|
|
|
DECLARE_bool(test_batches_snapshots);
|
|
|
|
DECLARE_bool(atomic_flush);
|
|
|
|
DECLARE_bool(test_cf_consistency);
|
|
|
|
DECLARE_bool(test_multi_ops_txns);
|
|
|
|
DECLARE_int32(threads);
|
|
|
|
DECLARE_int32(ttl);
|
|
|
|
DECLARE_int32(value_size_mult);
|
|
|
|
DECLARE_int32(compaction_readahead_size);
|
|
|
|
DECLARE_bool(enable_pipelined_write);
|
|
|
|
DECLARE_bool(verify_before_write);
|
|
|
|
DECLARE_bool(histogram);
|
|
|
|
DECLARE_bool(destroy_db_initially);
|
|
|
|
DECLARE_bool(verbose);
|
|
|
|
DECLARE_bool(progress_reports);
|
|
|
|
DECLARE_uint64(db_write_buffer_size);
|
|
|
|
DECLARE_int32(write_buffer_size);
|
|
|
|
DECLARE_int32(max_write_buffer_number);
|
|
|
|
DECLARE_int32(min_write_buffer_number_to_merge);
|
|
|
|
DECLARE_int32(max_write_buffer_number_to_maintain);
|
|
|
|
DECLARE_int64(max_write_buffer_size_to_maintain);
|
|
|
|
DECLARE_double(memtable_prefix_bloom_size_ratio);
|
|
|
|
DECLARE_bool(memtable_whole_key_filtering);
|
|
|
|
DECLARE_int32(open_files);
|
|
|
|
DECLARE_int64(compressed_cache_size);
|
|
|
|
DECLARE_int32(compaction_style);
|
|
|
|
DECLARE_int32(num_levels);
|
|
|
|
DECLARE_int32(level0_file_num_compaction_trigger);
|
|
|
|
DECLARE_int32(level0_slowdown_writes_trigger);
|
|
|
|
DECLARE_int32(level0_stop_writes_trigger);
|
|
|
|
DECLARE_int32(block_size);
|
|
|
|
DECLARE_int32(format_version);
|
|
|
|
DECLARE_int32(index_block_restart_interval);
|
|
|
|
DECLARE_bool(disable_auto_compactions);
|
|
|
|
DECLARE_int32(max_background_compactions);
|
|
|
|
DECLARE_int32(num_bottom_pri_threads);
|
|
|
|
DECLARE_int32(compaction_thread_pool_adjust_interval);
|
|
|
|
DECLARE_int32(compaction_thread_pool_variations);
|
|
|
|
DECLARE_int32(max_background_flushes);
|
|
|
|
DECLARE_int32(universal_size_ratio);
|
|
|
|
DECLARE_int32(universal_min_merge_width);
|
|
|
|
DECLARE_int32(universal_max_merge_width);
|
|
|
|
DECLARE_int32(universal_max_size_amplification_percent);
|
|
|
|
DECLARE_int32(clear_column_family_one_in);
|
|
|
|
DECLARE_int32(get_live_files_one_in);
|
|
|
|
DECLARE_int32(get_sorted_wal_files_one_in);
|
|
|
|
DECLARE_int32(get_current_wal_file_one_in);
|
|
|
|
DECLARE_int32(set_options_one_in);
|
|
|
|
DECLARE_int32(set_in_place_one_in);
|
|
|
|
DECLARE_int64(cache_size);
|
|
|
|
DECLARE_int32(cache_numshardbits);
|
|
|
|
DECLARE_bool(cache_index_and_filter_blocks);
|
|
|
|
DECLARE_bool(reserve_table_reader_memory);
|
|
|
|
DECLARE_int32(top_level_index_pinning);
|
|
|
|
DECLARE_int32(partition_pinning);
|
|
|
|
DECLARE_int32(unpartitioned_pinning);
|
|
|
|
DECLARE_bool(use_clock_cache);
|
|
|
|
DECLARE_uint64(subcompactions);
|
|
|
|
DECLARE_uint64(periodic_compaction_seconds);
|
|
|
|
DECLARE_uint64(compaction_ttl);
|
|
|
|
DECLARE_bool(allow_concurrent_memtable_write);
|
|
|
|
DECLARE_double(experimental_mempurge_threshold);
|
|
|
|
DECLARE_bool(enable_write_thread_adaptive_yield);
|
|
|
|
DECLARE_int32(reopen);
|
|
|
|
DECLARE_double(bloom_bits);
|
|
|
|
DECLARE_bool(use_block_based_filter);
|
Add Bloom/Ribbon hybrid API support (#8679)
Summary:
This is essentially resurrection and fixing of the part of
https://github.com/facebook/rocksdb/issues/8198 that was reverted in https://github.com/facebook/rocksdb/issues/8212, using data added in https://github.com/facebook/rocksdb/issues/8246. Basically,
when configuring Ribbon filter, you can specify an LSM level before which
Bloom will be used instead of Ribbon. But Bloom is only considered for
Leveled and Universal compaction styles and file going into a known LSM
level. This way, SST file writer, FIFO compaction, etc. use Ribbon filter as
you would expect with NewRibbonFilterPolicy.
So that this can be controlled with a single int value and so that flushes
can be distinguished from intra-L0, we consider flush to go to level -1 for
the purposes of this option. (Explained in API comment.)
I also expect the most common and recommended Ribbon configuration to
use Bloom during flush, to minimize slowing down writes and because according
to my estimates, Ribbon only pays off if the structure lives in memory for
more than an hour. Thus, I have changed the default for NewRibbonFilterPolicy
to be this mild hybrid configuration. I don't really want to add something like
NewHybridFilterPolicy because at least the mild hybrid configuration (Bloom for
flush, Ribbon otherwise) should be considered a natural choice.
C APIs also updated, but because they don't support overloading,
rocksdb_filterpolicy_create_ribbon is kept pure ribbon for clarity and
rocksdb_filterpolicy_create_ribbon_hybrid must be called for a hybrid
configuration. While touching C API, I changed bits per key options from
int to double.
BuiltinFilterPolicy is needed so that LevelThresholdFilterPolicy doesn't inherit
unused fields from BloomFilterPolicy.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8679
Test Plan: new + updated tests, including crash test
Reviewed By: jay-zhuang
Differential Revision: D30445797
Pulled By: pdillinger
fbshipit-source-id: 6f5aeddfd6d79f7e55493b563c2d1d2d568892e1
3 years ago
|
|
|
DECLARE_int32(ribbon_starting_level);
|
|
|
|
DECLARE_bool(partition_filters);
|
Minimize memory internal fragmentation for Bloom filters (#6427)
Summary:
New experimental option BBTO::optimize_filters_for_memory builds
filters that maximize their use of "usable size" from malloc_usable_size,
which is also used to compute block cache charges.
Rather than always "rounding up," we track state in the
BloomFilterPolicy object to mix essentially "rounding down" and
"rounding up" so that the average FP rate of all generated filters is
the same as without the option. (YMMV as heavily accessed filters might
be unluckily lower accuracy.)
Thus, the option near-minimizes what the block cache considers as
"memory used" for a given target Bloom filter false positive rate and
Bloom filter implementation. There are no forward or backward
compatibility issues with this change, though it only works on the
format_version=5 Bloom filter.
With Jemalloc, we see about 10% reduction in memory footprint (and block
cache charge) for Bloom filters, but 1-2% increase in storage footprint,
due to encoding efficiency losses (FP rate is non-linear with bits/key).
Why not weighted random round up/down rather than state tracking? By
only requiring malloc_usable_size, we don't actually know what the next
larger and next smaller usable sizes for the allocator are. We pick a
requested size, accept and use whatever usable size it has, and use the
difference to inform our next choice. This allows us to narrow in on the
right balance without tracking/predicting usable sizes.
Why not weight history of generated filter false positive rates by
number of keys? This could lead to excess skew in small filters after
generating a large filter.
Results from filter_bench with jemalloc (irrelevant details omitted):
(normal keys/filter, but high variance)
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=30000 -vary_key_count_ratio=0.9
Build avg ns/key: 29.6278
Number of filters: 5516
Total size (MB): 200.046
Reported total allocated memory (MB): 220.597
Reported internal fragmentation: 10.2732%
Bits/key stored: 10.0097
Average FP rate %: 0.965228
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=30000 -vary_key_count_ratio=0.9 -optimize_filters_for_memory
Build avg ns/key: 30.5104
Number of filters: 5464
Total size (MB): 200.015
Reported total allocated memory (MB): 200.322
Reported internal fragmentation: 0.153709%
Bits/key stored: 10.1011
Average FP rate %: 0.966313
(very few keys / filter, optimization not as effective due to ~59 byte
internal fragmentation in blocked Bloom filter representation)
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000 -vary_key_count_ratio=0.9
Build avg ns/key: 29.5649
Number of filters: 162950
Total size (MB): 200.001
Reported total allocated memory (MB): 224.624
Reported internal fragmentation: 12.3117%
Bits/key stored: 10.2951
Average FP rate %: 0.821534
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000 -vary_key_count_ratio=0.9 -optimize_filters_for_memory
Build avg ns/key: 31.8057
Number of filters: 159849
Total size (MB): 200
Reported total allocated memory (MB): 208.846
Reported internal fragmentation: 4.42297%
Bits/key stored: 10.4948
Average FP rate %: 0.811006
(high keys/filter)
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000000 -vary_key_count_ratio=0.9
Build avg ns/key: 29.7017
Number of filters: 164
Total size (MB): 200.352
Reported total allocated memory (MB): 221.5
Reported internal fragmentation: 10.5552%
Bits/key stored: 10.0003
Average FP rate %: 0.969358
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000000 -vary_key_count_ratio=0.9 -optimize_filters_for_memory
Build avg ns/key: 30.7131
Number of filters: 160
Total size (MB): 200.928
Reported total allocated memory (MB): 200.938
Reported internal fragmentation: 0.00448054%
Bits/key stored: 10.1852
Average FP rate %: 0.963387
And from db_bench (block cache) with jemalloc:
$ ./db_bench -db=/dev/shm/dbbench.no_optimize -benchmarks=fillrandom -format_version=5 -value_size=90 -bloom_bits=10 -num=2000000 -threads=8 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false
$ ./db_bench -db=/dev/shm/dbbench -benchmarks=fillrandom -format_version=5 -value_size=90 -bloom_bits=10 -num=2000000 -threads=8 -optimize_filters_for_memory -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false
$ (for FILE in /dev/shm/dbbench.no_optimize/*.sst; do ./sst_dump --file=$FILE --show_properties | grep 'filter block' ; done) | awk '{ t += $4; } END { print t; }'
17063835
$ (for FILE in /dev/shm/dbbench/*.sst; do ./sst_dump --file=$FILE --show_properties | grep 'filter block' ; done) | awk '{ t += $4; } END { print t; }'
17430747
$ #^ 2.1% additional filter storage
$ ./db_bench -db=/dev/shm/dbbench.no_optimize -use_existing_db -benchmarks=readrandom,stats -statistics -bloom_bits=10 -num=2000000 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false -duration=10 -cache_index_and_filter_blocks -cache_size=1000000000
rocksdb.block.cache.index.add COUNT : 33
rocksdb.block.cache.index.bytes.insert COUNT : 8440400
rocksdb.block.cache.filter.add COUNT : 33
rocksdb.block.cache.filter.bytes.insert COUNT : 21087528
rocksdb.bloom.filter.useful COUNT : 4963889
rocksdb.bloom.filter.full.positive COUNT : 1214081
rocksdb.bloom.filter.full.true.positive COUNT : 1161999
$ #^ 1.04 % observed FP rate
$ ./db_bench -db=/dev/shm/dbbench -use_existing_db -benchmarks=readrandom,stats -statistics -bloom_bits=10 -num=2000000 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false -optimize_filters_for_memory -duration=10 -cache_index_and_filter_blocks -cache_size=1000000000
rocksdb.block.cache.index.add COUNT : 33
rocksdb.block.cache.index.bytes.insert COUNT : 8448592
rocksdb.block.cache.filter.add COUNT : 33
rocksdb.block.cache.filter.bytes.insert COUNT : 18220328
rocksdb.bloom.filter.useful COUNT : 5360933
rocksdb.bloom.filter.full.positive COUNT : 1321315
rocksdb.bloom.filter.full.true.positive COUNT : 1262999
$ #^ 1.08 % observed FP rate, 13.6% less memory usage for filters
(Due to specific key density, this example tends to generate filters that are "worse than average" for internal fragmentation. "Better than average" cases can show little or no improvement.)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6427
Test Plan: unit test added, 'make check' with gcc, clang and valgrind
Reviewed By: siying
Differential Revision: D22124374
Pulled By: pdillinger
fbshipit-source-id: f3e3aa152f9043ddf4fae25799e76341d0d8714e
4 years ago
|
|
|
DECLARE_bool(optimize_filters_for_memory);
|
Detect (new) Bloom/Ribbon Filter construction corruption (#9342)
Summary:
Note: rebase on and merge after https://github.com/facebook/rocksdb/pull/9349, https://github.com/facebook/rocksdb/pull/9345, (optional) https://github.com/facebook/rocksdb/pull/9393
**Context:**
(Quoted from pdillinger) Layers of information during new Bloom/Ribbon Filter construction in building block-based tables includes the following:
a) set of keys to add to filter
b) set of hashes to add to filter (64-bit hash applied to each key)
c) set of Bloom indices to set in filter, with duplicates
d) set of Bloom indices to set in filter, deduplicated
e) final filter and its checksum
This PR aims to detect corruption (e.g, unexpected hardware/software corruption on data structures residing in the memory for a long time) from b) to e) and leave a) as future works for application level.
- b)'s corruption is detected by verifying the xor checksum of the hash entries calculated as the entries accumulate before being added to the filter. (i.e, `XXPH3FilterBitsBuilder::MaybeVerifyHashEntriesChecksum()`)
- c) - e)'s corruption is detected by verifying the hash entries indeed exists in the constructed filter by re-querying these hash entries in the filter (i.e, `FilterBitsBuilder::MaybePostVerify()`) after computing the block checksum (except for PartitionFilter, which is done right after each `FilterBitsBuilder::Finish` for impl simplicity - see code comment for more). For this stage of detection, we assume hash entries are not corrupted after checking on b) since the time interval from b) to c) is relatively short IMO.
Option to enable this feature of detection is `BlockBasedTableOptions::detect_filter_construct_corruption` which is false by default.
**Summary:**
- Implemented new functions `XXPH3FilterBitsBuilder::MaybeVerifyHashEntriesChecksum()` and `FilterBitsBuilder::MaybePostVerify()`
- Ensured hash entries, final filter and banding and their [cache reservation ](https://github.com/facebook/rocksdb/issues/9073) are released properly despite corruption
- See [Filter.construction.artifacts.release.point.pdf ](https://github.com/facebook/rocksdb/files/7923487/Design.Filter.construction.artifacts.release.point.pdf) for high-level design
- Bundled and refactored hash entries's related artifact in XXPH3FilterBitsBuilder into `HashEntriesInfo` for better control on lifetime of these artifact during `SwapEntires`, `ResetEntries`
- Ensured RocksDB block-based table builder calls `FilterBitsBuilder::MaybePostVerify()` after constructing the filter by `FilterBitsBuilder::Finish()`
- When encountering such filter construction corruption, stop writing the filter content to files and mark such a block-based table building non-ok by storing the corruption status in the builder.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9342
Test Plan:
- Added new unit test `DBFilterConstructionCorruptionTestWithParam.DetectCorruption`
- Included this new feature in `DBFilterConstructionReserveMemoryTestWithParam.ReserveMemory` as this feature heavily touch ReserveMemory's impl
- For fallback case, I run `./filter_bench -impl=3 -detect_filter_construct_corruption=true -reserve_table_builder_memory=true -strict_capacity_limit=true -quick -runs 10 | grep 'Build avg'` to make sure nothing break.
- Added to `filter_bench`: increased filter construction time by **30%**, mostly by `MaybePostVerify()`
- FastLocalBloom
- Before change: `./filter_bench -impl=2 -quick -runs 10 | grep 'Build avg'`: **28.86643s**
- After change:
- `./filter_bench -impl=2 -detect_filter_construct_corruption=false -quick -runs 10 | grep 'Build avg'` (expect a tiny increase due to MaybePostVerify is always called regardless): **27.6644s (-4% perf improvement might be due to now we don't drop bloom hash entry in `AddAllEntries` along iteration but in bulk later, same with the bypassing-MaybePostVerify case below)**
- `./filter_bench -impl=2 -detect_filter_construct_corruption=true -quick -runs 10 | grep 'Build avg'` (expect acceptable increase): **34.41159s (+20%)**
- `./filter_bench -impl=2 -detect_filter_construct_corruption=true -quick -runs 10 | grep 'Build avg'` (by-passing MaybePostVerify, expect minor increase): **27.13431s (-6%)**
- Standard128Ribbon
- Before change: `./filter_bench -impl=3 -quick -runs 10 | grep 'Build avg'`: **122.5384s**
- After change:
- `./filter_bench -impl=3 -detect_filter_construct_corruption=false -quick -runs 10 | grep 'Build avg'` (expect a tiny increase due to MaybePostVerify is always called regardless - verified by removing MaybePostVerify under this case and found only +-1ns difference): **124.3588s (+2%)**
- `./filter_bench -impl=3 -detect_filter_construct_corruption=true -quick -runs 10 | grep 'Build avg'`(expect acceptable increase): **159.4946s (+30%)**
- `./filter_bench -impl=3 -detect_filter_construct_corruption=true -quick -runs 10 | grep 'Build avg'`(by-passing MaybePostVerify, expect minor increase) : **125.258s (+2%)**
- Added to `db_stress`: `make crash_test`, `./db_stress --detect_filter_construct_corruption=true`
- Manually smoke-tested: manually corrupted the filter construction in some db level tests with basic PUT and background flush. As expected, the error did get returned to users in subsequent PUT and Flush status.
Reviewed By: pdillinger
Differential Revision: D33746928
Pulled By: hx235
fbshipit-source-id: cb056426be5a7debc1cd16f23bc250f36a08ca57
3 years ago
|
|
|
DECLARE_bool(detect_filter_construct_corruption);
|
|
|
|
DECLARE_int32(index_type);
|
|
|
|
DECLARE_string(db);
|
|
|
|
DECLARE_string(secondaries_base);
|
|
|
|
DECLARE_bool(test_secondary);
|
|
|
|
DECLARE_string(expected_values_dir);
|
|
|
|
DECLARE_bool(verify_checksum);
|
|
|
|
DECLARE_bool(mmap_read);
|
|
|
|
DECLARE_bool(mmap_write);
|
|
|
|
DECLARE_bool(use_direct_reads);
|
|
|
|
DECLARE_bool(use_direct_io_for_flush_and_compaction);
|
|
|
|
DECLARE_bool(mock_direct_io);
|
|
|
|
DECLARE_bool(statistics);
|
|
|
|
DECLARE_bool(sync);
|
|
|
|
DECLARE_bool(use_fsync);
|
|
|
|
DECLARE_int32(kill_random_test);
|
|
|
|
DECLARE_string(kill_exclude_prefixes);
|
|
|
|
DECLARE_bool(disable_wal);
|
|
|
|
DECLARE_uint64(recycle_log_file_num);
|
|
|
|
DECLARE_int64(target_file_size_base);
|
|
|
|
DECLARE_int32(target_file_size_multiplier);
|
|
|
|
DECLARE_uint64(max_bytes_for_level_base);
|
|
|
|
DECLARE_double(max_bytes_for_level_multiplier);
|
|
|
|
DECLARE_int32(range_deletion_width);
|
|
|
|
DECLARE_uint64(rate_limiter_bytes_per_sec);
|
|
|
|
DECLARE_bool(rate_limit_bg_reads);
|
|
|
|
DECLARE_bool(rate_limit_user_ops);
|
Rate-limit automatic WAL flush after each user write (#9607)
Summary:
**Context:**
WAL flush is currently not rate-limited by `Options::rate_limiter`. This PR is to provide rate-limiting to auto WAL flush, the one that automatically happen after each user write operation (i.e, `Options::manual_wal_flush == false`), by adding `WriteOptions::rate_limiter_options`.
Note that we are NOT rate-limiting WAL flush that do NOT automatically happen after each user write, such as `Options::manual_wal_flush == true + manual FlushWAL()` (rate-limiting multiple WAL flushes), for the benefits of:
- being consistent with [ReadOptions::rate_limiter_priority](https://github.com/facebook/rocksdb/blob/7.0.fb/include/rocksdb/options.h#L515)
- being able to turn off some WAL flush's rate-limiting but not all (e.g, turn off specific the WAL flush of a critical user write like a service's heartbeat)
`WriteOptions::rate_limiter_options` only accept `Env::IO_USER` and `Env::IO_TOTAL` currently due to an implementation constraint.
- The constraint is that we currently queue parallel writes (including WAL writes) based on FIFO policy which does not factor rate limiter priority into this layer's scheduling. If we allow lower priorities such as `Env::IO_HIGH/MID/LOW` and such writes specified with lower priorities occurs before ones specified with higher priorities (even just by a tiny bit in arrival time), the former would have blocked the latter, leading to a "priority inversion" issue and contradictory to what we promise for rate-limiting priority. Therefore we only allow `Env::IO_USER` and `Env::IO_TOTAL` right now before improving that scheduling.
A pre-requisite to this feature is to support operation-level rate limiting in `WritableFileWriter`, which is also included in this PR.
**Summary:**
- Renamed test suite `DBRateLimiterTest to DBRateLimiterOnReadTest` for adding a new test suite
- Accept `rate_limiter_priority` in `WritableFileWriter`'s private and public write functions
- Passed `WriteOptions::rate_limiter_options` to `WritableFileWriter` in the path of automatic WAL flush.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9607
Test Plan:
- Added new unit test to verify existing flush/compaction rate-limiting does not break, since `DBTest, RateLimitingTest` is disabled and current db-level rate-limiting tests focus on read only (e.g, `db_rate_limiter_test`, `DBTest2, RateLimitedCompactionReads`).
- Added new unit test `DBRateLimiterOnWriteWALTest, AutoWalFlush`
- `strace -ftt -e trace=write ./db_bench -benchmarks=fillseq -db=/dev/shm/testdb -rate_limit_auto_wal_flush=1 -rate_limiter_bytes_per_sec=15 -rate_limiter_refill_period_us=1000000 -write_buffer_size=100000000 -disable_auto_compactions=1 -num=100`
- verified that WAL flush(i.e, system-call _write_) were chunked into 15 bytes and each _write_ was roughly 1 second apart
- verified the chunking disappeared when `-rate_limit_auto_wal_flush=0`
- crash test: `python3 tools/db_crashtest.py blackbox --disable_wal=0 --rate_limit_auto_wal_flush=1 --rate_limiter_bytes_per_sec=10485760 --interval=10` killed as normal
**Benchmarked on flush/compaction to ensure no performance regression:**
- compaction with rate-limiting (see table 1, avg over 1280-run): pre-change: **915635 micros/op**; post-change:
**907350 micros/op (improved by 0.106%)**
```
#!/bin/bash
TEST_TMPDIR=/dev/shm/testdb
START=1
NUM_DATA_ENTRY=8
N=10
rm -f compact_bmk_output.txt compact_bmk_output_2.txt dont_care_output.txt
for i in $(eval echo "{$START..$NUM_DATA_ENTRY}")
do
NUM_RUN=$(($N*(2**($i-1))))
for j in $(eval echo "{$START..$NUM_RUN}")
do
./db_bench --benchmarks=fillrandom -db=$TEST_TMPDIR -disable_auto_compactions=1 -write_buffer_size=6710886 > dont_care_output.txt && ./db_bench --benchmarks=compact -use_existing_db=1 -db=$TEST_TMPDIR -level0_file_num_compaction_trigger=1 -rate_limiter_bytes_per_sec=100000000 | egrep 'compact'
done > compact_bmk_output.txt && awk -v NUM_RUN=$NUM_RUN '{sum+=$3;sum_sqrt+=$3^2}END{print sum/NUM_RUN, sqrt(sum_sqrt/NUM_RUN-(sum/NUM_RUN)^2)}' compact_bmk_output.txt >> compact_bmk_output_2.txt
done
```
- compaction w/o rate-limiting (see table 2, avg over 640-run): pre-change: **822197 micros/op**; post-change: **823148 micros/op (regressed by 0.12%)**
```
Same as above script, except that -rate_limiter_bytes_per_sec=0
```
- flush with rate-limiting (see table 3, avg over 320-run, run on the [patch](https://github.com/hx235/rocksdb/commit/ee5c6023a9f6533fab9afdc681568daa21da4953) to augment current db_bench ): pre-change: **745752 micros/op**; post-change: **745331 micros/op (regressed by 0.06 %)**
```
#!/bin/bash
TEST_TMPDIR=/dev/shm/testdb
START=1
NUM_DATA_ENTRY=8
N=10
rm -f flush_bmk_output.txt flush_bmk_output_2.txt
for i in $(eval echo "{$START..$NUM_DATA_ENTRY}")
do
NUM_RUN=$(($N*(2**($i-1))))
for j in $(eval echo "{$START..$NUM_RUN}")
do
./db_bench -db=$TEST_TMPDIR -write_buffer_size=1048576000 -num=1000000 -rate_limiter_bytes_per_sec=100000000 -benchmarks=fillseq,flush | egrep 'flush'
done > flush_bmk_output.txt && awk -v NUM_RUN=$NUM_RUN '{sum+=$3;sum_sqrt+=$3^2}END{print sum/NUM_RUN, sqrt(sum_sqrt/NUM_RUN-(sum/NUM_RUN)^2)}' flush_bmk_output.txt >> flush_bmk_output_2.txt
done
```
- flush w/o rate-limiting (see table 4, avg over 320-run, run on the [patch](https://github.com/hx235/rocksdb/commit/ee5c6023a9f6533fab9afdc681568daa21da4953) to augment current db_bench): pre-change: **487512 micros/op**, post-change: **485856 micors/ops (improved by 0.34%)**
```
Same as above script, except that -rate_limiter_bytes_per_sec=0
```
| table 1 - compact with rate-limiting|
#-run | (pre-change) avg micros/op | std micros/op | (post-change) avg micros/op | std micros/op | change in avg micros/op (%)
-- | -- | -- | -- | -- | --
10 | 896978 | 16046.9 | 901242 | 15670.9 | 0.475373978
20 | 893718 | 15813 | 886505 | 17544.7 | -0.8070778478
40 | 900426 | 23882.2 | 894958 | 15104.5 | -0.6072681153
80 | 906635 | 21761.5 | 903332 | 23948.3 | -0.3643141948
160 | 898632 | 21098.9 | 907583 | 21145 | 0.9960695813
3.20E+02 | 905252 | 22785.5 | 908106 | 25325.5 | 0.3152713278
6.40E+02 | 905213 | 23598.6 | 906741 | 21370.5 | 0.1688000504
**1.28E+03** | **908316** | **23533.1** | **907350** | **24626.8** | **-0.1063506533**
average over #-run | 901896.25 | 21064.9625 | 901977.125 | 20592.025 | 0.008967217682
| table 2 - compact w/o rate-limiting|
#-run | (pre-change) avg micros/op | std micros/op | (post-change) avg micros/op | std micros/op | change in avg micros/op (%)
-- | -- | -- | -- | -- | --
10 | 811211 | 26996.7 | 807586 | 28456.4 | -0.4468627768
20 | 815465 | 14803.7 | 814608 | 28719.7 | -0.105093413
40 | 809203 | 26187.1 | 797835 | 25492.1 | -1.404839082
80 | 822088 | 28765.3 | 822192 | 32840.4 | 0.01265071379
160 | 821719 | 36344.7 | 821664 | 29544.9 | -0.006693285661
3.20E+02 | 820921 | 27756.4 | 821403 | 28347.7 | 0.05871454135
**6.40E+02** | **822197** | **28960.6** | **823148** | **30055.1** | **0.1156657103**
average over #-run | 8.18E+05 | 2.71E+04 | 8.15E+05 | 2.91E+04 | -0.25
| table 3 - flush with rate-limiting|
#-run | (pre-change) avg micros/op | std micros/op | (post-change) avg micros/op | std micros/op | change in avg micros/op (%)
-- | -- | -- | -- | -- | --
10 | 741721 | 11770.8 | 740345 | 5949.76 | -0.1855144994
20 | 735169 | 3561.83 | 743199 | 9755.77 | 1.09226586
40 | 743368 | 8891.03 | 742102 | 8683.22 | -0.1703059588
80 | 742129 | 8148.51 | 743417 | 9631.58| 0.1735547324
160 | 749045 | 9757.21 | 746256 | 9191.86 | -0.3723407806
**3.20E+02** | **745752** | **9819.65** | **745331** | **9840.62** | **-0.0564530836**
6.40E+02 | 749006 | 11080.5 | 748173 | 10578.7 | -0.1112140624
average over #-run | 743741.4286 | 9004.218571 | 744117.5714 | 9090.215714 | 0.05057441238
| table 4 - flush w/o rate-limiting|
#-run | (pre-change) avg micros/op | std micros/op | (post-change) avg micros/op | std micros/op | change in avg micros/op (%)
-- | -- | -- | -- | -- | --
10 | 477283 | 24719.6 | 473864 | 12379 | -0.7163464863
20 | 486743 | 20175.2 | 502296 | 23931.3 | 3.195320734
40 | 482846 | 15309.2 | 489820 | 22259.5 | 1.444352858
80 | 491490 | 21883.1 | 490071 | 23085.7 | -0.2887139108
160 | 493347 | 28074.3 | 483609 | 21211.7 | -1.973864238
**3.20E+02** | **487512** | **21401.5** | **485856** | **22195.2** | **-0.3396839462**
6.40E+02 | 490307 | 25418.6 | 485435 | 22405.2 | -0.9936631539
average over #-run | 4.87E+05 | 2.24E+04 | 4.87E+05 | 2.11E+04 | 0.00E+00
Reviewed By: ajkr
Differential Revision: D34442441
Pulled By: hx235
fbshipit-source-id: 4790f13e1e5c0a95ae1d1cc93ffcf69dc6e78bdd
3 years ago
|
|
|
DECLARE_bool(rate_limit_auto_wal_flush);
|
|
|
|
DECLARE_uint64(sst_file_manager_bytes_per_sec);
|
|
|
|
DECLARE_uint64(sst_file_manager_bytes_per_truncate);
|
|
|
|
DECLARE_bool(use_txn);
|
|
|
|
DECLARE_uint64(txn_write_policy);
|
|
|
|
DECLARE_bool(unordered_write);
|
|
|
|
DECLARE_int32(backup_one_in);
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
4 years ago
|
|
|
DECLARE_uint64(backup_max_size);
|
|
|
|
DECLARE_int32(checkpoint_one_in);
|
|
|
|
DECLARE_int32(ingest_external_file_one_in);
|
|
|
|
DECLARE_int32(ingest_external_file_width);
|
|
|
|
DECLARE_int32(compact_files_one_in);
|
|
|
|
DECLARE_int32(compact_range_one_in);
|
|
|
|
DECLARE_int32(mark_for_compaction_one_file_in);
|
|
|
|
DECLARE_int32(flush_one_in);
|
|
|
|
DECLARE_int32(pause_background_one_in);
|
|
|
|
DECLARE_int32(compact_range_width);
|
|
|
|
DECLARE_int32(acquire_snapshot_one_in);
|
|
|
|
DECLARE_bool(compare_full_db_state_snapshot);
|
|
|
|
DECLARE_uint64(snapshot_hold_ops);
|
|
|
|
DECLARE_bool(long_running_snapshots);
|
|
|
|
DECLARE_bool(use_multiget);
|
|
|
|
DECLARE_int32(readpercent);
|
|
|
|
DECLARE_int32(prefixpercent);
|
|
|
|
DECLARE_int32(writepercent);
|
|
|
|
DECLARE_int32(delpercent);
|
|
|
|
DECLARE_int32(delrangepercent);
|
|
|
|
DECLARE_int32(nooverwritepercent);
|
|
|
|
DECLARE_int32(iterpercent);
|
|
|
|
DECLARE_uint64(num_iterations);
|
|
|
|
DECLARE_int32(customopspercent);
|
|
|
|
DECLARE_string(compression_type);
|
|
|
|
DECLARE_string(bottommost_compression_type);
|
|
|
|
DECLARE_int32(compression_max_dict_bytes);
|
|
|
|
DECLARE_int32(compression_zstd_max_train_bytes);
|
|
|
|
DECLARE_int32(compression_parallel_threads);
|
Limit buffering for collecting samples for compression dictionary (#7970)
Summary:
For dictionary compression, we need to collect some representative samples of the data to be compressed, which we use to either generate or train (when `CompressionOptions::zstd_max_train_bytes > 0`) a dictionary. Previously, the strategy was to buffer all the data blocks during flush, and up to the target file size during compaction. That strategy allowed us to randomly pick samples from as wide a range as possible that'd be guaranteed to land in a single output file.
However, some users try to make huge files in memory-constrained environments, where this strategy can cause OOM. This PR introduces an option, `CompressionOptions::max_dict_buffer_bytes`, that limits how much data blocks are buffered before we switch to unbuffered mode (which means creating the per-SST dictionary, writing out the buffered data, and compressing/writing new blocks as soon as they are built). It is not strict as we currently buffer more than just data blocks -- also keys are buffered. But it does make a step towards giving users predictable memory usage.
Related changes include:
- Changed sampling for dictionary compression to select unique data blocks when there is limited availability of data blocks
- Made use of `BlockBuilder::SwapAndReset()` to save an allocation+memcpy when buffering data blocks for building a dictionary
- Changed `ParseBoolean()` to accept an input containing characters after the boolean. This is necessary since, with this PR, a value for `CompressionOptions::enabled` is no longer necessarily the final component in the `CompressionOptions` string.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7970
Test Plan:
- updated `CompressionOptions` unit tests to verify limit is respected (to the extent expected in the current implementation) in various scenarios of flush/compaction to bottommost/non-bottommost level
- looked at jemalloc heap profiles right before and after switching to unbuffered mode during flush/compaction. Verified memory usage in buffering is proportional to the limit set.
Reviewed By: pdillinger
Differential Revision: D26467994
Pulled By: ajkr
fbshipit-source-id: 3da4ef9fba59974e4ef40e40c01611002c861465
4 years ago
|
|
|
DECLARE_uint64(compression_max_dict_buffer_bytes);
|
|
|
|
DECLARE_string(checksum_type);
|
|
|
|
DECLARE_string(env_uri);
|
|
|
|
DECLARE_string(fs_uri);
|
|
|
|
DECLARE_uint64(ops_per_thread);
|
|
|
|
DECLARE_uint64(log2_keys_per_lock);
|
|
|
|
DECLARE_uint64(max_manifest_file_size);
|
|
|
|
DECLARE_bool(in_place_update);
|
|
|
|
DECLARE_int32(secondary_catch_up_one_in);
|
|
|
|
DECLARE_string(memtablerep);
|
|
|
|
DECLARE_int32(prefix_size);
|
|
|
|
DECLARE_bool(use_merge);
|
|
|
|
DECLARE_bool(use_full_merge_v1);
|
|
|
|
DECLARE_int32(sync_wal_one_in);
|
|
|
|
DECLARE_bool(avoid_unnecessary_blocking_io);
|
|
|
|
DECLARE_bool(write_dbid_to_manifest);
|
|
|
|
DECLARE_bool(avoid_flush_during_recovery);
|
|
|
|
DECLARE_uint64(max_write_batch_group_size_bytes);
|
|
|
|
DECLARE_bool(level_compaction_dynamic_level_bytes);
|
|
|
|
DECLARE_int32(verify_checksum_one_in);
|
|
|
|
DECLARE_int32(verify_db_one_in);
|
|
|
|
DECLARE_int32(continuous_verification_interval);
|
|
|
|
DECLARE_int32(get_property_one_in);
|
|
|
|
DECLARE_string(file_checksum_impl);
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
// Options for StackableDB-based BlobDB
|
|
|
|
DECLARE_bool(use_blob_db);
|
|
|
|
DECLARE_uint64(blob_db_min_blob_size);
|
|
|
|
DECLARE_uint64(blob_db_bytes_per_sync);
|
|
|
|
DECLARE_uint64(blob_db_file_size);
|
|
|
|
DECLARE_bool(blob_db_enable_gc);
|
|
|
|
DECLARE_double(blob_db_gc_cutoff);
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
|
|
|
// Options for integrated BlobDB
|
|
|
|
DECLARE_bool(allow_setting_blob_options_dynamically);
|
|
|
|
DECLARE_bool(enable_blob_files);
|
|
|
|
DECLARE_uint64(min_blob_size);
|
|
|
|
DECLARE_uint64(blob_file_size);
|
|
|
|
DECLARE_string(blob_compression_type);
|
|
|
|
DECLARE_bool(enable_blob_garbage_collection);
|
|
|
|
DECLARE_double(blob_garbage_collection_age_cutoff);
|
Make it possible to force the garbage collection of the oldest blob files (#8994)
Summary:
The current BlobDB garbage collection logic works by relocating the valid
blobs from the oldest blob files as they are encountered during compaction,
and cleaning up blob files once they contain nothing but garbage. However,
with sufficiently skewed workloads, it is theoretically possible to end up in a
situation when few or no compactions get scheduled for the SST files that contain
references to the oldest blob files, which can lead to increased space amp due
to the lack of GC.
In order to efficiently handle such workloads, the patch adds a new BlobDB
configuration option called `blob_garbage_collection_force_threshold`,
which signals to BlobDB to schedule targeted compactions for the SST files
that keep alive the oldest batch of blob files if the overall ratio of garbage in
the given blob files meets the threshold *and* all the given blob files are
eligible for GC based on `blob_garbage_collection_age_cutoff`. (For example,
if the new option is set to 0.9, targeted compactions will get scheduled if the
sum of garbage bytes meets or exceeds 90% of the sum of total bytes in the
oldest blob files, assuming all affected blob files are below the age-based cutoff.)
The net result of these targeted compactions is that the valid blobs in the oldest
blob files are relocated and the oldest blob files themselves cleaned up (since
*all* SST files that rely on them get compacted away).
These targeted compactions are similar to periodic compactions in the sense
that they force certain SST files that otherwise would not get picked up to undergo
compaction and also in the sense that instead of merging files from multiple levels,
they target a single file. (Note: such compactions might still include neighboring files
from the same level due to the need of having a "clean cut" boundary but they never
include any files from any other level.)
This functionality is currently only supported with the leveled compaction style
and is inactive by default (since the default value is set to 1.0, i.e. 100%).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8994
Test Plan: Ran `make check` and tested using `db_bench` and the stress/crash tests.
Reviewed By: riversand963
Differential Revision: D31489850
Pulled By: ltamasi
fbshipit-source-id: 44057d511726a0e2a03c5d9313d7511b3f0c4eab
3 years ago
|
|
|
DECLARE_double(blob_garbage_collection_force_threshold);
|
|
|
|
DECLARE_uint64(blob_compaction_readahead_size);
|
|
|
|
|
|
|
|
DECLARE_int32(approximate_size_one_in);
|
|
|
|
DECLARE_bool(sync_fault_injection);
|
|
|
|
|
|
|
|
DECLARE_bool(best_efforts_recovery);
|
|
|
|
DECLARE_bool(skip_verifydb);
|
|
|
|
DECLARE_bool(enable_compaction_filter);
|
|
|
|
DECLARE_bool(paranoid_file_checks);
|
|
|
|
DECLARE_bool(fail_if_options_file_error);
|
Integrity protection for live updates to WriteBatch (#7748)
Summary:
This PR adds the foundation classes for key-value integrity protection and the first use case: protecting live updates from the source buffers added to `WriteBatch` through the destination buffer in `MemTable`. The width of the protection info is not yet configurable -- only eight bytes per key is supported. This PR allows users to enable protection by constructing `WriteBatch` with `protection_bytes_per_key == 8`. It does not yet expose a way for users to get integrity protection via other write APIs (e.g., `Put()`, `Merge()`, `Delete()`, etc.).
The foundation classes (`ProtectionInfo.*`) embed the coverage info in their type, and provide `Protect.*()` and `Strip.*()` functions to navigate between types with different coverage. For making bytes per key configurable (for powers of two up to eight) in the future, these classes are templated on the unsigned integer type used to store the protection info. That integer contains the XOR'd result of hashes with independent seeds for all covered fields. For integer fields, the hash is computed on the raw unadjusted bytes, so the result is endian-dependent. The most significant bytes are truncated when the hash value (8 bytes) is wider than the protection integer.
When `WriteBatch` is constructed with `protection_bytes_per_key == 8`, we hold a `ProtectionInfoKVOTC` (i.e., one that covers key, value, optype aka `ValueType`, timestamp, and CF ID) for each entry added to the batch. The protection info is generated from the original buffers passed by the user, as well as the original metadata generated internally. When writing to memtable, each entry is transformed to a `ProtectionInfoKVOTS` (i.e., dropping coverage of CF ID and adding coverage of sequence number), since at that point we know the sequence number, and have already selected a memtable corresponding to a particular CF. This protection info is verified once the entry is encoded in the `MemTable` buffer.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7748
Test Plan:
- an integration test to verify a wide variety of single-byte changes to the encoded `MemTable` buffer are caught
- add to stress/crash test to verify it works in variety of configs/operations without intentional corruption
- [deferred] unit tests for `ProtectionInfo.*` classes for edge cases like KV swap, `SliceParts` and `Slice` APIs are interchangeable, etc.
Reviewed By: pdillinger
Differential Revision: D25754492
Pulled By: ajkr
fbshipit-source-id: e481bac6c03c2ab268be41359730f1ceb9964866
4 years ago
|
|
|
DECLARE_uint64(batch_protection_bytes_per_key);
|
|
|
|
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
4 years ago
|
|
|
DECLARE_uint64(user_timestamp_size);
|
|
|
|
DECLARE_string(secondary_cache_uri);
|
|
|
|
DECLARE_int32(secondary_cache_fault_one_in);
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
4 years ago
|
|
|
|
|
|
|
DECLARE_int32(prepopulate_block_cache);
|
|
|
|
|
|
|
|
DECLARE_bool(two_write_queues);
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
DECLARE_bool(use_only_the_last_commit_time_batch_for_recovery);
|
|
|
|
DECLARE_uint64(wp_snapshot_cache_bits);
|
|
|
|
DECLARE_uint64(wp_commit_cache_bits);
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
|
|
|
DECLARE_bool(adaptive_readahead);
|
|
|
|
DECLARE_bool(async_io);
|
|
|
|
DECLARE_string(wal_compression);
|
|
|
|
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
4 years ago
|
|
|
constexpr long KB = 1024;
|
|
|
|
constexpr int kRandomValueMaxFactor = 3;
|
|
|
|
constexpr int kValueMaxLen = 100;
|
|
|
|
|
|
|
|
// wrapped posix environment
|
|
|
|
extern ROCKSDB_NAMESPACE::Env* db_stress_env;
|
|
|
|
extern ROCKSDB_NAMESPACE::Env* db_stress_listener_env;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
class FaultInjectionTestFS;
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
extern std::shared_ptr<ROCKSDB_NAMESPACE::FaultInjectionTestFS> fault_fs_guard;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern enum ROCKSDB_NAMESPACE::CompressionType compression_type_e;
|
|
|
|
extern enum ROCKSDB_NAMESPACE::CompressionType bottommost_compression_type_e;
|
|
|
|
extern enum ROCKSDB_NAMESPACE::ChecksumType checksum_type_e;
|
|
|
|
|
|
|
|
enum RepFactory { kSkipList, kHashSkipList, kVectorRep };
|
|
|
|
|
|
|
|
inline enum RepFactory StringToRepFactory(const char* ctype) {
|
|
|
|
assert(ctype);
|
|
|
|
|
|
|
|
if (!strcasecmp(ctype, "skip_list"))
|
|
|
|
return kSkipList;
|
|
|
|
else if (!strcasecmp(ctype, "prefix_hash"))
|
|
|
|
return kHashSkipList;
|
|
|
|
else if (!strcasecmp(ctype, "vector"))
|
|
|
|
return kVectorRep;
|
|
|
|
|
|
|
|
fprintf(stdout, "Cannot parse memreptable %s\n", ctype);
|
|
|
|
return kSkipList;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern enum RepFactory FLAGS_rep_factory;
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
inline enum ROCKSDB_NAMESPACE::CompressionType StringToCompressionType(
|
|
|
|
const char* ctype) {
|
|
|
|
assert(ctype);
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::CompressionType ret_compression_type;
|
|
|
|
|
|
|
|
if (!strcasecmp(ctype, "disable")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kDisableCompressionOption;
|
|
|
|
} else if (!strcasecmp(ctype, "none")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kNoCompression;
|
|
|
|
} else if (!strcasecmp(ctype, "snappy")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kSnappyCompression;
|
|
|
|
} else if (!strcasecmp(ctype, "zlib")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kZlibCompression;
|
|
|
|
} else if (!strcasecmp(ctype, "bzip2")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kBZip2Compression;
|
|
|
|
} else if (!strcasecmp(ctype, "lz4")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kLZ4Compression;
|
|
|
|
} else if (!strcasecmp(ctype, "lz4hc")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kLZ4HCCompression;
|
|
|
|
} else if (!strcasecmp(ctype, "xpress")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kXpressCompression;
|
|
|
|
} else if (!strcasecmp(ctype, "zstd")) {
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kZSTD;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Cannot parse compression type '%s'\n", ctype);
|
|
|
|
ret_compression_type =
|
|
|
|
ROCKSDB_NAMESPACE::kSnappyCompression; // default value
|
|
|
|
}
|
|
|
|
if (ret_compression_type != ROCKSDB_NAMESPACE::kDisableCompressionOption &&
|
|
|
|
!CompressionTypeSupported(ret_compression_type)) {
|
|
|
|
// Use no compression will be more portable but considering this is
|
|
|
|
// only a stress test and snappy is widely available. Use snappy here.
|
|
|
|
ret_compression_type = ROCKSDB_NAMESPACE::kSnappyCompression;
|
|
|
|
}
|
|
|
|
return ret_compression_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline enum ROCKSDB_NAMESPACE::ChecksumType StringToChecksumType(
|
|
|
|
const char* ctype) {
|
|
|
|
assert(ctype);
|
|
|
|
auto iter = ROCKSDB_NAMESPACE::checksum_type_string_map.find(ctype);
|
|
|
|
if (iter != ROCKSDB_NAMESPACE::checksum_type_string_map.end()) {
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "Cannot parse checksum type '%s'\n", ctype);
|
|
|
|
return ROCKSDB_NAMESPACE::kCRC32c;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string ChecksumTypeToString(ROCKSDB_NAMESPACE::ChecksumType ctype) {
|
|
|
|
auto iter = std::find_if(
|
|
|
|
ROCKSDB_NAMESPACE::checksum_type_string_map.begin(),
|
|
|
|
ROCKSDB_NAMESPACE::checksum_type_string_map.end(),
|
|
|
|
[&](const std::pair<std::string, ROCKSDB_NAMESPACE::ChecksumType>&
|
|
|
|
name_and_enum_val) { return name_and_enum_val.second == ctype; });
|
|
|
|
assert(iter != ROCKSDB_NAMESPACE::checksum_type_string_map.end());
|
|
|
|
return iter->first;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::vector<std::string> SplitString(std::string src) {
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
if (src.empty()) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
size_t pos = 0;
|
|
|
|
size_t pos_comma;
|
|
|
|
while ((pos_comma = src.find(',', pos)) != std::string::npos) {
|
|
|
|
ret.push_back(src.substr(pos, pos_comma - pos));
|
|
|
|
pos = pos_comma + 1;
|
|
|
|
}
|
|
|
|
ret.push_back(src.substr(pos, src.length()));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
// truncation of constant value on static_cast
|
|
|
|
#pragma warning(disable : 4309)
|
|
|
|
#endif
|
|
|
|
inline bool GetNextPrefix(const ROCKSDB_NAMESPACE::Slice& src, std::string* v) {
|
|
|
|
std::string ret = src.ToString();
|
|
|
|
for (int i = static_cast<int>(ret.size()) - 1; i >= 0; i--) {
|
|
|
|
if (ret[i] != static_cast<char>(255)) {
|
|
|
|
ret[i] = ret[i] + 1;
|
|
|
|
break;
|
|
|
|
} else if (i != 0) {
|
|
|
|
ret[i] = 0;
|
|
|
|
} else {
|
|
|
|
// all FF. No next prefix
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*v = ret;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Append `val` to `*key` in fixed-width big-endian format
|
|
|
|
extern inline void AppendIntToString(uint64_t val, std::string* key) {
|
|
|
|
// PutFixed64 uses little endian
|
|
|
|
PutFixed64(key, val);
|
|
|
|
// Reverse to get big endian
|
|
|
|
char* int_data = &((*key)[key->size() - sizeof(uint64_t)]);
|
|
|
|
for (size_t i = 0; i < sizeof(uint64_t) / 2; ++i) {
|
|
|
|
std::swap(int_data[i], int_data[sizeof(uint64_t) - 1 - i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A struct for maintaining the parameters for generating variable length keys
|
|
|
|
struct KeyGenContext {
|
|
|
|
// Number of adjacent keys in one cycle of key lengths
|
|
|
|
uint64_t window;
|
|
|
|
// Number of keys of each possible length in a given window
|
|
|
|
std::vector<uint64_t> weights;
|
|
|
|
};
|
|
|
|
extern KeyGenContext key_gen_ctx;
|
|
|
|
|
|
|
|
// Generate a variable length key string from the given int64 val. The
|
|
|
|
// order of the keys is preserved. The key could be anywhere from 8 to
|
|
|
|
// max_key_len * 8 bytes.
|
|
|
|
// The algorithm picks the length based on the
|
|
|
|
// offset of the val within a configured window and the distribution of the
|
|
|
|
// number of keys of various lengths in that window. For example, if x, y, x are
|
|
|
|
// the weights assigned to each possible key length, the keys generated would be
|
|
|
|
// - {0}...{x-1}
|
|
|
|
// {(x-1),0}..{(x-1),(y-1)},{(x-1),(y-1),0}..{(x-1),(y-1),(z-1)} and so on.
|
|
|
|
// Additionally, a trailer of 0-7 bytes could be appended.
|
|
|
|
extern inline std::string Key(int64_t val) {
|
|
|
|
uint64_t window = key_gen_ctx.window;
|
|
|
|
size_t levels = key_gen_ctx.weights.size();
|
|
|
|
std::string key;
|
|
|
|
// Over-reserve and for now do not bother `shrink_to_fit()` since the key
|
|
|
|
// strings are transient.
|
|
|
|
key.reserve(FLAGS_max_key_len * 8);
|
|
|
|
|
|
|
|
uint64_t window_idx = static_cast<uint64_t>(val) / window;
|
|
|
|
uint64_t offset = static_cast<uint64_t>(val) % window;
|
|
|
|
for (size_t level = 0; level < levels; ++level) {
|
|
|
|
uint64_t weight = key_gen_ctx.weights[level];
|
|
|
|
uint64_t pfx;
|
|
|
|
if (level == 0) {
|
|
|
|
pfx = window_idx * weight;
|
|
|
|
} else {
|
|
|
|
pfx = 0;
|
|
|
|
}
|
|
|
|
pfx += offset >= weight ? weight - 1 : offset;
|
|
|
|
AppendIntToString(pfx, &key);
|
|
|
|
if (offset < weight) {
|
|
|
|
// Use the bottom 3 bits of offset as the number of trailing 'x's in the
|
|
|
|
// key. If the next key is going to be of the next level, then skip the
|
|
|
|
// trailer as it would break ordering. If the key length is already at max,
|
|
|
|
// skip the trailer.
|
|
|
|
if (offset < weight - 1 && level < levels - 1) {
|
|
|
|
size_t trailer_len = offset & 0x7;
|
|
|
|
key.append(trailer_len, 'x');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset -= weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a string key, map it to an index into the expected values buffer
|
|
|
|
extern inline bool GetIntVal(std::string big_endian_key, uint64_t* key_p) {
|
|
|
|
size_t size_key = big_endian_key.size();
|
|
|
|
std::vector<uint64_t> prefixes;
|
|
|
|
|
|
|
|
assert(size_key <= key_gen_ctx.weights.size() * sizeof(uint64_t));
|
|
|
|
|
|
|
|
std::string little_endian_key;
|
|
|
|
little_endian_key.resize(size_key);
|
|
|
|
for (size_t start = 0; start + sizeof(uint64_t) <= size_key;
|
|
|
|
start += sizeof(uint64_t)) {
|
|
|
|
size_t end = start + sizeof(uint64_t);
|
|
|
|
for (size_t i = 0; i < sizeof(uint64_t); ++i) {
|
|
|
|
little_endian_key[start + i] = big_endian_key[end - 1 - i];
|
|
|
|
}
|
|
|
|
Slice little_endian_slice =
|
|
|
|
Slice(&little_endian_key[start], sizeof(uint64_t));
|
|
|
|
uint64_t pfx;
|
|
|
|
if (!GetFixed64(&little_endian_slice, &pfx)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
prefixes.emplace_back(pfx);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t key = 0;
|
|
|
|
for (size_t i = 0; i < prefixes.size(); ++i) {
|
|
|
|
uint64_t pfx = prefixes[i];
|
|
|
|
key += (pfx / key_gen_ctx.weights[i]) * key_gen_ctx.window +
|
|
|
|
pfx % key_gen_ctx.weights[i];
|
|
|
|
if (i < prefixes.size() - 1) {
|
|
|
|
// The encoding writes a `key_gen_ctx.weights[i] - 1` that counts for
|
|
|
|
// `key_gen_ctx.weights[i]` when there are more prefixes to come. So we
|
|
|
|
// need to add back the one here as we're at a non-last prefix.
|
|
|
|
++key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*key_p = key;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a string prefix, map it to the first corresponding index in the
|
|
|
|
// expected values buffer.
|
|
|
|
inline bool GetFirstIntValInPrefix(std::string big_endian_prefix,
|
|
|
|
uint64_t* key_p) {
|
|
|
|
size_t size_key = big_endian_prefix.size();
|
|
|
|
// Pad with zeros to make it a multiple of 8. This function may be called
|
|
|
|
// with a prefix, in which case we return the first index that falls
|
|
|
|
// inside or outside that prefix, dependeing on whether the prefix is
|
|
|
|
// the start of upper bound of a scan
|
|
|
|
unsigned int pad = sizeof(uint64_t) - (size_key % sizeof(uint64_t));
|
|
|
|
if (pad < sizeof(uint64_t)) {
|
|
|
|
big_endian_prefix.append(pad, '\0');
|
|
|
|
}
|
|
|
|
return GetIntVal(std::move(big_endian_prefix), key_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern inline uint64_t GetPrefixKeyCount(const std::string& prefix,
|
|
|
|
const std::string& ub) {
|
|
|
|
uint64_t start = 0;
|
|
|
|
uint64_t end = 0;
|
|
|
|
|
|
|
|
if (!GetFirstIntValInPrefix(prefix, &start) ||
|
|
|
|
!GetFirstIntValInPrefix(ub, &end)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return end - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern inline std::string StringToHex(const std::string& str) {
|
|
|
|
std::string result = "0x";
|
|
|
|
result.append(Slice(str).ToString(true));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unified output format for double parameters
|
|
|
|
extern inline std::string FormatDoubleParam(double param) {
|
|
|
|
return std::to_string(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that double parameter is a value we can reproduce by
|
|
|
|
// re-inputting the value printed.
|
|
|
|
extern inline void SanitizeDoubleParam(double* param) {
|
|
|
|
*param = std::atof(FormatDoubleParam(*param).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void PoolSizeChangeThread(void* v);
|
|
|
|
|
|
|
|
extern void DbVerificationThread(void* v);
|
|
|
|
|
|
|
|
extern void PrintKeyValue(int cf, uint64_t key, const char* value, size_t sz);
|
|
|
|
|
|
|
|
extern int64_t GenerateOneKey(ThreadState* thread, uint64_t iteration);
|
|
|
|
|
|
|
|
extern std::vector<int64_t> GenerateNKeys(ThreadState* thread, int num_keys,
|
|
|
|
uint64_t iteration);
|
|
|
|
|
|
|
|
extern size_t GenerateValue(uint32_t rand, char* v, size_t max_sz);
|
|
|
|
extern uint32_t GetValueBase(Slice s);
|
|
|
|
|
|
|
|
extern StressTest* CreateCfConsistencyStressTest();
|
|
|
|
extern StressTest* CreateBatchedOpsStressTest();
|
|
|
|
extern StressTest* CreateNonBatchedOpsStressTest();
|
|
|
|
extern StressTest* CreateMultiOpsTxnsStressTest();
|
|
|
|
extern void CheckAndSetOptionsForMultiOpsTxnStressTest();
|
|
|
|
extern void InitializeHotKeyGenerator(double alpha);
|
|
|
|
extern int64_t GetOneHotKeyID(double rand_seed, int64_t max_key);
|
|
|
|
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
4 years ago
|
|
|
extern std::string GenerateTimestampForRead();
|
|
|
|
extern std::string NowNanosStr();
|
|
|
|
|
|
|
|
std::shared_ptr<FileChecksumGenFactory> GetFileChecksumImpl(
|
|
|
|
const std::string& name);
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
#endif // GFLAGS
|