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).
8 #include "rocksdb/table.h"
9 #include "util/gflags_compat.h"
10 #include "util/random.h"
12 DECLARE_int32(mark_for_compaction_one_file_in
);
14 namespace ROCKSDB_NAMESPACE
{
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
{
22 DbStressTablePropertiesCollector()
23 : need_compact_(Random::GetTLSInstance()->OneInOpt(
24 FLAGS_mark_for_compaction_one_file_in
)) {}
26 virtual Status
AddUserKey(const Slice
& /* key */, const Slice
& /* value */,
27 EntryType
/*type*/, SequenceNumber
/*seq*/,
28 uint64_t /*file_size*/) override
{
32 virtual Status
Finish(UserCollectedProperties
* /* properties */) override
{
36 virtual UserCollectedProperties
GetReadableProperties() const override
{
37 return UserCollectedProperties
{};
40 virtual const char* Name() const override
{
41 return "DbStressTablePropertiesCollector";
44 virtual bool NeedCompact() const override
{ return need_compact_
; }
47 const bool need_compact_
;
50 // A `DbStressTablePropertiesCollectorFactory` creates
51 // `DbStressTablePropertiesCollectorFactory`s.
52 class DbStressTablePropertiesCollectorFactory
53 : public TablePropertiesCollectorFactory
{
55 virtual TablePropertiesCollector
* CreateTablePropertiesCollector(
56 TablePropertiesCollectorFactory::Context
/* context */) override
{
57 return new DbStressTablePropertiesCollector();
60 virtual const char* Name() const override
{
61 return "DbStressTablePropertiesCollectorFactory";
65 } // namespace ROCKSDB_NAMESPACE