rocksdb/db/compaction/sst_partitioner.cc
Tomas Kolda cd4592c220 SST Partitioner interface that allows to split SST files (#6957)
Summary:
SST Partitioner interface that allows to split SST files during compactions.

It basically instruct compaction to create a new file when needed. When one is using well defined prefixes and prefixed way of defining tables it is good to define also partitioning so that promotion of some SST file does not cover huge key space on next level (worst case complete space).

Pull Request resolved: https://github.com/facebook/rocksdb/pull/6957

Reviewed By: ajkr

Differential Revision: D22461239

fbshipit-source-id: 9ce07bba08b3ba89c2d45630520368f704d1316e
2020-07-24 13:44:49 -07:00

45 lines
1.5 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).
//
#include "rocksdb/sst_partitioner.h"
#include <algorithm>
namespace ROCKSDB_NAMESPACE {
PartitionerResult SstPartitionerFixedPrefix::ShouldPartition(
const PartitionerRequest& request) {
Slice last_key_fixed(*request.prev_user_key);
if (last_key_fixed.size() > len_) {
last_key_fixed.size_ = len_;
}
Slice current_key_fixed(*request.current_user_key);
if (current_key_fixed.size() > len_) {
current_key_fixed.size_ = len_;
}
return last_key_fixed.compare(current_key_fixed) != 0 ? kRequired
: kNotRequired;
}
bool SstPartitionerFixedPrefix::CanDoTrivialMove(
const Slice& smallest_user_key, const Slice& largest_user_key) {
return ShouldPartition(PartitionerRequest(smallest_user_key, largest_user_key,
0)) == kNotRequired;
}
std::unique_ptr<SstPartitioner>
SstPartitionerFixedPrefixFactory::CreatePartitioner(
const SstPartitioner::Context& /* context */) const {
return std::unique_ptr<SstPartitioner>(new SstPartitionerFixedPrefix(len_));
}
std::shared_ptr<SstPartitionerFactory> NewSstPartitionerFixedPrefixFactory(
size_t prefix_len) {
return std::make_shared<SstPartitionerFixedPrefixFactory>(prefix_len);
}
} // namespace ROCKSDB_NAMESPACE