2012-10-19 23:00:53 +02:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
//
|
2013-06-11 23:23:58 +02:00
|
|
|
// This class stores references to all the immutable memtables.
|
2012-11-29 01:42:36 +01:00
|
|
|
// The memtables are flushed to L0 as soon as possible and in
|
2012-10-19 23:00:53 +02:00
|
|
|
// any order. If there are more than one immutable memtable, their
|
2012-11-29 01:42:36 +01:00
|
|
|
// flushes can occur concurrently. However, they are 'committed'
|
2012-10-19 23:00:53 +02:00
|
|
|
// to the manifest in FIFO order to maintain correctness and
|
|
|
|
// recoverability from a crash.
|
|
|
|
//
|
|
|
|
class MemTableList {
|
|
|
|
public:
|
2012-11-29 01:42:36 +01:00
|
|
|
// A list of memtables.
|
2012-10-19 23:00:53 +02:00
|
|
|
MemTableList() : size_(0), num_flush_not_started_(0),
|
|
|
|
commit_in_progress_(false) {
|
2013-03-01 03:04:58 +01:00
|
|
|
imm_flush_needed.Release_Store(nullptr);
|
2012-10-19 23:00:53 +02:00
|
|
|
}
|
|
|
|
~MemTableList() {};
|
|
|
|
|
2013-03-01 03:04:58 +01:00
|
|
|
// so that backgrund threads can detect non-nullptr pointer to
|
2012-10-19 23:00:53 +02:00
|
|
|
// 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.
|
2013-06-11 23:23:58 +02:00
|
|
|
bool IsFlushPending(int min_write_buffer_number_to_merge);
|
2012-10-19 23:00:53 +02:00
|
|
|
|
2013-06-11 23:23:58 +02:00
|
|
|
// Returns the earliest memtables that needs to be flushed.
|
|
|
|
void PickMemtablesToFlush(std::vector<MemTable*>* mems);
|
2012-10-19 23:00:53 +02:00
|
|
|
|
|
|
|
// Commit a successful flush in the manifest file
|
2013-06-11 23:23:58 +02:00
|
|
|
Status InstallMemtableFlushResults(const std::vector<MemTable*> &m,
|
2012-10-19 23:00:53 +02:00
|
|
|
VersionSet* vset, Status flushStatus,
|
|
|
|
port::Mutex* mu, Logger* info_log,
|
|
|
|
uint64_t file_number,
|
|
|
|
std::set<uint64_t>& pending_outputs);
|
|
|
|
|
2012-11-29 01:42:36 +01:00
|
|
|
// New memtables are inserted at the front of the list.
|
2013-01-04 02:13:56 +01:00
|
|
|
// Takes ownership of the referenced held on *m by the caller of Add().
|
2012-10-19 23:00:53 +02:00
|
|
|
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.
|
2013-03-21 23:59:47 +01:00
|
|
|
bool Get(const LookupKey& key, std::string* value, Status* s,
|
|
|
|
const Options& options);
|
2012-10-19 23:00:53 +02:00
|
|
|
|
2012-11-29 01:42:36 +01:00
|
|
|
// Returns the list of underlying memtables.
|
2012-10-19 23:00:53 +02:00
|
|
|
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_
|