fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.5 KiB
109 lines
3.5 KiB
11 years ago
|
// 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.
|
||
|
//
|
||
12 years ago
|
|
||
11 years ago
|
#pragma once
|
||
12 years ago
|
#include <string>
|
||
|
#include <list>
|
||
11 years ago
|
#include <deque>
|
||
11 years ago
|
#include "rocksdb/db.h"
|
||
12 years ago
|
#include "db/dbformat.h"
|
||
|
#include "db/skiplist.h"
|
||
|
#include "memtable.h"
|
||
|
|
||
11 years ago
|
namespace rocksdb {
|
||
12 years ago
|
|
||
|
class InternalKeyComparator;
|
||
|
class Mutex;
|
||
|
class MemTableListIterator;
|
||
|
|
||
|
//
|
||
12 years ago
|
// This class stores references to all the immutable memtables.
|
||
12 years ago
|
// The memtables are flushed to L0 as soon as possible and in
|
||
12 years ago
|
// any order. If there are more than one immutable memtable, their
|
||
12 years ago
|
// flushes can occur concurrently. However, they are 'committed'
|
||
12 years ago
|
// to the manifest in FIFO order to maintain correctness and
|
||
|
// recoverability from a crash.
|
||
|
//
|
||
|
class MemTableList {
|
||
|
public:
|
||
12 years ago
|
// A list of memtables.
|
||
12 years ago
|
MemTableList() : size_(0), num_flush_not_started_(0),
|
||
11 years ago
|
commit_in_progress_(false),
|
||
|
flush_requested_(false) {
|
||
12 years ago
|
imm_flush_needed.Release_Store(nullptr);
|
||
12 years ago
|
}
|
||
|
~MemTableList() {};
|
||
|
|
||
12 years ago
|
// so that backgrund threads can detect non-nullptr pointer to
|
||
12 years ago
|
// determine whether this is anything more to start flushing.
|
||
|
port::AtomicPointer imm_flush_needed;
|
||
|
|
||
|
// Increase reference count on all underling memtables
|
||
|
void RefAll();
|
||
|
|
||
11 years ago
|
// Drop reference count on all underling memtables. If the refcount
|
||
|
// on an underlying memtable drops to zero, then return it in
|
||
|
// to_delete vector.
|
||
|
void UnrefAll(std::vector<MemTable*>* to_delete);
|
||
12 years ago
|
|
||
|
// 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.
|
||
12 years ago
|
bool IsFlushPending(int min_write_buffer_number_to_merge);
|
||
12 years ago
|
|
||
11 years ago
|
// Returns the earliest memtables that needs to be flushed. The returned
|
||
|
// memtables are guaranteed to be in the ascending order of created time.
|
||
12 years ago
|
void PickMemtablesToFlush(std::vector<MemTable*>* mems);
|
||
12 years ago
|
|
||
|
// Commit a successful flush in the manifest file
|
||
12 years ago
|
Status InstallMemtableFlushResults(const std::vector<MemTable*> &m,
|
||
12 years ago
|
VersionSet* vset, Status flushStatus,
|
||
|
port::Mutex* mu, Logger* info_log,
|
||
|
uint64_t file_number,
|
||
11 years ago
|
std::set<uint64_t>& pending_outputs,
|
||
|
std::vector<MemTable*>* to_delete);
|
||
12 years ago
|
|
||
12 years ago
|
// New memtables are inserted at the front of the list.
|
||
12 years ago
|
// Takes ownership of the referenced held on *m by the caller of Add().
|
||
12 years ago
|
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.
|
||
12 years ago
|
bool Get(const LookupKey& key, std::string* value, Status* s,
|
||
11 years ago
|
MergeContext& merge_context, const Options& options);
|
||
12 years ago
|
|
||
12 years ago
|
// Returns the list of underlying memtables.
|
||
12 years ago
|
void GetMemTables(std::vector<MemTable*>* list);
|
||
|
|
||
11 years ago
|
// Request a flush of all existing memtables to storage
|
||
|
void FlushRequested() { flush_requested_ = true; }
|
||
|
|
||
12 years ago
|
// 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_;
|
||
|
|
||
11 years ago
|
// Requested a flush of all memtables to storage
|
||
|
bool flush_requested_;
|
||
|
|
||
12 years ago
|
};
|
||
|
|
||
11 years ago
|
} // namespace rocksdb
|