]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db_stress_tool/db_stress_table_properties_collector.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / db_stress_tool / db_stress_table_properties_collector.h
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 #pragma once
7
8 #include "rocksdb/table.h"
9 #include "util/gflags_compat.h"
10 #include "util/random.h"
11
12 DECLARE_int32(mark_for_compaction_one_file_in);
13
14 namespace ROCKSDB_NAMESPACE {
15
16 // A `DbStressTablePropertiesCollector` ignores what keys/values were added to
17 // the table, adds no properties to the table, and decides at random whether the
18 // table will be marked for compaction according to
19 // `FLAGS_mark_for_compaction_one_file_in`.
20 class DbStressTablePropertiesCollector : public TablePropertiesCollector {
21 public:
22 DbStressTablePropertiesCollector()
23 : need_compact_(Random::GetTLSInstance()->OneInOpt(
24 FLAGS_mark_for_compaction_one_file_in)) {}
25
26 virtual Status AddUserKey(const Slice& /* key */, const Slice& /* value */,
27 EntryType /*type*/, SequenceNumber /*seq*/,
28 uint64_t /*file_size*/) override {
29 return Status::OK();
30 }
31
32 virtual Status Finish(UserCollectedProperties* /* properties */) override {
33 return Status::OK();
34 }
35
36 virtual UserCollectedProperties GetReadableProperties() const override {
37 return UserCollectedProperties{};
38 }
39
40 virtual const char* Name() const override {
41 return "DbStressTablePropertiesCollector";
42 }
43
44 virtual bool NeedCompact() const override { return need_compact_; }
45
46 private:
47 const bool need_compact_;
48 };
49
50 // A `DbStressTablePropertiesCollectorFactory` creates
51 // `DbStressTablePropertiesCollectorFactory`s.
52 class DbStressTablePropertiesCollectorFactory
53 : public TablePropertiesCollectorFactory {
54 public:
55 virtual TablePropertiesCollector* CreateTablePropertiesCollector(
56 TablePropertiesCollectorFactory::Context /* context */) override {
57 return new DbStressTablePropertiesCollector();
58 }
59
60 virtual const char* Name() const override {
61 return "DbStressTablePropertiesCollectorFactory";
62 }
63 };
64
65 } // namespace ROCKSDB_NAMESPACE