@@ -24,6 +24,10 @@ Phase 3: Everything else (orderbooks, header hash)
24
24
25
25
namespace speedex {
26
26
27
+ /* ! Call before sending transaction block to a validator.
28
+ Persists account block + header, and prepares memory database with a persistence
29
+ thunk.
30
+ */
27
31
std::unique_ptr<AccountModificationBlock>
28
32
persist_critical_round_data (
29
33
SpeedexManagementStructures& management_structures,
@@ -32,24 +36,28 @@ persist_critical_round_data(
32
36
bool get_block = false ,
33
37
uint64_t log_offset = 0 );
34
38
39
+ // ! Memory database loads persistence thunk into lmdb
35
40
void
36
41
persist_async_phase1 (
37
42
SpeedexManagementStructures& management_structures,
38
43
const uint64_t current_block_number,
39
44
BlockDataPersistenceMeasurements& measurements);
40
45
46
+ // ! Msync the memory database lmdb
41
47
void
42
48
persist_async_phase2 (
43
49
SpeedexManagementStructures& management_structures,
44
50
uint64_t current_block_number,
45
51
BlockDataPersistenceMeasurements& measurements);
46
52
53
+ // ! Finish persistence (orderbooks, header hash map).
47
54
void
48
55
persist_async_phase3 (
49
56
SpeedexManagementStructures& management_structures,
50
57
uint64_t current_block_number,
51
58
BlockDataPersistenceMeasurements& measurements);
52
59
60
+ // ! Operates a background thread for phase 3 persistence.
53
61
class AsyncPersisterPhase3 : public AsyncWorker {
54
62
using AsyncWorker::mtx;
55
63
using AsyncWorker::cv;
@@ -90,7 +98,8 @@ class AsyncPersisterPhase3 : public AsyncWorker {
90
98
}
91
99
};
92
100
93
-
101
+ // ! Operates a background thread for phase 2 persistence.
102
+ // ! Automatically calls phase 3 when done.
94
103
class AsyncPersisterPhase2 : public AsyncWorker {
95
104
using AsyncWorker::mtx;
96
105
using AsyncWorker::cv;
@@ -137,6 +146,8 @@ class AsyncPersisterPhase2 : public AsyncWorker {
137
146
}
138
147
};
139
148
149
+ // ! Operates a background thread for phase 1 persistence.
150
+ // ! Automatically calls phase 2 when done.
140
151
struct AsyncPersister : public AsyncWorker {
141
152
using AsyncWorker::mtx;
142
153
using AsyncWorker::cv;
@@ -157,7 +168,6 @@ struct AsyncPersister : public AsyncWorker {
157
168
return latest_measurements != nullptr ;
158
169
}
159
170
160
-
161
171
void run ();
162
172
163
173
public:
@@ -169,13 +179,15 @@ struct AsyncPersister : public AsyncWorker {
169
179
start_async_thread ([this ] {run ();});
170
180
}
171
181
172
-
173
-
174
182
uint64_t get_highest_persisted_block () {
175
183
std::lock_guard lock (mtx);
176
184
return highest_persisted_block;
177
185
}
178
186
187
+
188
+ // ! Begin persisting a block to disk
189
+ // ! (all blocks up to persist_block_number).
190
+ // ! When phase 1 finishes, phase 2 is automatically called.
179
191
void do_async_persist (
180
192
const uint64_t persist_block_number,
181
193
BlockDataPersistenceMeasurements& measurements) {
@@ -197,6 +209,10 @@ struct AsyncPersister : public AsyncWorker {
197
209
cv.notify_one ();
198
210
}
199
211
212
+ // ! Wait for all async persistence phases to complete.
213
+ // ! Clears up all uses of measurements object reference.
214
+ // ! Should be called before shutdown or before invalidating measurements
215
+ // ! object reference.
200
216
void wait_for_async_persist () {
201
217
// clears up all uses of measurements reference
202
218
wait_for_async_task ();
0 commit comments