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
99 lines
2.8 KiB
C++
99 lines
2.8 KiB
C++
// Copyright (c) 2012 Facebook.
|
|
|
|
#ifndef STORAGE_LEVELDB_DB_MEMTABLELIST_H_
|
|
#define STORAGE_LEVELDB_DB_MEMTABLELIST_H_
|
|
|
|
#include <string>
|
|
#include <list>
|
|
#include "leveldb/db.h"
|
|
#include "db/dbformat.h"
|
|
#include "db/skiplist.h"
|
|
#include "util/arena.h"
|
|
#include "memtable.h"
|
|
|
|
namespace leveldb {
|
|
|
|
class InternalKeyComparator;
|
|
class Mutex;
|
|
class MemTableListIterator;
|
|
|
|
//
|
|
// This class stores refeernces to all the immutable memtables.
|
|
// The memtables are flushed to L0 as soon as possible and in
|
|
// any order. If there are more than one immutable memtable, their
|
|
// flushes can occur concurrently. However, they are 'committed'
|
|
// to the manifest in FIFO order to maintain correctness and
|
|
// recoverability from a crash.
|
|
//
|
|
class MemTableList {
|
|
public:
|
|
// A list of memtables.
|
|
MemTableList() : size_(0), num_flush_not_started_(0),
|
|
commit_in_progress_(false) {
|
|
imm_flush_needed.Release_Store(nullptr);
|
|
}
|
|
~MemTableList() {};
|
|
|
|
// so that backgrund threads can detect non-nullptr pointer to
|
|
// determine whether this is anything more to start flushing.
|
|
port::AtomicPointer imm_flush_needed;
|
|
|
|
// Increase reference count on all underling memtables
|
|
void RefAll();
|
|
|
|
// Drop reference count on all underling memtables
|
|
void UnrefAll();
|
|
|
|
// Returns the total number of memtables in the list
|
|
int size();
|
|
|
|
// Returns true if there is at least one memtable on which flush has
|
|
// not yet started.
|
|
bool IsFlushPending();
|
|
|
|
// Returns the earliest memtable that needs to be flushed.
|
|
// Returns null, if no such memtable exist.
|
|
MemTable* PickMemtableToFlush();
|
|
|
|
// Commit a successful flush in the manifest file
|
|
Status InstallMemtableFlushResults(MemTable* m,
|
|
VersionSet* vset, Status flushStatus,
|
|
port::Mutex* mu, Logger* info_log,
|
|
uint64_t file_number,
|
|
std::set<uint64_t>& pending_outputs);
|
|
|
|
// New memtables are inserted at the front of the list.
|
|
// Takes ownership of the referenced held on *m by the caller of Add().
|
|
void Add(MemTable* m);
|
|
|
|
// Returns an estimate of the number of bytes of data in use.
|
|
size_t ApproximateMemoryUsage();
|
|
|
|
// Search all the memtables starting from the most recent one.
|
|
// Return the most recent value found, if any.
|
|
bool Get(const LookupKey& key, std::string* value, Status* s,
|
|
const Options& options);
|
|
|
|
// Returns the list of underlying memtables.
|
|
void GetMemTables(std::vector<MemTable*>* list);
|
|
|
|
// Copying allowed
|
|
// MemTableList(const MemTableList&);
|
|
// void operator=(const MemTableList&);
|
|
|
|
private:
|
|
std::list<MemTable*> memlist_;
|
|
int size_;
|
|
|
|
// the number of elements that still need flushing
|
|
int num_flush_not_started_;
|
|
|
|
// committing in progress
|
|
bool commit_in_progress_;
|
|
|
|
};
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif // STORAGE_LEVELDB_DB_MEMTABLELIST_H_
|