2013-10-29 01:54:09 +01:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2011-03-18 23:37:00 +01:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2013-10-29 01:54:09 +01:00
|
|
|
#pragma once
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <stdint.h>
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/status.h"
|
2013-10-30 18:52:33 +01:00
|
|
|
#include "rocksdb/table.h"
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
class BlockBuilder;
|
|
|
|
class BlockHandle;
|
|
|
|
class WritableFile;
|
2013-10-29 01:54:09 +01:00
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2013-10-29 01:54:09 +01:00
|
|
|
class BlockBasedTableBuilder : public TableBuilder {
|
2011-03-18 23:37:00 +01:00
|
|
|
public:
|
|
|
|
// Create a builder that will store the contents of the table it is
|
|
|
|
// building in *file. Does not close the file. It is up to the
|
2013-10-30 18:52:33 +01:00
|
|
|
// caller to close the file after calling Finish().
|
2013-10-29 01:54:09 +01:00
|
|
|
BlockBasedTableBuilder(const Options& options, WritableFile* file,
|
2013-10-30 18:52:33 +01:00
|
|
|
CompressionType compression_type);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// REQUIRES: Either Finish() or Abandon() has been called.
|
2013-10-29 01:54:09 +01:00
|
|
|
~BlockBasedTableBuilder();
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Add key,value to the table being constructed.
|
|
|
|
// REQUIRES: key is after any previously added key according to comparator.
|
|
|
|
// REQUIRES: Finish(), Abandon() have not been called
|
2013-10-29 01:54:09 +01:00
|
|
|
void Add(const Slice& key, const Slice& value) override;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Return non-ok iff some error has been detected.
|
2013-10-29 01:54:09 +01:00
|
|
|
Status status() const override;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Finish building the table. Stops using the file passed to the
|
|
|
|
// constructor after this function returns.
|
|
|
|
// REQUIRES: Finish(), Abandon() have not been called
|
2013-10-29 01:54:09 +01:00
|
|
|
Status Finish() override;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Indicate that the contents of this builder should be abandoned. Stops
|
|
|
|
// using the file passed to the constructor after this function returns.
|
|
|
|
// If the caller is not going to call Finish(), it must call Abandon()
|
|
|
|
// before destroying this builder.
|
|
|
|
// REQUIRES: Finish(), Abandon() have not been called
|
2013-10-29 01:54:09 +01:00
|
|
|
void Abandon() override;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Number of calls to Add() so far.
|
2013-10-29 01:54:09 +01:00
|
|
|
uint64_t NumEntries() const override;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Size of the file generated so far. If invoked after a successful
|
|
|
|
// Finish() call, returns the size of the final generated file.
|
2013-10-29 01:54:09 +01:00
|
|
|
uint64_t FileSize() const override;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool ok() const { return status().ok(); }
|
|
|
|
void WriteBlock(BlockBuilder* block, BlockHandle* handle);
|
2012-04-17 17:36:46 +02:00
|
|
|
void WriteRawBlock(const Slice& data, CompressionType, BlockHandle* handle);
|
2013-09-02 08:23:40 +02:00
|
|
|
Status InsertBlockInCache(const Slice& block_contents,
|
|
|
|
const CompressionType type, const BlockHandle* handle);
|
2011-03-18 23:37:00 +01:00
|
|
|
struct Rep;
|
|
|
|
Rep* rep_;
|
2013-10-29 01:54:09 +01:00
|
|
|
|
|
|
|
// Advanced operation: flush any buffered key/value pairs to file.
|
|
|
|
// Can be used to ensure that two adjacent entries never live in
|
|
|
|
// the same data block. Most clients should not need to use this method.
|
|
|
|
// REQUIRES: Finish(), Abandon() have not been called
|
|
|
|
void Flush();
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// No copying allowed
|
2013-10-29 01:54:09 +01:00
|
|
|
BlockBasedTableBuilder(const BlockBasedTableBuilder&) = delete;
|
|
|
|
void operator=(const BlockBasedTableBuilder&) = delete;
|
2011-03-18 23:37:00 +01:00
|
|
|
};
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|
|
|
|
|