forked from continuwuation/rocksdb
Summary: In anticipation of an enhancement related to parallel compression * Rename confusing state variables `seperator_is_key_plus_seq_` -> `must_use_separator_with_seq_` * Eliminate copy-paste code in `PartitionedIndexBuilder::AddIndexEntry` * Optimize/simplify `PartitionedIndexBuilder::flush_policy_` by allowing a single policy to be re-targetted to different block builders. Added some additional internal APIs to make this work, and it only works because the FlushBlockBySizePolicy is otherwise stateless (after creation). * Improve some comments, including another proposed optimization especially for the common case of no live snapshots affecting a large compaction Pull Request resolved: https://github.com/facebook/rocksdb/pull/13828 Test Plan: existing tests are pretty exhaustive, especially with crash test Planning to validate performance in combination with next change. (This change is saving some extra allocate/deallocate with partitioned index.) Reviewed By: cbi42 Differential Revision: D79570576 Pulled By: pdillinger fbshipit-source-id: f7a16f0e6e6ad2023a3d1a2ebaa3cc22aac717af
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
// 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).
|
|
|
|
#pragma once
|
|
#include "rocksdb/flush_block_policy.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
// FlushBlockEveryKeyPolicy currently used only in tests.
|
|
|
|
class FlushBlockEveryKeyPolicy : public FlushBlockPolicy {
|
|
public:
|
|
bool Update(const Slice& /*key*/, const Slice& /*value*/) override {
|
|
if (!start_) {
|
|
start_ = true;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
bool start_ = false;
|
|
};
|
|
|
|
class FlushBlockEveryKeyPolicyFactory : public FlushBlockPolicyFactory {
|
|
public:
|
|
explicit FlushBlockEveryKeyPolicyFactory() {}
|
|
|
|
static const char* kClassName() { return "FlushBlockEveryKeyPolicyFactory"; }
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
FlushBlockPolicy* NewFlushBlockPolicy(
|
|
const BlockBasedTableOptions& /*table_options*/,
|
|
const BlockBuilder& /*data_block_builder*/) const override {
|
|
return new FlushBlockEveryKeyPolicy;
|
|
}
|
|
};
|
|
|
|
// For internal use, policy that is stateless after creation, meaning it can
|
|
// be safely re-targeted to another block builder.
|
|
class RetargetableFlushBlockPolicy : public FlushBlockPolicy {
|
|
public:
|
|
explicit RetargetableFlushBlockPolicy(const BlockBuilder& data_block_builder)
|
|
: data_block_builder_(&data_block_builder) {}
|
|
|
|
void Retarget(const BlockBuilder& data_block_builder) {
|
|
data_block_builder_ = &data_block_builder;
|
|
}
|
|
|
|
protected:
|
|
const BlockBuilder* data_block_builder_;
|
|
};
|
|
|
|
std::unique_ptr<RetargetableFlushBlockPolicy> NewFlushBlockBySizePolicy(
|
|
const uint64_t size, const int deviation,
|
|
const BlockBuilder& data_block_builder);
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|