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). 5 6 #pragma once 7 8 #include <string> 9 #include "rocksdb/table.h" 10 11 namespace ROCKSDB_NAMESPACE { 12 13 class Slice; 14 class BlockBuilder; 15 struct Options; 16 17 // FlushBlockPolicy provides a configurable way to determine when to flush a 18 // block in the block based tables, 19 class FlushBlockPolicy { 20 public: 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; 24 ~FlushBlockPolicy()25 virtual ~FlushBlockPolicy() {} 26 }; 27 28 class FlushBlockPolicyFactory { 29 public: 30 // Return the name of the flush block policy. 31 virtual const char* Name() const = 0; 32 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. 36 // 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; 42 ~FlushBlockPolicyFactory()43 virtual ~FlushBlockPolicyFactory() {} 44 }; 45 46 class FlushBlockBySizePolicyFactory : public FlushBlockPolicyFactory { 47 public: FlushBlockBySizePolicyFactory()48 FlushBlockBySizePolicyFactory() {} 49 Name()50 const char* Name() const override { return "FlushBlockBySizePolicyFactory"; } 51 52 FlushBlockPolicy* NewFlushBlockPolicy( 53 const BlockBasedTableOptions& table_options, 54 const BlockBuilder& data_block_builder) const override; 55 56 static FlushBlockPolicy* NewFlushBlockPolicy( 57 const uint64_t size, const int deviation, 58 const BlockBuilder& data_block_builder); 59 }; 60 61 } // namespace ROCKSDB_NAMESPACE 62