mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-27 11:43:49 +00:00
05e8854085
Summary: This diff introduces a new Merge operation into rocksdb. The purpose of this review is mostly getting feedback from the team (everyone please) on the design. Please focus on the four files under include/leveldb/, as they spell the client visible interface change. include/leveldb/db.h include/leveldb/merge_operator.h include/leveldb/options.h include/leveldb/write_batch.h Please go over local/my_test.cc carefully, as it is a concerete use case. Please also review the impelmentation files to see if the straw man implementation makes sense. Note that, the diff does pass all make check and truly supports forward iterator over db and a version of Get that's based on iterator. Future work: - Integration with compaction - A raw Get implementation I am working on a wiki that explains the design and implementation choices, but coding comes just naturally and I think it might be a good idea to share the code earlier. The code is heavily commented. Test Plan: run all local tests Reviewers: dhruba, heyongqiang Reviewed By: dhruba CC: leveldb, zshao, sheki, emayanke, MarkCallaghan Differential Revision: https://reviews.facebook.net/D9651
65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
#ifndef MERGE_HELPER_H
|
|
#define MERGE_HELPER_H
|
|
|
|
#include "db/dbformat.h"
|
|
#include "leveldb/slice.h"
|
|
#include <string>
|
|
|
|
namespace leveldb {
|
|
|
|
class Comparator;
|
|
class Iterator;
|
|
class Logger;
|
|
class MergeOperator;
|
|
|
|
class MergeHelper {
|
|
public:
|
|
MergeHelper(const Comparator* user_comparator,
|
|
const MergeOperator* user_merge_operator,
|
|
Logger* logger,
|
|
bool assert_valid_internal_key)
|
|
: user_comparator_(user_comparator),
|
|
user_merge_operator_(user_merge_operator),
|
|
logger_(logger),
|
|
assert_valid_internal_key_(assert_valid_internal_key) {}
|
|
|
|
// Merge entries until we hit
|
|
// - a corrupted key
|
|
// - a Put/Delete,
|
|
// - a different user key,
|
|
// - a specific sequence number (snapshot boundary),
|
|
// or - the end of iteration
|
|
// iter: (IN) points to the first merge type entry
|
|
// (OUT) points to the first entry not included in the merge process
|
|
// stop_before: (IN) a sequence number that merge should not cross.
|
|
// 0 means no restriction
|
|
// at_bottom: (IN) true if the iterator covers the bottem level, which means
|
|
// we could reach the start of the history of this user key.
|
|
void MergeUntil(Iterator* iter, SequenceNumber stop_before = 0,
|
|
bool at_bottom = false);
|
|
|
|
// Query the merge result
|
|
// These are valid until the next MergeUtil call
|
|
// IMPORTANT: the key type could change after the MergeUntil call.
|
|
// Put/Delete + Merge + ... + Merge => Put
|
|
// Merge + ... + Merge => Merge
|
|
Slice key() { return Slice(key_); }
|
|
Slice value() { return Slice(value_); }
|
|
|
|
private:
|
|
const Comparator* user_comparator_;
|
|
const MergeOperator* user_merge_operator_;
|
|
Logger* logger_;
|
|
Iterator* iter_; // in: the internal iterator, positioned at the first merge entry
|
|
bool assert_valid_internal_key_; // enforce no internal key corruption?
|
|
|
|
// the scratch area that holds the result of MergeUntil
|
|
// valid up to the next MergeUntil call
|
|
std::string key_;
|
|
std::string value_;
|
|
};
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif
|