]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/db/compaction/sst_partitioner.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / db / compaction / sst_partitioner.cc
CommitLineData
20effc67
TL
1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
5//
6
7#include "rocksdb/sst_partitioner.h"
8
9#include <algorithm>
10
11namespace ROCKSDB_NAMESPACE {
12
13PartitionerResult SstPartitionerFixedPrefix::ShouldPartition(
14 const PartitionerRequest& request) {
15 Slice last_key_fixed(*request.prev_user_key);
16 if (last_key_fixed.size() > len_) {
17 last_key_fixed.size_ = len_;
18 }
19 Slice current_key_fixed(*request.current_user_key);
20 if (current_key_fixed.size() > len_) {
21 current_key_fixed.size_ = len_;
22 }
23 return last_key_fixed.compare(current_key_fixed) != 0 ? kRequired
24 : kNotRequired;
25}
26
27bool SstPartitionerFixedPrefix::CanDoTrivialMove(
28 const Slice& smallest_user_key, const Slice& largest_user_key) {
29 return ShouldPartition(PartitionerRequest(smallest_user_key, largest_user_key,
30 0)) == kNotRequired;
31}
32
33std::unique_ptr<SstPartitioner>
34SstPartitionerFixedPrefixFactory::CreatePartitioner(
35 const SstPartitioner::Context& /* context */) const {
36 return std::unique_ptr<SstPartitioner>(new SstPartitionerFixedPrefix(len_));
37}
38
39std::shared_ptr<SstPartitionerFactory> NewSstPartitionerFixedPrefixFactory(
40 size_t prefix_len) {
41 return std::make_shared<SstPartitionerFixedPrefixFactory>(prefix_len);
42}
43
44} // namespace ROCKSDB_NAMESPACE