YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/flush_block_policy.h
Line
Count
Source
1
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
// This source code is licensed under the BSD-style license found in the
3
// LICENSE file in the root directory of this source tree. An additional grant
4
// of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
#ifndef YB_ROCKSDB_FLUSH_BLOCK_POLICY_H
21
#define YB_ROCKSDB_FLUSH_BLOCK_POLICY_H
22
23
#pragma once
24
25
#include <string>
26
27
#include "yb/util/slice.h"
28
#include "yb/rocksdb/table.h"
29
30
namespace rocksdb {
31
32
class BlockBuilder;
33
struct Options;
34
35
// FlushBlockPolicy provides a configurable way to determine when to flush a
36
// block in the block based tables,
37
class FlushBlockPolicy {
38
 public:
39
  // Keep track of the key/value sequences and return the boolean value to
40
  // determine if table builder should flush current data block.
41
  virtual bool Update(const Slice& key,
42
                      const Slice& value) = 0;
43
44
137k
  virtual ~FlushBlockPolicy() { }
45
};
46
47
class FlushBlockPolicyFactory {
48
 public:
49
  // Return the name of the flush block policy.
50
  virtual const char* Name() const = 0;
51
52
  // Return a new block flush policy that flushes data blocks by data size.
53
  // FlushBlockPolicy may need to access the metadata of the data block
54
  // builder to determine when to flush the blocks.
55
  //
56
  // Callers must delete the result after any database that is using the
57
  // result has been closed.
58
  virtual FlushBlockPolicy* NewFlushBlockPolicy(
59
      const BlockBasedTableOptions& table_options,
60
      const BlockBuilder& data_block_builder) const = 0;
61
62
5.26M
  virtual ~FlushBlockPolicyFactory() { }
63
};
64
65
class FlushBlockBySizePolicyFactory : public FlushBlockPolicyFactory {
66
 public:
67
5.29M
  FlushBlockBySizePolicyFactory() {}
68
69
2.02M
  virtual const char* Name() const override {
70
2.02M
    return "FlushBlockBySizePolicyFactory";
71
2.02M
  }
72
73
  virtual FlushBlockPolicy* NewFlushBlockPolicy(
74
      const BlockBasedTableOptions& table_options,
75
      const BlockBuilder& data_block_builder) const override;
76
77
  static std::unique_ptr<FlushBlockPolicy> NewFlushBlockPolicy(
78
      const uint64_t size, const int deviation, const size_t min_keys_per_block,
79
      const BlockBuilder& data_block_builder);
80
};
81
82
}  // namespace rocksdb
83
84
#endif // YB_ROCKSDB_FLUSH_BLOCK_POLICY_H