2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2015-09-10 23:35:25 +02:00
|
|
|
|
2020-09-15 06:10:09 +02:00
|
|
|
#include "db/compaction/compaction_iterator.h"
|
|
|
|
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
#include <iterator>
|
|
|
|
#include <limits>
|
2019-10-30 21:47:08 +01:00
|
|
|
|
2020-09-15 06:10:09 +02:00
|
|
|
#include "db/blob/blob_file_builder.h"
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
#include "db/blob/blob_index.h"
|
2017-10-06 19:26:38 +02:00
|
|
|
#include "db/snapshot_checker.h"
|
2021-09-29 13:01:57 +02:00
|
|
|
#include "logging/logging.h"
|
2017-10-06 19:26:38 +02:00
|
|
|
#include "port/likely.h"
|
2017-04-27 21:19:55 +02:00
|
|
|
#include "rocksdb/listener.h"
|
2015-10-13 00:06:38 +02:00
|
|
|
#include "table/internal_iterator.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/sync_point.h"
|
2019-01-16 18:48:10 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-09-10 23:35:25 +02:00
|
|
|
CompactionIterator::CompactionIterator(
|
2015-10-13 00:06:38 +02:00
|
|
|
InternalIterator* input, const Comparator* cmp, MergeHelper* merge_helper,
|
2015-09-10 23:35:25 +02:00
|
|
|
SequenceNumber last_sequence, std::vector<SequenceNumber>* snapshots,
|
2017-10-06 19:26:38 +02:00
|
|
|
SequenceNumber earliest_write_conflict_snapshot,
|
|
|
|
const SnapshotChecker* snapshot_checker, Env* env,
|
2018-06-22 06:16:49 +02:00
|
|
|
bool report_detailed_time, bool expect_valid_internal_key,
|
2020-09-15 06:10:09 +02:00
|
|
|
CompactionRangeDelAggregator* range_del_agg,
|
2020-09-30 08:16:12 +02:00
|
|
|
BlobFileBuilder* blob_file_builder, bool allow_data_in_errors,
|
|
|
|
const Compaction* compaction, const CompactionFilter* compaction_filter,
|
Added support for differential snapshots
Summary:
The motivation for this PR is to add to RocksDB support for differential (incremental) snapshots, as snapshot of the DB changes between two points in time (one can think of it as diff between to sequence numbers, or the diff D which can be thought of as an SST file or just set of KVs that can be applied to sequence number S1 to get the database to the state at sequence number S2).
This feature would be useful for various distributed storages layers built on top of RocksDB, as it should help reduce resources (time and network bandwidth) needed to recover and rebuilt DB instances as replicas in the context of distributed storages.
From the API standpoint that would like client app requesting iterator between (start seqnum) and current DB state, and reading the "diff".
This is a very draft PR for initial review in the discussion on the approach, i'm going to rework some parts and keep updating the PR.
For now, what's done here according to initial discussions:
Preserving deletes:
- We want to be able to optionally preserve recent deletes for some defined period of time, so that if a delete came in recently and might need to be included in the next incremental snapshot it would't get dropped by a compaction. This is done by adding new param to Options (preserve deletes flag) and new variable to DB Impl where we keep track of the sequence number after which we don't want to drop tombstones, even if they are otherwise eligible for deletion.
- I also added a new API call for clients to be able to advance this cutoff seqnum after which we drop deletes; i assume it's more flexible to let clients control this, since otherwise we'd need to keep some kind of timestamp < -- > seqnum mapping inside the DB, which sounds messy and painful to support. Clients could make use of it by periodically calling GetLatestSequenceNumber(), noting the timestamp, doing some calculation and figuring out by how much we need to advance the cutoff seqnum.
- Compaction codepath in compaction_iterator.cc has been modified to avoid dropping tombstones with seqnum > cutoff seqnum.
Iterator changes:
- couple params added to ReadOptions, to optionally allow client to request internal keys instead of user keys (so that client can get the latest value of a key, be it delete marker or a put), as well as min timestamp and min seqnum.
TableCache changes:
- I modified table_cache code to be able to quickly exclude SST files from iterators heep if creation_time on the file is less then iter_start_ts as passed in ReadOptions. That would help a lot in some DB settings (like reading very recent data only or using FIFO compactions), but not so much for universal compaction with more or less long iterator time span.
What's left:
- Still looking at how to best plug that inside DBIter codepath. So far it seems that FindNextUserKeyInternal only parses values as UserKeys, and iter->key() call generally returns user key. Can we add new API to DBIter as internal_key(), and modify this internal method to optionally set saved_key_ to point to the full internal key? I don't need to store actual seqnum there, but I do need to store type.
Closes https://github.com/facebook/rocksdb/pull/2999
Differential Revision: D6175602
Pulled By: mikhail-antonov
fbshipit-source-id: c779a6696ee2d574d86c69cec866a3ae095aa900
2017-11-02 02:43:29 +01:00
|
|
|
const std::atomic<bool>* shutting_down,
|
2019-05-04 02:26:20 +02:00
|
|
|
const SequenceNumber preserve_deletes_seqnum,
|
2020-08-14 20:28:12 +02:00
|
|
|
const std::atomic<int>* manual_compaction_paused,
|
2021-06-07 20:40:31 +02:00
|
|
|
const std::atomic<bool>* manual_compaction_canceled,
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
const std::shared_ptr<Logger> info_log,
|
|
|
|
const std::string* full_history_ts_low)
|
2016-12-01 16:00:17 +01:00
|
|
|
: CompactionIterator(
|
|
|
|
input, cmp, merge_helper, last_sequence, snapshots,
|
2017-10-06 19:26:38 +02:00
|
|
|
earliest_write_conflict_snapshot, snapshot_checker, env,
|
2018-06-22 06:16:49 +02:00
|
|
|
report_detailed_time, expect_valid_internal_key, range_del_agg,
|
2020-09-30 08:16:12 +02:00
|
|
|
blob_file_builder, allow_data_in_errors,
|
2016-12-01 16:00:17 +01:00
|
|
|
std::unique_ptr<CompactionProxy>(
|
2020-11-12 17:48:14 +01:00
|
|
|
compaction ? new RealCompaction(compaction) : nullptr),
|
2019-05-04 02:26:20 +02:00
|
|
|
compaction_filter, shutting_down, preserve_deletes_seqnum,
|
2021-06-07 20:40:31 +02:00
|
|
|
manual_compaction_paused, manual_compaction_canceled, info_log,
|
|
|
|
full_history_ts_low) {}
|
2016-12-01 16:00:17 +01:00
|
|
|
|
|
|
|
CompactionIterator::CompactionIterator(
|
|
|
|
InternalIterator* input, const Comparator* cmp, MergeHelper* merge_helper,
|
2018-03-05 22:08:17 +01:00
|
|
|
SequenceNumber /*last_sequence*/, std::vector<SequenceNumber>* snapshots,
|
2017-10-06 19:26:38 +02:00
|
|
|
SequenceNumber earliest_write_conflict_snapshot,
|
|
|
|
const SnapshotChecker* snapshot_checker, Env* env,
|
2018-06-22 06:16:49 +02:00
|
|
|
bool report_detailed_time, bool expect_valid_internal_key,
|
2018-12-18 02:26:56 +01:00
|
|
|
CompactionRangeDelAggregator* range_del_agg,
|
2020-09-30 08:16:12 +02:00
|
|
|
BlobFileBuilder* blob_file_builder, bool allow_data_in_errors,
|
2016-12-01 16:00:17 +01:00
|
|
|
std::unique_ptr<CompactionProxy> compaction,
|
2017-01-12 00:01:21 +01:00
|
|
|
const CompactionFilter* compaction_filter,
|
Added support for differential snapshots
Summary:
The motivation for this PR is to add to RocksDB support for differential (incremental) snapshots, as snapshot of the DB changes between two points in time (one can think of it as diff between to sequence numbers, or the diff D which can be thought of as an SST file or just set of KVs that can be applied to sequence number S1 to get the database to the state at sequence number S2).
This feature would be useful for various distributed storages layers built on top of RocksDB, as it should help reduce resources (time and network bandwidth) needed to recover and rebuilt DB instances as replicas in the context of distributed storages.
From the API standpoint that would like client app requesting iterator between (start seqnum) and current DB state, and reading the "diff".
This is a very draft PR for initial review in the discussion on the approach, i'm going to rework some parts and keep updating the PR.
For now, what's done here according to initial discussions:
Preserving deletes:
- We want to be able to optionally preserve recent deletes for some defined period of time, so that if a delete came in recently and might need to be included in the next incremental snapshot it would't get dropped by a compaction. This is done by adding new param to Options (preserve deletes flag) and new variable to DB Impl where we keep track of the sequence number after which we don't want to drop tombstones, even if they are otherwise eligible for deletion.
- I also added a new API call for clients to be able to advance this cutoff seqnum after which we drop deletes; i assume it's more flexible to let clients control this, since otherwise we'd need to keep some kind of timestamp < -- > seqnum mapping inside the DB, which sounds messy and painful to support. Clients could make use of it by periodically calling GetLatestSequenceNumber(), noting the timestamp, doing some calculation and figuring out by how much we need to advance the cutoff seqnum.
- Compaction codepath in compaction_iterator.cc has been modified to avoid dropping tombstones with seqnum > cutoff seqnum.
Iterator changes:
- couple params added to ReadOptions, to optionally allow client to request internal keys instead of user keys (so that client can get the latest value of a key, be it delete marker or a put), as well as min timestamp and min seqnum.
TableCache changes:
- I modified table_cache code to be able to quickly exclude SST files from iterators heep if creation_time on the file is less then iter_start_ts as passed in ReadOptions. That would help a lot in some DB settings (like reading very recent data only or using FIFO compactions), but not so much for universal compaction with more or less long iterator time span.
What's left:
- Still looking at how to best plug that inside DBIter codepath. So far it seems that FindNextUserKeyInternal only parses values as UserKeys, and iter->key() call generally returns user key. Can we add new API to DBIter as internal_key(), and modify this internal method to optionally set saved_key_ to point to the full internal key? I don't need to store actual seqnum there, but I do need to store type.
Closes https://github.com/facebook/rocksdb/pull/2999
Differential Revision: D6175602
Pulled By: mikhail-antonov
fbshipit-source-id: c779a6696ee2d574d86c69cec866a3ae095aa900
2017-11-02 02:43:29 +01:00
|
|
|
const std::atomic<bool>* shutting_down,
|
2019-05-04 02:26:20 +02:00
|
|
|
const SequenceNumber preserve_deletes_seqnum,
|
2020-08-14 20:28:12 +02:00
|
|
|
const std::atomic<int>* manual_compaction_paused,
|
2021-06-07 20:40:31 +02:00
|
|
|
const std::atomic<bool>* manual_compaction_canceled,
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
const std::shared_ptr<Logger> info_log,
|
|
|
|
const std::string* full_history_ts_low)
|
2021-06-25 01:11:07 +02:00
|
|
|
: input_(input, cmp,
|
|
|
|
!compaction || compaction->DoesInputReferenceBlobFiles()),
|
2015-09-10 23:35:25 +02:00
|
|
|
cmp_(cmp),
|
|
|
|
merge_helper_(merge_helper),
|
|
|
|
snapshots_(snapshots),
|
2015-12-08 21:25:48 +01:00
|
|
|
earliest_write_conflict_snapshot_(earliest_write_conflict_snapshot),
|
2017-10-06 19:26:38 +02:00
|
|
|
snapshot_checker_(snapshot_checker),
|
2015-09-10 23:35:25 +02:00
|
|
|
env_(env),
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_(env_->GetSystemClock().get()),
|
2018-06-22 06:16:49 +02:00
|
|
|
report_detailed_time_(report_detailed_time),
|
2015-09-10 23:35:25 +02:00
|
|
|
expect_valid_internal_key_(expect_valid_internal_key),
|
Compaction Support for Range Deletion
Summary:
This diff introduces RangeDelAggregator, which takes ownership of iterators
provided to it via AddTombstones(). The tombstones are organized in a two-level
map (snapshot stripe -> begin key -> tombstone). Tombstone creation avoids data
copy by holding Slices returned by the iterator, which remain valid thanks to pinning.
For compaction, we create a hierarchical range tombstone iterator with structure
matching the iterator over compaction input data. An aggregator based on that
iterator is used by CompactionIterator to determine which keys are covered by
range tombstones. In case of merge operand, the same aggregator is used by
MergeHelper. Upon finishing each file in the compaction, relevant range tombstones
are added to the output file's range tombstone metablock and file boundaries are
updated accordingly.
To check whether a key is covered by range tombstone, RangeDelAggregator::ShouldDelete()
considers tombstones in the key's snapshot stripe. When this function is used outside of
compaction, it also checks newer stripes, which can contain covering tombstones. Currently
the intra-stripe check involves a linear scan; however, in the future we plan to collapse ranges
within a stripe such that binary search can be used.
RangeDelAggregator::AddToBuilder() adds all range tombstones in the table's key-range
to a new table's range tombstone meta-block. Since range tombstones may fall in the gap
between files, we may need to extend some files' key-ranges. The strategy is (1) first file
extends as far left as possible and other files do not extend left, (2) all files extend right
until either the start of the next file or the end of the last range tombstone in the gap,
whichever comes first.
One other notable change is adding release/move semantics to ScopedArenaIterator
such that it can be used to transfer ownership of an arena-allocated iterator, similar to
how unique_ptr is used for malloc'd data.
Depends on D61473
Test Plan: compaction_iterator_test, mock_table, end-to-end tests in D63927
Reviewers: sdong, IslamAbdelRahman, wanning, yhchiang, lightmark
Reviewed By: lightmark
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D62205
2016-10-18 21:04:56 +02:00
|
|
|
range_del_agg_(range_del_agg),
|
2020-09-15 06:10:09 +02:00
|
|
|
blob_file_builder_(blob_file_builder),
|
2016-12-01 16:00:17 +01:00
|
|
|
compaction_(std::move(compaction)),
|
2015-09-10 23:35:25 +02:00
|
|
|
compaction_filter_(compaction_filter),
|
2017-01-12 00:01:21 +01:00
|
|
|
shutting_down_(shutting_down),
|
2019-09-17 06:00:13 +02:00
|
|
|
manual_compaction_paused_(manual_compaction_paused),
|
2021-06-07 20:40:31 +02:00
|
|
|
manual_compaction_canceled_(manual_compaction_canceled),
|
Added support for differential snapshots
Summary:
The motivation for this PR is to add to RocksDB support for differential (incremental) snapshots, as snapshot of the DB changes between two points in time (one can think of it as diff between to sequence numbers, or the diff D which can be thought of as an SST file or just set of KVs that can be applied to sequence number S1 to get the database to the state at sequence number S2).
This feature would be useful for various distributed storages layers built on top of RocksDB, as it should help reduce resources (time and network bandwidth) needed to recover and rebuilt DB instances as replicas in the context of distributed storages.
From the API standpoint that would like client app requesting iterator between (start seqnum) and current DB state, and reading the "diff".
This is a very draft PR for initial review in the discussion on the approach, i'm going to rework some parts and keep updating the PR.
For now, what's done here according to initial discussions:
Preserving deletes:
- We want to be able to optionally preserve recent deletes for some defined period of time, so that if a delete came in recently and might need to be included in the next incremental snapshot it would't get dropped by a compaction. This is done by adding new param to Options (preserve deletes flag) and new variable to DB Impl where we keep track of the sequence number after which we don't want to drop tombstones, even if they are otherwise eligible for deletion.
- I also added a new API call for clients to be able to advance this cutoff seqnum after which we drop deletes; i assume it's more flexible to let clients control this, since otherwise we'd need to keep some kind of timestamp < -- > seqnum mapping inside the DB, which sounds messy and painful to support. Clients could make use of it by periodically calling GetLatestSequenceNumber(), noting the timestamp, doing some calculation and figuring out by how much we need to advance the cutoff seqnum.
- Compaction codepath in compaction_iterator.cc has been modified to avoid dropping tombstones with seqnum > cutoff seqnum.
Iterator changes:
- couple params added to ReadOptions, to optionally allow client to request internal keys instead of user keys (so that client can get the latest value of a key, be it delete marker or a put), as well as min timestamp and min seqnum.
TableCache changes:
- I modified table_cache code to be able to quickly exclude SST files from iterators heep if creation_time on the file is less then iter_start_ts as passed in ReadOptions. That would help a lot in some DB settings (like reading very recent data only or using FIFO compactions), but not so much for universal compaction with more or less long iterator time span.
What's left:
- Still looking at how to best plug that inside DBIter codepath. So far it seems that FindNextUserKeyInternal only parses values as UserKeys, and iter->key() call generally returns user key. Can we add new API to DBIter as internal_key(), and modify this internal method to optionally set saved_key_ to point to the full internal key? I don't need to store actual seqnum there, but I do need to store type.
Closes https://github.com/facebook/rocksdb/pull/2999
Differential Revision: D6175602
Pulled By: mikhail-antonov
fbshipit-source-id: c779a6696ee2d574d86c69cec866a3ae095aa900
2017-11-02 02:43:29 +01:00
|
|
|
preserve_deletes_seqnum_(preserve_deletes_seqnum),
|
2020-09-30 08:16:12 +02:00
|
|
|
info_log_(info_log),
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
allow_data_in_errors_(allow_data_in_errors),
|
|
|
|
timestamp_size_(cmp_ ? cmp_->timestamp_size() : 0),
|
|
|
|
full_history_ts_low_(full_history_ts_low),
|
2020-11-10 03:19:42 +01:00
|
|
|
current_user_key_sequence_(0),
|
|
|
|
current_user_key_snapshot_(0),
|
|
|
|
merge_out_iter_(merge_helper_),
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
blob_garbage_collection_cutoff_file_number_(
|
|
|
|
ComputeBlobGarbageCollectionCutoffFileNumber(compaction_.get())),
|
2020-11-10 03:19:42 +01:00
|
|
|
current_key_committed_(false),
|
2021-05-08 01:00:37 +02:00
|
|
|
cmp_with_history_ts_low_(0),
|
|
|
|
level_(compaction_ == nullptr ? 0 : compaction_->level()) {
|
2019-01-16 18:48:10 +01:00
|
|
|
assert(snapshots_ != nullptr);
|
2020-09-03 23:34:58 +02:00
|
|
|
bottommost_level_ = compaction_ == nullptr
|
|
|
|
? false
|
|
|
|
: compaction_->bottommost_level() &&
|
|
|
|
!compaction_->allow_ingest_behind();
|
2015-09-10 23:35:25 +02:00
|
|
|
if (compaction_ != nullptr) {
|
|
|
|
level_ptrs_ = std::vector<size_t>(compaction_->number_levels(), 0);
|
|
|
|
}
|
2019-09-19 05:24:17 +02:00
|
|
|
if (snapshots_->size() == 0) {
|
|
|
|
// optimize for fast path if there are no snapshots
|
|
|
|
visible_at_tip_ = true;
|
|
|
|
earliest_snapshot_iter_ = snapshots_->end();
|
|
|
|
earliest_snapshot_ = kMaxSequenceNumber;
|
|
|
|
latest_snapshot_ = 0;
|
|
|
|
} else {
|
|
|
|
visible_at_tip_ = false;
|
|
|
|
earliest_snapshot_iter_ = snapshots_->begin();
|
|
|
|
earliest_snapshot_ = snapshots_->at(0);
|
|
|
|
latest_snapshot_ = snapshots_->back();
|
|
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// findEarliestVisibleSnapshot assumes this ordering.
|
|
|
|
for (size_t i = 1; i < snapshots_->size(); ++i) {
|
|
|
|
assert(snapshots_->at(i - 1) < snapshots_->at(i));
|
|
|
|
}
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
assert(timestamp_size_ == 0 || !full_history_ts_low_ ||
|
|
|
|
timestamp_size_ == full_history_ts_low_->size());
|
2019-09-19 05:24:17 +02:00
|
|
|
#endif
|
2021-05-21 01:06:12 +02:00
|
|
|
input_.SetPinnedItersMgr(&pinned_iters_mgr_);
|
2019-01-16 06:32:15 +01:00
|
|
|
TEST_SYNC_POINT_CALLBACK("CompactionIterator:AfterInit", compaction_.get());
|
Introduce FullMergeV2 (eliminate memcpy from merge operators)
Summary:
This diff update the code to pin the merge operator operands while the merge operation is done, so that we can eliminate the memcpy cost, to do that we need a new public API for FullMerge that replace the std::deque<std::string> with std::vector<Slice>
This diff is stacked on top of D56493 and D56511
In this diff we
- Update FullMergeV2 arguments to be encapsulated in MergeOperationInput and MergeOperationOutput which will make it easier to add new arguments in the future
- Replace std::deque<std::string> with std::vector<Slice> to pass operands
- Replace MergeContext std::deque with std::vector (based on a simple benchmark I ran https://gist.github.com/IslamAbdelRahman/78fc86c9ab9f52b1df791e58943fb187)
- Allow FullMergeV2 output to be an existing operand
```
[Everything in Memtable | 10K operands | 10 KB each | 1 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="mergerandom,readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --merge_keys=10000 --num=10000 --disable_auto_compactions --value_size=10240 --write_buffer_size=1000000000
[FullMergeV2]
readseq : 0.607 micros/op 1648235 ops/sec; 16121.2 MB/s
readseq : 0.478 micros/op 2091546 ops/sec; 20457.2 MB/s
readseq : 0.252 micros/op 3972081 ops/sec; 38850.5 MB/s
readseq : 0.237 micros/op 4218328 ops/sec; 41259.0 MB/s
readseq : 0.247 micros/op 4043927 ops/sec; 39553.2 MB/s
[master]
readseq : 3.935 micros/op 254140 ops/sec; 2485.7 MB/s
readseq : 3.722 micros/op 268657 ops/sec; 2627.7 MB/s
readseq : 3.149 micros/op 317605 ops/sec; 3106.5 MB/s
readseq : 3.125 micros/op 320024 ops/sec; 3130.1 MB/s
readseq : 4.075 micros/op 245374 ops/sec; 2400.0 MB/s
```
```
[Everything in Memtable | 10K operands | 10 KB each | 10 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="mergerandom,readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --merge_keys=1000 --num=10000 --disable_auto_compactions --value_size=10240 --write_buffer_size=1000000000
[FullMergeV2]
readseq : 3.472 micros/op 288018 ops/sec; 2817.1 MB/s
readseq : 2.304 micros/op 434027 ops/sec; 4245.2 MB/s
readseq : 1.163 micros/op 859845 ops/sec; 8410.0 MB/s
readseq : 1.192 micros/op 838926 ops/sec; 8205.4 MB/s
readseq : 1.250 micros/op 800000 ops/sec; 7824.7 MB/s
[master]
readseq : 24.025 micros/op 41623 ops/sec; 407.1 MB/s
readseq : 18.489 micros/op 54086 ops/sec; 529.0 MB/s
readseq : 18.693 micros/op 53495 ops/sec; 523.2 MB/s
readseq : 23.621 micros/op 42335 ops/sec; 414.1 MB/s
readseq : 18.775 micros/op 53262 ops/sec; 521.0 MB/s
```
```
[Everything in Block cache | 10K operands | 10 KB each | 1 operand per key]
[FullMergeV2]
$ DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --num=100000 --db="/dev/shm/merge-random-10K-10KB" --cache_size=1000000000 --use_existing_db --disable_auto_compactions
readseq : 14.741 micros/op 67837 ops/sec; 663.5 MB/s
readseq : 1.029 micros/op 971446 ops/sec; 9501.6 MB/s
readseq : 0.974 micros/op 1026229 ops/sec; 10037.4 MB/s
readseq : 0.965 micros/op 1036080 ops/sec; 10133.8 MB/s
readseq : 0.943 micros/op 1060657 ops/sec; 10374.2 MB/s
[master]
readseq : 16.735 micros/op 59755 ops/sec; 584.5 MB/s
readseq : 3.029 micros/op 330151 ops/sec; 3229.2 MB/s
readseq : 3.136 micros/op 318883 ops/sec; 3119.0 MB/s
readseq : 3.065 micros/op 326245 ops/sec; 3191.0 MB/s
readseq : 3.014 micros/op 331813 ops/sec; 3245.4 MB/s
```
```
[Everything in Block cache | 10K operands | 10 KB each | 10 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --num=100000 --db="/dev/shm/merge-random-10-operands-10K-10KB" --cache_size=1000000000 --use_existing_db --disable_auto_compactions
[FullMergeV2]
readseq : 24.325 micros/op 41109 ops/sec; 402.1 MB/s
readseq : 1.470 micros/op 680272 ops/sec; 6653.7 MB/s
readseq : 1.231 micros/op 812347 ops/sec; 7945.5 MB/s
readseq : 1.091 micros/op 916590 ops/sec; 8965.1 MB/s
readseq : 1.109 micros/op 901713 ops/sec; 8819.6 MB/s
[master]
readseq : 27.257 micros/op 36687 ops/sec; 358.8 MB/s
readseq : 4.443 micros/op 225073 ops/sec; 2201.4 MB/s
readseq : 5.830 micros/op 171526 ops/sec; 1677.7 MB/s
readseq : 4.173 micros/op 239635 ops/sec; 2343.8 MB/s
readseq : 4.150 micros/op 240963 ops/sec; 2356.8 MB/s
```
Test Plan: COMPILE_WITH_ASAN=1 make check -j64
Reviewers: yhchiang, andrewkr, sdong
Reviewed By: sdong
Subscribers: lovro, andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D57075
2016-07-20 18:49:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CompactionIterator::~CompactionIterator() {
|
2021-03-26 05:17:17 +01:00
|
|
|
// input_ Iterator lifetime is longer than pinned_iters_mgr_ lifetime
|
2021-05-21 01:06:12 +02:00
|
|
|
input_.SetPinnedItersMgr(nullptr);
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompactionIterator::ResetRecordCounts() {
|
|
|
|
iter_stats_.num_record_drop_user = 0;
|
|
|
|
iter_stats_.num_record_drop_hidden = 0;
|
|
|
|
iter_stats_.num_record_drop_obsolete = 0;
|
2016-11-28 20:44:40 +01:00
|
|
|
iter_stats_.num_record_drop_range_del = 0;
|
|
|
|
iter_stats_.num_range_del_drop_obsolete = 0;
|
2017-08-19 23:01:25 +02:00
|
|
|
iter_stats_.num_optimized_del_drop_obsolete = 0;
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompactionIterator::SeekToFirst() {
|
|
|
|
NextFromInput();
|
|
|
|
PrepareOutput();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompactionIterator::Next() {
|
|
|
|
// If there is a merge output, return it before continuing to process the
|
|
|
|
// input.
|
|
|
|
if (merge_out_iter_.Valid()) {
|
|
|
|
merge_out_iter_.Next();
|
|
|
|
|
|
|
|
// Check if we returned all records of the merge output.
|
|
|
|
if (merge_out_iter_.Valid()) {
|
|
|
|
key_ = merge_out_iter_.key();
|
|
|
|
value_ = merge_out_iter_.value();
|
2020-10-28 18:11:13 +01:00
|
|
|
Status s = ParseInternalKey(key_, &ikey_, allow_data_in_errors_);
|
2015-09-10 23:35:25 +02:00
|
|
|
// MergeUntil stops when it encounters a corrupt key and does not
|
|
|
|
// include them in the result, so we expect the keys here to be valid.
|
2020-10-01 04:15:42 +02:00
|
|
|
assert(s.ok());
|
|
|
|
if (!s.ok()) {
|
2020-10-28 18:11:13 +01:00
|
|
|
ROCKS_LOG_FATAL(info_log_, "Invalid key in compaction. %s",
|
|
|
|
s.getState());
|
2019-10-30 21:47:08 +01:00
|
|
|
}
|
|
|
|
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
// Keep current_key_ in sync.
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
2017-04-04 23:17:16 +02:00
|
|
|
key_ = current_key_.GetInternalKey();
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
ikey_.user_key = current_key_.GetUserKey();
|
2015-09-10 23:35:25 +02:00
|
|
|
valid_ = true;
|
|
|
|
} else {
|
Introduce FullMergeV2 (eliminate memcpy from merge operators)
Summary:
This diff update the code to pin the merge operator operands while the merge operation is done, so that we can eliminate the memcpy cost, to do that we need a new public API for FullMerge that replace the std::deque<std::string> with std::vector<Slice>
This diff is stacked on top of D56493 and D56511
In this diff we
- Update FullMergeV2 arguments to be encapsulated in MergeOperationInput and MergeOperationOutput which will make it easier to add new arguments in the future
- Replace std::deque<std::string> with std::vector<Slice> to pass operands
- Replace MergeContext std::deque with std::vector (based on a simple benchmark I ran https://gist.github.com/IslamAbdelRahman/78fc86c9ab9f52b1df791e58943fb187)
- Allow FullMergeV2 output to be an existing operand
```
[Everything in Memtable | 10K operands | 10 KB each | 1 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="mergerandom,readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --merge_keys=10000 --num=10000 --disable_auto_compactions --value_size=10240 --write_buffer_size=1000000000
[FullMergeV2]
readseq : 0.607 micros/op 1648235 ops/sec; 16121.2 MB/s
readseq : 0.478 micros/op 2091546 ops/sec; 20457.2 MB/s
readseq : 0.252 micros/op 3972081 ops/sec; 38850.5 MB/s
readseq : 0.237 micros/op 4218328 ops/sec; 41259.0 MB/s
readseq : 0.247 micros/op 4043927 ops/sec; 39553.2 MB/s
[master]
readseq : 3.935 micros/op 254140 ops/sec; 2485.7 MB/s
readseq : 3.722 micros/op 268657 ops/sec; 2627.7 MB/s
readseq : 3.149 micros/op 317605 ops/sec; 3106.5 MB/s
readseq : 3.125 micros/op 320024 ops/sec; 3130.1 MB/s
readseq : 4.075 micros/op 245374 ops/sec; 2400.0 MB/s
```
```
[Everything in Memtable | 10K operands | 10 KB each | 10 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="mergerandom,readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --merge_keys=1000 --num=10000 --disable_auto_compactions --value_size=10240 --write_buffer_size=1000000000
[FullMergeV2]
readseq : 3.472 micros/op 288018 ops/sec; 2817.1 MB/s
readseq : 2.304 micros/op 434027 ops/sec; 4245.2 MB/s
readseq : 1.163 micros/op 859845 ops/sec; 8410.0 MB/s
readseq : 1.192 micros/op 838926 ops/sec; 8205.4 MB/s
readseq : 1.250 micros/op 800000 ops/sec; 7824.7 MB/s
[master]
readseq : 24.025 micros/op 41623 ops/sec; 407.1 MB/s
readseq : 18.489 micros/op 54086 ops/sec; 529.0 MB/s
readseq : 18.693 micros/op 53495 ops/sec; 523.2 MB/s
readseq : 23.621 micros/op 42335 ops/sec; 414.1 MB/s
readseq : 18.775 micros/op 53262 ops/sec; 521.0 MB/s
```
```
[Everything in Block cache | 10K operands | 10 KB each | 1 operand per key]
[FullMergeV2]
$ DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --num=100000 --db="/dev/shm/merge-random-10K-10KB" --cache_size=1000000000 --use_existing_db --disable_auto_compactions
readseq : 14.741 micros/op 67837 ops/sec; 663.5 MB/s
readseq : 1.029 micros/op 971446 ops/sec; 9501.6 MB/s
readseq : 0.974 micros/op 1026229 ops/sec; 10037.4 MB/s
readseq : 0.965 micros/op 1036080 ops/sec; 10133.8 MB/s
readseq : 0.943 micros/op 1060657 ops/sec; 10374.2 MB/s
[master]
readseq : 16.735 micros/op 59755 ops/sec; 584.5 MB/s
readseq : 3.029 micros/op 330151 ops/sec; 3229.2 MB/s
readseq : 3.136 micros/op 318883 ops/sec; 3119.0 MB/s
readseq : 3.065 micros/op 326245 ops/sec; 3191.0 MB/s
readseq : 3.014 micros/op 331813 ops/sec; 3245.4 MB/s
```
```
[Everything in Block cache | 10K operands | 10 KB each | 10 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --num=100000 --db="/dev/shm/merge-random-10-operands-10K-10KB" --cache_size=1000000000 --use_existing_db --disable_auto_compactions
[FullMergeV2]
readseq : 24.325 micros/op 41109 ops/sec; 402.1 MB/s
readseq : 1.470 micros/op 680272 ops/sec; 6653.7 MB/s
readseq : 1.231 micros/op 812347 ops/sec; 7945.5 MB/s
readseq : 1.091 micros/op 916590 ops/sec; 8965.1 MB/s
readseq : 1.109 micros/op 901713 ops/sec; 8819.6 MB/s
[master]
readseq : 27.257 micros/op 36687 ops/sec; 358.8 MB/s
readseq : 4.443 micros/op 225073 ops/sec; 2201.4 MB/s
readseq : 5.830 micros/op 171526 ops/sec; 1677.7 MB/s
readseq : 4.173 micros/op 239635 ops/sec; 2343.8 MB/s
readseq : 4.150 micros/op 240963 ops/sec; 2356.8 MB/s
```
Test Plan: COMPILE_WITH_ASAN=1 make check -j64
Reviewers: yhchiang, andrewkr, sdong
Reviewed By: sdong
Subscribers: lovro, andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D57075
2016-07-20 18:49:03 +02:00
|
|
|
// We consumed all pinned merge operands, release pinned iterators
|
2016-08-11 20:54:17 +02:00
|
|
|
pinned_iters_mgr_.ReleasePinnedData();
|
2015-09-10 23:35:25 +02:00
|
|
|
// MergeHelper moves the iterator to the first record after the merged
|
|
|
|
// records, so even though we reached the end of the merge output, we do
|
|
|
|
// not want to advance the iterator.
|
|
|
|
NextFromInput();
|
|
|
|
}
|
|
|
|
} else {
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
// Only advance the input iterator if there is no merge output and the
|
|
|
|
// iterator is not already at the next record.
|
|
|
|
if (!at_next_) {
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
NextFromInput();
|
|
|
|
}
|
|
|
|
|
2015-11-05 05:52:22 +01:00
|
|
|
if (valid_) {
|
2016-12-01 16:00:17 +01:00
|
|
|
// Record that we've outputted a record for the current key.
|
2015-11-05 05:52:22 +01:00
|
|
|
has_outputted_key_ = true;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:35:25 +02:00
|
|
|
PrepareOutput();
|
|
|
|
}
|
|
|
|
|
2020-06-30 02:30:04 +02:00
|
|
|
bool CompactionIterator::InvokeFilterIfNeeded(bool* need_skip,
|
2017-10-06 19:26:38 +02:00
|
|
|
Slice* skip_until) {
|
2021-02-26 01:30:27 +01:00
|
|
|
if (!compaction_filter_ ||
|
|
|
|
(ikey_.type != kTypeValue && ikey_.type != kTypeBlobIndex)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool error = false;
|
|
|
|
// If the user has specified a compaction filter and the sequence
|
|
|
|
// number is greater than any external snapshot, then invoke the
|
|
|
|
// filter. If the return value of the compaction filter is true,
|
|
|
|
// replace the entry with a deletion marker.
|
|
|
|
CompactionFilter::Decision filter = CompactionFilter::Decision::kUndetermined;
|
|
|
|
compaction_filter_value_.clear();
|
|
|
|
compaction_filter_skip_until_.Clear();
|
|
|
|
CompactionFilter::ValueType value_type =
|
|
|
|
ikey_.type == kTypeValue ? CompactionFilter::ValueType::kValue
|
|
|
|
: CompactionFilter::ValueType::kBlobIndex;
|
|
|
|
// Hack: pass internal key to BlobIndexCompactionFilter since it needs
|
|
|
|
// to get sequence number.
|
|
|
|
assert(compaction_filter_);
|
|
|
|
Slice& filter_key =
|
|
|
|
(ikey_.type == kTypeValue ||
|
|
|
|
!compaction_filter_->IsStackedBlobDbInternalCompactionFilter())
|
|
|
|
? ikey_.user_key
|
|
|
|
: key_;
|
|
|
|
{
|
|
|
|
StopWatchNano timer(clock_, report_detailed_time_);
|
|
|
|
if (kTypeBlobIndex == ikey_.type) {
|
|
|
|
blob_value_.Reset();
|
|
|
|
filter = compaction_filter_->FilterBlobByKey(
|
2021-05-08 01:00:37 +02:00
|
|
|
level_, filter_key, &compaction_filter_value_,
|
2021-02-26 01:30:27 +01:00
|
|
|
compaction_filter_skip_until_.rep());
|
|
|
|
if (CompactionFilter::Decision::kUndetermined == filter &&
|
|
|
|
!compaction_filter_->IsStackedBlobDbInternalCompactionFilter()) {
|
|
|
|
// For integrated BlobDB impl, CompactionIterator reads blob value.
|
|
|
|
// For Stacked BlobDB impl, the corresponding CompactionFilter's
|
|
|
|
// FilterV2 method should read the blob value.
|
|
|
|
BlobIndex blob_index;
|
|
|
|
Status s = blob_index.DecodeFrom(value_);
|
|
|
|
if (!s.ok()) {
|
|
|
|
status_ = s;
|
|
|
|
valid_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (blob_index.HasTTL() || blob_index.IsInlined()) {
|
|
|
|
status_ = Status::Corruption("Unexpected TTL/inlined blob index");
|
|
|
|
valid_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-08 01:00:37 +02:00
|
|
|
if (compaction_ == nullptr) {
|
|
|
|
status_ =
|
|
|
|
Status::Corruption("Unexpected blob index outside of compaction");
|
|
|
|
valid_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-26 01:30:27 +01:00
|
|
|
const Version* const version = compaction_->input_version();
|
|
|
|
assert(version);
|
2021-03-04 09:42:11 +01:00
|
|
|
|
|
|
|
uint64_t bytes_read = 0;
|
2021-02-26 01:30:27 +01:00
|
|
|
s = version->GetBlob(ReadOptions(), ikey_.user_key, blob_index,
|
2021-03-04 09:42:11 +01:00
|
|
|
&blob_value_, &bytes_read);
|
2021-02-26 01:30:27 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
status_ = s;
|
|
|
|
valid_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-04 09:42:11 +01:00
|
|
|
|
|
|
|
++iter_stats_.num_blobs_read;
|
|
|
|
iter_stats_.total_blob_bytes_read += bytes_read;
|
|
|
|
|
2021-02-26 01:30:27 +01:00
|
|
|
value_type = CompactionFilter::ValueType::kValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CompactionFilter::Decision::kUndetermined == filter) {
|
2017-10-06 19:26:38 +02:00
|
|
|
filter = compaction_filter_->FilterV2(
|
2021-05-08 01:00:37 +02:00
|
|
|
level_, filter_key, value_type,
|
2021-02-26 01:30:27 +01:00
|
|
|
blob_value_.empty() ? value_ : blob_value_, &compaction_filter_value_,
|
|
|
|
compaction_filter_skip_until_.rep());
|
2017-10-06 19:26:38 +02:00
|
|
|
}
|
2021-02-26 01:30:27 +01:00
|
|
|
iter_stats_.total_filter_time +=
|
|
|
|
env_ != nullptr && report_detailed_time_ ? timer.ElapsedNanos() : 0;
|
|
|
|
}
|
2017-10-06 19:26:38 +02:00
|
|
|
|
2021-02-26 01:30:27 +01:00
|
|
|
if (CompactionFilter::Decision::kUndetermined == filter) {
|
|
|
|
// Should not reach here, since FilterV2 should never return kUndetermined.
|
|
|
|
status_ =
|
|
|
|
Status::NotSupported("FilterV2() should never return kUndetermined");
|
|
|
|
valid_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-06 19:26:38 +02:00
|
|
|
|
2021-02-26 01:30:27 +01:00
|
|
|
if (filter == CompactionFilter::Decision::kRemoveAndSkipUntil &&
|
|
|
|
cmp_->Compare(*compaction_filter_skip_until_.rep(), ikey_.user_key) <=
|
|
|
|
0) {
|
|
|
|
// Can't skip to a key smaller than the current one.
|
|
|
|
// Keep the key as per FilterV2 documentation.
|
|
|
|
filter = CompactionFilter::Decision::kKeep;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter == CompactionFilter::Decision::kRemove) {
|
|
|
|
// convert the current key to a delete; key_ is pointing into
|
|
|
|
// current_key_ at this point, so updating current_key_ updates key()
|
|
|
|
ikey_.type = kTypeDeletion;
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, kTypeDeletion);
|
|
|
|
// no value associated with delete
|
|
|
|
value_.clear();
|
|
|
|
iter_stats_.num_record_drop_user++;
|
|
|
|
} else if (filter == CompactionFilter::Decision::kChangeValue) {
|
|
|
|
if (ikey_.type == kTypeBlobIndex) {
|
|
|
|
// value transfer from blob file to inlined data
|
|
|
|
ikey_.type = kTypeValue;
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
|
|
|
}
|
|
|
|
value_ = compaction_filter_value_;
|
|
|
|
} else if (filter == CompactionFilter::Decision::kRemoveAndSkipUntil) {
|
|
|
|
*need_skip = true;
|
|
|
|
compaction_filter_skip_until_.ConvertFromUserKey(kMaxSequenceNumber,
|
|
|
|
kValueTypeForSeek);
|
|
|
|
*skip_until = compaction_filter_skip_until_.Encode();
|
|
|
|
} else if (filter == CompactionFilter::Decision::kChangeBlobIndex) {
|
|
|
|
// Only the StackableDB-based BlobDB impl's compaction filter should return
|
|
|
|
// kChangeBlobIndex. Decision about rewriting blob and changing blob index
|
|
|
|
// in the integrated BlobDB impl is made in subsequent call to
|
|
|
|
// PrepareOutput() and its callees.
|
|
|
|
if (!compaction_filter_->IsStackedBlobDbInternalCompactionFilter()) {
|
|
|
|
status_ = Status::NotSupported(
|
|
|
|
"Only stacked BlobDB's internal compaction filter can return "
|
|
|
|
"kChangeBlobIndex.");
|
|
|
|
valid_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ikey_.type == kTypeValue) {
|
|
|
|
// value transfer from inlined data to blob file
|
|
|
|
ikey_.type = kTypeBlobIndex;
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
|
|
|
}
|
|
|
|
value_ = compaction_filter_value_;
|
|
|
|
} else if (filter == CompactionFilter::Decision::kIOError) {
|
|
|
|
if (!compaction_filter_->IsStackedBlobDbInternalCompactionFilter()) {
|
|
|
|
status_ = Status::NotSupported(
|
|
|
|
"CompactionFilter for integrated BlobDB should not return kIOError");
|
|
|
|
valid_ = false;
|
2020-06-30 02:30:04 +02:00
|
|
|
return false;
|
2017-10-06 19:26:38 +02:00
|
|
|
}
|
2021-02-26 01:30:27 +01:00
|
|
|
status_ = Status::IOError("Failed to access blob during compaction filter");
|
|
|
|
error = true;
|
2017-10-06 19:26:38 +02:00
|
|
|
}
|
2021-02-26 01:30:27 +01:00
|
|
|
return !error;
|
2017-10-06 19:26:38 +02:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:35:25 +02:00
|
|
|
void CompactionIterator::NextFromInput() {
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
at_next_ = false;
|
2015-09-10 23:35:25 +02:00
|
|
|
valid_ = false;
|
|
|
|
|
2021-05-21 01:06:12 +02:00
|
|
|
while (!valid_ && input_.Valid() && !IsPausingManualCompaction() &&
|
2019-09-19 21:32:33 +02:00
|
|
|
!IsShuttingDown()) {
|
2021-05-21 01:06:12 +02:00
|
|
|
key_ = input_.key();
|
|
|
|
value_ = input_.value();
|
2015-09-10 23:35:25 +02:00
|
|
|
iter_stats_.num_input_records++;
|
|
|
|
|
2020-10-28 18:11:13 +01:00
|
|
|
Status pik_status = ParseInternalKey(key_, &ikey_, allow_data_in_errors_);
|
|
|
|
if (!pik_status.ok()) {
|
2020-07-15 02:16:18 +02:00
|
|
|
iter_stats_.num_input_corrupt_records++;
|
2020-09-30 08:16:12 +02:00
|
|
|
|
2015-09-10 23:35:25 +02:00
|
|
|
// If `expect_valid_internal_key_` is false, return the corrupted key
|
|
|
|
// and let the caller decide what to do with it.
|
2015-09-11 00:16:32 +02:00
|
|
|
if (expect_valid_internal_key_) {
|
2020-10-28 18:11:13 +01:00
|
|
|
status_ = pik_status;
|
2020-09-30 08:16:12 +02:00
|
|
|
return;
|
2015-09-11 00:16:32 +02:00
|
|
|
}
|
2017-04-04 23:17:16 +02:00
|
|
|
key_ = current_key_.SetInternalKey(key_);
|
2015-09-10 23:35:25 +02:00
|
|
|
has_current_user_key_ = false;
|
|
|
|
current_user_key_sequence_ = kMaxSequenceNumber;
|
|
|
|
current_user_key_snapshot_ = 0;
|
|
|
|
valid_ = true;
|
|
|
|
break;
|
|
|
|
}
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
TEST_SYNC_POINT_CALLBACK("CompactionIterator:ProcessKV", &ikey_);
|
2015-09-10 23:35:25 +02:00
|
|
|
|
|
|
|
// Update input statistics
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
if (ikey_.type == kTypeDeletion || ikey_.type == kTypeSingleDeletion ||
|
|
|
|
ikey_.type == kTypeDeletionWithTimestamp) {
|
2015-09-10 23:35:25 +02:00
|
|
|
iter_stats_.num_input_deletion_records++;
|
|
|
|
}
|
|
|
|
iter_stats_.total_input_raw_key_bytes += key_.size();
|
|
|
|
iter_stats_.total_input_raw_value_bytes += value_.size();
|
|
|
|
|
2016-12-01 16:00:17 +01:00
|
|
|
// If need_skip is true, we should seek the input iterator
|
|
|
|
// to internal key skip_until and continue from there.
|
|
|
|
bool need_skip = false;
|
|
|
|
// Points either into compaction_filter_skip_until_ or into
|
|
|
|
// merge_helper_->compaction_filter_skip_until_.
|
|
|
|
Slice skip_until;
|
|
|
|
|
2021-03-10 20:13:55 +01:00
|
|
|
bool user_key_equal_without_ts = false;
|
2020-11-10 03:19:42 +01:00
|
|
|
int cmp_ts = 0;
|
|
|
|
if (has_current_user_key_) {
|
2021-03-10 20:13:55 +01:00
|
|
|
user_key_equal_without_ts =
|
|
|
|
cmp_->EqualWithoutTimestamp(ikey_.user_key, current_user_key_);
|
2020-11-10 03:19:42 +01:00
|
|
|
// if timestamp_size_ > 0, then curr_ts_ has been initialized by a
|
|
|
|
// previous key.
|
|
|
|
cmp_ts = timestamp_size_ ? cmp_->CompareTimestamp(
|
|
|
|
ExtractTimestampFromUserKey(
|
|
|
|
ikey_.user_key, timestamp_size_),
|
|
|
|
curr_ts_)
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
// Check whether the user key changed. After this if statement current_key_
|
|
|
|
// is a copy of the current input key (maybe converted to a delete by the
|
|
|
|
// compaction filter). ikey_.user_key is pointing to the copy.
|
2021-03-10 20:13:55 +01:00
|
|
|
if (!has_current_user_key_ || !user_key_equal_without_ts || cmp_ts != 0) {
|
2015-09-10 23:35:25 +02:00
|
|
|
// First occurrence of this user key
|
Compaction Support for Range Deletion
Summary:
This diff introduces RangeDelAggregator, which takes ownership of iterators
provided to it via AddTombstones(). The tombstones are organized in a two-level
map (snapshot stripe -> begin key -> tombstone). Tombstone creation avoids data
copy by holding Slices returned by the iterator, which remain valid thanks to pinning.
For compaction, we create a hierarchical range tombstone iterator with structure
matching the iterator over compaction input data. An aggregator based on that
iterator is used by CompactionIterator to determine which keys are covered by
range tombstones. In case of merge operand, the same aggregator is used by
MergeHelper. Upon finishing each file in the compaction, relevant range tombstones
are added to the output file's range tombstone metablock and file boundaries are
updated accordingly.
To check whether a key is covered by range tombstone, RangeDelAggregator::ShouldDelete()
considers tombstones in the key's snapshot stripe. When this function is used outside of
compaction, it also checks newer stripes, which can contain covering tombstones. Currently
the intra-stripe check involves a linear scan; however, in the future we plan to collapse ranges
within a stripe such that binary search can be used.
RangeDelAggregator::AddToBuilder() adds all range tombstones in the table's key-range
to a new table's range tombstone meta-block. Since range tombstones may fall in the gap
between files, we may need to extend some files' key-ranges. The strategy is (1) first file
extends as far left as possible and other files do not extend left, (2) all files extend right
until either the start of the next file or the end of the last range tombstone in the gap,
whichever comes first.
One other notable change is adding release/move semantics to ScopedArenaIterator
such that it can be used to transfer ownership of an arena-allocated iterator, similar to
how unique_ptr is used for malloc'd data.
Depends on D61473
Test Plan: compaction_iterator_test, mock_table, end-to-end tests in D63927
Reviewers: sdong, IslamAbdelRahman, wanning, yhchiang, lightmark
Reviewed By: lightmark
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D62205
2016-10-18 21:04:56 +02:00
|
|
|
// Copy key for output
|
2017-04-04 23:17:16 +02:00
|
|
|
key_ = current_key_.SetInternalKey(key_, &ikey_);
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
|
2020-11-10 03:19:42 +01:00
|
|
|
// If timestamp_size_ > 0, then copy from ikey_ to curr_ts_ for the use
|
|
|
|
// in next iteration to compare with the timestamp of next key.
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
UpdateTimestampAndCompareWithFullHistoryLow();
|
|
|
|
|
|
|
|
// If
|
|
|
|
// (1) !has_current_user_key_, OR
|
|
|
|
// (2) timestamp is disabled, OR
|
|
|
|
// (3) all history will be preserved, OR
|
|
|
|
// (4) user key (excluding timestamp) is different from previous key, OR
|
|
|
|
// (5) timestamp is NO older than *full_history_ts_low_
|
|
|
|
// then current_user_key_ must be treated as a different user key.
|
|
|
|
// This means, if a user key (excluding ts) is the same as the previous
|
|
|
|
// user key, and its ts is older than *full_history_ts_low_, then we
|
|
|
|
// consider this key for GC, e.g. it may be dropped if certain conditions
|
|
|
|
// match.
|
|
|
|
if (!has_current_user_key_ || !timestamp_size_ || !full_history_ts_low_ ||
|
2021-03-10 20:13:55 +01:00
|
|
|
!user_key_equal_without_ts || cmp_with_history_ts_low_ >= 0) {
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
// Initialize for future comparison for rule (A) and etc.
|
|
|
|
current_user_key_sequence_ = kMaxSequenceNumber;
|
|
|
|
current_user_key_snapshot_ = 0;
|
|
|
|
has_current_user_key_ = true;
|
|
|
|
}
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
current_user_key_ = ikey_.user_key;
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
|
2015-11-05 05:52:22 +01:00
|
|
|
has_outputted_key_ = false;
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
|
2019-01-16 18:48:10 +01:00
|
|
|
current_key_committed_ = KeyCommitted(ikey_.sequence);
|
2015-11-05 05:52:22 +01:00
|
|
|
|
2017-10-06 19:26:38 +02:00
|
|
|
// Apply the compaction filter to the first committed version of the user
|
|
|
|
// key.
|
2020-06-30 02:30:04 +02:00
|
|
|
if (current_key_committed_ &&
|
|
|
|
!InvokeFilterIfNeeded(&need_skip, &skip_until)) {
|
|
|
|
break;
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
} else {
|
|
|
|
// Update the current key to reflect the new sequence number/type without
|
|
|
|
// copying the user key.
|
2015-11-21 00:57:26 +01:00
|
|
|
// TODO(rven): Compaction filter does not process keys in this path
|
|
|
|
// Need to have the compaction filter process multiple versions
|
|
|
|
// if we have versions on both sides of a snapshot
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
2017-04-04 23:17:16 +02:00
|
|
|
key_ = current_key_.GetInternalKey();
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
ikey_.user_key = current_key_.GetUserKey();
|
2017-10-06 19:26:38 +02:00
|
|
|
|
|
|
|
// Note that newer version of a key is ordered before older versions. If a
|
|
|
|
// newer version of a key is committed, so as the older version. No need
|
|
|
|
// to query snapshot_checker_ in that case.
|
|
|
|
if (UNLIKELY(!current_key_committed_)) {
|
|
|
|
assert(snapshot_checker_ != nullptr);
|
2019-01-16 18:48:10 +01:00
|
|
|
current_key_committed_ = KeyCommitted(ikey_.sequence);
|
2017-10-06 19:26:38 +02:00
|
|
|
// Apply the compaction filter to the first committed version of the
|
|
|
|
// user key.
|
2020-06-30 02:30:04 +02:00
|
|
|
if (current_key_committed_ &&
|
|
|
|
!InvokeFilterIfNeeded(&need_skip, &skip_until)) {
|
|
|
|
break;
|
2017-10-06 19:26:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNLIKELY(!current_key_committed_)) {
|
|
|
|
assert(snapshot_checker_ != nullptr);
|
|
|
|
valid_ = true;
|
|
|
|
break;
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no snapshots, then this kv affect visibility at tip.
|
|
|
|
// Otherwise, search though all existing snapshots to find the earliest
|
|
|
|
// snapshot that is affected by this kv.
|
2020-09-12 02:44:06 +02:00
|
|
|
SequenceNumber last_sequence = current_user_key_sequence_;
|
2015-09-10 23:35:25 +02:00
|
|
|
current_user_key_sequence_ = ikey_.sequence;
|
|
|
|
SequenceNumber last_snapshot = current_user_key_snapshot_;
|
|
|
|
SequenceNumber prev_snapshot = 0; // 0 means no previous snapshot
|
|
|
|
current_user_key_snapshot_ =
|
2016-10-13 19:49:06 +02:00
|
|
|
visible_at_tip_
|
|
|
|
? earliest_snapshot_
|
|
|
|
: findEarliestVisibleSnapshot(ikey_.sequence, &prev_snapshot);
|
2015-09-10 23:35:25 +02:00
|
|
|
|
2016-12-01 16:00:17 +01:00
|
|
|
if (need_skip) {
|
|
|
|
// This case is handled below.
|
|
|
|
} else if (clear_and_output_next_key_) {
|
2015-11-05 05:52:22 +01:00
|
|
|
// In the previous iteration we encountered a single delete that we could
|
|
|
|
// not compact out. We will keep this Put, but can drop it's data.
|
|
|
|
// (See Optimization 3, below.)
|
2021-01-29 21:39:44 +01:00
|
|
|
assert(ikey_.type == kTypeValue || ikey_.type == kTypeBlobIndex);
|
|
|
|
if (ikey_.type != kTypeValue && ikey_.type != kTypeBlobIndex) {
|
2019-10-30 21:47:08 +01:00
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"Unexpected key type %d for compaction output",
|
|
|
|
ikey_.type);
|
|
|
|
}
|
2021-08-18 07:13:21 +02:00
|
|
|
assert(current_user_key_snapshot_ >= last_snapshot);
|
|
|
|
if (current_user_key_snapshot_ < last_snapshot) {
|
2019-10-30 21:47:08 +01:00
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"current_user_key_snapshot_ (%" PRIu64
|
2021-08-18 07:13:21 +02:00
|
|
|
") < last_snapshot (%" PRIu64 ")",
|
2019-10-30 21:47:08 +01:00
|
|
|
current_user_key_snapshot_, last_snapshot);
|
|
|
|
}
|
2015-11-05 05:52:22 +01:00
|
|
|
|
2021-01-29 21:39:44 +01:00
|
|
|
if (ikey_.type == kTypeBlobIndex) {
|
|
|
|
ikey_.type = kTypeValue;
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
|
|
|
}
|
|
|
|
|
2015-11-05 05:52:22 +01:00
|
|
|
value_.clear();
|
|
|
|
valid_ = true;
|
|
|
|
clear_and_output_next_key_ = false;
|
|
|
|
} else if (ikey_.type == kTypeSingleDeletion) {
|
|
|
|
// We can compact out a SingleDelete if:
|
|
|
|
// 1) We encounter the corresponding PUT -OR- we know that this key
|
|
|
|
// doesn't appear past this output level
|
|
|
|
// =AND=
|
|
|
|
// 2) We've already returned a record in this snapshot -OR-
|
|
|
|
// there are no earlier earliest_write_conflict_snapshot.
|
|
|
|
//
|
|
|
|
// Rule 1 is needed for SingleDelete correctness. Rule 2 is needed to
|
|
|
|
// allow Transactions to do write-conflict checking (if we compacted away
|
|
|
|
// all keys, then we wouldn't know that a write happened in this
|
|
|
|
// snapshot). If there is no earlier snapshot, then we know that there
|
|
|
|
// are no active transactions that need to know about any writes.
|
|
|
|
//
|
|
|
|
// Optimization 3:
|
|
|
|
// If we encounter a SingleDelete followed by a PUT and Rule 2 is NOT
|
|
|
|
// true, then we must output a SingleDelete. In this case, we will decide
|
|
|
|
// to also output the PUT. While we are compacting less by outputting the
|
|
|
|
// PUT now, hopefully this will lead to better compaction in the future
|
|
|
|
// when Rule 2 is later true (Ie, We are hoping we can later compact out
|
|
|
|
// both the SingleDelete and the Put, while we couldn't if we only
|
|
|
|
// outputted the SingleDelete now).
|
|
|
|
// In this case, we can save space by removing the PUT's value as it will
|
|
|
|
// never be read.
|
|
|
|
//
|
|
|
|
// Deletes and Merges are not supported on the same key that has a
|
|
|
|
// SingleDelete as it is not possible to correctly do any partial
|
|
|
|
// compaction of such a combination of operations. The result of mixing
|
|
|
|
// those operations for a given key is documented as being undefined. So
|
|
|
|
// we can choose how to handle such a combinations of operations. We will
|
|
|
|
// try to compact out as much as we can in these cases.
|
2016-08-16 17:21:43 +02:00
|
|
|
// We will report counts on these anomalous cases.
|
2021-09-27 20:49:35 +02:00
|
|
|
//
|
|
|
|
// Note: If timestamp is enabled, then record will be eligible for
|
|
|
|
// deletion, only if, along with above conditions (Rule 1 and Rule 2)
|
|
|
|
// full_history_ts_low_ is specified and timestamp for that key is less
|
|
|
|
// than *full_history_ts_low_. If it's not eligible for deletion, then we
|
|
|
|
// will output the SingleDelete. For Optimization 3 also, if
|
|
|
|
// full_history_ts_low_ is specified and timestamp for the key is less
|
|
|
|
// than *full_history_ts_low_ then only optimization will be applied.
|
2015-11-05 05:52:22 +01:00
|
|
|
|
|
|
|
// The easiest way to process a SingleDelete during iteration is to peek
|
|
|
|
// ahead at the next key.
|
2021-09-27 20:49:35 +02:00
|
|
|
const bool is_timestamp_eligible_for_gc =
|
|
|
|
(timestamp_size_ == 0 ||
|
|
|
|
(full_history_ts_low_ && cmp_with_history_ts_low_ < 0));
|
|
|
|
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
ParsedInternalKey next_ikey;
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
|
2015-11-05 05:52:22 +01:00
|
|
|
// Check whether the next key exists, is not corrupt, and is the same key
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
// as the single delete.
|
2021-05-21 01:06:12 +02:00
|
|
|
if (input_.Valid() &&
|
|
|
|
ParseInternalKey(input_.key(), &next_ikey, allow_data_in_errors_)
|
2020-10-28 18:11:13 +01:00
|
|
|
.ok() &&
|
2021-09-27 20:49:35 +02:00
|
|
|
cmp_->EqualWithoutTimestamp(ikey_.user_key, next_ikey.user_key)) {
|
2021-08-18 07:13:21 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
const Compaction* c =
|
|
|
|
compaction_ ? compaction_->real_compaction() : nullptr;
|
|
|
|
#endif
|
|
|
|
TEST_SYNC_POINT_CALLBACK(
|
|
|
|
"CompactionIterator::NextFromInput:SingleDelete:1",
|
|
|
|
const_cast<Compaction*>(c));
|
2015-11-05 05:52:22 +01:00
|
|
|
// Check whether the next key belongs to the same snapshot as the
|
|
|
|
// SingleDelete.
|
2019-01-16 18:48:10 +01:00
|
|
|
if (prev_snapshot == 0 ||
|
2021-07-28 23:52:35 +02:00
|
|
|
DefinitelyNotInSnapshot(next_ikey.sequence, prev_snapshot)) {
|
2021-08-18 07:13:21 +02:00
|
|
|
TEST_SYNC_POINT_CALLBACK(
|
|
|
|
"CompactionIterator::NextFromInput:SingleDelete:2", nullptr);
|
2015-11-05 05:52:22 +01:00
|
|
|
if (next_ikey.type == kTypeSingleDeletion) {
|
2021-09-27 20:49:35 +02:00
|
|
|
// We encountered two SingleDeletes for same key in a row. This
|
|
|
|
// could be due to unexpected user input. Skip the first
|
|
|
|
// SingleDelete and let the next iteration decide how to handle the
|
|
|
|
// second SingleDelete
|
2015-11-05 05:52:22 +01:00
|
|
|
|
|
|
|
// First SingleDelete has been skipped since we already called
|
2021-05-21 01:06:12 +02:00
|
|
|
// input_.Next().
|
2015-11-05 05:52:22 +01:00
|
|
|
++iter_stats_.num_record_drop_obsolete;
|
2016-08-16 17:21:43 +02:00
|
|
|
++iter_stats_.num_single_del_mismatch;
|
2021-09-27 20:49:35 +02:00
|
|
|
} else if (!is_timestamp_eligible_for_gc) {
|
|
|
|
// We cannot drop the SingleDelete as timestamp is enabled, and
|
|
|
|
// timestamp of this key is greater than or equal to
|
|
|
|
// *full_history_ts_low_. We will output the SingleDelete.
|
|
|
|
valid_ = true;
|
2017-12-12 20:02:07 +01:00
|
|
|
} else if (has_outputted_key_ ||
|
2021-07-28 23:52:35 +02:00
|
|
|
DefinitelyInSnapshot(ikey_.sequence,
|
|
|
|
earliest_write_conflict_snapshot_)) {
|
2015-11-05 05:52:22 +01:00
|
|
|
// Found a matching value, we can drop the single delete and the
|
|
|
|
// value. It is safe to drop both records since we've already
|
|
|
|
// outputted a key in this snapshot, or there is no earlier
|
|
|
|
// snapshot (Rule 2 above).
|
|
|
|
|
|
|
|
// Note: it doesn't matter whether the second key is a Put or if it
|
|
|
|
// is an unexpected Merge or Delete. We will compact it out
|
2016-08-16 17:21:43 +02:00
|
|
|
// either way. We will maintain counts of how many mismatches
|
|
|
|
// happened
|
2019-01-05 01:21:44 +01:00
|
|
|
if (next_ikey.type != kTypeValue &&
|
|
|
|
next_ikey.type != kTypeBlobIndex) {
|
2016-08-16 17:21:43 +02:00
|
|
|
++iter_stats_.num_single_del_mismatch;
|
|
|
|
}
|
|
|
|
|
2015-11-05 05:52:22 +01:00
|
|
|
++iter_stats_.num_record_drop_hidden;
|
|
|
|
++iter_stats_.num_record_drop_obsolete;
|
2021-05-21 01:06:12 +02:00
|
|
|
// Already called input_.Next() once. Call it a second time to
|
2015-11-05 05:52:22 +01:00
|
|
|
// skip past the second key.
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
2015-11-05 05:52:22 +01:00
|
|
|
} else {
|
|
|
|
// Found a matching value, but we cannot drop both keys since
|
|
|
|
// there is an earlier snapshot and we need to leave behind a record
|
|
|
|
// to know that a write happened in this snapshot (Rule 2 above).
|
|
|
|
// Clear the value and output the SingleDelete. (The value will be
|
|
|
|
// outputted on the next iteration.)
|
|
|
|
|
|
|
|
// Setting valid_ to true will output the current SingleDelete
|
|
|
|
valid_ = true;
|
|
|
|
|
|
|
|
// Set up the Put to be outputted in the next iteration.
|
|
|
|
// (Optimization 3).
|
|
|
|
clear_and_output_next_key_ = true;
|
2021-08-18 07:13:21 +02:00
|
|
|
TEST_SYNC_POINT_CALLBACK(
|
|
|
|
"CompactionIterator::NextFromInput:KeepSDForWW",
|
|
|
|
/*arg=*/nullptr);
|
2015-11-05 05:52:22 +01:00
|
|
|
}
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
} else {
|
|
|
|
// We hit the next snapshot without hitting a put, so the iterator
|
|
|
|
// returns the single delete.
|
|
|
|
valid_ = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We are at the end of the input, could not parse the next key, or hit
|
Compaction Support for Range Deletion
Summary:
This diff introduces RangeDelAggregator, which takes ownership of iterators
provided to it via AddTombstones(). The tombstones are organized in a two-level
map (snapshot stripe -> begin key -> tombstone). Tombstone creation avoids data
copy by holding Slices returned by the iterator, which remain valid thanks to pinning.
For compaction, we create a hierarchical range tombstone iterator with structure
matching the iterator over compaction input data. An aggregator based on that
iterator is used by CompactionIterator to determine which keys are covered by
range tombstones. In case of merge operand, the same aggregator is used by
MergeHelper. Upon finishing each file in the compaction, relevant range tombstones
are added to the output file's range tombstone metablock and file boundaries are
updated accordingly.
To check whether a key is covered by range tombstone, RangeDelAggregator::ShouldDelete()
considers tombstones in the key's snapshot stripe. When this function is used outside of
compaction, it also checks newer stripes, which can contain covering tombstones. Currently
the intra-stripe check involves a linear scan; however, in the future we plan to collapse ranges
within a stripe such that binary search can be used.
RangeDelAggregator::AddToBuilder() adds all range tombstones in the table's key-range
to a new table's range tombstone meta-block. Since range tombstones may fall in the gap
between files, we may need to extend some files' key-ranges. The strategy is (1) first file
extends as far left as possible and other files do not extend left, (2) all files extend right
until either the start of the next file or the end of the last range tombstone in the gap,
whichever comes first.
One other notable change is adding release/move semantics to ScopedArenaIterator
such that it can be used to transfer ownership of an arena-allocated iterator, similar to
how unique_ptr is used for malloc'd data.
Depends on D61473
Test Plan: compaction_iterator_test, mock_table, end-to-end tests in D63927
Reviewers: sdong, IslamAbdelRahman, wanning, yhchiang, lightmark
Reviewed By: lightmark
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D62205
2016-10-18 21:04:56 +02:00
|
|
|
// a different key. The iterator returns the single delete if the key
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
// possibly exists beyond the current output level. We set
|
|
|
|
// has_current_user_key to false so that if the iterator is at the next
|
|
|
|
// key, we do not compare it again against the previous key at the next
|
|
|
|
// iteration. If the next key is corrupt, we return before the
|
|
|
|
// comparison, so the value of has_current_user_key does not matter.
|
|
|
|
has_current_user_key_ = false;
|
2021-08-18 07:13:21 +02:00
|
|
|
if (compaction_ != nullptr &&
|
|
|
|
DefinitelyInSnapshot(ikey_.sequence, earliest_snapshot_) &&
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
compaction_->KeyNotExistsBeyondOutputLevel(ikey_.user_key,
|
2021-09-27 20:49:35 +02:00
|
|
|
&level_ptrs_) &&
|
|
|
|
is_timestamp_eligible_for_gc) {
|
2015-11-05 05:52:22 +01:00
|
|
|
// Key doesn't exist outside of this range.
|
|
|
|
// Can compact out this SingleDelete.
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
++iter_stats_.num_record_drop_obsolete;
|
2016-08-16 17:21:43 +02:00
|
|
|
++iter_stats_.num_single_del_fallthru;
|
2017-08-19 23:01:25 +02:00
|
|
|
if (!bottommost_level_) {
|
|
|
|
++iter_stats_.num_optimized_del_drop_obsolete;
|
|
|
|
}
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
} else {
|
2015-11-05 05:52:22 +01:00
|
|
|
// Output SingleDelete
|
Support for SingleDelete()
Summary:
This patch fixes #7460559. It introduces SingleDelete as a new database
operation. This operation can be used to delete keys that were never
overwritten (no put following another put of the same key). If an overwritten
key is single deleted the behavior is undefined. Single deletion of a
non-existent key has no effect but multiple consecutive single deletions are
not allowed (see limitations).
In contrast to the conventional Delete() operation, the deletion entry is
removed along with the value when the two are lined up in a compaction. Note:
The semantics are similar to @igor's prototype that allowed to have this
behavior on the granularity of a column family (
https://reviews.facebook.net/D42093 ). This new patch, however, is more
aggressive when it comes to removing tombstones: It removes the SingleDelete
together with the value whenever there is no snapshot between them while the
older patch only did this when the sequence number of the deletion was older
than the earliest snapshot.
Most of the complex additions are in the Compaction Iterator, all other changes
should be relatively straightforward. The patch also includes basic support for
single deletions in db_stress and db_bench.
Limitations:
- Not compatible with cuckoo hash tables
- Single deletions cannot be used in combination with merges and normal
deletions on the same key (other keys are not affected by this)
- Consecutive single deletions are currently not allowed (and older version of
this patch supported this so it could be resurrected if needed)
Test Plan: make all check
Reviewers: yhchiang, sdong, rven, anthony, yoshinorim, igor
Reviewed By: igor
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D43179
2015-09-17 20:42:56 +02:00
|
|
|
valid_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid_) {
|
|
|
|
at_next_ = true;
|
|
|
|
}
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
} else if (last_snapshot == current_user_key_snapshot_ ||
|
|
|
|
(last_snapshot > 0 &&
|
|
|
|
last_snapshot < current_user_key_snapshot_)) {
|
2015-09-10 23:35:25 +02:00
|
|
|
// If the earliest snapshot is which this key is visible in
|
|
|
|
// is the same as the visibility of a previous instance of the
|
|
|
|
// same key, then this kv is not visible in any snapshot.
|
|
|
|
// Hidden by an newer entry for same user key
|
Use SST files for Transaction conflict detection
Summary:
Currently, transactions can fail even if there is no actual write conflict. This is due to relying on only the memtables to check for write-conflicts. Users have to tune memtable settings to try to avoid this, but it's hard to figure out exactly how to tune these settings.
With this diff, TransactionDB will use both memtables and SST files to determine if there are any write conflicts. This relies on the fact that BlockBasedTable stores sequence numbers for all writes that happen after any open snapshot. Also, D50295 is needed to prevent SingleDelete from disappearing writes (the TODOs in this test code will be fixed once the other diff is approved and merged).
Note that Optimistic transactions will still rely on tuning memtable settings as we do not want to read from SST while on the write thread. Also, memtable settings can still be used to reduce how often TransactionDB needs to read SST files.
Test Plan: unit tests, db bench
Reviewers: rven, yhchiang, kradhakrishnan, IslamAbdelRahman, sdong
Reviewed By: sdong
Subscribers: dhruba, leveldb, yoshinorim
Differential Revision: https://reviews.facebook.net/D50475
2015-10-16 01:37:15 +02:00
|
|
|
//
|
|
|
|
// Note: Dropping this key will not affect TransactionDB write-conflict
|
|
|
|
// checking since there has already been a record returned for this key
|
|
|
|
// in this snapshot.
|
2015-09-10 23:35:25 +02:00
|
|
|
assert(last_sequence >= current_user_key_sequence_);
|
2019-10-30 21:47:08 +01:00
|
|
|
if (last_sequence < current_user_key_sequence_) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"last_sequence (%" PRIu64
|
|
|
|
") < current_user_key_sequence_ (%" PRIu64 ")",
|
|
|
|
last_sequence, current_user_key_sequence_);
|
|
|
|
}
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
++iter_stats_.num_record_drop_hidden; // rule (A)
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
} else if (compaction_ != nullptr &&
|
|
|
|
(ikey_.type == kTypeDeletion ||
|
|
|
|
(ikey_.type == kTypeDeletionWithTimestamp &&
|
|
|
|
cmp_with_history_ts_low_ < 0)) &&
|
2021-08-18 07:13:21 +02:00
|
|
|
DefinitelyInSnapshot(ikey_.sequence, earliest_snapshot_) &&
|
Added support for differential snapshots
Summary:
The motivation for this PR is to add to RocksDB support for differential (incremental) snapshots, as snapshot of the DB changes between two points in time (one can think of it as diff between to sequence numbers, or the diff D which can be thought of as an SST file or just set of KVs that can be applied to sequence number S1 to get the database to the state at sequence number S2).
This feature would be useful for various distributed storages layers built on top of RocksDB, as it should help reduce resources (time and network bandwidth) needed to recover and rebuilt DB instances as replicas in the context of distributed storages.
From the API standpoint that would like client app requesting iterator between (start seqnum) and current DB state, and reading the "diff".
This is a very draft PR for initial review in the discussion on the approach, i'm going to rework some parts and keep updating the PR.
For now, what's done here according to initial discussions:
Preserving deletes:
- We want to be able to optionally preserve recent deletes for some defined period of time, so that if a delete came in recently and might need to be included in the next incremental snapshot it would't get dropped by a compaction. This is done by adding new param to Options (preserve deletes flag) and new variable to DB Impl where we keep track of the sequence number after which we don't want to drop tombstones, even if they are otherwise eligible for deletion.
- I also added a new API call for clients to be able to advance this cutoff seqnum after which we drop deletes; i assume it's more flexible to let clients control this, since otherwise we'd need to keep some kind of timestamp < -- > seqnum mapping inside the DB, which sounds messy and painful to support. Clients could make use of it by periodically calling GetLatestSequenceNumber(), noting the timestamp, doing some calculation and figuring out by how much we need to advance the cutoff seqnum.
- Compaction codepath in compaction_iterator.cc has been modified to avoid dropping tombstones with seqnum > cutoff seqnum.
Iterator changes:
- couple params added to ReadOptions, to optionally allow client to request internal keys instead of user keys (so that client can get the latest value of a key, be it delete marker or a put), as well as min timestamp and min seqnum.
TableCache changes:
- I modified table_cache code to be able to quickly exclude SST files from iterators heep if creation_time on the file is less then iter_start_ts as passed in ReadOptions. That would help a lot in some DB settings (like reading very recent data only or using FIFO compactions), but not so much for universal compaction with more or less long iterator time span.
What's left:
- Still looking at how to best plug that inside DBIter codepath. So far it seems that FindNextUserKeyInternal only parses values as UserKeys, and iter->key() call generally returns user key. Can we add new API to DBIter as internal_key(), and modify this internal method to optionally set saved_key_ to point to the full internal key? I don't need to store actual seqnum there, but I do need to store type.
Closes https://github.com/facebook/rocksdb/pull/2999
Differential Revision: D6175602
Pulled By: mikhail-antonov
fbshipit-source-id: c779a6696ee2d574d86c69cec866a3ae095aa900
2017-11-02 02:43:29 +01:00
|
|
|
ikeyNotNeededForIncrementalSnapshot() &&
|
2015-09-10 23:35:25 +02:00
|
|
|
compaction_->KeyNotExistsBeyondOutputLevel(ikey_.user_key,
|
|
|
|
&level_ptrs_)) {
|
|
|
|
// TODO(noetzli): This is the only place where we use compaction_
|
|
|
|
// (besides the constructor). We should probably get rid of this
|
|
|
|
// dependency and find a way to do similar filtering during flushes.
|
|
|
|
//
|
|
|
|
// For this user key:
|
|
|
|
// (1) there is no data in higher levels
|
|
|
|
// (2) data in lower levels will have larger sequence numbers
|
|
|
|
// (3) data in layers that are being compacted here and have
|
|
|
|
// smaller sequence numbers will be dropped in the next
|
|
|
|
// few iterations of this loop (by rule (A) above).
|
|
|
|
// Therefore this deletion marker is obsolete and can be dropped.
|
Use SST files for Transaction conflict detection
Summary:
Currently, transactions can fail even if there is no actual write conflict. This is due to relying on only the memtables to check for write-conflicts. Users have to tune memtable settings to try to avoid this, but it's hard to figure out exactly how to tune these settings.
With this diff, TransactionDB will use both memtables and SST files to determine if there are any write conflicts. This relies on the fact that BlockBasedTable stores sequence numbers for all writes that happen after any open snapshot. Also, D50295 is needed to prevent SingleDelete from disappearing writes (the TODOs in this test code will be fixed once the other diff is approved and merged).
Note that Optimistic transactions will still rely on tuning memtable settings as we do not want to read from SST while on the write thread. Also, memtable settings can still be used to reduce how often TransactionDB needs to read SST files.
Test Plan: unit tests, db bench
Reviewers: rven, yhchiang, kradhakrishnan, IslamAbdelRahman, sdong
Reviewed By: sdong
Subscribers: dhruba, leveldb, yoshinorim
Differential Revision: https://reviews.facebook.net/D50475
2015-10-16 01:37:15 +02:00
|
|
|
//
|
|
|
|
// Note: Dropping this Delete will not affect TransactionDB
|
|
|
|
// write-conflict checking since it is earlier than any snapshot.
|
2018-02-06 23:06:44 +01:00
|
|
|
//
|
|
|
|
// It seems that we can also drop deletion later than earliest snapshot
|
|
|
|
// given that:
|
|
|
|
// (1) The deletion is earlier than earliest_write_conflict_snapshot, and
|
|
|
|
// (2) No value exist earlier than the deletion.
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
//
|
|
|
|
// Note also that a deletion marker of type kTypeDeletionWithTimestamp
|
|
|
|
// will be treated as a different user key unless the timestamp is older
|
|
|
|
// than *full_history_ts_low_.
|
2015-09-10 23:35:25 +02:00
|
|
|
++iter_stats_.num_record_drop_obsolete;
|
2017-08-19 23:01:25 +02:00
|
|
|
if (!bottommost_level_) {
|
|
|
|
++iter_stats_.num_optimized_del_drop_obsolete;
|
|
|
|
}
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
} else if ((ikey_.type == kTypeDeletion ||
|
|
|
|
(ikey_.type == kTypeDeletionWithTimestamp &&
|
|
|
|
cmp_with_history_ts_low_ < 0)) &&
|
|
|
|
bottommost_level_ && ikeyNotNeededForIncrementalSnapshot()) {
|
2018-08-24 23:57:37 +02:00
|
|
|
// Handle the case where we have a delete key at the bottom most level
|
|
|
|
// We can skip outputting the key iff there are no subsequent puts for this
|
|
|
|
// key
|
2020-09-12 02:44:06 +02:00
|
|
|
assert(!compaction_ || compaction_->KeyNotExistsBeyondOutputLevel(
|
|
|
|
ikey_.user_key, &level_ptrs_));
|
2018-08-24 23:57:37 +02:00
|
|
|
ParsedInternalKey next_ikey;
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
2021-08-18 07:13:21 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
const Compaction* c =
|
|
|
|
compaction_ ? compaction_->real_compaction() : nullptr;
|
|
|
|
#endif
|
|
|
|
TEST_SYNC_POINT_CALLBACK(
|
|
|
|
"CompactionIterator::NextFromInput:BottommostDelete:1",
|
|
|
|
const_cast<Compaction*>(c));
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
// Skip over all versions of this key that happen to occur in the same
|
|
|
|
// snapshot range as the delete.
|
|
|
|
//
|
|
|
|
// Note that a deletion marker of type kTypeDeletionWithTimestamp will be
|
|
|
|
// considered to have a different user key unless the timestamp is older
|
|
|
|
// than *full_history_ts_low_.
|
2020-09-12 02:44:06 +02:00
|
|
|
while (!IsPausingManualCompaction() && !IsShuttingDown() &&
|
2021-05-21 01:06:12 +02:00
|
|
|
input_.Valid() &&
|
|
|
|
(ParseInternalKey(input_.key(), &next_ikey, allow_data_in_errors_)
|
2020-10-28 18:11:13 +01:00
|
|
|
.ok()) &&
|
2021-03-10 20:13:55 +01:00
|
|
|
cmp_->EqualWithoutTimestamp(ikey_.user_key, next_ikey.user_key) &&
|
2019-01-16 18:48:10 +01:00
|
|
|
(prev_snapshot == 0 ||
|
2021-07-28 23:52:35 +02:00
|
|
|
DefinitelyNotInSnapshot(next_ikey.sequence, prev_snapshot))) {
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
2018-08-24 23:57:37 +02:00
|
|
|
}
|
|
|
|
// If you find you still need to output a row with this key, we need to output the
|
|
|
|
// delete too
|
2021-05-21 01:06:12 +02:00
|
|
|
if (input_.Valid() &&
|
|
|
|
(ParseInternalKey(input_.key(), &next_ikey, allow_data_in_errors_)
|
2020-10-28 18:11:13 +01:00
|
|
|
.ok()) &&
|
2021-03-10 20:13:55 +01:00
|
|
|
cmp_->EqualWithoutTimestamp(ikey_.user_key, next_ikey.user_key)) {
|
2018-08-24 23:57:37 +02:00
|
|
|
valid_ = true;
|
|
|
|
at_next_ = true;
|
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
} else if (ikey_.type == kTypeMerge) {
|
|
|
|
if (!merge_helper_->HasOperator()) {
|
|
|
|
status_ = Status::InvalidArgument(
|
|
|
|
"merge_operator is not properly initialized.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Introduce FullMergeV2 (eliminate memcpy from merge operators)
Summary:
This diff update the code to pin the merge operator operands while the merge operation is done, so that we can eliminate the memcpy cost, to do that we need a new public API for FullMerge that replace the std::deque<std::string> with std::vector<Slice>
This diff is stacked on top of D56493 and D56511
In this diff we
- Update FullMergeV2 arguments to be encapsulated in MergeOperationInput and MergeOperationOutput which will make it easier to add new arguments in the future
- Replace std::deque<std::string> with std::vector<Slice> to pass operands
- Replace MergeContext std::deque with std::vector (based on a simple benchmark I ran https://gist.github.com/IslamAbdelRahman/78fc86c9ab9f52b1df791e58943fb187)
- Allow FullMergeV2 output to be an existing operand
```
[Everything in Memtable | 10K operands | 10 KB each | 1 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="mergerandom,readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --merge_keys=10000 --num=10000 --disable_auto_compactions --value_size=10240 --write_buffer_size=1000000000
[FullMergeV2]
readseq : 0.607 micros/op 1648235 ops/sec; 16121.2 MB/s
readseq : 0.478 micros/op 2091546 ops/sec; 20457.2 MB/s
readseq : 0.252 micros/op 3972081 ops/sec; 38850.5 MB/s
readseq : 0.237 micros/op 4218328 ops/sec; 41259.0 MB/s
readseq : 0.247 micros/op 4043927 ops/sec; 39553.2 MB/s
[master]
readseq : 3.935 micros/op 254140 ops/sec; 2485.7 MB/s
readseq : 3.722 micros/op 268657 ops/sec; 2627.7 MB/s
readseq : 3.149 micros/op 317605 ops/sec; 3106.5 MB/s
readseq : 3.125 micros/op 320024 ops/sec; 3130.1 MB/s
readseq : 4.075 micros/op 245374 ops/sec; 2400.0 MB/s
```
```
[Everything in Memtable | 10K operands | 10 KB each | 10 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="mergerandom,readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --merge_keys=1000 --num=10000 --disable_auto_compactions --value_size=10240 --write_buffer_size=1000000000
[FullMergeV2]
readseq : 3.472 micros/op 288018 ops/sec; 2817.1 MB/s
readseq : 2.304 micros/op 434027 ops/sec; 4245.2 MB/s
readseq : 1.163 micros/op 859845 ops/sec; 8410.0 MB/s
readseq : 1.192 micros/op 838926 ops/sec; 8205.4 MB/s
readseq : 1.250 micros/op 800000 ops/sec; 7824.7 MB/s
[master]
readseq : 24.025 micros/op 41623 ops/sec; 407.1 MB/s
readseq : 18.489 micros/op 54086 ops/sec; 529.0 MB/s
readseq : 18.693 micros/op 53495 ops/sec; 523.2 MB/s
readseq : 23.621 micros/op 42335 ops/sec; 414.1 MB/s
readseq : 18.775 micros/op 53262 ops/sec; 521.0 MB/s
```
```
[Everything in Block cache | 10K operands | 10 KB each | 1 operand per key]
[FullMergeV2]
$ DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --num=100000 --db="/dev/shm/merge-random-10K-10KB" --cache_size=1000000000 --use_existing_db --disable_auto_compactions
readseq : 14.741 micros/op 67837 ops/sec; 663.5 MB/s
readseq : 1.029 micros/op 971446 ops/sec; 9501.6 MB/s
readseq : 0.974 micros/op 1026229 ops/sec; 10037.4 MB/s
readseq : 0.965 micros/op 1036080 ops/sec; 10133.8 MB/s
readseq : 0.943 micros/op 1060657 ops/sec; 10374.2 MB/s
[master]
readseq : 16.735 micros/op 59755 ops/sec; 584.5 MB/s
readseq : 3.029 micros/op 330151 ops/sec; 3229.2 MB/s
readseq : 3.136 micros/op 318883 ops/sec; 3119.0 MB/s
readseq : 3.065 micros/op 326245 ops/sec; 3191.0 MB/s
readseq : 3.014 micros/op 331813 ops/sec; 3245.4 MB/s
```
```
[Everything in Block cache | 10K operands | 10 KB each | 10 operand per key]
DEBUG_LEVEL=0 make db_bench -j64 && ./db_bench --benchmarks="readseq,readseq,readseq,readseq,readseq" --merge_operator="max" --num=100000 --db="/dev/shm/merge-random-10-operands-10K-10KB" --cache_size=1000000000 --use_existing_db --disable_auto_compactions
[FullMergeV2]
readseq : 24.325 micros/op 41109 ops/sec; 402.1 MB/s
readseq : 1.470 micros/op 680272 ops/sec; 6653.7 MB/s
readseq : 1.231 micros/op 812347 ops/sec; 7945.5 MB/s
readseq : 1.091 micros/op 916590 ops/sec; 8965.1 MB/s
readseq : 1.109 micros/op 901713 ops/sec; 8819.6 MB/s
[master]
readseq : 27.257 micros/op 36687 ops/sec; 358.8 MB/s
readseq : 4.443 micros/op 225073 ops/sec; 2201.4 MB/s
readseq : 5.830 micros/op 171526 ops/sec; 1677.7 MB/s
readseq : 4.173 micros/op 239635 ops/sec; 2343.8 MB/s
readseq : 4.150 micros/op 240963 ops/sec; 2356.8 MB/s
```
Test Plan: COMPILE_WITH_ASAN=1 make check -j64
Reviewers: yhchiang, andrewkr, sdong
Reviewed By: sdong
Subscribers: lovro, andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D57075
2016-07-20 18:49:03 +02:00
|
|
|
pinned_iters_mgr_.StartPinning();
|
2021-06-25 03:10:32 +02:00
|
|
|
Version* version = compaction_ ? compaction_->input_version() : nullptr;
|
|
|
|
|
2015-09-10 23:35:25 +02:00
|
|
|
// We know the merge type entry is not hidden, otherwise we would
|
|
|
|
// have hit (A)
|
|
|
|
// We encapsulate the merge related state machine in a different
|
|
|
|
// object to minimize change to the existing flow.
|
2021-06-25 03:10:32 +02:00
|
|
|
Status s = merge_helper_->MergeUntil(&input_, range_del_agg_,
|
|
|
|
prev_snapshot, bottommost_level_,
|
|
|
|
allow_data_in_errors_, version);
|
2015-09-10 23:35:25 +02:00
|
|
|
merge_out_iter_.SeekToFirst();
|
|
|
|
|
2017-01-12 00:01:21 +01:00
|
|
|
if (!s.ok() && !s.IsMergeInProgress()) {
|
|
|
|
status_ = s;
|
|
|
|
return;
|
|
|
|
} else if (merge_out_iter_.Valid()) {
|
Compaction filter on merge operands
Summary:
Since Andres' internship is over, I took over https://reviews.facebook.net/D42555 and rebased and simplified it a bit.
The behavior in this diff is a bit simpler than in D42555:
* only merge operators are passed through FilterMergeValue(). If fitler function returns true, the merge operator is ignored
* compaction filter is *not* called on: 1) results of merge operations and 2) base values that are getting merged with merge operands (the second case was also true in previous diff)
Do we also need a compaction filter to get called on merge results?
Test Plan: make && make check
Reviewers: lovro, tnovak, rven, yhchiang, sdong
Reviewed By: sdong
Subscribers: noetzli, kolmike, leveldb, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D47847
2015-10-07 18:30:03 +02:00
|
|
|
// NOTE: key, value, and ikey_ refer to old entries.
|
|
|
|
// These will be correctly set below.
|
|
|
|
key_ = merge_out_iter_.key();
|
|
|
|
value_ = merge_out_iter_.value();
|
2020-10-28 18:11:13 +01:00
|
|
|
pik_status = ParseInternalKey(key_, &ikey_, allow_data_in_errors_);
|
Compaction filter on merge operands
Summary:
Since Andres' internship is over, I took over https://reviews.facebook.net/D42555 and rebased and simplified it a bit.
The behavior in this diff is a bit simpler than in D42555:
* only merge operators are passed through FilterMergeValue(). If fitler function returns true, the merge operator is ignored
* compaction filter is *not* called on: 1) results of merge operations and 2) base values that are getting merged with merge operands (the second case was also true in previous diff)
Do we also need a compaction filter to get called on merge results?
Test Plan: make && make check
Reviewers: lovro, tnovak, rven, yhchiang, sdong
Reviewed By: sdong
Subscribers: noetzli, kolmike, leveldb, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D47847
2015-10-07 18:30:03 +02:00
|
|
|
// MergeUntil stops when it encounters a corrupt key and does not
|
|
|
|
// include them in the result, so we expect the keys here to valid.
|
2020-10-28 18:11:13 +01:00
|
|
|
assert(pik_status.ok());
|
|
|
|
if (!pik_status.ok()) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_, "Invalid key in compaction. %s",
|
|
|
|
pik_status.getState());
|
2019-10-30 21:47:08 +01:00
|
|
|
}
|
Compaction filter on merge operands
Summary:
Since Andres' internship is over, I took over https://reviews.facebook.net/D42555 and rebased and simplified it a bit.
The behavior in this diff is a bit simpler than in D42555:
* only merge operators are passed through FilterMergeValue(). If fitler function returns true, the merge operator is ignored
* compaction filter is *not* called on: 1) results of merge operations and 2) base values that are getting merged with merge operands (the second case was also true in previous diff)
Do we also need a compaction filter to get called on merge results?
Test Plan: make && make check
Reviewers: lovro, tnovak, rven, yhchiang, sdong
Reviewed By: sdong
Subscribers: noetzli, kolmike, leveldb, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D47847
2015-10-07 18:30:03 +02:00
|
|
|
// Keep current_key_ in sync.
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
2017-04-04 23:17:16 +02:00
|
|
|
key_ = current_key_.GetInternalKey();
|
Compaction filter on merge operands
Summary:
Since Andres' internship is over, I took over https://reviews.facebook.net/D42555 and rebased and simplified it a bit.
The behavior in this diff is a bit simpler than in D42555:
* only merge operators are passed through FilterMergeValue(). If fitler function returns true, the merge operator is ignored
* compaction filter is *not* called on: 1) results of merge operations and 2) base values that are getting merged with merge operands (the second case was also true in previous diff)
Do we also need a compaction filter to get called on merge results?
Test Plan: make && make check
Reviewers: lovro, tnovak, rven, yhchiang, sdong
Reviewed By: sdong
Subscribers: noetzli, kolmike, leveldb, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D47847
2015-10-07 18:30:03 +02:00
|
|
|
ikey_.user_key = current_key_.GetUserKey();
|
|
|
|
valid_ = true;
|
|
|
|
} else {
|
|
|
|
// all merge operands were filtered out. reset the user key, since the
|
|
|
|
// batch consumed by the merge operator should not shadow any keys
|
|
|
|
// coming after the merges
|
|
|
|
has_current_user_key_ = false;
|
2016-08-11 20:54:17 +02:00
|
|
|
pinned_iters_mgr_.ReleasePinnedData();
|
2016-12-06 00:07:01 +01:00
|
|
|
|
|
|
|
if (merge_helper_->FilteredUntil(&skip_until)) {
|
|
|
|
need_skip = true;
|
|
|
|
}
|
Compaction filter on merge operands
Summary:
Since Andres' internship is over, I took over https://reviews.facebook.net/D42555 and rebased and simplified it a bit.
The behavior in this diff is a bit simpler than in D42555:
* only merge operators are passed through FilterMergeValue(). If fitler function returns true, the merge operator is ignored
* compaction filter is *not* called on: 1) results of merge operations and 2) base values that are getting merged with merge operands (the second case was also true in previous diff)
Do we also need a compaction filter to get called on merge results?
Test Plan: make && make check
Reviewers: lovro, tnovak, rven, yhchiang, sdong
Reviewed By: sdong
Subscribers: noetzli, kolmike, leveldb, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D47847
2015-10-07 18:30:03 +02:00
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
} else {
|
Compaction Support for Range Deletion
Summary:
This diff introduces RangeDelAggregator, which takes ownership of iterators
provided to it via AddTombstones(). The tombstones are organized in a two-level
map (snapshot stripe -> begin key -> tombstone). Tombstone creation avoids data
copy by holding Slices returned by the iterator, which remain valid thanks to pinning.
For compaction, we create a hierarchical range tombstone iterator with structure
matching the iterator over compaction input data. An aggregator based on that
iterator is used by CompactionIterator to determine which keys are covered by
range tombstones. In case of merge operand, the same aggregator is used by
MergeHelper. Upon finishing each file in the compaction, relevant range tombstones
are added to the output file's range tombstone metablock and file boundaries are
updated accordingly.
To check whether a key is covered by range tombstone, RangeDelAggregator::ShouldDelete()
considers tombstones in the key's snapshot stripe. When this function is used outside of
compaction, it also checks newer stripes, which can contain covering tombstones. Currently
the intra-stripe check involves a linear scan; however, in the future we plan to collapse ranges
within a stripe such that binary search can be used.
RangeDelAggregator::AddToBuilder() adds all range tombstones in the table's key-range
to a new table's range tombstone meta-block. Since range tombstones may fall in the gap
between files, we may need to extend some files' key-ranges. The strategy is (1) first file
extends as far left as possible and other files do not extend left, (2) all files extend right
until either the start of the next file or the end of the last range tombstone in the gap,
whichever comes first.
One other notable change is adding release/move semantics to ScopedArenaIterator
such that it can be used to transfer ownership of an arena-allocated iterator, similar to
how unique_ptr is used for malloc'd data.
Depends on D61473
Test Plan: compaction_iterator_test, mock_table, end-to-end tests in D63927
Reviewers: sdong, IslamAbdelRahman, wanning, yhchiang, lightmark
Reviewed By: lightmark
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D62205
2016-10-18 21:04:56 +02:00
|
|
|
// 1. new user key -OR-
|
|
|
|
// 2. different snapshot stripe
|
Maintain position in range deletions map
Summary:
When deletion-collapsing mode is enabled (i.e., for DBIter/CompactionIterator), we maintain position in the tombstone maps across calls to ShouldDelete(). Since iterators often access keys sequentially (or reverse-sequentially), scanning forward/backward from the last position can be faster than binary-searching the map for every key.
- When Next() is invoked on an iterator, we use kForwardTraversal to scan forwards, if needed, until arriving at the range deletion containing the next key.
- Similarly for Prev(), we use kBackwardTraversal to scan backwards in the range deletion map.
- When the iterator seeks, we use kBinarySearch for repositioning
- After tombstones are added or before the first ShouldDelete() invocation, the current position is set to invalid, which forces kBinarySearch to be used.
- Non-iterator users (i.e., Get()) use kFullScan, which has the same behavior as before---scan the whole map for every key passed to ShouldDelete().
Closes https://github.com/facebook/rocksdb/pull/1701
Differential Revision: D4350318
Pulled By: ajkr
fbshipit-source-id: 5129b76
2017-01-05 19:22:46 +01:00
|
|
|
bool should_delete = range_del_agg_->ShouldDelete(
|
Range deletion performance improvements + cleanup (#4014)
Summary:
This fixes the same performance issue that #3992 fixes but with much more invasive cleanup.
I'm more excited about this PR because it paves the way for fixing another problem we uncovered at Cockroach where range deletion tombstones can cause massive compactions. For example, suppose L4 contains deletions from [a, c) and [x, z) and no other keys, and L5 is entirely empty. L6, however, is full of data. When compacting L4 -> L5, we'll end up with one file that spans, massively, from [a, z). When we go to compact L5 -> L6, we'll have to rewrite all of L6! If, instead of range deletions in L4, we had keys a, b, x, y, and z, RocksDB would have been smart enough to create two files in L5: one for a and b and another for x, y, and z.
With the changes in this PR, it will be possible to adjust the compaction logic to split tombstones/start new output files when they would span too many files in the grandparent level.
ajkr please take a look when you have a minute!
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4014
Differential Revision: D8773253
Pulled By: ajkr
fbshipit-source-id: ec62fa85f648fdebe1380b83ed997f9baec35677
2018-07-12 23:28:10 +02:00
|
|
|
key_, RangeDelPositioningMode::kForwardTraversal);
|
Compaction Support for Range Deletion
Summary:
This diff introduces RangeDelAggregator, which takes ownership of iterators
provided to it via AddTombstones(). The tombstones are organized in a two-level
map (snapshot stripe -> begin key -> tombstone). Tombstone creation avoids data
copy by holding Slices returned by the iterator, which remain valid thanks to pinning.
For compaction, we create a hierarchical range tombstone iterator with structure
matching the iterator over compaction input data. An aggregator based on that
iterator is used by CompactionIterator to determine which keys are covered by
range tombstones. In case of merge operand, the same aggregator is used by
MergeHelper. Upon finishing each file in the compaction, relevant range tombstones
are added to the output file's range tombstone metablock and file boundaries are
updated accordingly.
To check whether a key is covered by range tombstone, RangeDelAggregator::ShouldDelete()
considers tombstones in the key's snapshot stripe. When this function is used outside of
compaction, it also checks newer stripes, which can contain covering tombstones. Currently
the intra-stripe check involves a linear scan; however, in the future we plan to collapse ranges
within a stripe such that binary search can be used.
RangeDelAggregator::AddToBuilder() adds all range tombstones in the table's key-range
to a new table's range tombstone meta-block. Since range tombstones may fall in the gap
between files, we may need to extend some files' key-ranges. The strategy is (1) first file
extends as far left as possible and other files do not extend left, (2) all files extend right
until either the start of the next file or the end of the last range tombstone in the gap,
whichever comes first.
One other notable change is adding release/move semantics to ScopedArenaIterator
such that it can be used to transfer ownership of an arena-allocated iterator, similar to
how unique_ptr is used for malloc'd data.
Depends on D61473
Test Plan: compaction_iterator_test, mock_table, end-to-end tests in D63927
Reviewers: sdong, IslamAbdelRahman, wanning, yhchiang, lightmark
Reviewed By: lightmark
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D62205
2016-10-18 21:04:56 +02:00
|
|
|
if (should_delete) {
|
2016-11-28 20:44:40 +01:00
|
|
|
++iter_stats_.num_record_drop_hidden;
|
|
|
|
++iter_stats_.num_record_drop_range_del;
|
2021-05-21 01:06:12 +02:00
|
|
|
AdvanceInputIter();
|
Compaction Support for Range Deletion
Summary:
This diff introduces RangeDelAggregator, which takes ownership of iterators
provided to it via AddTombstones(). The tombstones are organized in a two-level
map (snapshot stripe -> begin key -> tombstone). Tombstone creation avoids data
copy by holding Slices returned by the iterator, which remain valid thanks to pinning.
For compaction, we create a hierarchical range tombstone iterator with structure
matching the iterator over compaction input data. An aggregator based on that
iterator is used by CompactionIterator to determine which keys are covered by
range tombstones. In case of merge operand, the same aggregator is used by
MergeHelper. Upon finishing each file in the compaction, relevant range tombstones
are added to the output file's range tombstone metablock and file boundaries are
updated accordingly.
To check whether a key is covered by range tombstone, RangeDelAggregator::ShouldDelete()
considers tombstones in the key's snapshot stripe. When this function is used outside of
compaction, it also checks newer stripes, which can contain covering tombstones. Currently
the intra-stripe check involves a linear scan; however, in the future we plan to collapse ranges
within a stripe such that binary search can be used.
RangeDelAggregator::AddToBuilder() adds all range tombstones in the table's key-range
to a new table's range tombstone meta-block. Since range tombstones may fall in the gap
between files, we may need to extend some files' key-ranges. The strategy is (1) first file
extends as far left as possible and other files do not extend left, (2) all files extend right
until either the start of the next file or the end of the last range tombstone in the gap,
whichever comes first.
One other notable change is adding release/move semantics to ScopedArenaIterator
such that it can be used to transfer ownership of an arena-allocated iterator, similar to
how unique_ptr is used for malloc'd data.
Depends on D61473
Test Plan: compaction_iterator_test, mock_table, end-to-end tests in D63927
Reviewers: sdong, IslamAbdelRahman, wanning, yhchiang, lightmark
Reviewed By: lightmark
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D62205
2016-10-18 21:04:56 +02:00
|
|
|
} else {
|
|
|
|
valid_ = true;
|
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
2016-12-01 16:00:17 +01:00
|
|
|
|
|
|
|
if (need_skip) {
|
2021-05-21 01:06:12 +02:00
|
|
|
SkipUntil(skip_until);
|
2016-12-01 16:00:17 +01:00
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
2017-01-12 00:01:21 +01:00
|
|
|
|
|
|
|
if (!valid_ && IsShuttingDown()) {
|
|
|
|
status_ = Status::ShutdownInProgress();
|
|
|
|
}
|
2019-09-17 06:00:13 +02:00
|
|
|
|
|
|
|
if (IsPausingManualCompaction()) {
|
|
|
|
status_ = Status::Incomplete(Status::SubCode::kManualCompactionPaused);
|
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
|
|
|
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
bool CompactionIterator::ExtractLargeValueIfNeededImpl() {
|
|
|
|
if (!blob_file_builder_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
blob_index_.clear();
|
|
|
|
const Status s = blob_file_builder_->Add(user_key(), value_, &blob_index_);
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
status_ = s;
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blob_index_.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
value_ = blob_index_;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompactionIterator::ExtractLargeValueIfNeeded() {
|
|
|
|
assert(ikey_.type == kTypeValue);
|
|
|
|
|
|
|
|
if (!ExtractLargeValueIfNeededImpl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ikey_.type = kTypeBlobIndex;
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompactionIterator::GarbageCollectBlobIfNeeded() {
|
|
|
|
assert(ikey_.type == kTypeBlobIndex);
|
|
|
|
|
|
|
|
if (!compaction_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GC for integrated BlobDB
|
|
|
|
if (compaction_->enable_blob_garbage_collection()) {
|
|
|
|
BlobIndex blob_index;
|
|
|
|
|
|
|
|
{
|
|
|
|
const Status s = blob_index.DecodeFrom(value_);
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
status_ = s;
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blob_index.IsInlined() || blob_index.HasTTL()) {
|
|
|
|
status_ = Status::Corruption("Unexpected TTL/inlined blob index");
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blob_index.file_number() >=
|
|
|
|
blob_garbage_collection_cutoff_file_number_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Version* const version = compaction_->input_version();
|
|
|
|
assert(version);
|
|
|
|
|
2021-03-04 09:42:11 +01:00
|
|
|
uint64_t bytes_read = 0;
|
|
|
|
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
{
|
2021-03-04 09:42:11 +01:00
|
|
|
const Status s = version->GetBlob(ReadOptions(), user_key(), blob_index,
|
|
|
|
&blob_value_, &bytes_read);
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
status_ = s;
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-04 09:42:11 +01:00
|
|
|
++iter_stats_.num_blobs_read;
|
|
|
|
iter_stats_.total_blob_bytes_read += bytes_read;
|
|
|
|
|
2021-08-18 02:21:16 +02:00
|
|
|
++iter_stats_.num_blobs_relocated;
|
|
|
|
iter_stats_.total_blob_bytes_relocated += blob_index.size();
|
|
|
|
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
value_ = blob_value_;
|
|
|
|
|
|
|
|
if (ExtractLargeValueIfNeededImpl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ikey_.type = kTypeValue;
|
|
|
|
current_key_.UpdateInternalKey(ikey_.sequence, ikey_.type);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GC for stacked BlobDB
|
2021-02-26 01:30:27 +01:00
|
|
|
if (compaction_filter_ &&
|
|
|
|
compaction_filter_->IsStackedBlobDbInternalCompactionFilter()) {
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
const auto blob_decision = compaction_filter_->PrepareBlobOutput(
|
|
|
|
user_key(), value_, &compaction_filter_value_);
|
|
|
|
|
|
|
|
if (blob_decision == CompactionFilter::BlobDecision::kCorruption) {
|
|
|
|
status_ =
|
|
|
|
Status::Corruption("Corrupted blob reference encountered during GC");
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blob_decision == CompactionFilter::BlobDecision::kIOError) {
|
|
|
|
status_ = Status::IOError("Could not relocate blob during GC");
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blob_decision == CompactionFilter::BlobDecision::kChangeValue) {
|
|
|
|
value_ = compaction_filter_value_;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:35:25 +02:00
|
|
|
void CompactionIterator::PrepareOutput() {
|
2019-12-13 19:11:03 +01:00
|
|
|
if (valid_) {
|
2020-09-15 06:10:09 +02:00
|
|
|
if (ikey_.type == kTypeValue) {
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
ExtractLargeValueIfNeeded();
|
2020-09-15 06:10:09 +02:00
|
|
|
} else if (ikey_.type == kTypeBlobIndex) {
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
GarbageCollectBlobIfNeeded();
|
2019-12-13 19:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Zeroing out the sequence number leads to better compression.
|
|
|
|
// If this is the bottommost level (no files in lower levels)
|
|
|
|
// and the earliest snapshot is larger than this seqno
|
|
|
|
// and the userkey differs from the last userkey in compaction
|
|
|
|
// then we can squash the seqno to zero.
|
|
|
|
//
|
|
|
|
// This is safe for TransactionDB write-conflict checking since transactions
|
|
|
|
// only care about sequence number larger than any active snapshots.
|
|
|
|
//
|
|
|
|
// Can we do the same for levels above bottom level as long as
|
|
|
|
// KeyNotExistsBeyondOutputLevel() return true?
|
2019-12-17 19:17:27 +01:00
|
|
|
if (valid_ && compaction_ != nullptr &&
|
|
|
|
!compaction_->allow_ingest_behind() &&
|
2019-12-13 19:11:03 +01:00
|
|
|
ikeyNotNeededForIncrementalSnapshot() && bottommost_level_ &&
|
2021-08-18 07:13:21 +02:00
|
|
|
DefinitelyInSnapshot(ikey_.sequence, earliest_snapshot_) &&
|
|
|
|
ikey_.type != kTypeMerge) {
|
2021-09-27 20:49:35 +02:00
|
|
|
assert(ikey_.type != kTypeDeletion);
|
|
|
|
assert(ikey_.type != kTypeSingleDeletion ||
|
|
|
|
(timestamp_size_ || full_history_ts_low_));
|
|
|
|
if (ikey_.type == kTypeDeletion ||
|
|
|
|
(ikey_.type == kTypeSingleDeletion &&
|
|
|
|
(!timestamp_size_ || !full_history_ts_low_))) {
|
2019-12-13 19:11:03 +01:00
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"Unexpected key type %d for seq-zero optimization",
|
|
|
|
ikey_.type);
|
|
|
|
}
|
|
|
|
ikey_.sequence = 0;
|
Allow compaction iterator to perform garbage collection (#7556)
Summary:
Add a threshold timestamp, full_history_ts_low_ of type `std::string*` to
`CompactionIterator`, so that RocksDB can also perform garbage collection during
compaction.
* If full_history_ts_low_ is nullptr, then compaction iterator does not perform
GC, preserving all timestamp history for all keys. Compaction iterator will
treat user key with different timestamps as different user keys.
* If full_history_ts_low_ is not nullptr, then compaction iterator performs
GC. GC will look at keys older than `*full_history_ts_low_` and determine their
eligibility based on factors including snapshots.
Current rules of GC:
* If an internal key is in the same snapshot as a previous counterpart
with the same user key, and this key is eligible for GC, and the key is
not single-delete or merge operand, then this key can be dropped. Note
that the previous internal key cannot be a merge operand either.
* If a tombstone is the most recent one in the earliest snapshot and it
is eligible for GC, and keyNotExistsBeyondLevel() is true, then this
tombstone can be dropped.
* If a tombstone is the most recent one in a snapshot and it is eligible
for GC, and the compaction is at bottommost level, then all other older
internal keys of the same user key must also be eligible for GC, thus
can be dropped
* Single-delete, delete-range and merge are not currently supported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7556
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D24507728
Pulled By: riversand963
fbshipit-source-id: 3c09c7301f41eed76dfcf4d1527e68cf6e0a8bb3
2020-10-24 07:58:05 +02:00
|
|
|
if (!timestamp_size_) {
|
|
|
|
current_key_.UpdateInternalKey(0, ikey_.type);
|
|
|
|
} else if (full_history_ts_low_ && cmp_with_history_ts_low_ < 0) {
|
|
|
|
// We can also zero out timestamp for better compression.
|
|
|
|
// For the same user key (excluding timestamp), the timestamp-based
|
|
|
|
// history can be collapsed to save some space if the timestamp is
|
|
|
|
// older than *full_history_ts_low_.
|
|
|
|
const std::string kTsMin(timestamp_size_, static_cast<char>(0));
|
|
|
|
const Slice ts_slice = kTsMin;
|
|
|
|
ikey_.SetTimestamp(ts_slice);
|
|
|
|
current_key_.UpdateInternalKey(0, ikey_.type, &ts_slice);
|
|
|
|
}
|
2019-10-30 21:47:08 +01:00
|
|
|
}
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SequenceNumber CompactionIterator::findEarliestVisibleSnapshot(
|
|
|
|
SequenceNumber in, SequenceNumber* prev_snapshot) {
|
|
|
|
assert(snapshots_->size());
|
2019-10-30 21:47:08 +01:00
|
|
|
if (snapshots_->size() == 0) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"No snapshot left in findEarliestVisibleSnapshot");
|
|
|
|
}
|
2018-10-16 01:18:55 +02:00
|
|
|
auto snapshots_iter = std::lower_bound(
|
|
|
|
snapshots_->begin(), snapshots_->end(), in);
|
|
|
|
if (snapshots_iter == snapshots_->begin()) {
|
|
|
|
*prev_snapshot = 0;
|
|
|
|
} else {
|
|
|
|
*prev_snapshot = *std::prev(snapshots_iter);
|
|
|
|
assert(*prev_snapshot < in);
|
2019-10-30 21:47:08 +01:00
|
|
|
if (*prev_snapshot >= in) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"*prev_snapshot >= in in findEarliestVisibleSnapshot");
|
|
|
|
}
|
2018-10-16 01:18:55 +02:00
|
|
|
}
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
if (snapshot_checker_ == nullptr) {
|
|
|
|
return snapshots_iter != snapshots_->end()
|
|
|
|
? *snapshots_iter : kMaxSequenceNumber;
|
|
|
|
}
|
|
|
|
bool has_released_snapshot = !released_snapshots_.empty();
|
2018-10-16 01:18:55 +02:00
|
|
|
for (; snapshots_iter != snapshots_->end(); ++snapshots_iter) {
|
|
|
|
auto cur = *snapshots_iter;
|
|
|
|
assert(in <= cur);
|
2019-10-30 21:47:08 +01:00
|
|
|
if (in > cur) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_, "in > cur in findEarliestVisibleSnapshot");
|
|
|
|
}
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
// Skip if cur is in released_snapshots.
|
|
|
|
if (has_released_snapshot && released_snapshots_.count(cur) > 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto res = snapshot_checker_->CheckInSnapshot(in, cur);
|
|
|
|
if (res == SnapshotCheckerResult::kInSnapshot) {
|
2015-09-10 23:35:25 +02:00
|
|
|
return cur;
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
} else if (res == SnapshotCheckerResult::kSnapshotReleased) {
|
|
|
|
released_snapshots_.insert(cur);
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
2018-10-16 01:18:55 +02:00
|
|
|
*prev_snapshot = cur;
|
2015-09-10 23:35:25 +02:00
|
|
|
}
|
|
|
|
return kMaxSequenceNumber;
|
|
|
|
}
|
|
|
|
|
Added support for differential snapshots
Summary:
The motivation for this PR is to add to RocksDB support for differential (incremental) snapshots, as snapshot of the DB changes between two points in time (one can think of it as diff between to sequence numbers, or the diff D which can be thought of as an SST file or just set of KVs that can be applied to sequence number S1 to get the database to the state at sequence number S2).
This feature would be useful for various distributed storages layers built on top of RocksDB, as it should help reduce resources (time and network bandwidth) needed to recover and rebuilt DB instances as replicas in the context of distributed storages.
From the API standpoint that would like client app requesting iterator between (start seqnum) and current DB state, and reading the "diff".
This is a very draft PR for initial review in the discussion on the approach, i'm going to rework some parts and keep updating the PR.
For now, what's done here according to initial discussions:
Preserving deletes:
- We want to be able to optionally preserve recent deletes for some defined period of time, so that if a delete came in recently and might need to be included in the next incremental snapshot it would't get dropped by a compaction. This is done by adding new param to Options (preserve deletes flag) and new variable to DB Impl where we keep track of the sequence number after which we don't want to drop tombstones, even if they are otherwise eligible for deletion.
- I also added a new API call for clients to be able to advance this cutoff seqnum after which we drop deletes; i assume it's more flexible to let clients control this, since otherwise we'd need to keep some kind of timestamp < -- > seqnum mapping inside the DB, which sounds messy and painful to support. Clients could make use of it by periodically calling GetLatestSequenceNumber(), noting the timestamp, doing some calculation and figuring out by how much we need to advance the cutoff seqnum.
- Compaction codepath in compaction_iterator.cc has been modified to avoid dropping tombstones with seqnum > cutoff seqnum.
Iterator changes:
- couple params added to ReadOptions, to optionally allow client to request internal keys instead of user keys (so that client can get the latest value of a key, be it delete marker or a put), as well as min timestamp and min seqnum.
TableCache changes:
- I modified table_cache code to be able to quickly exclude SST files from iterators heep if creation_time on the file is less then iter_start_ts as passed in ReadOptions. That would help a lot in some DB settings (like reading very recent data only or using FIFO compactions), but not so much for universal compaction with more or less long iterator time span.
What's left:
- Still looking at how to best plug that inside DBIter codepath. So far it seems that FindNextUserKeyInternal only parses values as UserKeys, and iter->key() call generally returns user key. Can we add new API to DBIter as internal_key(), and modify this internal method to optionally set saved_key_ to point to the full internal key? I don't need to store actual seqnum there, but I do need to store type.
Closes https://github.com/facebook/rocksdb/pull/2999
Differential Revision: D6175602
Pulled By: mikhail-antonov
fbshipit-source-id: c779a6696ee2d574d86c69cec866a3ae095aa900
2017-11-02 02:43:29 +01:00
|
|
|
// used in 2 places - prevents deletion markers to be dropped if they may be
|
|
|
|
// needed and disables seqnum zero-out in PrepareOutput for recent keys.
|
|
|
|
inline bool CompactionIterator::ikeyNotNeededForIncrementalSnapshot() {
|
|
|
|
return (!compaction_->preserve_deletes()) ||
|
|
|
|
(ikey_.sequence < preserve_deletes_seqnum_);
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:13:21 +02:00
|
|
|
bool CompactionIterator::IsInCurrentEarliestSnapshot(SequenceNumber sequence) {
|
2019-01-16 18:48:10 +01:00
|
|
|
assert(snapshot_checker_ != nullptr);
|
2019-10-30 21:47:08 +01:00
|
|
|
bool pre_condition = (earliest_snapshot_ == kMaxSequenceNumber ||
|
|
|
|
(earliest_snapshot_iter_ != snapshots_->end() &&
|
|
|
|
*earliest_snapshot_iter_ == earliest_snapshot_));
|
|
|
|
assert(pre_condition);
|
|
|
|
if (!pre_condition) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"Pre-Condition is not hold in IsInEarliestSnapshot");
|
|
|
|
}
|
2019-01-16 18:48:10 +01:00
|
|
|
auto in_snapshot =
|
|
|
|
snapshot_checker_->CheckInSnapshot(sequence, earliest_snapshot_);
|
|
|
|
while (UNLIKELY(in_snapshot == SnapshotCheckerResult::kSnapshotReleased)) {
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
// Avoid the the current earliest_snapshot_ being return as
|
|
|
|
// earliest visible snapshot for the next value. So if a value's sequence
|
|
|
|
// is zero-ed out by PrepareOutput(), the next value will be compact out.
|
|
|
|
released_snapshots_.insert(earliest_snapshot_);
|
2019-01-16 18:48:10 +01:00
|
|
|
earliest_snapshot_iter_++;
|
WritePrepared: fix two versions in compaction see different status for released snapshots (#4890)
Summary:
Fix how CompactionIterator::findEarliestVisibleSnapshots handles released snapshot. It fixing the two scenarios:
Scenario 1:
key1 has two values v1 and v2. There're two snapshots s1 and s2 taken after v1 and v2 are committed. Right after compaction output v2, s1 is released. Now findEarliestVisibleSnapshot may see s1 being released, and return the next snapshot, which is s2. That's larger than v2's earliest visible snapshot, which was s1.
The fix: the only place we check against last snapshot and current key snapshot is when we decide whether to compact out a value if it is hidden by a later value. In the check if we see current snapshot is even larger than last snapshot, we know last snapshot is released, and we are safe to compact out current key.
Scenario 2:
key1 has two values v1 and v2. there are two snapshots s1 and s2 taken after v1 and v2 are committed. During compaction before we process the key, s1 is released. When compaction process v2, snapshot checker may return kSnapshotReleased, and the earliest visible snapshot for v2 become s2. When compaction process v1, snapshot checker may return kIsInSnapshot (for WritePrepared transaction, it could be because v1 is still in commit cache). The result will become inconsistent here.
The fix: remember the set of released snapshots ever reported by snapshot checker, and ignore them when finding result for findEarliestVisibleSnapshot.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4890
Differential Revision: D13705538
Pulled By: maysamyabandeh
fbshipit-source-id: e577f0d9ee1ff5a6035f26859e56902ecc85a5a4
2019-01-19 02:20:13 +01:00
|
|
|
|
2019-01-16 18:48:10 +01:00
|
|
|
if (earliest_snapshot_iter_ == snapshots_->end()) {
|
|
|
|
earliest_snapshot_ = kMaxSequenceNumber;
|
|
|
|
} else {
|
|
|
|
earliest_snapshot_ = *earliest_snapshot_iter_;
|
|
|
|
}
|
|
|
|
in_snapshot =
|
|
|
|
snapshot_checker_->CheckInSnapshot(sequence, earliest_snapshot_);
|
|
|
|
}
|
|
|
|
assert(in_snapshot != SnapshotCheckerResult::kSnapshotReleased);
|
2019-10-30 21:47:08 +01:00
|
|
|
if (in_snapshot == SnapshotCheckerResult::kSnapshotReleased) {
|
|
|
|
ROCKS_LOG_FATAL(info_log_,
|
|
|
|
"Unexpected released snapshot in IsInEarliestSnapshot");
|
|
|
|
}
|
2019-01-16 18:48:10 +01:00
|
|
|
return in_snapshot == SnapshotCheckerResult::kInSnapshot;
|
|
|
|
}
|
|
|
|
|
Integrated blob garbage collection: relocate blobs (#7694)
Summary:
The patch adds basic garbage collection support to the integrated BlobDB
implementation. Valid blobs residing in the oldest blob files are relocated
as they are encountered during compaction. The threshold that determines
which blob files qualify is computed based on the configuration option
`blob_garbage_collection_age_cutoff`, which was introduced in https://github.com/facebook/rocksdb/issues/7661 .
Once a blob is retrieved for the purposes of relocation, it passes through the
same logic that extracts large values to blob files in general. This means that
if, for instance, the size threshold for key-value separation (`min_blob_size`)
got changed or writing blob files got disabled altogether, it is possible for the
value to be moved back into the LSM tree. In particular, one way to re-inline
all blob values if needed would be to perform a full manual compaction with
`enable_blob_files` set to `false`, `enable_blob_garbage_collection` set to
`true`, and `blob_file_garbage_collection_age_cutoff` set to `1.0`.
Some TODOs that I plan to address in separate PRs:
1) We'll have to measure the amount of new garbage in each blob file and log
`BlobFileGarbage` entries as part of the compaction job's `VersionEdit`.
(For the time being, blob files are cleaned up solely based on the
`oldest_blob_file_number` relationships.)
2) When compression is used for blobs, the compression type hasn't changed,
and the blob still qualifies for being written to a blob file, we can simply copy
the compressed blob to the new file instead of going through decompression
and compression.
3) We need to update the formula for computing write amplification to account
for the amount of data read from blob files as part of GC.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7694
Test Plan: `make check`
Reviewed By: riversand963
Differential Revision: D25069663
Pulled By: ltamasi
fbshipit-source-id: bdfa8feb09afcf5bca3b4eba2ba72ce2f15cd06a
2020-11-24 06:07:01 +01:00
|
|
|
uint64_t CompactionIterator::ComputeBlobGarbageCollectionCutoffFileNumber(
|
|
|
|
const CompactionProxy* compaction) {
|
|
|
|
if (!compaction) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!compaction->enable_blob_garbage_collection()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Version* const version = compaction->input_version();
|
|
|
|
assert(version);
|
|
|
|
|
|
|
|
const VersionStorageInfo* const storage_info = version->storage_info();
|
|
|
|
assert(storage_info);
|
|
|
|
|
|
|
|
const auto& blob_files = storage_info->GetBlobFiles();
|
|
|
|
|
|
|
|
auto it = blob_files.begin();
|
|
|
|
std::advance(
|
|
|
|
it, compaction->blob_garbage_collection_age_cutoff() * blob_files.size());
|
|
|
|
|
|
|
|
return it != blob_files.end() ? it->first
|
|
|
|
: std::numeric_limits<uint64_t>::max();
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|