mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
25511b7 Merge branch 'master' of github.com:rescrv/HyperLevelDB into hyperdb ed01020 Make "source" universal 3784d92 Ignore the static file 507319b Don't package with snappy 3e2cc8b Tolerate -fno-rtti 4dcdd6e Drop revision down to 1.0.dev 2542163 Drop all but the latest kept for garbage reasons 9c270b7 Update .gitignore 5331878 Add upack script adc2a7a Explicitly add -lpthread for Ubuntu 7b57bbd Strip NULL chars passed to LiveBackup e3b87e7 Add write-buffer-size option to benchmark 2f11087 Followup to snappy support with -DSNAPPY af503da Improve efficiency of ReplayIterator; fix a bug 33c1f0c Add snappy support ce1cacf Fix a race in ReplayIterator 5c4679b Fix a bug in the replay_iterator ca332bd Fix sort algorithm used for compaction boundaries. d9ec544 make checK b83a9cd Fix a deadlock in the ReplayIterator dtor 273547b Fix a double-delete in ReplayIterator 3377c7a Add "all" to set of special timestamps 387f43a Timestamp comparison and validation. f9a6eb1 make distcheck 9a4d0b7 Add a ReplayIterator. 1d53869 Conditionally enable read-driven compaction. f6fa561 16% end-to-end performance improvement from the skiplist 28ffd32 Merge remote-tracking branch 'upstream/master' a58de73 Revert "Remove read-driven compactions." e19fc0c Fix upstream issue 200 748539c LevelDB 1.13 78b7812 Add install instructions to README e47a48e Make benchmark dir variable 820a096 Update distributed files. 486ca7f Live backup of LevelDB instances 6579884 Put a reference counter on log_/logfile_ 3075253 Update internal benchmark. 2a6b0bd Make the Version a parameter of PickCompaction 5bd76dc Release leveldb 1.12 git-subtree-dir: src/hyperleveldb git-subtree-split: 25511b7a9101b0bafb57349d2194ba80ccbf7bc3
96 lines
2.9 KiB
C++
96 lines
2.9 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.
|
|
|
|
#ifndef STORAGE_HYPERLEVELDB_DB_MEMTABLE_H_
|
|
#define STORAGE_HYPERLEVELDB_DB_MEMTABLE_H_
|
|
|
|
#include <string>
|
|
#include "../hyperleveldb/db.h"
|
|
#include "dbformat.h"
|
|
#include "skiplist.h"
|
|
#include "../util/arena.h"
|
|
|
|
namespace hyperleveldb {
|
|
|
|
class InternalKeyComparator;
|
|
class Mutex;
|
|
class MemTableIterator;
|
|
|
|
class MemTable {
|
|
public:
|
|
// MemTables are reference counted. The initial reference count
|
|
// is zero and the caller must call Ref() at least once.
|
|
explicit MemTable(const InternalKeyComparator& comparator);
|
|
|
|
// Increase reference count.
|
|
// XXX use a release increment if not using GCC intrinsics
|
|
void Ref() { __sync_add_and_fetch(&refs_, 1); }
|
|
|
|
// Drop reference count. Delete if no more references exist.
|
|
// XXX use an acquire decrement if not using GCC intrinsics
|
|
void Unref() {
|
|
int refs = __sync_sub_and_fetch(&refs_, 1);
|
|
assert(refs >= 0);
|
|
if (refs <= 0) {
|
|
delete this;
|
|
}
|
|
}
|
|
|
|
// Returns an estimate of the number of bytes of data in use by this
|
|
// data structure.
|
|
//
|
|
// REQUIRES: external synchronization to prevent simultaneous
|
|
// operations on the same MemTable.
|
|
size_t ApproximateMemoryUsage();
|
|
|
|
// Return an iterator that yields the contents of the memtable.
|
|
//
|
|
// The caller must ensure that the underlying MemTable remains live
|
|
// while the returned iterator is live. The keys returned by this
|
|
// iterator are internal keys encoded by AppendInternalKey in the
|
|
// db/format.{h,cc} module.
|
|
Iterator* NewIterator();
|
|
|
|
// Add an entry into memtable that maps key to value at the
|
|
// specified sequence number and with the specified type.
|
|
// Typically value will be empty if type==kTypeDeletion.
|
|
void Add(SequenceNumber seq, ValueType type,
|
|
const Slice& key,
|
|
const Slice& value);
|
|
|
|
// If memtable contains a value for key, store it in *value and return true.
|
|
// If memtable contains a deletion for key, store a NotFound() error
|
|
// in *status and return true.
|
|
// Else, return false.
|
|
bool Get(const LookupKey& key, std::string* value, Status* s);
|
|
|
|
private:
|
|
~MemTable(); // Private since only Unref() should be used to delete it
|
|
typedef std::pair<uint64_t, const char*> TableKey;
|
|
|
|
struct KeyComparator {
|
|
const InternalKeyComparator comparator;
|
|
explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { }
|
|
int operator()(TableKey a, TableKey b) const;
|
|
};
|
|
friend class MemTableIterator;
|
|
friend class MemTableBackwardIterator;
|
|
|
|
typedef SkipList<TableKey, KeyComparator> Table;
|
|
|
|
KeyComparator comparator_;
|
|
int refs_;
|
|
port::Mutex mtx_;
|
|
Arena arena_;
|
|
Table table_;
|
|
|
|
// No copying allowed
|
|
MemTable(const MemTable&);
|
|
void operator=(const MemTable&);
|
|
};
|
|
|
|
} // namespace hyperleveldb
|
|
|
|
#endif // STORAGE_HYPERLEVELDB_DB_MEMTABLE_H_
|