2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-11-08 06:27:21 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2021-07-12 18:03:41 +02:00
|
|
|
|
|
|
|
#include "rocksdb/customizable.h"
|
2014-08-25 23:22:05 +02:00
|
|
|
#include "rocksdb/table.h"
|
2013-11-08 06:27:21 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2013-11-08 06:27:21 +01:00
|
|
|
|
|
|
|
class Slice;
|
|
|
|
class BlockBuilder;
|
2021-07-12 18:03:41 +02:00
|
|
|
struct ConfigOptions;
|
2014-03-01 01:39:27 +01:00
|
|
|
struct Options;
|
2013-11-08 06:27:21 +01:00
|
|
|
|
|
|
|
// FlushBlockPolicy provides a configurable way to determine when to flush a
|
|
|
|
// block in the block based tables,
|
|
|
|
class FlushBlockPolicy {
|
|
|
|
public:
|
|
|
|
// Keep track of the key/value sequences and return the boolean value to
|
|
|
|
// determine if table builder should flush current data block.
|
2019-03-27 21:21:27 +01:00
|
|
|
virtual bool Update(const Slice& key, const Slice& value) = 0;
|
2013-11-08 06:27:21 +01:00
|
|
|
|
2019-03-27 21:21:27 +01:00
|
|
|
virtual ~FlushBlockPolicy() {}
|
2013-11-08 06:27:21 +01:00
|
|
|
};
|
|
|
|
|
2021-07-12 18:03:41 +02:00
|
|
|
class FlushBlockPolicyFactory : public Customizable {
|
2013-11-08 06:27:21 +01:00
|
|
|
public:
|
2021-07-12 18:03:41 +02:00
|
|
|
static const char* Type() { return "FlushBlockPolicyFactory"; }
|
|
|
|
|
|
|
|
// Creates a FlushBlockPolicyFactory based on the input value.
|
|
|
|
// By default, this method can create EveryKey or BySize PolicyFactory,
|
|
|
|
// which take now config_options.
|
|
|
|
static Status CreateFromString(
|
|
|
|
const ConfigOptions& config_options, const std::string& value,
|
|
|
|
std::shared_ptr<FlushBlockPolicyFactory>* result);
|
2013-11-08 06:27:21 +01:00
|
|
|
|
|
|
|
// Return a new block flush policy that flushes data blocks by data size.
|
|
|
|
// FlushBlockPolicy may need to access the metadata of the data block
|
|
|
|
// builder to determine when to flush the blocks.
|
|
|
|
//
|
|
|
|
// Callers must delete the result after any database that is using the
|
|
|
|
// result has been closed.
|
|
|
|
virtual FlushBlockPolicy* NewFlushBlockPolicy(
|
2014-08-25 23:22:05 +02:00
|
|
|
const BlockBasedTableOptions& table_options,
|
|
|
|
const BlockBuilder& data_block_builder) const = 0;
|
2013-11-08 06:27:21 +01:00
|
|
|
|
2019-03-27 21:21:27 +01:00
|
|
|
virtual ~FlushBlockPolicyFactory() {}
|
2013-11-08 06:27:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class FlushBlockBySizePolicyFactory : public FlushBlockPolicyFactory {
|
|
|
|
public:
|
2021-07-12 18:03:41 +02:00
|
|
|
FlushBlockBySizePolicyFactory();
|
2013-11-08 06:27:21 +01:00
|
|
|
|
2021-07-12 18:03:41 +02:00
|
|
|
static const char* kClassName() { return "FlushBlockBySizePolicyFactory"; }
|
|
|
|
const char* Name() const override { return kClassName(); }
|
2013-11-08 06:27:21 +01:00
|
|
|
|
2017-06-27 19:49:34 +02:00
|
|
|
FlushBlockPolicy* NewFlushBlockPolicy(
|
2014-08-25 23:22:05 +02:00
|
|
|
const BlockBasedTableOptions& table_options,
|
2013-11-08 06:27:21 +01:00
|
|
|
const BlockBuilder& data_block_builder) const override;
|
2017-03-28 20:56:56 +02:00
|
|
|
|
|
|
|
static FlushBlockPolicy* NewFlushBlockPolicy(
|
|
|
|
const uint64_t size, const int deviation,
|
|
|
|
const BlockBuilder& data_block_builder);
|
2013-11-08 06:27:21 +01:00
|
|
|
};
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|