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