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 #include "rocksdb/flush_block_policy.h" 7 8 namespace ROCKSDB_NAMESPACE { 9 10 // FlushBlockEveryKeyPolicy currently used only in tests. 11 12 class FlushBlockEveryKeyPolicy : public FlushBlockPolicy { 13 public: Update(const Slice &,const Slice &)14 bool Update(const Slice& /*key*/, const Slice& /*value*/) override { 15 if (!start_) { 16 start_ = true; 17 return false; 18 } 19 return true; 20 } 21 22 private: 23 bool start_ = false; 24 }; 25 26 class FlushBlockEveryKeyPolicyFactory : public FlushBlockPolicyFactory { 27 public: FlushBlockEveryKeyPolicyFactory()28 explicit FlushBlockEveryKeyPolicyFactory() {} 29 Name()30 const char* Name() const override { 31 return "FlushBlockEveryKeyPolicyFactory"; 32 } 33 NewFlushBlockPolicy(const BlockBasedTableOptions &,const BlockBuilder &)34 FlushBlockPolicy* NewFlushBlockPolicy( 35 const BlockBasedTableOptions& /*table_options*/, 36 const BlockBuilder& /*data_block_builder*/) const override { 37 return new FlushBlockEveryKeyPolicy; 38 } 39 }; 40 41 } // namespace ROCKSDB_NAMESPACE 42