aboutsummaryrefslogtreecommitdiff
path: root/db/memtable.cuh
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-02-20 15:41:14 +0800
committerKunoiSayami <[email protected]>2022-02-20 15:41:14 +0800
commit32ce8b311269df205e192c2b61dc47faaa2c5971 (patch)
tree6f4bf4c7f2882215c49f6790df7022310e78d93d /db/memtable.cuh
parenta66cea8f77aeafa8523d28ea63a159826cef38a3 (diff)
feat(memtable): Add kernel function in cuda code
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'db/memtable.cuh')
-rw-r--r--db/memtable.cuh90
1 files changed, 90 insertions, 0 deletions
diff --git a/db/memtable.cuh b/db/memtable.cuh
new file mode 100644
index 0000000..ac3c2b6
--- /dev/null
+++ b/db/memtable.cuh
@@ -0,0 +1,90 @@
+// 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_LEVELDB_DB_MEMTABLE_H_
+#define STORAGE_LEVELDB_DB_MEMTABLE_H_
+
+#include <string>
+
+#include "db/dbformat.h"
+#include "db/skiplist.cuh"
+#include "leveldb/db.h"
+#include "util/arena.cuh"
+
+namespace leveldb {
+
+class InternalKeyComparator;
+class MemTableIterator;
+
+class MemTable {
+ public:
+ // MemTables are reference counted. The initial reference count
+ // is zero and the caller must call Ref() at least once.
+ __device__ explicit MemTable(const InternalKeyComparator& comparator);
+
+ MemTable(const MemTable&) = delete;
+ MemTable& operator=(const MemTable&) = delete;
+
+ // Increase reference count.
+ void Ref() { ++refs_; }
+
+ // Drop reference count. Delete if no more references exist.
+ void Unref() {
+ --refs_;
+ assert(refs_ >= 0);
+ if (refs_ <= 0) {
+ delete this;
+ }
+ }
+
+ // Returns an estimate of the number of bytes of data in use by this
+ // data structure. It is safe to call when MemTable is being modified.
+ 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:
+ friend class MemTableIterator;
+ friend class MemTableBackwardIterator;
+ friend __global__ void Add_(MemTable *, SequenceNumber, ValueType, size_t, size_t, char*, size_t, char *, size_t);
+ friend __global__ void Get_(MemTable *, bool * ret);
+
+ struct KeyComparator {
+ const InternalKeyComparator comparator;
+ __device__ explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) {}
+ __device__ int operator()(const char* a, const char* b) const;
+ __device__ ~KeyComparator() = default;
+ };
+
+ typedef SkipList<const char*, KeyComparator> Table;
+
+ ~MemTable(); // Private since only Unref() should be used to delete it
+
+ KeyComparator comparator_;
+ int refs_;
+ Arena arena_;
+ Table table_;
+};
+
+} // namespace leveldb
+
+#endif // STORAGE_LEVELDB_DB_MEMTABLE_H_