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).
9 #include "rocksdb/table.h"
17 // FlushBlockPolicy provides a configurable way to determine when to flush a
18 // block in the block based tables,
19 class FlushBlockPolicy
{
21 // Keep track of the key/value sequences and return the boolean value to
22 // determine if table builder should flush current data block.
23 virtual bool Update(const Slice
& key
, const Slice
& value
) = 0;
25 virtual ~FlushBlockPolicy() {}
28 class FlushBlockPolicyFactory
{
30 // Return the name of the flush block policy.
31 virtual const char* Name() const = 0;
33 // Return a new block flush policy that flushes data blocks by data size.
34 // FlushBlockPolicy may need to access the metadata of the data block
35 // builder to determine when to flush the blocks.
37 // Callers must delete the result after any database that is using the
38 // result has been closed.
39 virtual FlushBlockPolicy
* NewFlushBlockPolicy(
40 const BlockBasedTableOptions
& table_options
,
41 const BlockBuilder
& data_block_builder
) const = 0;
43 virtual ~FlushBlockPolicyFactory() {}
46 class FlushBlockBySizePolicyFactory
: public FlushBlockPolicyFactory
{
48 FlushBlockBySizePolicyFactory() {}
50 const char* Name() const override
{ return "FlushBlockBySizePolicyFactory"; }
52 FlushBlockPolicy
* NewFlushBlockPolicy(
53 const BlockBasedTableOptions
& table_options
,
54 const BlockBuilder
& data_block_builder
) const override
;
56 static FlushBlockPolicy
* NewFlushBlockPolicy(
57 const uint64_t size
, const int deviation
,
58 const BlockBuilder
& data_block_builder
);
61 } // namespace rocksdb