2017-11-02 18:05:55 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
|
|
|
|
#include "utilities/transactions/write_prepared_txn_db.h"
|
|
|
|
|
2017-12-13 15:52:02 +00:00
|
|
|
#include <algorithm>
|
2019-06-10 18:47:16 +00:00
|
|
|
#include <cinttypes>
|
2017-11-02 18:05:55 +00:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-09-13 20:48:04 +00:00
|
|
|
#include "db/arena_wrapped_db_iter.h"
|
2019-05-31 18:52:59 +00:00
|
|
|
#include "db/db_impl/db_impl.h"
|
2021-09-29 11:01:57 +00:00
|
|
|
#include "logging/logging.h"
|
2017-11-02 18:05:55 +00:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/utilities/transaction_db.h"
|
2019-05-31 00:39:43 +00:00
|
|
|
#include "test_util/sync_point.h"
|
2018-04-03 03:19:21 +00:00
|
|
|
#include "util/cast_util.h"
|
2017-11-02 18:05:55 +00:00
|
|
|
#include "util/mutexlock.h"
|
2018-01-09 16:47:46 +00:00
|
|
|
#include "util/string_util.h"
|
2017-11-02 18:05:55 +00:00
|
|
|
#include "utilities/transactions/pessimistic_transaction.h"
|
|
|
|
#include "utilities/transactions/transaction_db_mutex_impl.h"
|
|
|
|
|
2022-04-28 00:50:54 +00:00
|
|
|
// This function is for testing only. If it returns true, then all entries in
|
|
|
|
// the commit cache will be evicted. Unit and/or stress tests (db_stress)
|
|
|
|
// can implement this function and customize how frequently commit cache
|
|
|
|
// eviction occurs.
|
|
|
|
// TODO: remove this function once we can configure commit cache to be very
|
|
|
|
// small so that eviction occurs very frequently. This requires the commit
|
|
|
|
// cache entry to be able to encode prepare and commit sequence numbers so that
|
|
|
|
// the commit sequence number does not have to be within a certain range of
|
|
|
|
// prepare sequence number.
|
|
|
|
extern "C" bool rocksdb_write_prepared_TEST_ShouldClearCommitCache(void)
|
|
|
|
__attribute__((__weak__));
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-11-02 18:05:55 +00:00
|
|
|
|
|
|
|
Status WritePreparedTxnDB::Initialize(
|
|
|
|
const std::vector<size_t>& compaction_enabled_cf_indices,
|
|
|
|
const std::vector<ColumnFamilyHandle*>& handles) {
|
2020-04-29 20:06:27 +00:00
|
|
|
auto dbimpl = static_cast_with_check<DBImpl>(GetRootDB());
|
2017-11-02 18:05:55 +00:00
|
|
|
assert(dbimpl != nullptr);
|
|
|
|
auto rtxns = dbimpl->recovered_transactions();
|
2019-06-12 02:52:08 +00:00
|
|
|
std::map<SequenceNumber, SequenceNumber> ordered_seq_cnt;
|
2017-11-02 18:05:55 +00:00
|
|
|
for (auto rtxn : rtxns) {
|
2018-07-07 00:17:36 +00:00
|
|
|
// There should only one batch for WritePrepared policy.
|
|
|
|
assert(rtxn.second->batches_.size() == 1);
|
|
|
|
const auto& seq = rtxn.second->batches_.begin()->first;
|
|
|
|
const auto& batch_info = rtxn.second->batches_.begin()->second;
|
|
|
|
auto cnt = batch_info.batch_cnt_ ? batch_info.batch_cnt_ : 1;
|
2019-06-12 02:52:08 +00:00
|
|
|
ordered_seq_cnt[seq] = cnt;
|
|
|
|
}
|
|
|
|
// AddPrepared must be called in order
|
2019-09-20 19:00:55 +00:00
|
|
|
for (auto seq_cnt : ordered_seq_cnt) {
|
2019-06-12 02:52:08 +00:00
|
|
|
auto seq = seq_cnt.first;
|
|
|
|
auto cnt = seq_cnt.second;
|
2018-03-24 00:21:47 +00:00
|
|
|
for (size_t i = 0; i < cnt; i++) {
|
2018-07-07 00:17:36 +00:00
|
|
|
AddPrepared(seq + i);
|
2018-03-24 00:21:47 +00:00
|
|
|
}
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
SequenceNumber prev_max = max_evicted_seq_;
|
|
|
|
SequenceNumber last_seq = db_impl_->GetLatestSequenceNumber();
|
|
|
|
AdvanceMaxEvictedSeq(prev_max, last_seq);
|
2019-01-08 19:23:10 +00:00
|
|
|
// Create a gap between max and the next snapshot. This simplifies the logic
|
|
|
|
// in IsInSnapshot by not having to consider the special case of max ==
|
|
|
|
// snapshot after recovery. This is tested in IsInSnapshotEmptyMapTest.
|
|
|
|
if (last_seq) {
|
|
|
|
db_impl_->versions_->SetLastAllocatedSequence(last_seq + 1);
|
|
|
|
db_impl_->versions_->SetLastSequence(last_seq + 1);
|
|
|
|
db_impl_->versions_->SetLastPublishedSequence(last_seq + 1);
|
|
|
|
}
|
2017-11-02 18:05:55 +00:00
|
|
|
|
|
|
|
db_impl_->SetSnapshotChecker(new WritePreparedSnapshotChecker(this));
|
2018-03-28 19:01:09 +00:00
|
|
|
// A callback to commit a single sub-batch
|
|
|
|
class CommitSubBatchPreReleaseCallback : public PreReleaseCallback {
|
|
|
|
public:
|
|
|
|
explicit CommitSubBatchPreReleaseCallback(WritePreparedTxnDB* db)
|
|
|
|
: db_(db) {}
|
2019-04-02 22:14:41 +00:00
|
|
|
Status Callback(SequenceNumber commit_seq,
|
2019-06-10 18:47:16 +00:00
|
|
|
bool is_mem_disabled __attribute__((__unused__)), uint64_t,
|
|
|
|
size_t /*index*/, size_t /*total*/) override {
|
2018-03-28 19:01:09 +00:00
|
|
|
assert(!is_mem_disabled);
|
2018-04-12 02:59:25 +00:00
|
|
|
db_->AddCommitted(commit_seq, commit_seq);
|
2018-03-28 19:01:09 +00:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WritePreparedTxnDB* db_;
|
|
|
|
};
|
|
|
|
db_impl_->SetRecoverableStatePreReleaseCallback(
|
|
|
|
new CommitSubBatchPreReleaseCallback(this));
|
2017-11-02 18:05:55 +00:00
|
|
|
|
|
|
|
auto s = PessimisticTransactionDB::Initialize(compaction_enabled_cf_indices,
|
|
|
|
handles);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-02-06 02:32:54 +00:00
|
|
|
Status WritePreparedTxnDB::VerifyCFOptions(
|
|
|
|
const ColumnFamilyOptions& cf_options) {
|
|
|
|
Status s = PessimisticTransactionDB::VerifyCFOptions(cf_options);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
if (!cf_options.memtable_factory->CanHandleDuplicatedKey()) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"memtable_factory->CanHandleDuplicatedKey() cannot be false with "
|
|
|
|
"WritePrpeared transactions");
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2017-11-02 18:05:55 +00:00
|
|
|
Transaction* WritePreparedTxnDB::BeginTransaction(
|
|
|
|
const WriteOptions& write_options, const TransactionOptions& txn_options,
|
|
|
|
Transaction* old_txn) {
|
|
|
|
if (old_txn != nullptr) {
|
|
|
|
ReinitializeTransaction(old_txn, write_options, txn_options);
|
|
|
|
return old_txn;
|
|
|
|
} else {
|
|
|
|
return new WritePreparedTxn(this, write_options, txn_options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 23:26:14 +00:00
|
|
|
Status WritePreparedTxnDB::Write(const WriteOptions& opts,
|
|
|
|
WriteBatch* updates) {
|
|
|
|
if (txn_db_options_.skip_concurrency_control) {
|
|
|
|
// Skip locking the rows
|
|
|
|
const size_t UNKNOWN_BATCH_CNT = 0;
|
|
|
|
WritePreparedTxn* NO_TXN = nullptr;
|
|
|
|
return WriteInternal(opts, updates, UNKNOWN_BATCH_CNT, NO_TXN);
|
|
|
|
} else {
|
|
|
|
return PessimisticTransactionDB::WriteWithConcurrencyControl(opts, updates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 00:27:39 +00:00
|
|
|
Status WritePreparedTxnDB::Write(
|
|
|
|
const WriteOptions& opts,
|
|
|
|
const TransactionDBWriteOptimizations& optimizations, WriteBatch* updates) {
|
|
|
|
if (optimizations.skip_concurrency_control) {
|
|
|
|
// Skip locking the rows
|
|
|
|
const size_t UNKNOWN_BATCH_CNT = 0;
|
|
|
|
const size_t ONE_BATCH_CNT = 1;
|
|
|
|
const size_t batch_cnt = optimizations.skip_duplicate_key_check
|
|
|
|
? ONE_BATCH_CNT
|
|
|
|
: UNKNOWN_BATCH_CNT;
|
|
|
|
WritePreparedTxn* NO_TXN = nullptr;
|
|
|
|
return WriteInternal(opts, updates, batch_cnt, NO_TXN);
|
|
|
|
} else {
|
|
|
|
// TODO(myabandeh): Make use of skip_duplicate_key_check hint
|
|
|
|
// Fall back to unoptimized version
|
2019-05-28 23:26:14 +00:00
|
|
|
return PessimisticTransactionDB::WriteWithConcurrencyControl(opts, updates);
|
2018-02-13 00:27:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status WritePreparedTxnDB::WriteInternal(const WriteOptions& write_options_orig,
|
|
|
|
WriteBatch* batch, size_t batch_cnt,
|
|
|
|
WritePreparedTxn* txn) {
|
|
|
|
ROCKS_LOG_DETAILS(db_impl_->immutable_db_options().info_log,
|
|
|
|
"CommitBatchInternal");
|
|
|
|
if (batch->Count() == 0) {
|
|
|
|
// Otherwise our 1 seq per batch logic will break since there is no seq
|
|
|
|
// increased for this batch.
|
|
|
|
return Status::OK();
|
|
|
|
}
|
2022-06-17 06:10:07 +00:00
|
|
|
|
|
|
|
if (write_options_orig.protection_bytes_per_key > 0) {
|
|
|
|
auto s = WriteBatchInternal::UpdateProtectionInfo(
|
|
|
|
batch, write_options_orig.protection_bytes_per_key);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 00:27:39 +00:00
|
|
|
if (batch_cnt == 0) { // not provided, then compute it
|
|
|
|
// TODO(myabandeh): add an option to allow user skipping this cost
|
|
|
|
SubBatchCounter counter(*GetCFComparatorMap());
|
|
|
|
auto s = batch->Iterate(&counter);
|
2021-02-05 23:55:34 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2018-02-13 00:27:39 +00:00
|
|
|
batch_cnt = counter.BatchCount();
|
2018-04-08 04:55:42 +00:00
|
|
|
WPRecordTick(TXN_DUPLICATE_KEY_OVERHEAD);
|
|
|
|
ROCKS_LOG_DETAILS(info_log_, "Duplicate key overhead: %" PRIu64 " batches",
|
|
|
|
static_cast<uint64_t>(batch_cnt));
|
2018-02-13 00:27:39 +00:00
|
|
|
}
|
|
|
|
assert(batch_cnt);
|
|
|
|
|
|
|
|
bool do_one_write = !db_impl_->immutable_db_options().two_write_queues;
|
|
|
|
WriteOptions write_options(write_options_orig);
|
|
|
|
// In the absence of Prepare markers, use Noop as a batch separator
|
2020-10-21 21:02:00 +00:00
|
|
|
auto s = WriteBatchInternal::InsertNoop(batch);
|
|
|
|
assert(s.ok());
|
2018-02-13 00:27:39 +00:00
|
|
|
const bool DISABLE_MEMTABLE = true;
|
|
|
|
const uint64_t no_log_ref = 0;
|
|
|
|
uint64_t seq_used = kMaxSequenceNumber;
|
|
|
|
const size_t ZERO_PREPARES = 0;
|
2019-04-02 22:14:41 +00:00
|
|
|
const bool kSeperatePrepareCommitBatches = true;
|
2018-04-03 03:19:21 +00:00
|
|
|
// Since this is not 2pc, there is no need for AddPrepared but having it in
|
|
|
|
// the PreReleaseCallback enables an optimization. Refer to
|
|
|
|
// SmallestUnCommittedSeq for more details.
|
|
|
|
AddPreparedCallback add_prepared_callback(
|
2019-04-02 22:14:41 +00:00
|
|
|
this, db_impl_, batch_cnt,
|
|
|
|
db_impl_->immutable_db_options().two_write_queues,
|
|
|
|
!kSeperatePrepareCommitBatches);
|
2018-02-13 00:27:39 +00:00
|
|
|
WritePreparedCommitEntryPreReleaseCallback update_commit_map(
|
|
|
|
this, db_impl_, kMaxSequenceNumber, ZERO_PREPARES, batch_cnt);
|
2018-04-03 03:19:21 +00:00
|
|
|
PreReleaseCallback* pre_release_callback;
|
|
|
|
if (do_one_write) {
|
|
|
|
pre_release_callback = &update_commit_map;
|
|
|
|
} else {
|
|
|
|
pre_release_callback = &add_prepared_callback;
|
|
|
|
}
|
2020-10-21 21:02:00 +00:00
|
|
|
s = db_impl_->WriteImpl(write_options, batch, nullptr, nullptr, no_log_ref,
|
|
|
|
!DISABLE_MEMTABLE, &seq_used, batch_cnt,
|
|
|
|
pre_release_callback);
|
2018-02-13 00:27:39 +00:00
|
|
|
assert(!s.ok() || seq_used != kMaxSequenceNumber);
|
2018-04-12 02:59:25 +00:00
|
|
|
uint64_t prepare_seq = seq_used;
|
2018-02-13 00:27:39 +00:00
|
|
|
if (txn != nullptr) {
|
|
|
|
txn->SetId(prepare_seq);
|
|
|
|
}
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
if (do_one_write) {
|
|
|
|
return s;
|
|
|
|
} // else do the 2nd write for commit
|
|
|
|
ROCKS_LOG_DETAILS(db_impl_->immutable_db_options().info_log,
|
|
|
|
"CommitBatchInternal 2nd write prepare_seq: %" PRIu64,
|
|
|
|
prepare_seq);
|
|
|
|
// Commit the batch by writing an empty batch to the 2nd queue that will
|
|
|
|
// release the commit sequence number to readers.
|
2018-02-16 16:36:47 +00:00
|
|
|
const size_t ZERO_COMMITS = 0;
|
2018-02-13 00:27:39 +00:00
|
|
|
WritePreparedCommitEntryPreReleaseCallback update_commit_map_with_prepare(
|
2018-04-12 02:59:25 +00:00
|
|
|
this, db_impl_, prepare_seq, batch_cnt, ZERO_COMMITS);
|
2018-02-13 00:27:39 +00:00
|
|
|
WriteBatch empty_batch;
|
2019-05-28 21:18:24 +00:00
|
|
|
write_options.disableWAL = true;
|
|
|
|
write_options.sync = false;
|
2019-06-04 02:47:02 +00:00
|
|
|
const size_t ONE_BATCH = 1; // Just to inc the seq
|
2018-02-13 00:27:39 +00:00
|
|
|
s = db_impl_->WriteImpl(write_options, &empty_batch, nullptr, nullptr,
|
|
|
|
no_log_ref, DISABLE_MEMTABLE, &seq_used, ONE_BATCH,
|
|
|
|
&update_commit_map_with_prepare);
|
|
|
|
assert(!s.ok() || seq_used != kMaxSequenceNumber);
|
2019-06-10 18:47:16 +00:00
|
|
|
// Note: RemovePrepared is called from within PreReleaseCallback
|
2018-02-13 00:27:39 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
Status WritePreparedTxnDB::Get(const ReadOptions& _read_options,
|
2017-11-02 18:05:55 +00:00
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key, PinnableSlice* value) {
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
if (_read_options.io_activity != Env::IOActivity::kUnknown &&
|
|
|
|
_read_options.io_activity != Env::IOActivity::kGet) {
|
2023-04-21 16:07:18 +00:00
|
|
|
return Status::InvalidArgument(
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
"Can only call Get with `ReadOptions::io_activity` is "
|
|
|
|
"`Env::IOActivity::kUnknown` or `Env::IOActivity::kGet`");
|
2023-04-21 16:07:18 +00:00
|
|
|
}
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
ReadOptions read_options(_read_options);
|
|
|
|
if (read_options.io_activity == Env::IOActivity::kUnknown) {
|
|
|
|
read_options.io_activity = Env::IOActivity::kGet;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetImpl(read_options, column_family, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status WritePreparedTxnDB::GetImpl(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key, PinnableSlice* value) {
|
2019-04-12 21:36:36 +00:00
|
|
|
SequenceNumber min_uncommitted, snap_seq;
|
2019-08-05 20:30:56 +00:00
|
|
|
const SnapshotBackup backed_by_snapshot =
|
2019-04-12 21:36:36 +00:00
|
|
|
AssignMinMaxSeqs(options.snapshot, &min_uncommitted, &snap_seq);
|
2019-08-05 20:30:56 +00:00
|
|
|
WritePreparedTxnReadCallback callback(this, snap_seq, min_uncommitted,
|
|
|
|
backed_by_snapshot);
|
2019-04-12 21:36:36 +00:00
|
|
|
bool* dont_care = nullptr;
|
New API to get all merge operands for a Key (#5604)
Summary:
This is a new API added to db.h to allow for fetching all merge operands associated with a Key. The main motivation for this API is to support use cases where doing a full online merge is not necessary as it is performance sensitive. Example use-cases:
1. Update subset of columns and read subset of columns -
Imagine a SQL Table, a row is encoded as a K/V pair (as it is done in MyRocks). If there are many columns and users only updated one of them, we can use merge operator to reduce write amplification. While users only read one or two columns in the read query, this feature can avoid a full merging of the whole row, and save some CPU.
2. Updating very few attributes in a value which is a JSON-like document -
Updating one attribute can be done efficiently using merge operator, while reading back one attribute can be done more efficiently if we don't need to do a full merge.
----------------------------------------------------------------------------------------------------
API :
Status GetMergeOperands(
const ReadOptions& options, ColumnFamilyHandle* column_family,
const Slice& key, PinnableSlice* merge_operands,
GetMergeOperandsOptions* get_merge_operands_options,
int* number_of_operands)
Example usage :
int size = 100;
int number_of_operands = 0;
std::vector<PinnableSlice> values(size);
GetMergeOperandsOptions merge_operands_info;
db_->GetMergeOperands(ReadOptions(), db_->DefaultColumnFamily(), "k1", values.data(), merge_operands_info, &number_of_operands);
Description :
Returns all the merge operands corresponding to the key. If the number of merge operands in DB is greater than merge_operands_options.expected_max_number_of_operands no merge operands are returned and status is Incomplete. Merge operands returned are in the order of insertion.
merge_operands-> Points to an array of at-least merge_operands_options.expected_max_number_of_operands and the caller is responsible for allocating it. If the status returned is Incomplete then number_of_operands will contain the total number of merge operands found in DB for key.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5604
Test Plan:
Added unit test and perf test in db_bench that can be run using the command:
./db_bench -benchmarks=getmergeoperands --merge_operator=sortlist
Differential Revision: D16657366
Pulled By: vjnadimpalli
fbshipit-source-id: 0faadd752351745224ee12d4ae9ef3cb529951bf
2019-08-06 21:22:34 +00:00
|
|
|
DBImpl::GetImplOptions get_impl_options;
|
|
|
|
get_impl_options.column_family = column_family;
|
|
|
|
get_impl_options.value = value;
|
|
|
|
get_impl_options.value_found = dont_care;
|
|
|
|
get_impl_options.callback = &callback;
|
|
|
|
auto res = db_impl_->GetImpl(options, key, get_impl_options);
|
2019-08-05 20:30:56 +00:00
|
|
|
if (LIKELY(callback.valid() && ValidateSnapshot(callback.max_visible_seq(),
|
|
|
|
backed_by_snapshot))) {
|
2019-04-12 21:36:36 +00:00
|
|
|
return res;
|
2018-04-03 03:19:21 +00:00
|
|
|
} else {
|
Revise APIs related to user-defined timestamp (#8946)
Summary:
ajkr reminded me that we have a rule of not including per-kv related data in `WriteOptions`.
Namely, `WriteOptions` should not include information about "what-to-write", but should just
include information about "how-to-write".
According to this rule, `WriteOptions::timestamp` (experimental) is clearly a violation. Therefore,
this PR removes `WriteOptions::timestamp` for compliance.
After the removal, we need to pass timestamp info via another set of APIs. This PR proposes a set
of overloaded functions `Put(write_opts, key, value, ts)`, `Delete(write_opts, key, ts)`, and
`SingleDelete(write_opts, key, ts)`. Planned to add `Write(write_opts, batch, ts)`, but its complexity
made me reconsider doing it in another PR (maybe).
For better checking and returning error early, we also add a new set of APIs to `WriteBatch` that take
extra `timestamp` information when writing to `WriteBatch`es.
These set of APIs in `WriteBatchWithIndex` are currently not supported, and are on our TODO list.
Removed `WriteBatch::AssignTimestamps()` and renamed `WriteBatch::AssignTimestamp()` to
`WriteBatch::UpdateTimestamps()` since this method require that all keys have space for timestamps
allocated already and multiple timestamps can be updated.
The constructor of `WriteBatch` now takes a fourth argument `default_cf_ts_sz` which is the timestamp
size of the default column family. This will be used to allocate space when calling APIs that do not
specify a column family handle.
Also, updated `DB::Get()`, `DB::MultiGet()`, `DB::NewIterator()`, `DB::NewIterators()` methods, replacing
some assertions about timestamp to returning Status code.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8946
Test Plan:
make check
./db_bench -benchmarks=fillseq,fillrandom,readrandom,readseq,deleterandom -user_timestamp_size=8
./db_stress --user_timestamp_size=8 -nooverwritepercent=0 -test_secondary=0 -secondary_catch_up_one_in=0 -continuous_verification_interval=0
Make sure there is no perf regression by running the following
```
./db_bench_opt -db=/dev/shm/rocksdb -use_existing_db=0 -level0_stop_writes_trigger=256 -level0_slowdown_writes_trigger=256 -level0_file_num_compaction_trigger=256 -disable_wal=1 -duration=10 -benchmarks=fillrandom
```
Before this PR
```
DB path: [/dev/shm/rocksdb]
fillrandom : 1.831 micros/op 546235 ops/sec; 60.4 MB/s
```
After this PR
```
DB path: [/dev/shm/rocksdb]
fillrandom : 1.820 micros/op 549404 ops/sec; 60.8 MB/s
```
Reviewed By: ltamasi
Differential Revision: D33721359
Pulled By: riversand963
fbshipit-source-id: c131561534272c120ffb80711d42748d21badf09
2022-02-02 06:17:46 +00:00
|
|
|
res.PermitUncheckedError();
|
2019-08-05 20:30:56 +00:00
|
|
|
WPRecordTick(TXN_GET_TRY_AGAIN);
|
2019-04-12 21:36:36 +00:00
|
|
|
return Status::TryAgain();
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 16:36:47 +00:00
|
|
|
void WritePreparedTxnDB::UpdateCFComparatorMap(
|
|
|
|
const std::vector<ColumnFamilyHandle*>& handles) {
|
|
|
|
auto cf_map = new std::map<uint32_t, const Comparator*>();
|
2018-05-03 01:09:55 +00:00
|
|
|
auto handle_map = new std::map<uint32_t, ColumnFamilyHandle*>();
|
2018-02-16 16:36:47 +00:00
|
|
|
for (auto h : handles) {
|
|
|
|
auto id = h->GetID();
|
|
|
|
const Comparator* comparator = h->GetComparator();
|
|
|
|
(*cf_map)[id] = comparator;
|
2018-05-03 01:09:55 +00:00
|
|
|
if (id != 0) {
|
|
|
|
(*handle_map)[id] = h;
|
|
|
|
} else {
|
|
|
|
// The pointer to the default cf handle in the handles will be deleted.
|
|
|
|
// Use the pointer maintained by the db instead.
|
|
|
|
(*handle_map)[id] = DefaultColumnFamily();
|
|
|
|
}
|
2018-02-16 16:36:47 +00:00
|
|
|
}
|
2018-05-03 01:09:55 +00:00
|
|
|
cf_map_.reset(cf_map);
|
|
|
|
handle_map_.reset(handle_map);
|
2018-02-16 16:36:47 +00:00
|
|
|
}
|
|
|
|
|
2018-05-03 01:09:55 +00:00
|
|
|
void WritePreparedTxnDB::UpdateCFComparatorMap(ColumnFamilyHandle* h) {
|
|
|
|
auto old_cf_map_ptr = cf_map_.get();
|
2018-02-16 16:36:47 +00:00
|
|
|
assert(old_cf_map_ptr);
|
|
|
|
auto cf_map = new std::map<uint32_t, const Comparator*>(*old_cf_map_ptr);
|
2018-05-03 01:09:55 +00:00
|
|
|
auto old_handle_map_ptr = handle_map_.get();
|
|
|
|
assert(old_handle_map_ptr);
|
|
|
|
auto handle_map =
|
|
|
|
new std::map<uint32_t, ColumnFamilyHandle*>(*old_handle_map_ptr);
|
2018-02-16 16:36:47 +00:00
|
|
|
auto id = h->GetID();
|
|
|
|
const Comparator* comparator = h->GetComparator();
|
|
|
|
(*cf_map)[id] = comparator;
|
2018-05-03 01:09:55 +00:00
|
|
|
(*handle_map)[id] = h;
|
|
|
|
cf_map_.reset(cf_map);
|
|
|
|
handle_map_.reset(handle_map);
|
2018-02-16 16:36:47 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 16:49:30 +00:00
|
|
|
std::vector<Status> WritePreparedTxnDB::MultiGet(
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
const ReadOptions& _read_options,
|
2017-11-27 16:49:30 +00:00
|
|
|
const std::vector<ColumnFamilyHandle*>& column_family,
|
|
|
|
const std::vector<Slice>& keys, std::vector<std::string>* values) {
|
|
|
|
assert(values);
|
|
|
|
size_t num_keys = keys.size();
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
std::vector<Status> stat_list(num_keys);
|
|
|
|
|
|
|
|
if (_read_options.io_activity != Env::IOActivity::kUnknown &&
|
|
|
|
_read_options.io_activity != Env::IOActivity::kMultiGet) {
|
|
|
|
Status s = Status::InvalidArgument(
|
|
|
|
"Can only call MultiGet with `ReadOptions::io_activity` is "
|
|
|
|
"`Env::IOActivity::kUnknown` or `Env::IOActivity::kMultiGet`");
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_keys; ++i) {
|
|
|
|
stat_list[i] = s;
|
|
|
|
}
|
|
|
|
return stat_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadOptions read_options(_read_options);
|
|
|
|
if (read_options.io_activity == Env::IOActivity::kUnknown) {
|
|
|
|
read_options.io_activity = Env::IOActivity::kMultiGet;
|
|
|
|
}
|
|
|
|
|
2017-11-27 16:49:30 +00:00
|
|
|
values->resize(num_keys);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_keys; ++i) {
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
stat_list[i] =
|
|
|
|
this->GetImpl(read_options, column_family[i], keys[i], &(*values)[i]);
|
2017-11-27 16:49:30 +00:00
|
|
|
}
|
|
|
|
return stat_list;
|
|
|
|
}
|
|
|
|
|
2017-11-02 18:05:55 +00:00
|
|
|
// Struct to hold ownership of snapshot and read callback for iterator cleanup.
|
|
|
|
struct WritePreparedTxnDB::IteratorState {
|
|
|
|
IteratorState(WritePreparedTxnDB* txn_db, SequenceNumber sequence,
|
2018-04-03 03:19:21 +00:00
|
|
|
std::shared_ptr<ManagedSnapshot> s,
|
|
|
|
SequenceNumber min_uncommitted)
|
2019-08-05 20:30:56 +00:00
|
|
|
: callback(txn_db, sequence, min_uncommitted, kBackedByDBSnapshot),
|
|
|
|
snapshot(s) {}
|
2017-11-02 18:05:55 +00:00
|
|
|
|
|
|
|
WritePreparedTxnReadCallback callback;
|
|
|
|
std::shared_ptr<ManagedSnapshot> snapshot;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
2018-03-05 21:08:17 +00:00
|
|
|
static void CleanupWritePreparedTxnDBIterator(void* arg1, void* /*arg2*/) {
|
2017-11-02 18:05:55 +00:00
|
|
|
delete reinterpret_cast<WritePreparedTxnDB::IteratorState*>(arg1);
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
Iterator* WritePreparedTxnDB::NewIterator(const ReadOptions& _read_options,
|
2017-11-02 18:05:55 +00:00
|
|
|
ColumnFamilyHandle* column_family) {
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
if (_read_options.io_activity != Env::IOActivity::kUnknown &&
|
|
|
|
_read_options.io_activity != Env::IOActivity::kDBIterator) {
|
2023-04-21 16:07:18 +00:00
|
|
|
return NewErrorIterator(Status::InvalidArgument(
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
"Can only call NewIterator with `ReadOptions::io_activity` is "
|
|
|
|
"`Env::IOActivity::kUnknown` or `Env::IOActivity::kDBIterator`"));
|
|
|
|
}
|
|
|
|
ReadOptions read_options(_read_options);
|
|
|
|
if (read_options.io_activity == Env::IOActivity::kUnknown) {
|
|
|
|
read_options.io_activity = Env::IOActivity::kDBIterator;
|
2023-04-21 16:07:18 +00:00
|
|
|
}
|
2020-12-05 05:28:26 +00:00
|
|
|
constexpr bool expose_blob_index = false;
|
|
|
|
constexpr bool allow_refresh = false;
|
2017-11-02 18:05:55 +00:00
|
|
|
std::shared_ptr<ManagedSnapshot> own_snapshot = nullptr;
|
|
|
|
SequenceNumber snapshot_seq = kMaxSequenceNumber;
|
2018-04-03 03:19:21 +00:00
|
|
|
SequenceNumber min_uncommitted = 0;
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
if (read_options.snapshot != nullptr) {
|
|
|
|
snapshot_seq = read_options.snapshot->GetSequenceNumber();
|
2018-06-27 19:05:29 +00:00
|
|
|
min_uncommitted =
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
static_cast_with_check<const SnapshotImpl>(read_options.snapshot)
|
2018-06-27 19:05:29 +00:00
|
|
|
->min_uncommitted_;
|
2017-11-02 18:05:55 +00:00
|
|
|
} else {
|
2018-04-03 03:19:21 +00:00
|
|
|
auto* snapshot = GetSnapshot();
|
2017-11-11 21:08:22 +00:00
|
|
|
// We take a snapshot to make sure that the related data in the commit map
|
|
|
|
// are not deleted.
|
2017-11-02 18:05:55 +00:00
|
|
|
snapshot_seq = snapshot->GetSequenceNumber();
|
2018-04-03 03:19:21 +00:00
|
|
|
min_uncommitted =
|
2020-04-29 20:06:27 +00:00
|
|
|
static_cast_with_check<const SnapshotImpl>(snapshot)->min_uncommitted_;
|
2017-11-02 18:05:55 +00:00
|
|
|
own_snapshot = std::make_shared<ManagedSnapshot>(db_impl_, snapshot);
|
|
|
|
}
|
|
|
|
assert(snapshot_seq != kMaxSequenceNumber);
|
2020-07-03 02:24:25 +00:00
|
|
|
auto* cfd =
|
|
|
|
static_cast_with_check<ColumnFamilyHandleImpl>(column_family)->cfd();
|
2018-04-03 03:19:21 +00:00
|
|
|
auto* state =
|
|
|
|
new IteratorState(this, snapshot_seq, own_snapshot, min_uncommitted);
|
2023-09-13 23:34:18 +00:00
|
|
|
SuperVersion* super_version = cfd->GetReferencedSuperVersion(db_impl_);
|
|
|
|
auto* db_iter = db_impl_->NewIteratorImpl(read_options, cfd, super_version,
|
|
|
|
snapshot_seq, &state->callback,
|
|
|
|
expose_blob_index, allow_refresh);
|
2017-11-02 18:05:55 +00:00
|
|
|
db_iter->RegisterCleanup(CleanupWritePreparedTxnDBIterator, state, nullptr);
|
|
|
|
return db_iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status WritePreparedTxnDB::NewIterators(
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
const ReadOptions& _read_options,
|
2017-11-02 18:05:55 +00:00
|
|
|
const std::vector<ColumnFamilyHandle*>& column_families,
|
|
|
|
std::vector<Iterator*>* iterators) {
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
if (_read_options.io_activity != Env::IOActivity::kUnknown &&
|
|
|
|
_read_options.io_activity != Env::IOActivity::kDBIterator) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"Can only call NewIterator with `ReadOptions::io_activity` is "
|
|
|
|
"`Env::IOActivity::kUnknown` or `Env::IOActivity::kDBIterator`");
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadOptions read_options(_read_options);
|
|
|
|
if (read_options.io_activity == Env::IOActivity::kUnknown) {
|
|
|
|
read_options.io_activity = Env::IOActivity::kDBIterator;
|
|
|
|
}
|
2020-12-05 05:28:26 +00:00
|
|
|
constexpr bool expose_blob_index = false;
|
|
|
|
constexpr bool allow_refresh = false;
|
2017-11-02 18:05:55 +00:00
|
|
|
std::shared_ptr<ManagedSnapshot> own_snapshot = nullptr;
|
|
|
|
SequenceNumber snapshot_seq = kMaxSequenceNumber;
|
2018-04-03 03:19:21 +00:00
|
|
|
SequenceNumber min_uncommitted = 0;
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
if (read_options.snapshot != nullptr) {
|
|
|
|
snapshot_seq = read_options.snapshot->GetSequenceNumber();
|
2020-04-29 20:06:27 +00:00
|
|
|
min_uncommitted =
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
static_cast_with_check<const SnapshotImpl>(read_options.snapshot)
|
2020-04-29 20:06:27 +00:00
|
|
|
->min_uncommitted_;
|
2017-11-02 18:05:55 +00:00
|
|
|
} else {
|
2018-04-03 03:19:21 +00:00
|
|
|
auto* snapshot = GetSnapshot();
|
2017-11-11 21:08:22 +00:00
|
|
|
// We take a snapshot to make sure that the related data in the commit map
|
|
|
|
// are not deleted.
|
2017-11-02 18:05:55 +00:00
|
|
|
snapshot_seq = snapshot->GetSequenceNumber();
|
|
|
|
own_snapshot = std::make_shared<ManagedSnapshot>(db_impl_, snapshot);
|
2018-04-03 03:19:21 +00:00
|
|
|
min_uncommitted =
|
2020-04-29 20:06:27 +00:00
|
|
|
static_cast_with_check<const SnapshotImpl>(snapshot)->min_uncommitted_;
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
iterators->clear();
|
|
|
|
iterators->reserve(column_families.size());
|
|
|
|
for (auto* column_family : column_families) {
|
2020-07-03 02:24:25 +00:00
|
|
|
auto* cfd =
|
|
|
|
static_cast_with_check<ColumnFamilyHandleImpl>(column_family)->cfd();
|
2018-04-03 03:19:21 +00:00
|
|
|
auto* state =
|
|
|
|
new IteratorState(this, snapshot_seq, own_snapshot, min_uncommitted);
|
2023-09-13 23:34:18 +00:00
|
|
|
SuperVersion* super_version = cfd->GetReferencedSuperVersion(db_impl_);
|
|
|
|
auto* db_iter = db_impl_->NewIteratorImpl(read_options, cfd, super_version,
|
|
|
|
snapshot_seq, &state->callback,
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
expose_blob_index, allow_refresh);
|
2017-11-02 18:05:55 +00:00
|
|
|
db_iter->RegisterCleanup(CleanupWritePreparedTxnDBIterator, state, nullptr);
|
|
|
|
iterators->push_back(db_iter);
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
Add rollback_deletion_type_callback to TxnDBOptions (#9873)
Summary:
This PR does not affect write-committed.
Add a member, `rollback_deletion_type_callback` to TransactionDBOptions
so that a write-prepared transaction, when rolling back, can call this
callback to decide if a `Delete` or `SingleDelete` should be used to
cancel a prior `Put` written to the database during prepare phase.
The purpose of this PR is to prevent mixing `Delete` and `SingleDelete`
for the same key, causing undefined behaviors. Without this PR, the
following can happen:
```
// The application always issues SingleDelete when deleting keys.
txn1->Put('a');
txn1->Prepare(); // writes to memtable and potentially gets flushed/compacted to Lmax
txn1->Rollback(); // inserts DELETE('a')
txn2->Put('a');
txn2->Commit(); // writes to memtable and potentially gets flushed/compacted
```
In the database, we may have
```
L0: [PUT('a', s=100)]
L1: [DELETE('a', s=90)]
Lmax: [PUT('a', s=0)]
```
If a compaction compacts L0 and L1, then we have
```
L1: [PUT('a', s=100)]
Lmax: [PUT('a', s=0)]
```
If a future transaction issues a SingleDelete, we have
```
L0: [SD('a', s=110)]
L1: [PUT('a', s=100)]
Lmax: [PUT('a', s=0)]
```
Then, a compaction including L0, L1 and Lmax leads to
```
Lmax: [PUT('a', s=0)]
```
which is incorrect.
Similar bugs reported and addressed in
https://github.com/cockroachdb/pebble/issues/1255. Based on our team's
current priority, we have decided to take this approach for now. We may
come back and revisit in the future.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9873
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D35762170
Pulled By: riversand963
fbshipit-source-id: b28d56eefc786b53c9844b9ef4a7807acdd82c8d
2022-04-21 01:57:32 +00:00
|
|
|
void WritePreparedTxnDB::Init(const TransactionDBOptions& txn_db_opts) {
|
2017-11-02 18:05:55 +00:00
|
|
|
// Adcance max_evicted_seq_ no more than 100 times before the cache wraps
|
|
|
|
// around.
|
|
|
|
INC_STEP_FOR_MAX_EVICTED =
|
2018-01-09 16:47:46 +00:00
|
|
|
std::max(COMMIT_CACHE_SIZE / 100, static_cast<size_t>(1));
|
2018-11-09 19:17:34 +00:00
|
|
|
snapshot_cache_ = std::unique_ptr<std::atomic<SequenceNumber>[]>(
|
2017-11-02 18:05:55 +00:00
|
|
|
new std::atomic<SequenceNumber>[SNAPSHOT_CACHE_SIZE] {});
|
2018-11-09 19:17:34 +00:00
|
|
|
commit_cache_ = std::unique_ptr<std::atomic<CommitEntry64b>[]>(
|
2017-11-02 18:05:55 +00:00
|
|
|
new std::atomic<CommitEntry64b>[COMMIT_CACHE_SIZE] {});
|
2019-08-05 20:30:56 +00:00
|
|
|
dummy_max_snapshot_.number_ = kMaxSequenceNumber;
|
Add rollback_deletion_type_callback to TxnDBOptions (#9873)
Summary:
This PR does not affect write-committed.
Add a member, `rollback_deletion_type_callback` to TransactionDBOptions
so that a write-prepared transaction, when rolling back, can call this
callback to decide if a `Delete` or `SingleDelete` should be used to
cancel a prior `Put` written to the database during prepare phase.
The purpose of this PR is to prevent mixing `Delete` and `SingleDelete`
for the same key, causing undefined behaviors. Without this PR, the
following can happen:
```
// The application always issues SingleDelete when deleting keys.
txn1->Put('a');
txn1->Prepare(); // writes to memtable and potentially gets flushed/compacted to Lmax
txn1->Rollback(); // inserts DELETE('a')
txn2->Put('a');
txn2->Commit(); // writes to memtable and potentially gets flushed/compacted
```
In the database, we may have
```
L0: [PUT('a', s=100)]
L1: [DELETE('a', s=90)]
Lmax: [PUT('a', s=0)]
```
If a compaction compacts L0 and L1, then we have
```
L1: [PUT('a', s=100)]
Lmax: [PUT('a', s=0)]
```
If a future transaction issues a SingleDelete, we have
```
L0: [SD('a', s=110)]
L1: [PUT('a', s=100)]
Lmax: [PUT('a', s=0)]
```
Then, a compaction including L0, L1 and Lmax leads to
```
Lmax: [PUT('a', s=0)]
```
which is incorrect.
Similar bugs reported and addressed in
https://github.com/cockroachdb/pebble/issues/1255. Based on our team's
current priority, we have decided to take this approach for now. We may
come back and revisit in the future.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9873
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D35762170
Pulled By: riversand963
fbshipit-source-id: b28d56eefc786b53c9844b9ef4a7807acdd82c8d
2022-04-21 01:57:32 +00:00
|
|
|
rollback_deletion_type_callback_ =
|
|
|
|
txn_db_opts.rollback_deletion_type_callback;
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 18:47:16 +00:00
|
|
|
void WritePreparedTxnDB::CheckPreparedAgainstMax(SequenceNumber new_max,
|
|
|
|
bool locked) {
|
2019-03-07 15:32:01 +00:00
|
|
|
// When max_evicted_seq_ advances, move older entries from prepared_txns_
|
|
|
|
// to delayed_prepared_. This guarantees that if a seq is lower than max,
|
|
|
|
// then it is not in prepared_txns_ and save an expensive, synchronized
|
|
|
|
// lookup from a shared set. delayed_prepared_ is expected to be empty in
|
|
|
|
// normal cases.
|
|
|
|
ROCKS_LOG_DETAILS(
|
|
|
|
info_log_,
|
|
|
|
"CheckPreparedAgainstMax prepared_txns_.empty() %d top: %" PRIu64,
|
|
|
|
prepared_txns_.empty(),
|
|
|
|
prepared_txns_.empty() ? 0 : prepared_txns_.top());
|
2019-06-10 18:47:16 +00:00
|
|
|
const SequenceNumber prepared_top = prepared_txns_.top();
|
|
|
|
const bool empty = prepared_top == kMaxSequenceNumber;
|
|
|
|
// Preliminary check to avoid the synchronization cost
|
|
|
|
if (!empty && prepared_top <= new_max) {
|
|
|
|
if (locked) {
|
|
|
|
// Needed to avoid double locking in pop().
|
|
|
|
prepared_txns_.push_pop_mutex()->Unlock();
|
|
|
|
}
|
|
|
|
WriteLock wl(&prepared_mutex_);
|
|
|
|
// Need to fetch fresh values of ::top after mutex is acquired
|
|
|
|
while (!prepared_txns_.empty() && prepared_txns_.top() <= new_max) {
|
|
|
|
auto to_be_popped = prepared_txns_.top();
|
|
|
|
delayed_prepared_.insert(to_be_popped);
|
|
|
|
ROCKS_LOG_WARN(info_log_,
|
|
|
|
"prepared_mutex_ overhead %" PRIu64 " (prep=%" PRIu64
|
Add rollback_deletion_type_callback to TxnDBOptions (#9873)
Summary:
This PR does not affect write-committed.
Add a member, `rollback_deletion_type_callback` to TransactionDBOptions
so that a write-prepared transaction, when rolling back, can call this
callback to decide if a `Delete` or `SingleDelete` should be used to
cancel a prior `Put` written to the database during prepare phase.
The purpose of this PR is to prevent mixing `Delete` and `SingleDelete`
for the same key, causing undefined behaviors. Without this PR, the
following can happen:
```
// The application always issues SingleDelete when deleting keys.
txn1->Put('a');
txn1->Prepare(); // writes to memtable and potentially gets flushed/compacted to Lmax
txn1->Rollback(); // inserts DELETE('a')
txn2->Put('a');
txn2->Commit(); // writes to memtable and potentially gets flushed/compacted
```
In the database, we may have
```
L0: [PUT('a', s=100)]
L1: [DELETE('a', s=90)]
Lmax: [PUT('a', s=0)]
```
If a compaction compacts L0 and L1, then we have
```
L1: [PUT('a', s=100)]
Lmax: [PUT('a', s=0)]
```
If a future transaction issues a SingleDelete, we have
```
L0: [SD('a', s=110)]
L1: [PUT('a', s=100)]
Lmax: [PUT('a', s=0)]
```
Then, a compaction including L0, L1 and Lmax leads to
```
Lmax: [PUT('a', s=0)]
```
which is incorrect.
Similar bugs reported and addressed in
https://github.com/cockroachdb/pebble/issues/1255. Based on our team's
current priority, we have decided to take this approach for now. We may
come back and revisit in the future.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9873
Test Plan: make check
Reviewed By: ltamasi
Differential Revision: D35762170
Pulled By: riversand963
fbshipit-source-id: b28d56eefc786b53c9844b9ef4a7807acdd82c8d
2022-04-21 01:57:32 +00:00
|
|
|
" new_max=%" PRIu64 ")",
|
2019-06-10 18:47:16 +00:00
|
|
|
static_cast<uint64_t>(delayed_prepared_.size()),
|
|
|
|
to_be_popped, new_max);
|
|
|
|
delayed_prepared_empty_.store(false, std::memory_order_release);
|
2019-08-09 23:35:16 +00:00
|
|
|
// Update prepared_txns_ after updating delayed_prepared_empty_ otherwise
|
|
|
|
// there will be a point in time that the entry is neither in
|
|
|
|
// prepared_txns_ nor in delayed_prepared_, which will not be checked if
|
|
|
|
// delayed_prepared_empty_ is false.
|
|
|
|
prepared_txns_.pop();
|
2019-06-10 18:47:16 +00:00
|
|
|
}
|
|
|
|
if (locked) {
|
|
|
|
prepared_txns_.push_pop_mutex()->Lock();
|
|
|
|
}
|
2019-03-07 15:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 18:47:16 +00:00
|
|
|
void WritePreparedTxnDB::AddPrepared(uint64_t seq, bool locked) {
|
2019-03-07 15:32:01 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_, "Txn %" PRIu64 " Preparing with max %" PRIu64,
|
2019-01-18 19:33:30 +00:00
|
|
|
seq, max_evicted_seq_.load());
|
2019-03-07 15:32:01 +00:00
|
|
|
TEST_SYNC_POINT("AddPrepared::begin:pause");
|
|
|
|
TEST_SYNC_POINT("AddPrepared::begin:resume");
|
2019-06-10 18:47:16 +00:00
|
|
|
if (!locked) {
|
|
|
|
prepared_txns_.push_pop_mutex()->Lock();
|
|
|
|
}
|
|
|
|
prepared_txns_.push_pop_mutex()->AssertHeld();
|
2019-03-07 15:32:01 +00:00
|
|
|
prepared_txns_.push(seq);
|
|
|
|
auto new_max = future_max_evicted_seq_.load();
|
|
|
|
if (UNLIKELY(seq <= new_max)) {
|
2019-01-18 19:33:30 +00:00
|
|
|
// This should not happen in normal case
|
|
|
|
ROCKS_LOG_ERROR(
|
|
|
|
info_log_,
|
|
|
|
"Added prepare_seq is not larger than max_evicted_seq_: %" PRIu64
|
|
|
|
" <= %" PRIu64,
|
2019-03-07 15:32:01 +00:00
|
|
|
seq, new_max);
|
2019-06-10 18:47:16 +00:00
|
|
|
CheckPreparedAgainstMax(new_max, true /*locked*/);
|
|
|
|
}
|
|
|
|
if (!locked) {
|
|
|
|
prepared_txns_.push_pop_mutex()->Unlock();
|
2019-01-18 19:33:30 +00:00
|
|
|
}
|
2019-03-07 15:32:01 +00:00
|
|
|
TEST_SYNC_POINT("AddPrepared::end");
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:47:46 +00:00
|
|
|
void WritePreparedTxnDB::AddCommitted(uint64_t prepare_seq, uint64_t commit_seq,
|
2018-04-12 02:59:25 +00:00
|
|
|
uint8_t loop_cnt) {
|
|
|
|
ROCKS_LOG_DETAILS(info_log_, "Txn %" PRIu64 " Committing with %" PRIu64,
|
|
|
|
prepare_seq, commit_seq);
|
2017-12-01 07:39:56 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::AddCommitted:start");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::AddCommitted:start:pause");
|
2017-11-02 18:05:55 +00:00
|
|
|
auto indexed_seq = prepare_seq % COMMIT_CACHE_SIZE;
|
|
|
|
CommitEntry64b evicted_64b;
|
|
|
|
CommitEntry evicted;
|
|
|
|
bool to_be_evicted = GetCommitEntry(indexed_seq, &evicted_64b, &evicted);
|
2018-03-05 18:48:29 +00:00
|
|
|
if (LIKELY(to_be_evicted)) {
|
|
|
|
assert(evicted.prep_seq != prepare_seq);
|
2017-11-02 18:05:55 +00:00
|
|
|
auto prev_max = max_evicted_seq_.load(std::memory_order_acquire);
|
2018-01-09 16:47:46 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_,
|
|
|
|
"Evicting %" PRIu64 ",%" PRIu64 " with max %" PRIu64,
|
|
|
|
evicted.prep_seq, evicted.commit_seq, prev_max);
|
2017-11-02 18:05:55 +00:00
|
|
|
if (prev_max < evicted.commit_seq) {
|
2019-01-16 02:07:50 +00:00
|
|
|
auto last = db_impl_->GetLastPublishedSequence(); // could be 0
|
|
|
|
SequenceNumber max_evicted_seq;
|
|
|
|
if (LIKELY(evicted.commit_seq < last)) {
|
|
|
|
assert(last > 0);
|
|
|
|
// Inc max in larger steps to avoid frequent updates
|
|
|
|
max_evicted_seq =
|
|
|
|
std::min(evicted.commit_seq + INC_STEP_FOR_MAX_EVICTED, last - 1);
|
|
|
|
} else {
|
|
|
|
// legit when a commit entry in a write batch overwrite the previous one
|
|
|
|
max_evicted_seq = evicted.commit_seq;
|
|
|
|
}
|
2022-04-28 00:50:54 +00:00
|
|
|
#ifdef OS_LINUX
|
|
|
|
if (rocksdb_write_prepared_TEST_ShouldClearCommitCache &&
|
|
|
|
rocksdb_write_prepared_TEST_ShouldClearCommitCache()) {
|
|
|
|
max_evicted_seq = last;
|
|
|
|
}
|
|
|
|
#endif // OS_LINUX
|
2019-01-16 02:07:50 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_,
|
|
|
|
"%lu Evicting %" PRIu64 ",%" PRIu64 " with max %" PRIu64
|
|
|
|
" => %lu",
|
|
|
|
prepare_seq, evicted.prep_seq, evicted.commit_seq,
|
|
|
|
prev_max, max_evicted_seq);
|
2017-11-02 18:05:55 +00:00
|
|
|
AdvanceMaxEvictedSeq(prev_max, max_evicted_seq);
|
|
|
|
}
|
2019-01-18 19:33:30 +00:00
|
|
|
if (UNLIKELY(!delayed_prepared_empty_.load(std::memory_order_acquire))) {
|
|
|
|
WriteLock wl(&prepared_mutex_);
|
2021-07-30 19:06:47 +00:00
|
|
|
auto dp_iter = delayed_prepared_.find(evicted.prep_seq);
|
|
|
|
if (dp_iter != delayed_prepared_.end()) {
|
|
|
|
// This is a rare case that txn is committed but prepared_txns_ is not
|
|
|
|
// cleaned up yet. Refer to delayed_prepared_commits_ definition for
|
|
|
|
// why it should be kept updated.
|
|
|
|
delayed_prepared_commits_[evicted.prep_seq] = evicted.commit_seq;
|
|
|
|
ROCKS_LOG_DEBUG(info_log_,
|
|
|
|
"delayed_prepared_commits_[%" PRIu64 "]=%" PRIu64,
|
|
|
|
evicted.prep_seq, evicted.commit_seq);
|
2019-01-18 19:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-30 19:06:47 +00:00
|
|
|
// After each eviction from commit cache, check if the commit entry should
|
|
|
|
// be kept around because it overlaps with a live snapshot.
|
|
|
|
CheckAgainstSnapshots(evicted);
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
bool succ =
|
|
|
|
ExchangeCommitEntry(indexed_seq, evicted_64b, {prepare_seq, commit_seq});
|
2018-03-05 18:48:29 +00:00
|
|
|
if (UNLIKELY(!succ)) {
|
|
|
|
ROCKS_LOG_ERROR(info_log_,
|
|
|
|
"ExchangeCommitEntry failed on [%" PRIu64 "] %" PRIu64
|
|
|
|
",%" PRIu64 " retrying...",
|
|
|
|
indexed_seq, prepare_seq, commit_seq);
|
2017-11-02 18:05:55 +00:00
|
|
|
// A very rare event, in which the commit entry is updated before we do.
|
|
|
|
// Here we apply a very simple solution of retrying.
|
2018-01-09 16:47:46 +00:00
|
|
|
if (loop_cnt > 100) {
|
|
|
|
throw std::runtime_error("Infinite loop in AddCommitted!");
|
|
|
|
}
|
2018-04-12 02:59:25 +00:00
|
|
|
AddCommitted(prepare_seq, commit_seq, ++loop_cnt);
|
2017-11-02 18:05:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-12 02:59:25 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::AddCommitted:end");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::AddCommitted:end:pause");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WritePreparedTxnDB::RemovePrepared(const uint64_t prepare_seq,
|
|
|
|
const size_t batch_cnt) {
|
2019-01-18 19:33:30 +00:00
|
|
|
TEST_SYNC_POINT_CALLBACK(
|
|
|
|
"RemovePrepared:Start",
|
|
|
|
const_cast<void*>(reinterpret_cast<const void*>(&prepare_seq)));
|
2019-02-06 16:43:16 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::RemovePrepared:pause");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::RemovePrepared:resume");
|
2019-01-18 19:33:30 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_,
|
|
|
|
"RemovePrepared %" PRIu64 " cnt: %" ROCKSDB_PRIszt,
|
|
|
|
prepare_seq, batch_cnt);
|
2018-04-12 02:59:25 +00:00
|
|
|
WriteLock wl(&prepared_mutex_);
|
|
|
|
for (size_t i = 0; i < batch_cnt; i++) {
|
|
|
|
prepared_txns_.erase(prepare_seq + i);
|
2017-11-02 18:05:55 +00:00
|
|
|
bool was_empty = delayed_prepared_.empty();
|
|
|
|
if (!was_empty) {
|
2018-04-12 02:59:25 +00:00
|
|
|
delayed_prepared_.erase(prepare_seq + i);
|
2019-01-18 19:33:30 +00:00
|
|
|
auto it = delayed_prepared_commits_.find(prepare_seq + i);
|
|
|
|
if (it != delayed_prepared_commits_.end()) {
|
|
|
|
ROCKS_LOG_DETAILS(info_log_, "delayed_prepared_commits_.erase %" PRIu64,
|
|
|
|
prepare_seq + i);
|
|
|
|
delayed_prepared_commits_.erase(it);
|
|
|
|
}
|
2017-11-02 18:05:55 +00:00
|
|
|
bool is_empty = delayed_prepared_.empty();
|
|
|
|
if (was_empty != is_empty) {
|
|
|
|
delayed_prepared_empty_.store(is_empty, std::memory_order_release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WritePreparedTxnDB::GetCommitEntry(const uint64_t indexed_seq,
|
|
|
|
CommitEntry64b* entry_64b,
|
|
|
|
CommitEntry* entry) const {
|
2022-10-25 21:15:22 +00:00
|
|
|
*entry_64b = commit_cache_[static_cast<size_t>(indexed_seq)].load(
|
|
|
|
std::memory_order_acquire);
|
2017-11-02 18:05:55 +00:00
|
|
|
bool valid = entry_64b->Parse(indexed_seq, entry, FORMAT);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WritePreparedTxnDB::AddCommitEntry(const uint64_t indexed_seq,
|
|
|
|
const CommitEntry& new_entry,
|
|
|
|
CommitEntry* evicted_entry) {
|
|
|
|
CommitEntry64b new_entry_64b(new_entry, FORMAT);
|
2022-10-25 21:15:22 +00:00
|
|
|
CommitEntry64b evicted_entry_64b =
|
|
|
|
commit_cache_[static_cast<size_t>(indexed_seq)].exchange(
|
|
|
|
new_entry_64b, std::memory_order_acq_rel);
|
2017-11-02 18:05:55 +00:00
|
|
|
bool valid = evicted_entry_64b.Parse(indexed_seq, evicted_entry, FORMAT);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WritePreparedTxnDB::ExchangeCommitEntry(const uint64_t indexed_seq,
|
|
|
|
CommitEntry64b& expected_entry_64b,
|
|
|
|
const CommitEntry& new_entry) {
|
2018-09-06 01:07:53 +00:00
|
|
|
auto& atomic_entry = commit_cache_[static_cast<size_t>(indexed_seq)];
|
2017-11-02 18:05:55 +00:00
|
|
|
CommitEntry64b new_entry_64b(new_entry, FORMAT);
|
|
|
|
bool succ = atomic_entry.compare_exchange_strong(
|
|
|
|
expected_entry_64b, new_entry_64b, std::memory_order_acq_rel,
|
|
|
|
std::memory_order_acquire);
|
|
|
|
return succ;
|
|
|
|
}
|
|
|
|
|
2018-02-21 21:40:31 +00:00
|
|
|
void WritePreparedTxnDB::AdvanceMaxEvictedSeq(const SequenceNumber& prev_max,
|
|
|
|
const SequenceNumber& new_max) {
|
|
|
|
ROCKS_LOG_DETAILS(info_log_,
|
2019-02-06 16:43:16 +00:00
|
|
|
"AdvanceMaxEvictedSeq overhead %" PRIu64 " => %" PRIu64,
|
|
|
|
prev_max, new_max);
|
2019-01-18 19:33:30 +00:00
|
|
|
// Declare the intention before getting snapshot from the DB. This helps a
|
|
|
|
// concurrent GetSnapshot to wait to catch up with future_max_evicted_seq_ if
|
|
|
|
// it has not already. Otherwise the new snapshot is when we ask DB for
|
|
|
|
// snapshots smaller than future max.
|
|
|
|
auto updated_future_max = prev_max;
|
|
|
|
while (updated_future_max < new_max &&
|
|
|
|
!future_max_evicted_seq_.compare_exchange_weak(
|
|
|
|
updated_future_max, new_max, std::memory_order_acq_rel,
|
|
|
|
std::memory_order_relaxed)) {
|
|
|
|
};
|
2019-03-07 15:32:01 +00:00
|
|
|
|
2019-06-10 18:47:16 +00:00
|
|
|
CheckPreparedAgainstMax(new_max, false /*locked*/);
|
2017-11-02 18:05:55 +00:00
|
|
|
|
|
|
|
// With each change to max_evicted_seq_ fetch the live snapshots behind it.
|
|
|
|
// We use max as the version of snapshots to identify how fresh are the
|
|
|
|
// snapshot list. This works because the snapshots are between 0 and
|
|
|
|
// max, so the larger the max, the more complete they are.
|
|
|
|
SequenceNumber new_snapshots_version = new_max;
|
|
|
|
std::vector<SequenceNumber> snapshots;
|
|
|
|
bool update_snapshots = false;
|
|
|
|
if (new_snapshots_version > snapshots_version_) {
|
|
|
|
// This is to avoid updating the snapshots_ if it already updated
|
|
|
|
// with a more recent vesion by a concrrent thread
|
|
|
|
update_snapshots = true;
|
|
|
|
// We only care about snapshots lower then max
|
|
|
|
snapshots = GetSnapshotListFromDB(new_max);
|
|
|
|
}
|
|
|
|
if (update_snapshots) {
|
|
|
|
UpdateSnapshots(snapshots, new_snapshots_version);
|
2019-01-08 22:43:24 +00:00
|
|
|
if (!snapshots.empty()) {
|
|
|
|
WriteLock wl(&old_commit_map_mutex_);
|
|
|
|
for (auto snap : snapshots) {
|
|
|
|
// This allows IsInSnapshot to tell apart the reads from in valid
|
|
|
|
// snapshots from the reads from committed values in valid snapshots.
|
|
|
|
old_commit_map_[snap];
|
|
|
|
}
|
|
|
|
old_commit_map_empty_.store(false, std::memory_order_release);
|
|
|
|
}
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
2018-02-21 21:40:31 +00:00
|
|
|
auto updated_prev_max = prev_max;
|
2019-03-07 15:32:01 +00:00
|
|
|
TEST_SYNC_POINT("AdvanceMaxEvictedSeq::update_max:pause");
|
|
|
|
TEST_SYNC_POINT("AdvanceMaxEvictedSeq::update_max:resume");
|
2018-02-21 21:40:31 +00:00
|
|
|
while (updated_prev_max < new_max &&
|
|
|
|
!max_evicted_seq_.compare_exchange_weak(updated_prev_max, new_max,
|
|
|
|
std::memory_order_acq_rel,
|
|
|
|
std::memory_order_relaxed)) {
|
2017-11-02 18:05:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-03 03:19:21 +00:00
|
|
|
const Snapshot* WritePreparedTxnDB::GetSnapshot() {
|
2019-01-16 02:07:50 +00:00
|
|
|
const bool kForWWConflictCheck = true;
|
|
|
|
return GetSnapshotInternal(!kForWWConflictCheck);
|
|
|
|
}
|
|
|
|
|
|
|
|
SnapshotImpl* WritePreparedTxnDB::GetSnapshotInternal(
|
|
|
|
bool for_ww_conflict_check) {
|
|
|
|
// Note: for this optimization setting the last sequence number and obtaining
|
|
|
|
// the smallest uncommitted seq should be done atomically. However to avoid
|
|
|
|
// the mutex overhead, we call SmallestUnCommittedSeq BEFORE taking the
|
|
|
|
// snapshot. Since we always updated the list of unprepared seq (via
|
|
|
|
// AddPrepared) AFTER the last sequence is updated, this guarantees that the
|
|
|
|
// smallest uncommitted seq that we pair with the snapshot is smaller or equal
|
|
|
|
// the value that would be obtained otherwise atomically. That is ok since
|
|
|
|
// this optimization works as long as min_uncommitted is less than or equal
|
|
|
|
// than the smallest uncommitted seq when the snapshot was taken.
|
2018-04-12 02:59:25 +00:00
|
|
|
auto min_uncommitted = WritePreparedTxnDB::SmallestUnCommittedSeq();
|
2019-01-16 02:07:50 +00:00
|
|
|
SnapshotImpl* snap_impl = db_impl_->GetSnapshotImpl(for_ww_conflict_check);
|
2019-06-10 18:47:16 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::GetSnapshotInternal:first");
|
2018-04-03 03:19:21 +00:00
|
|
|
assert(snap_impl);
|
2019-01-16 02:07:50 +00:00
|
|
|
SequenceNumber snap_seq = snap_impl->GetSequenceNumber();
|
2019-01-18 19:33:30 +00:00
|
|
|
// Note: Check against future_max_evicted_seq_ (in contrast with
|
|
|
|
// max_evicted_seq_) in case there is a concurrent AdvanceMaxEvictedSeq.
|
|
|
|
if (UNLIKELY(snap_seq != 0 && snap_seq <= future_max_evicted_seq_)) {
|
2019-01-16 02:07:50 +00:00
|
|
|
// There is a very rare case in which the commit entry evicts another commit
|
|
|
|
// entry that is not published yet thus advancing max evicted seq beyond the
|
|
|
|
// last published seq. This case is not likely in real-world setup so we
|
|
|
|
// handle it with a few retries.
|
|
|
|
size_t retry = 0;
|
2019-01-18 19:33:30 +00:00
|
|
|
SequenceNumber max;
|
|
|
|
while ((max = future_max_evicted_seq_.load()) != 0 &&
|
|
|
|
snap_impl->GetSequenceNumber() <= max && retry < 100) {
|
|
|
|
ROCKS_LOG_WARN(info_log_,
|
|
|
|
"GetSnapshot snap: %" PRIu64 " max: %" PRIu64
|
|
|
|
" retry %" ROCKSDB_PRIszt,
|
|
|
|
snap_impl->GetSequenceNumber(), max, retry);
|
2019-01-16 02:07:50 +00:00
|
|
|
ReleaseSnapshot(snap_impl);
|
|
|
|
// Wait for last visible seq to catch up with max, and also go beyond it
|
|
|
|
// by one.
|
|
|
|
AdvanceSeqByOne();
|
|
|
|
snap_impl = db_impl_->GetSnapshotImpl(for_ww_conflict_check);
|
|
|
|
assert(snap_impl);
|
|
|
|
retry++;
|
|
|
|
}
|
2019-01-18 19:33:30 +00:00
|
|
|
assert(snap_impl->GetSequenceNumber() > max);
|
|
|
|
if (snap_impl->GetSequenceNumber() <= max) {
|
|
|
|
throw std::runtime_error(
|
2022-05-06 20:03:58 +00:00
|
|
|
"Snapshot seq " + std::to_string(snap_impl->GetSequenceNumber()) +
|
|
|
|
" after " + std::to_string(retry) +
|
|
|
|
" retries is still less than futre_max_evicted_seq_" +
|
|
|
|
std::to_string(max));
|
2019-01-16 02:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-12 02:59:25 +00:00
|
|
|
EnhanceSnapshot(snap_impl, min_uncommitted);
|
2019-01-16 02:07:50 +00:00
|
|
|
ROCKS_LOG_DETAILS(
|
|
|
|
db_impl_->immutable_db_options().info_log,
|
|
|
|
"GetSnapshot %" PRIu64 " ww:%" PRIi32 " min_uncommitted: %" PRIu64,
|
2019-01-18 19:33:30 +00:00
|
|
|
snap_impl->GetSequenceNumber(), for_ww_conflict_check, min_uncommitted);
|
2019-06-10 18:47:16 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::GetSnapshotInternal:end");
|
2018-04-03 03:19:21 +00:00
|
|
|
return snap_impl;
|
|
|
|
}
|
|
|
|
|
2019-01-16 02:07:50 +00:00
|
|
|
void WritePreparedTxnDB::AdvanceSeqByOne() {
|
|
|
|
// Inserting an empty value will i) let the max evicted entry to be
|
|
|
|
// published, i.e., max == last_published, increase the last published to
|
|
|
|
// be one beyond max, i.e., max < last_published.
|
Group SST write in flush, compaction and db open with new stats (#11910)
Summary:
## Context/Summary
Similar to https://github.com/facebook/rocksdb/pull/11288, https://github.com/facebook/rocksdb/pull/11444, categorizing SST/blob file write according to different io activities allows more insight into the activity.
For that, this PR does the following:
- Tag different write IOs by passing down and converting WriteOptions to IOOptions
- Add new SST_WRITE_MICROS histogram in WritableFileWriter::Append() and breakdown FILE_WRITE_{FLUSH|COMPACTION|DB_OPEN}_MICROS
Some related code refactory to make implementation cleaner:
- Blob stats
- Replace high-level write measurement with low-level WritableFileWriter::Append() measurement for BLOB_DB_BLOB_FILE_WRITE_MICROS. This is to make FILE_WRITE_{FLUSH|COMPACTION|DB_OPEN}_MICROS include blob file. As a consequence, this introduces some behavioral changes on it, see HISTORY and db bench test plan below for more info.
- Fix bugs where BLOB_DB_BLOB_FILE_SYNCED/BLOB_DB_BLOB_FILE_BYTES_WRITTEN include file failed to sync and bytes failed to write.
- Refactor WriteOptions constructor for easier construction with io_activity and rate_limiter_priority
- Refactor DBImpl::~DBImpl()/BlobDBImpl::Close() to bypass thread op verification
- Build table
- TableBuilderOptions now includes Read/WriteOpitons so BuildTable() do not need to take these two variables
- Replace the io_priority passed into BuildTable() with TableBuilderOptions::WriteOpitons::rate_limiter_priority. Similar for BlobFileBuilder.
This parameter is used for dynamically changing file io priority for flush, see https://github.com/facebook/rocksdb/pull/9988?fbclid=IwAR1DtKel6c-bRJAdesGo0jsbztRtciByNlvokbxkV6h_L-AE9MACzqRTT5s for more
- Update ThreadStatus::FLUSH_BYTES_WRITTEN to use io_activity to track flush IO in flush job and db open instead of io_priority
## Test
### db bench
Flush
```
./db_bench --statistics=1 --benchmarks=fillseq --num=100000 --write_buffer_size=100
rocksdb.sst.write.micros P50 : 1.830863 P95 : 4.094720 P99 : 6.578947 P100 : 26.000000 COUNT : 7875 SUM : 20377
rocksdb.file.write.flush.micros P50 : 1.830863 P95 : 4.094720 P99 : 6.578947 P100 : 26.000000 COUNT : 7875 SUM : 20377
rocksdb.file.write.compaction.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0
rocksdb.file.write.db.open.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0
```
compaction, db oopen
```
Setup: ./db_bench --statistics=1 --benchmarks=fillseq --num=10000 --disable_auto_compactions=1 -write_buffer_size=100 --db=../db_bench
Run:./db_bench --statistics=1 --benchmarks=compact --db=../db_bench --use_existing_db=1
rocksdb.sst.write.micros P50 : 2.675325 P95 : 9.578788 P99 : 18.780000 P100 : 314.000000 COUNT : 638 SUM : 3279
rocksdb.file.write.flush.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0
rocksdb.file.write.compaction.micros P50 : 2.757353 P95 : 9.610687 P99 : 19.316667 P100 : 314.000000 COUNT : 615 SUM : 3213
rocksdb.file.write.db.open.micros P50 : 2.055556 P95 : 3.925000 P99 : 9.000000 P100 : 9.000000 COUNT : 23 SUM : 66
```
blob stats - just to make sure they aren't broken by this PR
```
Integrated Blob DB
Setup: ./db_bench --enable_blob_files=1 --statistics=1 --benchmarks=fillseq --num=10000 --disable_auto_compactions=1 -write_buffer_size=100 --db=../db_bench
Run:./db_bench --enable_blob_files=1 --statistics=1 --benchmarks=compact --db=../db_bench --use_existing_db=1
pre-PR:
rocksdb.blobdb.blob.file.write.micros P50 : 7.298246 P95 : 9.771930 P99 : 9.991813 P100 : 16.000000 COUNT : 235 SUM : 1600
rocksdb.blobdb.blob.file.synced COUNT : 1
rocksdb.blobdb.blob.file.bytes.written COUNT : 34842
post-PR:
rocksdb.blobdb.blob.file.write.micros P50 : 2.000000 P95 : 2.829360 P99 : 2.993779 P100 : 9.000000 COUNT : 707 SUM : 1614
- COUNT is higher and values are smaller as it includes header and footer write
- COUNT is 3X higher due to each Append() count as one post-PR, while in pre-PR, 3 Append()s counts as one. See https://github.com/facebook/rocksdb/pull/11910/files#diff-32b811c0a1c000768cfb2532052b44dc0b3bf82253f3eab078e15ff201a0dabfL157-L164
rocksdb.blobdb.blob.file.synced COUNT : 1 (stay the same)
rocksdb.blobdb.blob.file.bytes.written COUNT : 34842 (stay the same)
```
```
Stacked Blob DB
Run: ./db_bench --use_blob_db=1 --statistics=1 --benchmarks=fillseq --num=10000 --disable_auto_compactions=1 -write_buffer_size=100 --db=../db_bench
pre-PR:
rocksdb.blobdb.blob.file.write.micros P50 : 12.808042 P95 : 19.674497 P99 : 28.539683 P100 : 51.000000 COUNT : 10000 SUM : 140876
rocksdb.blobdb.blob.file.synced COUNT : 8
rocksdb.blobdb.blob.file.bytes.written COUNT : 1043445
post-PR:
rocksdb.blobdb.blob.file.write.micros P50 : 1.657370 P95 : 2.952175 P99 : 3.877519 P100 : 24.000000 COUNT : 30001 SUM : 67924
- COUNT is higher and values are smaller as it includes header and footer write
- COUNT is 3X higher due to each Append() count as one post-PR, while in pre-PR, 3 Append()s counts as one. See https://github.com/facebook/rocksdb/pull/11910/files#diff-32b811c0a1c000768cfb2532052b44dc0b3bf82253f3eab078e15ff201a0dabfL157-L164
rocksdb.blobdb.blob.file.synced COUNT : 8 (stay the same)
rocksdb.blobdb.blob.file.bytes.written COUNT : 1043445 (stay the same)
```
### Rehearsal CI stress test
Trigger 3 full runs of all our CI stress tests
### Performance
Flush
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_pre_pr --benchmark_filter=ManualFlush/key_num:524288/per_key_size:256 --benchmark_repetitions=1000
-- default: 1 thread is used to run benchmark; enable_statistics = true
Pre-pr: avg 507515519.3 ns
497686074,499444327,500862543,501389862,502994471,503744435,504142123,504224056,505724198,506610393,506837742,506955122,507695561,507929036,508307733,508312691,508999120,509963561,510142147,510698091,510743096,510769317,510957074,511053311,511371367,511409911,511432960,511642385,511691964,511730908,
Post-pr: avg 511971266.5 ns, regressed 0.88%
502744835,506502498,507735420,507929724,508313335,509548582,509994942,510107257,510715603,511046955,511352639,511458478,512117521,512317380,512766303,512972652,513059586,513804934,513808980,514059409,514187369,514389494,514447762,514616464,514622882,514641763,514666265,514716377,514990179,515502408,
```
Compaction
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{pre|post}_pr --benchmark_filter=ManualCompaction/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1 --benchmark_repetitions=1000
-- default: 1 thread is used to run benchmark
Pre-pr: avg 495346098.30 ns
492118301,493203526,494201411,494336607,495269217,495404950,496402598,497012157,497358370,498153846
Post-pr: avg 504528077.20, regressed 1.85%. "ManualCompaction" include flush so the isolated regression for compaction should be around 1.85-0.88 = 0.97%
502465338,502485945,502541789,502909283,503438601,504143885,506113087,506629423,507160414,507393007
```
Put with WAL (in case passing WriteOptions slows down this path even without collecting SST write stats)
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_pre_pr --benchmark_filter=DBPut/comp_style:0/max_data:107374182400/per_key_size:256/enable_statistics:1/wal:1 --benchmark_repetitions=1000
-- default: 1 thread is used to run benchmark
Pre-pr: avg 3848.10 ns
3814,3838,3839,3848,3854,3854,3854,3860,3860,3860
Post-pr: avg 3874.20 ns, regressed 0.68%
3863,3867,3871,3874,3875,3877,3877,3877,3880,3881
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11910
Reviewed By: ajkr
Differential Revision: D49788060
Pulled By: hx235
fbshipit-source-id: 79e73699cda5be3b66461687e5147c2484fc5eff
2023-12-29 23:29:23 +00:00
|
|
|
// TODO: plumb Env::IOActivity, Env::IOPriority
|
2019-01-16 02:07:50 +00:00
|
|
|
WriteOptions woptions;
|
|
|
|
TransactionOptions txn_options;
|
|
|
|
Transaction* txn0 = BeginTransaction(woptions, txn_options, nullptr);
|
|
|
|
std::hash<std::thread::id> hasher;
|
|
|
|
char name[64];
|
|
|
|
snprintf(name, 64, "txn%" ROCKSDB_PRIszt, hasher(std::this_thread::get_id()));
|
|
|
|
assert(strlen(name) < 64 - 1);
|
|
|
|
Status s = txn0->SetName(name);
|
|
|
|
assert(s.ok());
|
|
|
|
if (s.ok()) {
|
|
|
|
// Without prepare it would simply skip the commit
|
|
|
|
s = txn0->Prepare();
|
|
|
|
}
|
|
|
|
assert(s.ok());
|
|
|
|
if (s.ok()) {
|
|
|
|
s = txn0->Commit();
|
|
|
|
}
|
|
|
|
assert(s.ok());
|
|
|
|
delete txn0;
|
|
|
|
}
|
|
|
|
|
2017-11-02 18:05:55 +00:00
|
|
|
const std::vector<SequenceNumber> WritePreparedTxnDB::GetSnapshotListFromDB(
|
|
|
|
SequenceNumber max) {
|
2018-01-09 16:47:46 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_, "GetSnapshotListFromDB with max %" PRIu64, max);
|
2019-01-11 21:39:26 +00:00
|
|
|
InstrumentedMutexLock dblock(db_impl_->mutex());
|
|
|
|
db_impl_->mutex()->AssertHeld();
|
2017-11-02 18:05:55 +00:00
|
|
|
return db_impl_->snapshots().GetAll(nullptr, max);
|
|
|
|
}
|
|
|
|
|
2017-12-13 15:52:02 +00:00
|
|
|
void WritePreparedTxnDB::ReleaseSnapshotInternal(
|
|
|
|
const SequenceNumber snap_seq) {
|
2019-02-04 20:53:55 +00:00
|
|
|
// TODO(myabandeh): relax should enough since the synchronizatin is already
|
|
|
|
// done by snapshots_mutex_ under which this function is called.
|
|
|
|
if (snap_seq <= max_evicted_seq_.load(std::memory_order_acquire)) {
|
2017-12-13 15:52:02 +00:00
|
|
|
// Then this is a rare case that transaction did not finish before max
|
|
|
|
// advances. It is expected for a few read-only backup snapshots. For such
|
|
|
|
// snapshots we might have kept around a couple of entries in the
|
|
|
|
// old_commit_map_. Check and do garbage collection if that is the case.
|
|
|
|
bool need_gc = false;
|
|
|
|
{
|
2018-04-08 04:55:42 +00:00
|
|
|
WPRecordTick(TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD);
|
2018-11-06 07:02:01 +00:00
|
|
|
ROCKS_LOG_WARN(info_log_, "old_commit_map_mutex_ overhead for %" PRIu64,
|
|
|
|
snap_seq);
|
2017-12-13 15:52:02 +00:00
|
|
|
ReadLock rl(&old_commit_map_mutex_);
|
|
|
|
auto prep_set_entry = old_commit_map_.find(snap_seq);
|
|
|
|
need_gc = prep_set_entry != old_commit_map_.end();
|
|
|
|
}
|
|
|
|
if (need_gc) {
|
2018-04-08 04:55:42 +00:00
|
|
|
WPRecordTick(TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD);
|
2018-11-06 07:02:01 +00:00
|
|
|
ROCKS_LOG_WARN(info_log_, "old_commit_map_mutex_ overhead for %" PRIu64,
|
|
|
|
snap_seq);
|
2017-12-13 15:52:02 +00:00
|
|
|
WriteLock wl(&old_commit_map_mutex_);
|
|
|
|
old_commit_map_.erase(snap_seq);
|
|
|
|
old_commit_map_empty_.store(old_commit_map_.empty(),
|
|
|
|
std::memory_order_release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 03:01:37 +00:00
|
|
|
void WritePreparedTxnDB::CleanupReleasedSnapshots(
|
|
|
|
const std::vector<SequenceNumber>& new_snapshots,
|
|
|
|
const std::vector<SequenceNumber>& old_snapshots) {
|
|
|
|
auto newi = new_snapshots.begin();
|
|
|
|
auto oldi = old_snapshots.begin();
|
|
|
|
for (; newi != new_snapshots.end() && oldi != old_snapshots.end();) {
|
|
|
|
assert(*newi >= *oldi); // cannot have new snapshots with lower seq
|
|
|
|
if (*newi == *oldi) { // still not released
|
2018-11-30 04:59:52 +00:00
|
|
|
auto value = *newi;
|
|
|
|
while (newi != new_snapshots.end() && *newi == value) {
|
|
|
|
newi++;
|
|
|
|
}
|
|
|
|
while (oldi != old_snapshots.end() && *oldi == value) {
|
|
|
|
oldi++;
|
|
|
|
}
|
2018-11-29 03:01:37 +00:00
|
|
|
} else {
|
|
|
|
assert(*newi > *oldi); // *oldi is released
|
|
|
|
ReleaseSnapshotInternal(*oldi);
|
|
|
|
oldi++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Everything remained in old_snapshots is released and must be cleaned up
|
|
|
|
for (; oldi != old_snapshots.end(); oldi++) {
|
|
|
|
ReleaseSnapshotInternal(*oldi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 18:05:55 +00:00
|
|
|
void WritePreparedTxnDB::UpdateSnapshots(
|
|
|
|
const std::vector<SequenceNumber>& snapshots,
|
|
|
|
const SequenceNumber& version) {
|
2018-01-09 16:47:46 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_, "UpdateSnapshots with version %" PRIu64,
|
|
|
|
version);
|
2017-11-02 18:05:55 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:p:start");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:s:start");
|
|
|
|
#ifndef NDEBUG
|
|
|
|
size_t sync_i = 0;
|
|
|
|
#endif
|
2018-04-08 04:55:42 +00:00
|
|
|
ROCKS_LOG_DETAILS(info_log_, "snapshots_mutex_ overhead");
|
2017-11-02 18:05:55 +00:00
|
|
|
WriteLock wl(&snapshots_mutex_);
|
|
|
|
snapshots_version_ = version;
|
|
|
|
// We update the list concurrently with the readers.
|
|
|
|
// Both new and old lists are sorted and the new list is subset of the
|
|
|
|
// previous list plus some new items. Thus if a snapshot repeats in
|
|
|
|
// both new and old lists, it will appear upper in the new list. So if
|
|
|
|
// we simply insert the new snapshots in order, if an overwritten item
|
|
|
|
// is still valid in the new list is either written to the same place in
|
|
|
|
// the array or it is written in a higher palce before it gets
|
|
|
|
// overwritten by another item. This guarantess a reader that reads the
|
|
|
|
// list bottom-up will eventaully see a snapshot that repeats in the
|
|
|
|
// update, either before it gets overwritten by the writer or
|
|
|
|
// afterwards.
|
|
|
|
size_t i = 0;
|
|
|
|
auto it = snapshots.begin();
|
2019-05-15 20:14:18 +00:00
|
|
|
for (; it != snapshots.end() && i < SNAPSHOT_CACHE_SIZE; ++it, ++i) {
|
2017-11-02 18:05:55 +00:00
|
|
|
snapshot_cache_[i].store(*it, std::memory_order_release);
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:p:", ++sync_i);
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:s:", sync_i);
|
|
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Release the remaining sync points since they are useless given that the
|
|
|
|
// reader would also use lock to access snapshots
|
|
|
|
for (++sync_i; sync_i <= 10; ++sync_i) {
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:p:", sync_i);
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:s:", sync_i);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
snapshots_.clear();
|
2019-05-15 20:14:18 +00:00
|
|
|
for (; it != snapshots.end(); ++it) {
|
2017-11-02 18:05:55 +00:00
|
|
|
// Insert them to a vector that is less efficient to access
|
|
|
|
// concurrently
|
|
|
|
snapshots_.push_back(*it);
|
|
|
|
}
|
|
|
|
// Update the size at the end. Otherwise a parallel reader might read
|
|
|
|
// items that are not set yet.
|
|
|
|
snapshots_total_.store(snapshots.size(), std::memory_order_release);
|
2018-11-29 03:01:37 +00:00
|
|
|
|
|
|
|
// Note: this must be done after the snapshots data structures are updated
|
|
|
|
// with the new list of snapshots.
|
|
|
|
CleanupReleasedSnapshots(snapshots, snapshots_all_);
|
|
|
|
snapshots_all_ = snapshots;
|
|
|
|
|
2017-11-02 18:05:55 +00:00
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:p:end");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::UpdateSnapshots:s:end");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WritePreparedTxnDB::CheckAgainstSnapshots(const CommitEntry& evicted) {
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:p:start");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:s:start");
|
|
|
|
#ifndef NDEBUG
|
|
|
|
size_t sync_i = 0;
|
|
|
|
#endif
|
|
|
|
// First check the snapshot cache that is efficient for concurrent access
|
|
|
|
auto cnt = snapshots_total_.load(std::memory_order_acquire);
|
|
|
|
// The list might get updated concurrently as we are reading from it. The
|
|
|
|
// reader should be able to read all the snapshots that are still valid
|
|
|
|
// after the update. Since the survived snapshots are written in a higher
|
|
|
|
// place before gets overwritten the reader that reads bottom-up will
|
|
|
|
// eventully see it.
|
|
|
|
const bool next_is_larger = true;
|
2018-11-06 07:02:01 +00:00
|
|
|
// We will set to true if the border line snapshot suggests that.
|
|
|
|
bool search_larger_list = false;
|
2017-11-02 18:05:55 +00:00
|
|
|
size_t ip1 = std::min(cnt, SNAPSHOT_CACHE_SIZE);
|
|
|
|
for (; 0 < ip1; ip1--) {
|
2018-11-06 07:02:01 +00:00
|
|
|
SequenceNumber snapshot_seq =
|
|
|
|
snapshot_cache_[ip1 - 1].load(std::memory_order_acquire);
|
2017-11-02 18:05:55 +00:00
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:p:",
|
|
|
|
++sync_i);
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:s:", sync_i);
|
2018-11-06 07:02:01 +00:00
|
|
|
if (ip1 == SNAPSHOT_CACHE_SIZE) { // border line snapshot
|
|
|
|
// snapshot_seq < commit_seq => larger_snapshot_seq <= commit_seq
|
|
|
|
// then later also continue the search to larger snapshots
|
|
|
|
search_larger_list = snapshot_seq < evicted.commit_seq;
|
|
|
|
}
|
2017-11-02 18:05:55 +00:00
|
|
|
if (!MaybeUpdateOldCommitMap(evicted.prep_seq, evicted.commit_seq,
|
|
|
|
snapshot_seq, !next_is_larger)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Release the remaining sync points before accquiring the lock
|
|
|
|
for (++sync_i; sync_i <= 10; ++sync_i) {
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:p:", sync_i);
|
|
|
|
TEST_IDX_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:s:", sync_i);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:p:end");
|
|
|
|
TEST_SYNC_POINT("WritePreparedTxnDB::CheckAgainstSnapshots:s:end");
|
2018-11-06 07:02:01 +00:00
|
|
|
if (UNLIKELY(SNAPSHOT_CACHE_SIZE < cnt && search_larger_list)) {
|
2017-11-02 18:05:55 +00:00
|
|
|
// Then access the less efficient list of snapshots_
|
2018-04-08 04:55:42 +00:00
|
|
|
WPRecordTick(TXN_SNAPSHOT_MUTEX_OVERHEAD);
|
2018-11-06 07:02:01 +00:00
|
|
|
ROCKS_LOG_WARN(info_log_,
|
|
|
|
"snapshots_mutex_ overhead for <%" PRIu64 ",%" PRIu64
|
|
|
|
"> with %" ROCKSDB_PRIszt " snapshots",
|
|
|
|
evicted.prep_seq, evicted.commit_seq, cnt);
|
2017-11-02 18:05:55 +00:00
|
|
|
ReadLock rl(&snapshots_mutex_);
|
|
|
|
// Items could have moved from the snapshots_ to snapshot_cache_ before
|
|
|
|
// accquiring the lock. To make sure that we do not miss a valid snapshot,
|
|
|
|
// read snapshot_cache_ again while holding the lock.
|
|
|
|
for (size_t i = 0; i < SNAPSHOT_CACHE_SIZE; i++) {
|
2018-11-06 07:02:01 +00:00
|
|
|
SequenceNumber snapshot_seq =
|
|
|
|
snapshot_cache_[i].load(std::memory_order_acquire);
|
2017-11-02 18:05:55 +00:00
|
|
|
if (!MaybeUpdateOldCommitMap(evicted.prep_seq, evicted.commit_seq,
|
|
|
|
snapshot_seq, next_is_larger)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto snapshot_seq_2 : snapshots_) {
|
|
|
|
if (!MaybeUpdateOldCommitMap(evicted.prep_seq, evicted.commit_seq,
|
|
|
|
snapshot_seq_2, next_is_larger)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WritePreparedTxnDB::MaybeUpdateOldCommitMap(
|
|
|
|
const uint64_t& prep_seq, const uint64_t& commit_seq,
|
|
|
|
const uint64_t& snapshot_seq, const bool next_is_larger = true) {
|
2017-12-13 15:52:02 +00:00
|
|
|
// If we do not store an entry in old_commit_map_ we assume it is committed in
|
|
|
|
// all snapshots. If commit_seq <= snapshot_seq, it is considered already in
|
2017-11-02 18:05:55 +00:00
|
|
|
// the snapshot so we need not to keep the entry around for this snapshot.
|
|
|
|
if (commit_seq <= snapshot_seq) {
|
|
|
|
// continue the search if the next snapshot could be smaller than commit_seq
|
|
|
|
return !next_is_larger;
|
|
|
|
}
|
|
|
|
// then snapshot_seq < commit_seq
|
|
|
|
if (prep_seq <= snapshot_seq) { // overlapping range
|
2018-04-08 04:55:42 +00:00
|
|
|
WPRecordTick(TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD);
|
2018-11-06 07:02:01 +00:00
|
|
|
ROCKS_LOG_WARN(info_log_,
|
|
|
|
"old_commit_map_mutex_ overhead for %" PRIu64
|
|
|
|
" commit entry: <%" PRIu64 ",%" PRIu64 ">",
|
|
|
|
snapshot_seq, prep_seq, commit_seq);
|
2017-11-02 18:05:55 +00:00
|
|
|
WriteLock wl(&old_commit_map_mutex_);
|
|
|
|
old_commit_map_empty_.store(false, std::memory_order_release);
|
2017-12-13 15:52:02 +00:00
|
|
|
auto& vec = old_commit_map_[snapshot_seq];
|
|
|
|
vec.insert(std::upper_bound(vec.begin(), vec.end(), prep_seq), prep_seq);
|
|
|
|
// We need to store it once for each overlapping snapshot. Returning true to
|
|
|
|
// continue the search if there is more overlapping snapshot.
|
|
|
|
return true;
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
// continue the search if the next snapshot could be larger than prep_seq
|
|
|
|
return next_is_larger;
|
|
|
|
}
|
|
|
|
|
|
|
|
WritePreparedTxnDB::~WritePreparedTxnDB() {
|
|
|
|
// At this point there could be running compaction/flush holding a
|
|
|
|
// SnapshotChecker, which holds a pointer back to WritePreparedTxnDB.
|
|
|
|
// Make sure those jobs finished before destructing WritePreparedTxnDB.
|
2020-01-07 23:33:05 +00:00
|
|
|
if (!db_impl_->shutting_down_) {
|
|
|
|
db_impl_->CancelAllBackgroundWork(true /*wait*/);
|
|
|
|
}
|
2017-11-02 18:05:55 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 18:48:29 +00:00
|
|
|
void SubBatchCounter::InitWithComp(const uint32_t cf) {
|
|
|
|
auto cmp = comparators_[cf];
|
|
|
|
keys_[cf] = CFKeys(SetComparator(cmp));
|
|
|
|
}
|
|
|
|
|
2018-02-13 00:27:39 +00:00
|
|
|
void SubBatchCounter::AddKey(const uint32_t cf, const Slice& key) {
|
|
|
|
CFKeys& cf_keys = keys_[cf];
|
|
|
|
if (cf_keys.size() == 0) { // just inserted
|
2018-03-05 18:48:29 +00:00
|
|
|
InitWithComp(cf);
|
2018-02-13 00:27:39 +00:00
|
|
|
}
|
|
|
|
auto it = cf_keys.insert(key);
|
|
|
|
if (it.second == false) { // second is false if a element already existed.
|
|
|
|
batches_++;
|
|
|
|
keys_.clear();
|
2018-03-05 18:48:29 +00:00
|
|
|
InitWithComp(cf);
|
2018-02-13 00:27:39 +00:00
|
|
|
keys_[cf].insert(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|