1. 14 1月, 2023 1 次提交
  2. 13 1月, 2023 1 次提交
  3. 12 1月, 2023 1 次提交
    • P
      Major Cache refactoring, CPU efficiency improvement (#10975) · 9f7801c5
      Peter Dillinger 提交于
      Summary:
      This is several refactorings bundled into one to avoid having to incrementally re-modify uses of Cache several times. Overall, there are breaking changes to Cache class, and it becomes more of low-level interface for implementing caches, especially block cache. New internal APIs make using Cache cleaner than before, and more insulated from block cache evolution. Hopefully, this is the last really big block cache refactoring, because of rather effectively decoupling the implementations from the uses. This change also removes the EXPERIMENTAL designation on the SecondaryCache support in Cache. It seems reasonably mature at this point but still subject to change/evolution (as I warn in the API docs for Cache).
      
      The high-level motivation for this refactoring is to minimize code duplication / compounding complexity in adding SecondaryCache support to HyperClockCache (in a later PR). Other benefits listed below.
      
      * static_cast lines of code +29 -35 (net removed 6)
      * reinterpret_cast lines of code +6 -32 (net removed 26)
      
      ## cache.h and secondary_cache.h
      * Always use CacheItemHelper with entries instead of just a Deleter. There are several motivations / justifications:
        * Simpler for implementations to deal with just one Insert and one Lookup.
        * Simpler and more efficient implementation because we don't have to track which entries are using helpers and which are using deleters
        * Gets rid of hack to classify cache entries by their deleter. Instead, the CacheItemHelper includes a CacheEntryRole. This simplifies a lot of code (cache_entry_roles.h almost eliminated). Fixes https://github.com/facebook/rocksdb/issues/9428.
        * Makes it trivial to adjust SecondaryCache behavior based on kind of block (e.g. don't re-compress filter blocks).
        * It is arguably less convenient for many direct users of Cache, but direct users of Cache are now rare with introduction of typed_cache.h (below).
        * I considered and rejected an alternative approach in which we reduce customizability by assuming each secondary cache compatible value starts with a Slice referencing the uncompressed block contents (already true or mostly true), but we apparently intend to stack secondary caches. Saving an entry from a compressed secondary to a lower tier requires custom handling offered by SaveToCallback, etc.
      * Make CreateCallback part of the helper and introduce CreateContext to work with it (alternative to https://github.com/facebook/rocksdb/issues/10562). This cleans up the interface while still allowing context to be provided for loading/parsing values into primary cache. This model works for async lookup in BlockBasedTable reader (reader owns a CreateContext) under the assumption that it always waits on secondary cache operations to finish. (Otherwise, the CreateContext could be destroyed while async operation depending on it continues.) This likely contributes most to the observed performance improvement because it saves an std::function backed by a heap allocation.
      * Use char* for serialized data, e.g. in SaveToCallback, where void* was confusingly used. (We use `char*` for serialized byte data all over RocksDB, with many advantages over `void*`. `memcpy` etc. are legacy APIs that should not be mimicked.)
      * Add a type alias Cache::ObjectPtr = void*, so that we can better indicate the intent of the void* when it is to be the object associated with a Cache entry. Related: started (but did not complete) a refactoring to move away from "value" of a cache entry toward "object" or "obj". (It is confusing to call Cache a key-value store (like DB) when it is really storing arbitrary in-memory objects, not byte strings.)
      * Remove unnecessary key param from DeleterFn. This is good for efficiency in HyperClockCache, which does not directly store the cache key in memory. (Alternative to https://github.com/facebook/rocksdb/issues/10774)
      * Add allocator to Cache DeleterFn. This is a kind of future-proofing change in case we get more serious about using the Cache allocator for memory tracked by the Cache. Right now, only the uncompressed block contents are allocated using the allocator, and a pointer to that allocator is saved as part of the cached object so that the deleter can use it. (See CacheAllocationPtr.) If in the future we are able to "flatten out" our Cache objects some more, it would be good not to have to track the allocator as part of each object.
      * Removes legacy `ApplyToAllCacheEntries` and changes `ApplyToAllEntries` signature for Deleter->CacheItemHelper change.
      
      ## typed_cache.h
      Adds various "typed" interfaces to the Cache as internal APIs, so that most uses of Cache can use simple type safe code without casting and without explicit deleters, etc. Almost all of the non-test, non-glue code uses of Cache have been migrated. (Follow-up work: CompressedSecondaryCache deserves deeper attention to migrate.) This change expands RocksDB's internal usage of metaprogramming and SFINAE (https://en.cppreference.com/w/cpp/language/sfinae).
      
      The existing usages of Cache are divided up at a high level into these new interfaces. See updated existing uses of Cache for examples of how these are used.
      * PlaceholderCacheInterface - Used for making cache reservations, with entries that have a charge but no value.
      * BasicTypedCacheInterface<TValue> - Used for primary cache storage of objects of type TValue, which can be cleaned up with std::default_delete<TValue>. The role is provided by TValue::kCacheEntryRole or given in an optional template parameter.
      * FullTypedCacheInterface<TValue, TCreateContext> - Used for secondary cache compatible storage of objects of type TValue. In addition to BasicTypedCacheInterface constraints, we require TValue::ContentSlice() to return persistable data. This simplifies usage for the normal case of simple secondary cache compatibility (can give you a Slice to the data already in memory). In addition to TCreateContext performing the role of Cache::CreateContext, it is also expected to provide a factory function for creating TValue.
      * For each of these, there's a "Shared" version (e.g. FullTypedSharedCacheInterface) that holds a shared_ptr to the Cache, rather than assuming external ownership by holding only a raw `Cache*`.
      
      These interfaces introduce specific handle types for each interface instantiation, so that it's easy to see what kind of object is controlled by a handle. (Ultimately, this might not be worth the extra complexity, but it seems OK so far.)
      
      Note: I attempted to make the cache 'charge' automatically inferred from the cache object type, such as by expecting an ApproximateMemoryUsage() function, but this is not so clean because there are cases where we need to compute the charge ahead of time and don't want to re-compute it.
      
      ## block_cache.h
      This header is essentially the replacement for the old block_like_traits.h. It includes various things to support block cache access with typed_cache.h for block-based table.
      
      ## block_based_table_reader.cc
      Before this change, accessing the block cache here was an awkward mix of static polymorphism (template TBlocklike) and switch-case on a dynamic BlockType value. This change mostly unifies on static polymorphism, relying on minor hacks in block_cache.h to distinguish variants of Block. We still check BlockType in some places (especially for stats, which could be improved in follow-up work) but at least the BlockType is a static constant from the template parameter. (No more awkward partial redundancy between static and dynamic info.) This likely contributes to the overall performance improvement, but hasn't been tested in isolation.
      
      The other key source of simplification here is a more unified system of creating block cache objects: for directly populating from primary cache and for promotion from secondary cache. Both use BlockCreateContext, for context and for factory functions.
      
      ## block_based_table_builder.cc, cache_dump_load_impl.cc
      Before this change, warming caches was super ugly code. Both of these source files had switch statements to basically transition from the dynamic BlockType world to the static TBlocklike world. None of that mess is needed anymore as there's a new, untyped WarmInCache function that handles all the details just as promotion from SecondaryCache would. (Fixes `TODO akanksha: Dedup below code` in block_based_table_builder.cc.)
      
      ## Everything else
      Mostly just updating Cache users to use new typed APIs when reasonably possible, or changed Cache APIs when not.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10975
      
      Test Plan:
      tests updated
      
      Performance test setup similar to https://github.com/facebook/rocksdb/issues/10626 (by cache size, LRUCache when not "hyper" for HyperClockCache):
      
      34MB 1thread base.hyper -> kops/s: 0.745 io_bytes/op: 2.52504e+06 miss_ratio: 0.140906 max_rss_mb: 76.4844
      34MB 1thread new.hyper -> kops/s: 0.751 io_bytes/op: 2.5123e+06 miss_ratio: 0.140161 max_rss_mb: 79.3594
      34MB 1thread base -> kops/s: 0.254 io_bytes/op: 1.36073e+07 miss_ratio: 0.918818 max_rss_mb: 45.9297
      34MB 1thread new -> kops/s: 0.252 io_bytes/op: 1.36157e+07 miss_ratio: 0.918999 max_rss_mb: 44.1523
      34MB 32thread base.hyper -> kops/s: 7.272 io_bytes/op: 2.88323e+06 miss_ratio: 0.162532 max_rss_mb: 516.602
      34MB 32thread new.hyper -> kops/s: 7.214 io_bytes/op: 2.99046e+06 miss_ratio: 0.168818 max_rss_mb: 518.293
      34MB 32thread base -> kops/s: 3.528 io_bytes/op: 1.35722e+07 miss_ratio: 0.914691 max_rss_mb: 264.926
      34MB 32thread new -> kops/s: 3.604 io_bytes/op: 1.35744e+07 miss_ratio: 0.915054 max_rss_mb: 264.488
      233MB 1thread base.hyper -> kops/s: 53.909 io_bytes/op: 2552.35 miss_ratio: 0.0440566 max_rss_mb: 241.984
      233MB 1thread new.hyper -> kops/s: 62.792 io_bytes/op: 2549.79 miss_ratio: 0.044043 max_rss_mb: 241.922
      233MB 1thread base -> kops/s: 1.197 io_bytes/op: 2.75173e+06 miss_ratio: 0.103093 max_rss_mb: 241.559
      233MB 1thread new -> kops/s: 1.199 io_bytes/op: 2.73723e+06 miss_ratio: 0.10305 max_rss_mb: 240.93
      233MB 32thread base.hyper -> kops/s: 1298.69 io_bytes/op: 2539.12 miss_ratio: 0.0440307 max_rss_mb: 371.418
      233MB 32thread new.hyper -> kops/s: 1421.35 io_bytes/op: 2538.75 miss_ratio: 0.0440307 max_rss_mb: 347.273
      233MB 32thread base -> kops/s: 9.693 io_bytes/op: 2.77304e+06 miss_ratio: 0.103745 max_rss_mb: 569.691
      233MB 32thread new -> kops/s: 9.75 io_bytes/op: 2.77559e+06 miss_ratio: 0.103798 max_rss_mb: 552.82
      1597MB 1thread base.hyper -> kops/s: 58.607 io_bytes/op: 1449.14 miss_ratio: 0.0249324 max_rss_mb: 1583.55
      1597MB 1thread new.hyper -> kops/s: 69.6 io_bytes/op: 1434.89 miss_ratio: 0.0247167 max_rss_mb: 1584.02
      1597MB 1thread base -> kops/s: 60.478 io_bytes/op: 1421.28 miss_ratio: 0.024452 max_rss_mb: 1589.45
      1597MB 1thread new -> kops/s: 63.973 io_bytes/op: 1416.07 miss_ratio: 0.0243766 max_rss_mb: 1589.24
      1597MB 32thread base.hyper -> kops/s: 1436.2 io_bytes/op: 1357.93 miss_ratio: 0.0235353 max_rss_mb: 1692.92
      1597MB 32thread new.hyper -> kops/s: 1605.03 io_bytes/op: 1358.04 miss_ratio: 0.023538 max_rss_mb: 1702.78
      1597MB 32thread base -> kops/s: 280.059 io_bytes/op: 1350.34 miss_ratio: 0.023289 max_rss_mb: 1675.36
      1597MB 32thread new -> kops/s: 283.125 io_bytes/op: 1351.05 miss_ratio: 0.0232797 max_rss_mb: 1703.83
      
      Almost uniformly improving over base revision, especially for hot paths with HyperClockCache, up to 12% higher throughput seen (1597MB, 32thread, hyper). The improvement for that is likely coming from much simplified code for providing context for secondary cache promotion (CreateCallback/CreateContext), and possibly from less branching in block_based_table_reader. And likely a small improvement from not reconstituting key for DeleterFn.
      
      Reviewed By: anand1976
      
      Differential Revision: D42417818
      
      Pulled By: pdillinger
      
      fbshipit-source-id: f86bfdd584dce27c028b151ba56818ad14f7a432
      9f7801c5
  4. 06 1月, 2023 1 次提交
  5. 05 1月, 2023 2 次提交
  6. 04 1月, 2023 1 次提交
    • H
      Add back Options::CompactionOptionsFIFO::allow_compaction to stress/crash test (#11063) · b965a5a8
      Hui Xiao 提交于
      Summary:
      **Context/Summary:**
      https://github.com/facebook/rocksdb/pull/10777 was reverted (https://github.com/facebook/rocksdb/pull/10999) due to internal blocker and replaced with a better fix https://github.com/facebook/rocksdb/pull/10922. However, the revert also reverted the `Options::CompactionOptionsFIFO::allow_compaction` stress/crash coverage added by the PR.
      
      It's an useful coverage cuz setting `Options::CompactionOptionsFIFO::allow_compaction=true` will [increase](https://github.com/facebook/rocksdb/blob/7.8.fb/db/version_set.cc#L3255) the compaction score of L0 files for FIFO and then trigger more FIFO compaction. This speed up discovery of bug related to FIFO compaction like https://github.com/facebook/rocksdb/pull/10955. To see the speedup, compare the failure occurrence in following commands with `Options::CompactionOptionsFIFO::allow_compaction=true/false`
      
      ```
      --fifo_allow_compaction=1 --acquire_snapshot_one_in=10000 --adaptive_readahead=0 --allow_concurrent_memtable_write=0 --allow_data_in_errors=True --async_io=1 --avoid_flush_during_recovery=0 --avoid_unnecessary_blocking_io=1 --backup_max_size=104857600 --backup_one_in=100000 --batch_protection_bytes_per_key=0 --block_size=16384 --bloom_bits=8.869062094789008 --bottommost_compression_type=none --bytes_per_sync=0 --cache_index_and_filter_blocks=1 --cache_size=8388608 --cache_type=lru_cache --charge_compression_dictionary_building_buffer=1 --charge_file_metadata=1 --charge_filter_construction=0 --charge_table_reader=1 --checkpoint_one_in=1000000 --checksum_type=kxxHash --clear_column_family_one_in=0 --column_families=1 --compact_files_one_in=1000000 --compact_range_one_in=1000000 --compaction_pri=3 --compaction_style=2 --compaction_ttl=0 --compression_max_dict_buffer_bytes=8589934591 --compression_max_dict_bytes=16384 --compression_parallel_threads=1 --compression_type=xpress --compression_use_zstd_dict_trainer=1 --compression_zstd_max_train_bytes=0 --continuous_verification_interval=0 --data_block_index_type=0 --db=/dev/shm/rocksdb_test/rocksdb_crashtest_whitebox --db_write_buffer_size=1048576 --delpercent=4 --delrangepercent=1 --destroy_db_initially=1 --detect_filter_construct_corruption=0 --disable_wal=0 --enable_compaction_filter=0 --enable_pipelined_write=1 --expected_values_dir=/dev/shm/rocksdb_test/rocksdb_crashtest_expected --fail_if_options_file_error=1 --file_checksum_impl=xxh64 --flush_one_in=1000000 --format_version=4 --get_current_wal_file_one_in=0 --get_live_files_one_in=1000000 --get_property_one_in=1000000 --get_sorted_wal_files_one_in=0 --index_block_restart_interval=10 --index_type=2 --ingest_external_file_one_in=100 --initial_auto_readahead_size=16384 --iterpercent=10 --key_len_percent_dist=1,30,69 --level_compaction_dynamic_level_bytes=False --log2_keys_per_lock=10 --long_running_snapshots=0 --manual_wal_flush_one_in=0 --mark_for_compaction_one_file_in=10 --max_auto_readahead_size=524288 --max_background_compactions=1 --max_bytes_for_level_base=67108864 --max_key=25000000 --max_key_len=3 --max_manifest_file_size=1073741824 --max_write_batch_group_size_bytes=1048576 --max_write_buffer_number=3 --max_write_buffer_size_to_maintain=0 --memtable_prefix_bloom_size_ratio=0.01 --memtable_protection_bytes_per_key=1 --memtable_whole_key_filtering=1 --memtablerep=skip_list --min_write_buffer_number_to_merge=2 --mmap_read=0 --mock_direct_io=True --nooverwritepercent=1 --num_file_reads_for_auto_readahead=2 --open_files=-1 --open_metadata_write_fault_one_in=0 --open_read_fault_one_in=0 --open_write_fault_one_in=0 --ops_per_thread=40000 --optimize_filters_for_memory=0 --paranoid_file_checks=1 --partition_filters=0 --partition_pinning=3 --pause_background_one_in=1000000 --periodic_compaction_seconds=0 --prefix_size=7 --prefixpercent=5 --prepopulate_block_cache=0 --preserve_internal_time_seconds=3600 --progress_reports=0 --read_fault_one_in=1000 --readahead_size=0 --readpercent=15 --recycle_log_file_num=1 --reopen=0 --ribbon_starting_level=999 --secondary_cache_fault_one_in=0  --snapshot_hold_ops=100000 --sst_file_manager_bytes_per_sec=0 --sst_file_manager_bytes_per_truncate=0 --stats_dump_period_sec=0 --subcompactions=2 --sync=0 --sync_fault_injection=0 --target_file_size_base=16777216 --target_file_size_multiplier=1 --test_batches_snapshots=0 --top_level_index_pinning=1 --unpartitioned_pinning=1 --use_direct_io_for_flush_and_compaction=1 --use_direct_reads=1 --use_full_merge_v1=1 --use_merge=0 --use_multiget=0 --use_put_entity_one_in=0 --user_timestamp_size=0 --value_size_mult=32 --verify_checksum=1 --verify_checksum_one_in=1000000 --verify_db_one_in=100000 --verify_iterator_with_expected_state_one_in=5 --verify_sst_unique_id_in_manifest=1 --wal_bytes_per_sync=0 --wal_compression=none --write_buffer_size=33554432 --write_dbid_to_manifest=1 --writepercent=65
      ```
      
      Therefore this PR is adding it back to stress/crash test.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11063
      
      Test Plan: Rehearsal stress test to make sure stress/crash test is stable
      
      Reviewed By: ajkr
      
      Differential Revision: D42283650
      
      Pulled By: hx235
      
      fbshipit-source-id: 132e6396ab6e24d8dcb8fe51c62dd5211cdf53ef
      b965a5a8
  7. 01 1月, 2023 1 次提交
    • C
      Fix BackupEngineTest.ExcludeFiles memory leak (#11066) · f24ef5d6
      Changyu Bi 提交于
      Summary:
      Valgrind was complaining about the test BackupEngineTest.ExcludeFiles. The cause is backup_engine not being freed similar to https://github.com/facebook/rocksdb/issues/9610.
      ```
      ==18228== Command: ./backup_engine_test --gtest_filter=BackupEngineTest.ExcludeFiles
      ==18228==
      Note: Google Test filter = BackupEngineTest.ExcludeFiles
      [==========] Running 1 test from 1 test case.
      [----------] Global test environment set-up.
      [----------] 1 test from BackupEngineTest
      [ RUN      ] BackupEngineTest.ExcludeFiles
      [       OK ] BackupEngineTest.ExcludeFiles (16264 ms)
      [----------] 1 test from BackupEngineTest (16273 ms total)
      
      [----------] Global test environment tear-down
      [==========] 1 test from 1 test case ran. (16306 ms total)
      [  PASSED  ] 1 test.
      ==18228==
      ==18228== HEAP SUMMARY:
      ==18228==     in use at exit: 14,099 bytes in 159 blocks
      ==18228==   total heap usage: 255,328 allocs, 255,169 frees, 497,538,546 bytes allocated
      ==18228==
      ==18228== 19 bytes in 1 blocks are possibly lost in loss record 4 of 67
      ==18228==    at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==18228==    by 0x1E752D: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) [clone .constprop.0] (basic_string.tcc:219)
      ==18228==    by 0x1F1898: _M_construct_aux<char*> (basic_string.h:251)
      ==18228==    by 0x1F1898: _M_construct<char*> (basic_string.h:270)
      ==18228==    by 0x1F1898: basic_string (basic_string.h:455)
      ==18228==    by 0x1F1898: construct<std::__cxx11::basic_string<char>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&> (new_allocator.h:146)
      ==18228==    by 0x1F1898: construct<std::__cxx11::basic_string<char>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&> (alloc_traits.h:483)
      ==18228==    by 0x1F1898: push_back (stl_vector.h:1189)
      ==18228==    by 0x1F1898: rocksdb::(anonymous namespace)::TestFs::NewWritableFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rocksdb::FileOptions const&, std::unique_ptr<rocksdb::FSWritableFile, std::default_delete<rocksdb::FSWritableFile> >*, rocksdb::IODebugContext*) (backup_engine_test.cc:208)
      ==18228==    by 0x4B3583: rocksdb::NewWritableFile(rocksdb::FileSystem*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<rocksdb::FSWritableFile, std::default_delete<rocksdb::FSWritableFile> >*, rocksdb::FileOptions const&) (read_write_util.cc:23)
      ==18228==    by 0x31C3A8: rocksdb::DBImpl::CreateWAL(unsigned long, unsigned long, unsigned long, rocksdb::log::Writer**) (db_impl_open.cc:1752)
      ==18228==    by 0x321A8C: rocksdb::DBImpl::Open(rocksdb::DBOptions const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<rocksdb::ColumnFamilyDescriptor, std::allocator<rocksdb::ColumnFamilyDescriptor> > const&, std::vector<rocksdb::ColumnFamilyHandle*, std::allocator<rocksdb::ColumnFamilyHandle*> >*, rocksdb::DB**, bool, bool) (db_impl_open.cc:1852)
      ==18228==    by 0x322E7F: Open (db_impl_open.cc:1660)
      ==18228==    by 0x322E7F: rocksdb::DB::Open(rocksdb::Options const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rocksdb::DB**) (db_impl_open.cc:1637)
      ==18228==    by 0x1EE1CD: InitializeDBAndBackupEngine (backup_engine_test.cc:724)
      ==18228==    by 0x1EE1CD: rocksdb::(anonymous namespace)::BackupEngineTest::OpenDBAndBackupEngine(bool, bool, rocksdb::(anonymous namespace)::BackupEngineTest::ShareOption) (backup_engine_test.cc:732)
      ==18228==    by 0x217585: rocksdb::(anonymous namespace)::BackupEngineTest_ExcludeFiles_Test::TestBody() (backup_engine_test.cc:4232)
      ==18228==    by 0x296143: HandleSehExceptionsInMethodIfSupported<testing::Test, void> (gtest-all.cc:3899)
      ==18228==    by 0x296143: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest-all.cc:3935)
      ==18228==    by 0x28A0A5: testing::Test::Run() [clone .part.0] (gtest-all.cc:3973)
      ==18228==    by 0x28A364: Run (gtest-all.cc:3965)
      ==18228==    by 0x28A364: testing::TestInfo::Run() [clone .part.0] (gtest-all.cc:4149)
      ...
      ```
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11066
      
      Test Plan: make -j24 J=24 ROCKSDBTESTS_SUBSET=backup_engine_test valgrind_check_some
      
      Reviewed By: ajkr
      
      Differential Revision: D42297791
      
      Pulled By: cbi42
      
      fbshipit-source-id: db67982b27b91cc78e1a9f4a96da0cba7c9785b7
      f24ef5d6
  8. 31 12月, 2022 3 次提交
  9. 30 12月, 2022 3 次提交
    • H
      Add missing range conflict check between file ingestion and RefitLevel() (#10988) · 9502856e
      Hui Xiao 提交于
      Summary:
      **Context:**
      File ingestion never checks whether the key range it acts on overlaps with an ongoing RefitLevel() (used in `CompactRange()` with `change_level=true`). That's because RefitLevel() doesn't register and make its key range known to file ingestion. Though it checks overlapping with other compactions by https://github.com/facebook/rocksdb/blob/7.8.fb/db/external_sst_file_ingestion_job.cc#L998.
      
      RefitLevel() (used in `CompactRange()` with `change_level=true`) doesn't check whether the key range it acts on overlaps with an ongoing file ingestion. That's because file ingestion does not register and make its key range known to other compactions.
      - Note that non-refitlevel-compaction (e.g, manual compaction w/o RefitLevel() or general compaction) also does not check key range overlap with ongoing file ingestion for the same reason.
      - But it's fine. Credited to cbi42's discovery, `WaitForIngestFile` was called by background and foreground compactions. They were introduced in https://github.com/facebook/rocksdb/commit/0f88160f67d36ea30e3aca3a3cef924c3a009be6, https://github.com/facebook/rocksdb/commit/5c64fb67d2fc198f1a73ff3ae543749a6a41f513 and https://github.com/facebook/rocksdb/commit/87dfc1d23e0e16ff73e15f63c6fa0fb3b3fc8c8c.
      - Regardless, this PR registers file ingestion like a compaction is a general approach that will also add range conflict check between file ingestion and non-refitlevel-compaction, though it has not been the issue motivated this PR.
      
      Above are bugs resulting in two bad consequences:
      - If file ingestion and RefitLevel() creates files in the same level, then range-overlapped files will be created at that level and caught as corruption by `force_consistency_checks=true`
      - If file ingestion and RefitLevel() creates file in different levels, then with one further compaction on the ingested file, it can result in two same keys both with seqno 0 in two different levels. Then with iterator's [optimization](https://github.com/facebook/rocksdb/blame/c62f3221698fd273b673d4f7e54eabb8329a4369/db/db_iter.cc#L342-L343) that assumes no two same keys both with seqno 0, it will either break this assertion in debug build or, even worst, return value of this same key for the key after it, which is the wrong value to return, in release build.
      
      Therefore we decide to introduce range conflict check for file ingestion and RefitLevel() inspired from the existing range conflict check among compactions.
      
      **Summary:**
      - Treat file ingestion job and RefitLevel() as `Compaction` of new compaction reasons: `CompactionReason::kExternalSstIngestion` and `CompactionReason::kRefitLevel` and register/unregister them.  File ingestion is treated as compaction from L0 to different levels and RefitLevel() as compaction from source level to target level.
      - Check for `RangeOverlapWithCompaction` with other ongoing compactions, `RegisterCompaction()` on this "compaction" before changing the LSM state in `VersionStorageInfo`, and `UnregisterCompaction()` after changing.
      - Replace scattered fixes (https://github.com/facebook/rocksdb/commit/0f88160f67d36ea30e3aca3a3cef924c3a009be6, https://github.com/facebook/rocksdb/commit/5c64fb67d2fc198f1a73ff3ae543749a6a41f513 and https://github.com/facebook/rocksdb/commit/87dfc1d23e0e16ff73e15f63c6fa0fb3b3fc8c8c.) that prevents overlapping between file ingestion and non-refit-level compaction with this fix cuz those practices are easy to overlook.
      - Misc: logic cleanup, see PR comments
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10988
      
      Test Plan:
      - New unit test `DBCompactionTestWithOngoingFileIngestionParam*` that failed pre-fix and passed afterwards.
      - Made compatible with existing tests, see PR comments
      - make check
      - [Ongoing] Stress test rehearsal with normal value and aggressive CI value https://github.com/facebook/rocksdb/pull/10761
      
      Reviewed By: cbi42
      
      Differential Revision: D41535685
      
      Pulled By: hx235
      
      fbshipit-source-id: 549833a577ba1496d20a870583d4caa737da1258
      9502856e
    • C
      Include estimated bytes deleted by range tombstones in compensated file size (#10734) · cc6f3237
      Changyu Bi 提交于
      Summary:
      compensate file sizes in compaction picking so files with range tombstones are preferred, such that they get compacted down earlier as they tend to delete a lot of data. This PR adds a `compensated_range_deletion_size` field in FileMeta that is computed during Flush/Compaction and persisted in MANIFEST. This value is added to `compensated_file_size` which will be used for compaction picking. Currently, for a file in level L, `compensated_range_deletion_size` is set to the estimated bytes deleted by range tombstone of this file in all levels > L. This helps to reduce space amp when data in older levels are covered by range tombstones in level L.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10734
      
      Test Plan:
      - Added unit tests.
      - benchmark to check if the above definition `compensated_range_deletion_size` is reducing space amp as intended, without affecting write amp too much. The experiment set up favorable for this optimization: large range tombstone issued infrequently. Command used:
      ```
      ./db_bench -benchmarks=fillrandom,waitforcompaction,stats,levelstats -use_existing_db=false -avoid_flush_during_recovery=true -write_buffer_size=33554432 -level_compaction_dynamic_level_bytes=true -max_background_jobs=8 -max_bytes_for_level_base=134217728 -target_file_size_base=33554432 -writes_per_range_tombstone=500000 -range_tombstone_width=5000000 -num=50000000 -benchmark_write_rate_limit=8388608 -threads=16 -duration=1800 --max_num_range_tombstones=1000000000
      ```
      
      In this experiment, each thread wrote 16 range tombstones over the duration of 30 minutes, each range tombstone has width 5M that is the 10% of the key space width. Results shows this PR generates a smaller DB size.
      
      Compaction stats from this PR:
      ```
      Level    Files   Size     Score Read(GB)  Rn(GB) Rnp1(GB) Write(GB) Wnew(GB) Moved(GB) W-Amp Rd(MB/s) Wr(MB/s) Comp(sec) CompMergeCPU(sec) Comp(cnt) Avg(sec) KeyIn KeyDrop Rblob(GB) Wblob(GB)
      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        L0      2/0   31.54 MB   0.5      0.0     0.0      0.0       8.4      8.4       0.0   1.0      0.0     63.4    135.56            110.94       544    0.249       0      0       0.0       0.0
        L4      3/0   96.55 MB   0.8     18.5     6.7     11.8      18.4      6.6       0.0   2.7     65.3     64.9    290.08            284.03       108    2.686    284M  1957K       0.0       0.0
        L5     15/0   404.41 MB   1.0     19.1     7.7     11.4      18.8      7.4       0.3   2.5     66.6     65.7    292.93            285.34       220    1.332    293M  3808K       0.0       0.0
        L6    143/0    4.12 GB   0.0     45.0     7.5     37.5      41.6      4.1       0.0   5.5     71.2     65.9    647.00            632.66       251    2.578    739M    47M       0.0       0.0
       Sum    163/0    4.64 GB   0.0     82.6    21.9     60.7      87.2     26.5       0.3  10.4     61.9     65.4   1365.58           1312.97      1123    1.216   1318M    52M       0.0       0.0
      ```
      
      Compaction stats from main:
      ```
      Level    Files   Size     Score Read(GB)  Rn(GB) Rnp1(GB) Write(GB) Wnew(GB) Moved(GB) W-Amp Rd(MB/s) Wr(MB/s) Comp(sec) CompMergeCPU(sec) Comp(cnt) Avg(sec) KeyIn KeyDrop Rblob(GB) Wblob(GB)
      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        L0      0/0    0.00 KB   0.0      0.0     0.0      0.0       8.4      8.4       0.0   1.0      0.0     60.5    142.12            115.89       569    0.250       0      0       0.0       0.0
        L4      3/0   85.68 MB   1.0     17.7     6.8     10.9      17.6      6.7       0.0   2.6     62.7     62.3    289.05            281.79       112    2.581    272M  2309K       0.0       0.0
        L5     11/0   293.73 MB   1.0     18.8     7.5     11.2      18.5      7.2       0.5   2.5     64.9     63.9    296.07            288.50       220    1.346    288M  4365K       0.0       0.0
        L6    130/0    3.94 GB   0.0     51.5     7.6     43.9      47.9      3.9       0.0   6.3     67.2     62.4    784.95            765.92       258    3.042    848M    51M       0.0       0.0
       Sum    144/0    4.31 GB   0.0     88.0    21.9     66.0      92.3     26.3       0.5  11.0     59.6     62.5   1512.19           1452.09      1159    1.305   1409M    58M       0.0       0.0```
      
      Reviewed By: ajkr
      
      Differential Revision: D39834713
      
      Pulled By: cbi42
      
      fbshipit-source-id: fe9341040b8704a8fbb10cad5cf5c43e962c7e6b
      cc6f3237
    • P
      Add BackupEngine feature to exclude files (#11030) · 02f2b208
      Peter Dillinger 提交于
      Summary:
      We have a request for RocksDB to essentially support
      disconnected incremental backup. In other words, if there is limited
      or no connectivity to the primary backup dir, we should still be able to
      take an incremental backup relative to that primary backup dir,
      assuming some metadata about that primary dir is available (and
      obviously anticipating primary backup dir will be fully available if
      restore is needed).
      
      To support that, this feature allows the API user to "exclude" DB
      files from backup. This only applies to files that can be shared
      between backups (sst and blob files), and excluded files are
      tracked in the backup metadata sufficiently to ensure they are
      restored at restore time. At restore time, the user provides
      a set of alternate backup directories (as open BackupEngines, which
      can be read-only), and excluded files must be found in one of the
      backup directories ("included" in some backup).
      
      This feature depends on backup schema version 2 features, though
      schema version 2.0 support is not sufficient to read / restore a
      backup with exclusions. This change updates the schema version to
      2.1 because of this feature, so that it's easy to recognize whether
      a RocksDB release supports this feature, while backups not using the
      feature are fully compatible with 2.0.
      
      Also in this PR:
      * Stacked on https://github.com/facebook/rocksdb/pull/11029
      * Allow progress_callback to be empty, not just no-op function, and
      recover from exceptions thrown by BackupEngine callbacks.
      * The internal-only `AsBackupEngine()` function is working around the
      diamond hierarchy of `BackupEngineImplThreadSafe` to get to the
      internals, without using confusing features like virtual inheritance.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11030
      
      Test Plan: unit tests added / updated
      
      Reviewed By: ajkr
      
      Differential Revision: D42004388
      
      Pulled By: pdillinger
      
      fbshipit-source-id: 31b6e533d308a5462e528d9012d650482d974077
      02f2b208
  10. 22 12月, 2022 4 次提交
    • A
      Avoid mixing sync and async prefetch (#11050) · bec42648
      anand76 提交于
      Summary:
      Reading uncompression dict block always uses sync reads, while data blocks may use async reads and prefetching. This causes problems in FilePrefetchBuffer. So avoid mixing the two by reading the uncompression dict straight from the file.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11050
      
      Test Plan: Crash test
      
      Reviewed By: akankshamahajan15
      
      Differential Revision: D42194682
      
      Pulled By: anand1976
      
      fbshipit-source-id: aaa8b396fdfe966b157e210f5ef8501c45b7b69e
      bec42648
    • P
      Make CompactRange() more aware of SstPartitionerFactory (#11032) · e6b6e741
      Peter Dillinger 提交于
      Summary:
      Some users are at least considering using SstPartitioner to support efficient physical migration of specific key ranges between RocksDB instances. One might expect manual `CompactRange()` over a narrow key range across some partition to enforce partitioning of any SST files crossing that partition boundary, but that currently only works if there are keys within that range.
      
      This change makes the overlap logic in CompactRange more aware of the partitioner to automatically select relevant files crossing a partition boundary, even when they otherwise would not be selected due to the compaction range falling in a gap between entries.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11032
      
      Test Plan: unit test included
      
      Reviewed By: hx235
      
      Differential Revision: D41981380
      
      Pulled By: pdillinger
      
      fbshipit-source-id: 2fe445bdddc73c00276c20f295cc1fa33d15b05a
      e6b6e741
    • A
      Improve Java API get() performance by reducing copies (#10970) · f8969ad7
      Alan Paxton 提交于
      Summary:
      Performance improvements for `get()` paths in the RocksJava API (JNI).
      Document describing the performance results.
      
      Replace uses of the legacy `DB::Get()` method wrapper returning data in a `std::string` with direct calls to `DB::Get()` passing a pinnable slice to receive this data. Copying from a pinned slice direct to the destination java byte array, without going via an intervening std::string, is a major performance gain for this code path.
      
      Note that this gain only comes where `DB::Get()` is able to return a pinned buffer; where it has to copy into the buffer owned by the slice, there is still the intervening copy and no performance gain. It may be possible to address this case too, but it is not trivial.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10970
      
      Reviewed By: pdillinger
      
      Differential Revision: D42125567
      
      Pulled By: ajkr
      
      fbshipit-source-id: b7a4df7523b0420cadb1e9b6c7da3ec030a8da34
      f8969ad7
    • A
      Fix async prefetch heap use after free (#11049) · dbf37c29
      anand76 提交于
      Summary:
      This PR fixes a heap use after free bug in the async prefetch code that happens in the following scenario -
      1. Scan thread starts 2 async reads for Seek, one for the seek block and one for prefetching
      2. Before the first read in https://github.com/facebook/rocksdb/issues/1 completes, another thread reads and loads the block in cache
      3. The first scan thread finds the block in cache, continues and the next block cache miss is for a block that spans the boundary of the 2 prefetch buffers, and the 1st read is complete but the 2nd one is not complete yet
      4. The scan thread will reallocate (i.e free the old buffer and allocate a new one) the 2nd prefetch buffer, and the in-progress prefetch is orphaned
      5. The orphaned prefetch finally completes, resulting in a use after free
      
      Also add a few asserts to surface bugs earlier in the crash tests.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11049
      
      Test Plan: Repro with db_stress and verify the fix
      
      Reviewed By: akankshamahajan15
      
      Differential Revision: D42181118
      
      Pulled By: anand1976
      
      fbshipit-source-id: 1ac55d2f64a89ce128c1c574262b8aa7d82eb8cc
      dbf37c29
  11. 20 12月, 2022 3 次提交
  12. 16 12月, 2022 2 次提交
    • A
      Enable ReadAsync testing and fault injection in db_stress (#11037) · c3f720c6
      anand76 提交于
      Summary:
      The db_stress code uses a wrapper Env on top of the raw/fault injection Env. The wrapper, DbStressEnvWrapper, is a legacy Env and thus has a default implementation of ReadAsync that just does a sync read. As a result, the ReadAsync implementations of PosixFileSystem and other file systems weren't being tested. Also, the ReadAsync interface wasn't implemented in FaultInjectionTestFS. This change implements the necessary interfaces in FaultInjectionTestFS and derives DbStressEnvWrapper from FileSystemWrapper rather than EnvWrapper.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11037
      
      Test Plan: Run db_stress standalone and crash test. With this change, db_stress is able to repro the bug fixed in https://github.com/facebook/rocksdb/issues/10890.
      
      Reviewed By: akankshamahajan15
      
      Differential Revision: D42061290
      
      Pulled By: anand1976
      
      fbshipit-source-id: 7f0331fd15ee33fb4f7f0f4b22b206fe801ba074
      c3f720c6
    • C
      Consider range tombstone in compaction output file cutting (#10802) · f02c708a
      Changyu Bi 提交于
      Summary:
      This PR is the first step for Issue https://github.com/facebook/rocksdb/issues/4811. Currently compaction output files are cut at point keys, and the decision is made mainly in `CompactionOutputs::ShouldStopBefore()`. This makes it possible for range tombstones to cause large compactions that does not respect `max_compaction_bytes`. For example, we can have a large range tombstone that overlaps with too many files from the next level. Another example is when there is a gap between a range tombstone and another key. The first issue may be more acceptable, as a lot of data is deleted. This PR address the second issue by calling `ShouldStopBefore()` for range tombstone start keys. The main change is for `CompactionIterator` to emit range tombstone start keys to be processed by `CompactionOutputs`. A new `CompactionMergingIterator` is introduced and only used under `CompactionIterator` for this purpose. Further improvement after this PR include 1) cut compaction output at some grandparent boundary key instead of at the next point key or range tombstone start key and 2) cut compaction output file within a large range tombstone (it may be easier and reasonable to only do it for range tombstones at the end of a compaction output).
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10802
      
      Test Plan:
      - added unit tests in db_range_del_test.
      - stress test: `python3 tools/db_crashtest.py whitebox --[simple|enable_ts] --verify_iterator_with_expected_state_one_in=5 --delrangepercent=5 --prefixpercent=2 --writepercent=58 --readpercen=21 --duration=36000 --range_deletion_width=1000000`
      
      Reviewed By: ajkr, jay-zhuang
      
      Differential Revision: D40308827
      
      Pulled By: cbi42
      
      fbshipit-source-id: a8fd6f70a3f09d0ef7a40e006f6c964bba8c00df
      f02c708a
  13. 15 12月, 2022 2 次提交
    • S
      ~SleepingBackgroundTask() to wake up the sleeping task (#11036) · 1928902a
      sdong 提交于
      Summary:
      Right now, in unit tests, when background tests are sleeping using SleepingBackgroundTask, and the test exits with test assertion failure, the process will hang and it might prevent us to see the test failure message in CI runs. Try to wake up the thread so that the test can exit correctly.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11036
      
      Test Plan: Watch CI succeeds
      
      Reviewed By: riversand963
      
      Differential Revision: D42020489
      
      fbshipit-source-id: 5b8441b18d5f67bbb3ade59a1225a8d3c860c2eb
      1928902a
    • A
      JNI native memory leak - release array elements (#10981) · 6a8920f9
      Alan Paxton 提交于
      Summary:
      Closes https://github.com/facebook/rocksdb/issues/10980
      
      Reproduced as per the suggestion in the ticket, and `$ jcmd <PID> VM.native_memory | grep Internal` reports that we are no longer leaking internal memory with the suggested fix.
      
      I did the repro in `MultiGetTest.java` which I have optimized imports on. It did not seem helpful to leave the test code around as it would be onerous to build a memory leak reproducer, and regression seems a remote possibility.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10981
      
      Reviewed By: riversand963
      
      Differential Revision: D41498748
      
      Pulled By: ajkr
      
      fbshipit-source-id: 8c6dd0d608172879c8bda479c7c9c05c12d34e70
      6a8920f9
  14. 14 12月, 2022 3 次提交
    • Y
      Revise LockWAL/UnlockWAL implementation (#11020) · c93ba7db
      Yanqin Jin 提交于
      Summary:
      RocksDB has two public APIs: `DB::LockWAL()`/`DB::UnlockWAL()`. The current implementation acquires and
      releases the internal `DBImpl::log_write_mutex_`.
      
      According to the comment on `DBImpl::log_write_mutex_`: https://github.com/facebook/rocksdb/blob/7.8.fb/db/db_impl/db_impl.h#L2287:L2288
      > Note: to avoid dealock, if needed to acquire both log_write_mutex_ and mutex_, the order should be first mutex_ and then log_write_mutex_.
      
      This puts limitations on how applications can use the `LockWAL()` API. After `LockWAL()` returns ok, then application
      should not perform any operation that acquires `mutex_`. Currently, the use case of `LockWAL()` is MyRocks implementing
      the MySQL storage engine handlerton `lock_hton_log` interface. The operation that MyRocks performs after `LockWAL()`
      is `GetSortedWalFiless()` which not only acquires mutex_, but also `log_write_mutex_`.
      
      There are two issues:
      1. Applications using these two APIs may hang if one thread calls `GetSortedWalFiles()` after
      calling `LockWAL()` because log_write_mutex is not recursive.
      2. Two threads may dead lock due to lock order inversion.
      
      To fix these issues, we can modify the implementation of LockWAL so that it does not keep
      `log_write_mutex_` held until UnlockWAL. To achieve the goal of locking the WAL, we can
      instead manually inject a write stall so that all future writes will be stopped.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11020
      
      Test Plan: make check
      
      Reviewed By: ajkr
      
      Differential Revision: D41785203
      
      Pulled By: riversand963
      
      fbshipit-source-id: 5ccb7a9c6eb9a2c3fa80fd2c399cc2568b8f89ce
      c93ba7db
    • H
      Sort L0 files by newly introduced epoch_num (#10922) · 98d5db5c
      Hui Xiao 提交于
      Summary:
      **Context:**
      Sorting L0 files by `largest_seqno` has at least two inconvenience:
      -  File ingestion and compaction involving ingested files can create files of overlapping seqno range with the existing files. `force_consistency_check=true` will catch such overlap seqno range even those harmless overlap.
          - For example, consider the following sequence of events ("key@n" indicates key at seqno "n")
             - insert k1@1 to memtable m1
             - ingest file s1 with k2@2, ingest file s2 with k3@3
              - insert k4@4 to m1
             - compact files s1, s2 and  result in new file s3 of seqno range [2, 3]
             - flush m1 and result in new file s4 of seqno range [1, 4]. And `force_consistency_check=true` will think s4 and s3 has file reordering corruption that might cause retuning an old value of k1
          - However such caught corruption is a false positive since s1, s2 will not have overlapped keys with k1 or whatever inserted into m1 before ingest file s1 by the requirement of file ingestion (otherwise the m1 will be flushed first before any of the file ingestion completes). Therefore there in fact isn't any file reordering corruption.
      - Single delete can decrease a file's largest seqno and ordering by `largest_seqno` can introduce a wrong ordering hence file reordering corruption
          - For example, consider the following sequence of events ("key@n" indicates key at seqno "n", Credit to ajkr  for this example)
              - an existing SST s1 contains only k1@1
              - insert k1@2 to memtable m1
              - ingest file s2 with k3@3, ingest file s3 with k4@4
              - insert single delete k5@5 in m1
              - flush m1 and result in new file s4 of seqno range [2, 5]
              - compact s1, s2, s3 and result in new file s5 of seqno range [1, 4]
              - compact s4 and result in new file s6 of seqno range [2] due to single delete
          - By the last step, we have file ordering by largest seqno (">" means "newer") : s5 > s6 while s6 contains a newer version of the k1's value (i.e, k1@2) than s5, which is a real reordering corruption. While this can be caught by `force_consistency_check=true`, there isn't a good way to prevent this from happening if ordering by `largest_seqno`
      
      Therefore, we are redesigning the sorting criteria of L0 files and avoid above inconvenience. Credit to ajkr , we now introduce `epoch_num` which describes the order of a file being flushed or ingested/imported (compaction output file will has the minimum `epoch_num` among input files'). This will avoid the above inconvenience in the following ways:
      - In the first case above, there will no longer be overlap seqno range check in `force_consistency_check=true` but `epoch_number`  ordering check. This will result in file ordering s1 <  s2 <  s4 (pre-compaction) and s3 < s4 (post-compaction) which won't trigger false positive corruption. See test class `DBCompactionTestL0FilesMisorderCorruption*` for more.
      - In the second case above, this will result in file ordering s1 < s2 < s3 < s4 (pre-compacting s1, s2, s3), s5 < s4 (post-compacting s1, s2, s3), s5 < s6 (post-compacting s4), which are correct file ordering without causing any corruption.
      
      **Summary:**
      - Introduce `epoch_number` stored per `ColumnFamilyData` and sort CF's L0 files by their assigned `epoch_number` instead of `largest_seqno`.
        - `epoch_number` is increased and assigned upon `VersionEdit::AddFile()` for flush (or similarly for WriteLevel0TableForRecovery) and file ingestion (except for allow_behind_true, which will always get assigned as the `kReservedEpochNumberForFileIngestedBehind`)
        - Compaction output file  is assigned with the minimum `epoch_number` among input files'
            - Refit level: reuse refitted file's epoch_number
        -  Other paths needing `epoch_number` treatment:
           - Import column families: reuse file's epoch_number if exists. If not, assign one based on `NewestFirstBySeqNo`
           - Repair: reuse file's epoch_number if exists. If not, assign one based on `NewestFirstBySeqNo`.
        -  Assigning new epoch_number to a file and adding this file to LSM tree should be atomic. This is guaranteed by us assigning epoch_number right upon `VersionEdit::AddFile()` where this version edit will be apply to LSM tree shape right after by holding the db mutex (e.g, flush, file ingestion, import column family) or  by there is only 1 ongoing edit per CF (e.g, WriteLevel0TableForRecovery, Repair).
        - Assigning the minimum input epoch number to compaction output file won't misorder L0 files (even through later `Refit(target_level=0)`). It's due to for every key "k" in the input range, a legit compaction will cover a continuous epoch number range of that key. As long as we assign the key "k" the minimum input epoch number, it won't become newer or older than the versions of this key that aren't included in this compaction hence no misorder.
      - Persist `epoch_number` of each file in manifest and recover `epoch_number` on db recovery
         - Backward compatibility with old db without `epoch_number` support is guaranteed by assigning `epoch_number` to recovered files by `NewestFirstBySeqno` order. See `VersionStorageInfo::RecoverEpochNumbers()` for more
         - Forward compatibility with manifest is guaranteed by flexibility of `NewFileCustomTag`
      - Replace `force_consistent_check` on L0 with `epoch_number` and remove false positive check like case 1 with `largest_seqno` above
         - Due to backward compatibility issue, we might encounter files with missing epoch number at the beginning of db recovery. We will still use old L0 sorting mechanism (`NewestFirstBySeqno`) to check/sort them till we infer their epoch number. See usages of `EpochNumberRequirement`.
      - Remove fix https://github.com/facebook/rocksdb/pull/5958#issue-511150930 and their outdated tests to file reordering corruption because such fix can be replaced by this PR.
      - Misc:
         - update existing tests with `epoch_number` so make check will pass
         - update https://github.com/facebook/rocksdb/pull/5958#issue-511150930 tests to verify corruption is fixed using `epoch_number` and cover universal/fifo compaction/CompactRange/CompactFile cases
         - assert db_mutex is held for a few places before calling ColumnFamilyData::NewEpochNumber()
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10922
      
      Test Plan:
      - `make check`
      - New unit tests under `db/db_compaction_test.cc`, `db/db_test2.cc`, `db/version_builder_test.cc`, `db/repair_test.cc`
      - Updated tests (i.e, `DBCompactionTestL0FilesMisorderCorruption*`) under https://github.com/facebook/rocksdb/pull/5958#issue-511150930
      - [Ongoing] Compatibility test: manually run https://github.com/ajkr/rocksdb/commit/36a5686ec012f35a4371e409aa85c404ca1c210d (with file ingestion off for running the `.orig` binary to prevent this bug affecting upgrade/downgrade formality checking) for 1 hour on `simple black/white box`, `cf_consistency/txn/enable_ts with whitebox + test_best_efforts_recovery with blackbox`
      - [Ongoing] normal db stress test
      - [Ongoing] db stress test with aggressive value https://github.com/facebook/rocksdb/pull/10761
      
      Reviewed By: ajkr
      
      Differential Revision: D41063187
      
      Pulled By: hx235
      
      fbshipit-source-id: 826cb23455de7beaabe2d16c57682a82733a32a9
      98d5db5c
    • P
      Fix bug updating latest backup on delete (#11029) · 9b34c097
      Peter Dillinger 提交于
      Summary:
      Previously, the "latest" valid backup would not be updated on delete.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11029
      
      Test Plan: unit test included (added to an existing test for efficiency)
      
      Reviewed By: hx235
      
      Differential Revision: D41967925
      
      Pulled By: pdillinger
      
      fbshipit-source-id: ca143354d281eb979557ea421902cd26803a1137
      9b34c097
  15. 13 12月, 2022 2 次提交
  16. 11 12月, 2022 1 次提交
    • A
      Use VersionBuilder for CF import ordering/validation (#11028) · 4d60cbc6
      Andrew Kryczka 提交于
      Summary:
      Besides the existing ordering and validation, more is coming to VersionBuilder/VersionStorageInfo, like migration of epoch_numbers from older RocksDB versions. We should start using those common classes for importing CFs, instead of duplicating their ordering, validation, and migration logic.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11028
      
      Test Plan: rely on existing tests
      
      Reviewed By: hx235
      
      Differential Revision: D41865427
      
      Pulled By: ajkr
      
      fbshipit-source-id: 873f5cd87b8902a2380c3b71373ce0b0db3a0c50
      4d60cbc6
  17. 10 12月, 2022 1 次提交
    • P
      Improve error messages for SST footer and size errors (#11009) · 433d7e45
      Peter Dillinger 提交于
      Summary:
      Previously, you could get a format_version error if SST file size was too small in manifest, or a weird "too short" error if too big in manifest. Now we ensure:
      * Magic number error is reported first if we attempt to open an SST file and the footer is completely bad.
      * Footer errors are reported with affected file.
      * If manifest file size doesn't match actual, then the error includes expected and actual sizes (if an error is reported; in some cases we allow the file to be too big)
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/11009
      
      Test Plan:
      unit tests added, some manual
      
      Previously, the code for "file too short" in footer processing was only covered by some tests attempting to verify SST checksums on non-SST files (fixed).
      
      Reviewed By: siying
      
      Differential Revision: D41656272
      
      Pulled By: pdillinger
      
      fbshipit-source-id: 3da32702eb5aaedbea0e5e74742ad57edd7ad3df
      433d7e45
  18. 09 12月, 2022 1 次提交
  19. 07 12月, 2022 2 次提交
  20. 06 12月, 2022 1 次提交
  21. 05 12月, 2022 1 次提交
    • A
      Fix table cache leak in MultiGet with async_io (#10997) · 8ffabdc2
      anand76 提交于
      Summary:
      When MultiGet with the async_io option encounters an IO error in TableCache::GetTableReader, it may result in leakage of table cache handles due to queued coroutines being abandoned. This PR fixes it by ensuring any queued coroutines are run before aborting the MultiGet.
      
      Pull Request resolved: https://github.com/facebook/rocksdb/pull/10997
      
      Test Plan:
      1. New unit test in db_basic_test
      2. asan_crash
      
      Reviewed By: pdillinger
      
      Differential Revision: D41587244
      
      Pulled By: anand1976
      
      fbshipit-source-id: 900920cd3fba47cb0fc744a62facc5ffe2eccb64
      8ffabdc2
  22. 02 12月, 2022 1 次提交
  23. 01 12月, 2022 2 次提交