MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
ob_lsm_transaction.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11#pragma once
12
13#include "common/sys/rc.h"
14#include "common/lang/string_view.h"
15#include "common/lang/string.h"
16#include "oblsm/include/ob_lsm_iterator.h"
17#include "oblsm/include/ob_lsm_options.h"
18#include "oblsm/include/ob_lsm.h"
19#include "oblsm/memtable/ob_skiplist.h"
20#include "oblsm/util/ob_arena.h"
21#include "oblsm/util/ob_coding.h"
22#include "common/lang/map.h"
23
24namespace oceanbase {
25
36{
37public:
47 ObLsmTransaction(ObLsm *db, uint64_t ts);
48
49 ~ObLsmTransaction() = default;
50
51 /*
52 * @brief Retrieves the value associated with a given key.
53 *
54 * @param key The key to look up within the database.
55 * @param value A pointer to a string where the associated value will be stored, if found.
56 */
57 RC get(const string_view &key, string *value);
58
62 RC put(const string_view &key, const string_view &value);
63
70 RC remove(const string_view &key);
71
80
85 RC commit();
86
90 RC rollback();
91
92private:
99 [[maybe_unused]] ObLsm *db_ = nullptr;
100
105 [[maybe_unused]] uint64_t ts_ = 0;
106
114 map<string, string> inner_store_;
115};
116
122{};
123} // namespace oceanbase
Abstract class for iterating over key-value pairs in an LSM-Tree.
Definition: ob_lsm_iterator.h:41
A class representing a transaction in oblsm.
Definition: ob_lsm_transaction.h:36
RC commit()
Commits the transaction, persisting all transaction changes to the database.
Definition: ob_lsm_transaction.cpp:53
ObLsmIterator * new_iterator(ObLsmReadOptions options)
Definition: ob_lsm_transaction.cpp:51
uint64_t ts_
The transaction's unique timestamp.
Definition: ob_lsm_transaction.h:105
map< string, string > inner_store_
In-memory store for transactional changes.
Definition: ob_lsm_transaction.h:114
RC put(const string_view &key, const string_view &value)
Adds or updates a key-value pair within the transaction's in-memory store.
Definition: ob_lsm_transaction.cpp:47
RC remove(const string_view &key)
Removes a key from the database within the transaction's scope.
Definition: ob_lsm_transaction.cpp:49
RC rollback()
Rollback the transaction, discarding all uncommitted changes.
Definition: ob_lsm_transaction.cpp:55
ObLsm * db_
Pointer to the associated ObLsm database.
Definition: ob_lsm_transaction.h:99
ObLsm is a key-value storage engine for educational purpose. ObLsm learned a lot about design from le...
Definition: ob_lsm.h:29
An iterator for traversing the transaction's in-memory store
Definition: ob_lsm_transaction.h:122
Definition: ob_lsm_options.h:48