mirror of
https://github.com/facebook/rocksdb.git
synced 2024-12-04 02:02:41 +00:00
36a5f8ed7f
- Replace raw slice comparison with a call to user comparator. Added test for custom comparators. - Fix end of namespace comments. - Fixed bug in picking inputs for a level-0 compaction. When finding overlapping files, the covered range may expand as files are added to the input set. We now correctly expand the range when this happens instead of continuing to use the old range. For example, suppose L0 contains files with the following ranges: F1: a .. d F2: c .. g F3: f .. j and the initial compaction target is F3. We used to search for range f..j which yielded {F2,F3}. However we now expand the range as soon as another file is added. In this case, when F2 is added, we expand the range to c..j and restart the search. That picks up file F1 as well. This change fixes a bug related to deleted keys showing up incorrectly after a compaction as described in Issue 44. (Sync with upstream @25072954)
92 lines
3.2 KiB
C++
92 lines
3.2 KiB
C++
// 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.
|
|
//
|
|
// TableBuilder provides the interface used to build a Table
|
|
// (an immutable and sorted map from keys to values).
|
|
//
|
|
// Multiple threads can invoke const methods on a TableBuilder without
|
|
// external synchronization, but if any of the threads may call a
|
|
// non-const method, all threads accessing the same TableBuilder must use
|
|
// external synchronization.
|
|
|
|
#ifndef STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
|
|
#define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
|
|
|
|
#include <stdint.h>
|
|
#include "leveldb/options.h"
|
|
#include "leveldb/status.h"
|
|
|
|
namespace leveldb {
|
|
|
|
class BlockBuilder;
|
|
class BlockHandle;
|
|
class WritableFile;
|
|
|
|
class TableBuilder {
|
|
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
|
|
// caller to close the file after calling Finish().
|
|
TableBuilder(const Options& options, WritableFile* file);
|
|
|
|
// REQUIRES: Either Finish() or Abandon() has been called.
|
|
~TableBuilder();
|
|
|
|
// Change the options used by this builder. Note: only some of the
|
|
// option fields can be changed after construction. If a field is
|
|
// not allowed to change dynamically and its value in the structure
|
|
// passed to the constructor is different from its value in the
|
|
// structure passed to this method, this method will return an error
|
|
// without changing any fields.
|
|
Status ChangeOptions(const Options& options);
|
|
|
|
// 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
|
|
void Add(const Slice& key, const Slice& value);
|
|
|
|
// 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();
|
|
|
|
// Return non-ok iff some error has been detected.
|
|
Status status() const;
|
|
|
|
// Finish building the table. Stops using the file passed to the
|
|
// constructor after this function returns.
|
|
// REQUIRES: Finish(), Abandon() have not been called
|
|
Status Finish();
|
|
|
|
// 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
|
|
void Abandon();
|
|
|
|
// Number of calls to Add() so far.
|
|
uint64_t NumEntries() const;
|
|
|
|
// Size of the file generated so far. If invoked after a successful
|
|
// Finish() call, returns the size of the final generated file.
|
|
uint64_t FileSize() const;
|
|
|
|
private:
|
|
bool ok() const { return status().ok(); }
|
|
void WriteBlock(BlockBuilder* block, BlockHandle* handle);
|
|
|
|
struct Rep;
|
|
Rep* rep_;
|
|
|
|
// No copying allowed
|
|
TableBuilder(const TableBuilder&);
|
|
void operator=(const TableBuilder&);
|
|
};
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif // STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
|