]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/table/block_builder.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / table / block_builder.h
CommitLineData
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// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10#pragma once
11#include <vector>
12
13#include <stdint.h>
14#include "rocksdb/slice.h"
11fdf7f2
TL
15#include "rocksdb/table.h"
16#include "table/data_block_hash_index.h"
7c673cae
FG
17
18namespace rocksdb {
19
20class BlockBuilder {
21 public:
22 BlockBuilder(const BlockBuilder&) = delete;
23 void operator=(const BlockBuilder&) = delete;
24
25 explicit BlockBuilder(int block_restart_interval,
11fdf7f2
TL
26 bool use_delta_encoding = true,
27 bool use_value_delta_encoding = false,
28 BlockBasedTableOptions::DataBlockIndexType index_type =
29 BlockBasedTableOptions::kDataBlockBinarySearch,
30 double data_block_hash_table_util_ratio = 0.75);
7c673cae
FG
31
32 // Reset the contents as if the BlockBuilder was just constructed.
33 void Reset();
34
35 // REQUIRES: Finish() has not been called since the last call to Reset().
36 // REQUIRES: key is larger than any previously added key
11fdf7f2
TL
37 void Add(const Slice& key, const Slice& value,
38 const Slice* const delta_value = nullptr);
7c673cae
FG
39
40 // Finish building the block and return a slice that refers to the
41 // block contents. The returned slice will remain valid for the
42 // lifetime of this builder or until Reset() is called.
43 Slice Finish();
44
45 // Returns an estimate of the current (uncompressed) size of the block
46 // we are building.
11fdf7f2
TL
47 inline size_t CurrentSizeEstimate() const {
48 return estimate_ + (data_block_hash_index_builder_.Valid()
49 ? data_block_hash_index_builder_.EstimateSize()
50 : 0);
51 }
7c673cae
FG
52
53 // Returns an estimated block size after appending key and value.
54 size_t EstimateSizeAfterKV(const Slice& key, const Slice& value) const;
55
56 // Return true iff no entries have been added since the last Reset()
494da23a 57 bool empty() const { return buffer_.empty(); }
7c673cae
FG
58
59 private:
494da23a 60 const int block_restart_interval_;
11fdf7f2 61 // TODO(myabandeh): put it into a separate IndexBlockBuilder
494da23a 62 const bool use_delta_encoding_;
11fdf7f2
TL
63 // Refer to BlockIter::DecodeCurrentValue for format of delta encoded values
64 const bool use_value_delta_encoding_;
7c673cae 65
494da23a 66 std::string buffer_; // Destination buffer
7c673cae 67 std::vector<uint32_t> restarts_; // Restart points
494da23a
TL
68 size_t estimate_;
69 int counter_; // Number of entries emitted since restart
70 bool finished_; // Has Finish() been called?
71 std::string last_key_;
11fdf7f2 72 DataBlockHashIndexBuilder data_block_hash_index_builder_;
7c673cae
FG
73};
74
75} // namespace rocksdb