22
33#include " leanstore-c/perf_counters.h"
44#include " leanstore/concurrency/transaction.hpp"
5+ #include " leanstore/concurrency/wal_entry.hpp"
56#include " leanstore/sync/optimistic_guarded.hpp"
67#include " leanstore/units.hpp"
78#include " leanstore/utils/counter_util.hpp"
@@ -54,6 +55,10 @@ class WalPayloadHandler;
5455// / Helps to transaction concurrenct control and write-ahead logging.
5556class Logging {
5657public:
58+ // / Logical sequence number, i.e., the unique ID of each WAL.
59+ LID lsn_clock_ = 0 ;
60+
61+ // / The previous LSN of the current transaction, used to link WAL entries.
5762 LID prev_lsn_;
5863
5964 // / The active complex WalEntry for the current transaction, usually used for insert, update,
@@ -85,18 +90,17 @@ class Logging {
8590
8691 storage::OptimisticGuarded<WalFlushReq> wal_flush_req_;
8792
88- // / The ring buffer of the current worker thread. All the wal entries of the current worker are
89- // / writtern to this ring buffer firstly, then flushed to disk by the group commit thread.
90- ALIGNAS (512 ) uint8_t * wal_buffer_;
93+ // / The maximum writtern system transaction ID in the worker.
94+ TXID sys_tx_writtern_ = 0 ;
9195
92- // / The size of the wal ring buffer .
93- uint64_t wal_buffer_bytes_ ;
96+ // / File descriptor for the write-ahead log .
97+ int32_t wal_fd_ = - 1 ;
9498
95- // / Used to track the write order of wal entries .
96- LID lsn_clock_ = 0 ;
99+ // / Start offset of the next WalEntry .
100+ uint64_t wal_size_ = 0 ;
97101
98- // / The maximum writtern system transaction ID in the worker .
99- TXID sys_tx_writtern_ = 0 ;
102+ // / The size of the wal ring buffer .
103+ uint64_t wal_buffer_bytes_ ;
100104
101105 // / Written offset of the wal ring buffer.
102106 uint64_t wal_buffered_ = 0 ;
@@ -106,19 +110,14 @@ class Logging {
106110 // / thread.
107111 std::atomic<uint64_t > wal_flushed_ = 0 ;
108112
109- // / The first WAL record of the current active transaction.
110- uint64_t tx_wal_begin_;
111-
112- // / File descriptor for the write-ahead log.
113- int32_t wal_fd_ = -1 ;
114-
115- // / Start offset of the next WalEntry.
116- uint64_t wal_size_ = 0 ;
113+ // / The ring buffer of the current worker thread. All the wal entries of the current worker are
114+ // / writtern to this ring buffer firstly, then flushed to disk by the group commit thread.
115+ ALIGNAS (512 ) uint8_t * wal_buffer_;
117116
118117public:
119118 Logging (uint64_t wal_buffer_bytes)
120- : wal_buffer_(( uint8_t *)(std::aligned_alloc( 512 , wal_buffer_bytes)) ),
121- wal_buffer_bytes_ ( wal_buffer_bytes) {
119+ : wal_buffer_bytes_( wal_buffer_bytes),
120+ wal_buffer_ (( uint8_t *)(std::aligned_alloc( 512 , wal_buffer_bytes)) ) {
122121 std::memset (wal_buffer_, 0 , wal_buffer_bytes);
123122 }
124123
@@ -129,6 +128,12 @@ class Logging {
129128 }
130129 }
131130
131+ LID ReserveLsn () {
132+ return lsn_clock_++;
133+ }
134+
135+ void ReserveWalBuffer (uint32_t requested_size);
136+
132137 void UpdateSignaledCommitTs (const LID signaled_commit_ts) {
133138 signaled_commit_ts_.store (signaled_commit_ts, std::memory_order_release);
134139 }
@@ -139,19 +144,14 @@ class Logging {
139144 }
140145 }
141146
142- void ReserveContiguousBuffer (uint32_t requested_size);
143-
144147 // / Iterate over current TX entries
145- void IterateCurrentTxWALs (std::function<void (const WalEntry& entry)> callback);
148+ void IterateCurrentTxWALs (uint64_t first_wal,
149+ std::function<void (const WalEntry& entry)> callback);
146150
147151 void WriteWalTxAbort ();
148152 void WriteWalTxFinish ();
149153 void WriteWalCarriageReturn ();
150154
151- template <typename T, typename ... Args>
152- WalPayloadHandler<T> ReserveWALEntryComplex (uint64_t payload_size, PID page_id, LID psn,
153- TREEID tree_id, Args&&... args);
154-
155155 // / Submits wal record to group committer when it is ready to flush to disk.
156156 // / @param totalSize size of the wal record to be flush.
157157 void SubmitWALEntryComplex (uint64_t total_size);
0 commit comments