-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersisted-log.h
More file actions
71 lines (50 loc) · 1.77 KB
/
Copy pathpersisted-log.h
File metadata and controls
71 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef PROTOTYPE_PERSISTED_LOG_H
#define PROTOTYPE_PERSISTED_LOG_H
#include <velocypack/Buffer.h>
#include "scheduler.h"
#include <velocypack/velocypack-aliases.h>
#include <mutex>
#include <utility>
#include "futures.h"
#include "rocksdb-handle.h"
#include "rocksdb-transaction.h"
namespace plog {
using log_index_type = uint64_t;
using log_id_type = uint64_t;
struct persisted_log {
persisted_log(log_id_type logId, std::shared_ptr<RocksDBHandle> rocks,
std::shared_ptr<sched::scheduler> scheduler);
struct InsertResult {
log_index_type index;
};
struct InsertIterator {
virtual ~InsertIterator() = default;
virtual auto next() -> std::optional<VPackBufferUInt8> = 0;
virtual void reset() = 0;
};
auto append(log_index_type insert_after, std::unique_ptr<InsertIterator> iter)
-> futures::future<InsertResult>;
auto seek(log_index_type ) -> void;
private:
struct InsertRequest {
log_index_type insert_after;
std::unique_ptr<InsertIterator> iter;
futures::promise<InsertResult> promise;
InsertRequest(log_index_type insertAfter, std::unique_ptr<InsertIterator> iter,
futures::promise<InsertResult> promise);
};
auto handleInsertRequest(log_index_type insert_after,
std::unique_ptr<InsertIterator> iter) -> InsertResult;
void runStoreOperation();
void triggerStoreOperation();
std::mutex _mutex;
std::deque<InsertRequest> _requests;
bool storeOperationRunning = false;
futures::future<void> storeOperation = futures::make_fulfilled_promise();
log_index_type _current_index = 0;
log_id_type const _log_id;
std::shared_ptr<RocksDBHandle> _rocks;
std::shared_ptr<sched::scheduler> _scheduler;
};
} // namespace plog
#endif // PROTOTYPE_PERSISTED_LOG_H