]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | #pragma once | |
7 | ||
8 | #ifndef ROCKSDB_LITE | |
9 | #include "rocksdb/utilities/table_properties_collectors.h" | |
f67539c2 | 10 | namespace ROCKSDB_NAMESPACE { |
7c673cae | 11 | |
7c673cae FG |
12 | class CompactOnDeletionCollector : public TablePropertiesCollector { |
13 | public: | |
20effc67 TL |
14 | CompactOnDeletionCollector(size_t sliding_window_size, |
15 | size_t deletion_trigger, double deletion_raatio); | |
7c673cae FG |
16 | |
17 | // AddUserKey() will be called when a new key/value pair is inserted into the | |
18 | // table. | |
19 | // @params key the user key that is inserted into the table. | |
20 | // @params value the value that is inserted into the table. | |
21 | // @params file_size file size up to now | |
22 | virtual Status AddUserKey(const Slice& key, const Slice& value, | |
23 | EntryType type, SequenceNumber seq, | |
24 | uint64_t file_size) override; | |
25 | ||
26 | // Finish() will be called when a table has already been built and is ready | |
27 | // for writing the properties block. | |
28 | // @params properties User will add their collected statistics to | |
29 | // `properties`. | |
20effc67 | 30 | virtual Status Finish(UserCollectedProperties* /*properties*/) override; |
7c673cae FG |
31 | |
32 | // Return the human-readable properties, where the key is property name and | |
33 | // the value is the human-readable form of value. | |
34 | virtual UserCollectedProperties GetReadableProperties() const override { | |
35 | return UserCollectedProperties(); | |
36 | } | |
37 | ||
38 | // The name of the properties collector can be used for debugging purpose. | |
39 | virtual const char* Name() const override { | |
40 | return "CompactOnDeletionCollector"; | |
41 | } | |
42 | ||
43 | // EXPERIMENTAL Return whether the output file should be further compacted | |
44 | virtual bool NeedCompact() const override { | |
45 | return need_compaction_; | |
46 | } | |
47 | ||
48 | static const int kNumBuckets = 128; | |
49 | ||
50 | private: | |
51 | void Reset(); | |
52 | ||
53 | // A ring buffer that used to count the number of deletion entries for every | |
54 | // "bucket_size_" keys. | |
55 | size_t num_deletions_in_buckets_[kNumBuckets]; | |
56 | // the number of keys in a bucket | |
57 | size_t bucket_size_; | |
58 | ||
59 | size_t current_bucket_; | |
60 | size_t num_keys_in_current_bucket_; | |
61 | size_t num_deletions_in_observation_window_; | |
62 | size_t deletion_trigger_; | |
20effc67 TL |
63 | const double deletion_ratio_; |
64 | const bool deletion_ratio_enabled_; | |
65 | size_t total_entries_ = 0; | |
66 | size_t deletion_entries_ = 0; | |
7c673cae FG |
67 | // true if the current SST file needs to be compacted. |
68 | bool need_compaction_; | |
11fdf7f2 | 69 | bool finished_; |
7c673cae | 70 | }; |
f67539c2 | 71 | } // namespace ROCKSDB_NAMESPACE |
7c673cae | 72 | #endif // !ROCKSDB_LITE |