Kùzu C++ API
Loading...
Searching...
No Matches
transaction.h
Go to the documentation of this file.
1#pragma once
2
3#include "statement_type.h"
4#include "timestamp_t.h"
5#include "local_storage.h"
6#include "undo_buffer.h"
7
8namespace kuzu {
9namespace catalog {
10class CatalogEntry;
11class CatalogSet;
12class SequenceCatalogEntry;
13struct SequenceRollbackData;
14} // namespace catalog
15namespace main {
16class ClientContext;
17} // namespace main
18namespace storage {
19class LocalStorage;
20class UndoBuffer;
21class WAL;
22} // namespace storage
23namespace transaction {
24class TransactionManager;
25
27
29 friend class TransactionManager;
30
31public:
35 static_cast<common::transaction_t>(1) << 63;
36
37 Transaction(main::ClientContext& clientContext, TransactionType transactionType,
38 common::transaction_t transactionID, common::transaction_t startTS);
39
40 explicit Transaction(TransactionType transactionType) noexcept
41 : type{transactionType}, ID{DUMMY_TRANSACTION_ID}, startTS{DUMMY_START_TIMESTAMP},
42 commitTS{common::INVALID_TRANSACTION}, clientContext{nullptr}, undoBuffer{nullptr},
43 forceCheckpoint{false} {
45 }
47 common::transaction_t startTS) noexcept
48 : type{transactionType}, ID{ID}, startTS{startTS}, commitTS{common::INVALID_TRANSACTION},
49 clientContext{nullptr}, undoBuffer{nullptr}, forceCheckpoint{false} {
51 }
52
53 TransactionType getType() const { return type; }
54 bool isReadOnly() const { return TransactionType::READ_ONLY == type; }
55 bool isWriteTransaction() const { return TransactionType::WRITE == type; }
56 bool isDummy() const { return TransactionType::DUMMY == type; }
57 bool isRecovery() const { return TransactionType::RECOVERY == type; }
58 common::transaction_t getID() const { return ID; }
59 common::transaction_t getStartTS() const { return startTS; }
60 common::transaction_t getCommitTS() const { return commitTS; }
61 int64_t getCurrentTS() const { return currentTS; }
62 main::ClientContext* getClientContext() const { return clientContext; }
63
65 // Note: We always force checkpoint for COPY_FROM statement.
66 if (statementType == common::StatementType::COPY_FROM) {
67 forceCheckpoint = true;
68 }
69 }
71 return getID() > DUMMY_TRANSACTION_ID && !isReadOnly();
72 }
73 bool shouldLogToWAL() const;
74
76
77 void commit(storage::WAL* wal) const;
78 void rollback(storage::WAL* wal) const;
79
80 uint64_t getEstimatedMemUsage() const;
81 storage::LocalStorage* getLocalStorage() const { return localStorage.get(); }
83 return maxCommittedNodeOffsets.contains(tableID);
84 }
86 maxCommittedNodeOffsets[tableID] = offset;
87 }
89 KU_ASSERT(maxCommittedNodeOffsets.contains(tableID));
90 return maxCommittedNodeOffsets.at(tableID);
91 }
92
94 bool skipLoggingToWAL = false) const;
95 void pushSequenceChange(catalog::SequenceCatalogEntry* sequenceEntry, int64_t kCount,
96 const catalog::SequenceRollbackData& data) const;
98 common::row_idx_t startRowInVector, common::row_idx_t numRows) const;
100 common::row_idx_t startRowInVector, common::row_idx_t numRows) const;
102 storage::VectorUpdateInfo& vectorUpdateInfo) const;
103
104private:
105 TransactionType type;
107 common::transaction_t startTS;
108 common::transaction_t commitTS;
109 int64_t currentTS;
110 main::ClientContext* clientContext;
111 std::unique_ptr<storage::LocalStorage> localStorage;
112 std::unique_ptr<storage::UndoBuffer> undoBuffer;
113 bool forceCheckpoint;
114
115 std::unordered_map<common::table_id_t, common::offset_t> maxCommittedNodeOffsets;
116};
117
118static auto DUMMY_TRANSACTION = Transaction(TransactionType::DUMMY);
119static auto DUMMY_CHECKPOINT_TRANSACTION = Transaction(TransactionType::CHECKPOINT,
121
122} // namespace transaction
123} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition catalog_entry.h:18
Definition catalog_set.h:24
static KUZU_API timestamp_t getCurrentTimestamp()
Contain client side configuration. We make profiler associated per query, so profiler is not maintain...
Definition client_context.h:51
Definition local_storage.h:19
Definition update_info.h:46
Definition version_info.h:75
Definition transaction.h:28
storage::LocalStorage * getLocalStorage() const
Definition transaction.h:81
void checkForceCheckpoint(common::StatementType statementType)
Definition transaction.h:64
common::transaction_t getStartTS() const
Definition transaction.h:59
void setMaxCommittedNodeOffset(common::table_id_t tableID, common::offset_t offset)
Definition transaction.h:85
void pushVectorInsertInfo(storage::VersionInfo &versionInfo, common::idx_t vectorIdx, common::row_idx_t startRowInVector, common::row_idx_t numRows) const
Transaction(TransactionType transactionType) noexcept
Definition transaction.h:40
void pushVectorDeleteInfo(storage::VersionInfo &versionInfo, common::idx_t vectorIdx, common::row_idx_t startRowInVector, common::row_idx_t numRows) const
Transaction(main::ClientContext &clientContext, TransactionType transactionType, common::transaction_t transactionID, common::transaction_t startTS)
bool hasNewlyInsertedNodes(common::table_id_t tableID) const
Definition transaction.h:82
bool isRecovery() const
Definition transaction.h:57
Transaction(TransactionType transactionType, common::transaction_t ID, common::transaction_t startTS) noexcept
Definition transaction.h:46
common::transaction_t getCommitTS() const
Definition transaction.h:60
void pushCatalogEntry(catalog::CatalogSet &catalogSet, catalog::CatalogEntry &catalogEntry, bool skipLoggingToWAL=false) const
bool shouldAppendToUndoBuffer() const
Definition transaction.h:70
bool isWriteTransaction() const
Definition transaction.h:55
static constexpr common::transaction_t DUMMY_TRANSACTION_ID
Definition transaction.h:32
TransactionType getType() const
Definition transaction.h:53
common::offset_t getMaxNodeOffsetBeforeCommit(common::table_id_t tableID) const
Definition transaction.h:88
void pushVectorUpdateInfo(storage::UpdateInfo &updateInfo, common::idx_t vectorIdx, storage::VectorUpdateInfo &vectorUpdateInfo) const
static constexpr common::transaction_t DUMMY_START_TIMESTAMP
Definition transaction.h:33
main::ClientContext * getClientContext() const
Definition transaction.h:62
void commit(storage::WAL *wal) const
common::transaction_t getID() const
Definition transaction.h:58
void pushSequenceChange(catalog::SequenceCatalogEntry *sequenceEntry, int64_t kCount, const catalog::SequenceRollbackData &data) const
friend class TransactionManager
Definition transaction.h:29
bool isReadOnly() const
Definition transaction.h:54
void rollback(storage::WAL *wal) const
static constexpr common::transaction_t START_TRANSACTION_ID
Definition transaction.h:34
int64_t getCurrentTS() const
Definition transaction.h:61
bool isDummy() const
Definition transaction.h:56
uint64_t getEstimatedMemUsage() const
uint32_t idx_t
Definition types.h:39
constexpr transaction_t INVALID_TRANSACTION
Definition types.h:58
uint64_t transaction_t
Definition types.h:57
uint64_t table_id_t
Definition internal_id_t.h:14
uint64_t offset_t
Definition internal_id_t.h:22
uint64_t row_idx_t
Definition types.h:46
StatementType
Definition statement_type.h:8
TransactionType
Definition transaction.h:26
Definition alter_type.h:5
int64_t value
Definition timestamp_t.h:11
Definition update_info.h:21