Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Readonly_Journal.h
Go to the documentation of this file.
1#ifndef joedb_Readonly_Journal_declared
2#define joedb_Readonly_Journal_declared
3
4#include "joedb/Writable.h"
8
9#include <array>
10
11namespace joedb
12{
13 class Writable_Journal;
14
15 /// @ingroup journal
17 {
18 friend class Writable_Journal;
19 friend class Journal_Hasher;
20
21 private:
22 void read_checkpoint(const std::array<int64_t, 4> &pos);
23 void pull_without_locking();
24
25 #define TYPE_MACRO(cpp_type, return_type, type_id, read_method, W)\
26 void perform_update_##type_id(Writable &writable);
27 #include "joedb/TYPE_MACRO.h"
28
29 protected:
34
38
39 void reset_context();
40
42 std::string safe_read_string();
43
44 #define TYPE_MACRO(cpp_type, return_type, type_id, read_method, W)\
45 void read_vector_of_##type_id(cpp_type *data, size_t size);
46 #include "joedb/TYPE_MACRO.h"
47
48 enum class operation_t: uint8_t
49 {
50 create_table = 0x01,
51 drop_table = 0x02,
52 add_field = 0x03,
53 drop_field = 0x04,
54 insert_into = 0x05,
55 delete_from = 0x06,
56 update = 0x07, // deprecated
57 append = 0x08,
58 update_last = 0x09, // deprecated
59 comment = 0x0a,
60 timestamp = 0x0b,
61 rename_table = 0x0c,
62 rename_field = 0x0d,
63 valid_data = 0x0e,
64 insert_vector = 0x0f,
65 custom = 0x10,
66 update_vector = 0x11, // deprecated
67 update_next = 0x12, // deprecated
68 blob = 0x13,
69 delete_vector = 0x14,
70 updates = 0x80,
71 #define TYPE_MACRO(t, rt, type_id, r, w)\
72 update_##type_id,\
73 update_last_##type_id,\
74 update_next_##type_id,\
75 update_vector_##type_id,
76 #include "joedb/TYPE_MACRO.h"
77 };
78
79 public:
81
84 {
85 }
86
91
92 int64_t get_position() const {return file.get_position();}
93 int64_t get_checkpoint() const {return checkpoint_position;}
94 bool is_empty() const {return file.get_size() == Header::ssize;}
95 bool is_shared() const {return file.is_shared();}
96 int64_t pull();
97 const Buffered_File &get_file() const {return file;}
98 void replay_log(Writable &writable);
100 void rewind();
101 void one_step(Writable &writable);
102 void play_until(Writable &writable, int64_t end);
103 void append_until(Writable &writable, int64_t end);
105 {
107 }
108 void skip_directly_to(int64_t position)
109 {
110 file.set_position(position);
111 }
112 bool equal_to(Readonly_Journal &journal, int64_t until) const
113 {
114 return file.equal_to(journal.file, Header::ssize, until);
115 }
116
117 Async_Reader get_async_tail_reader(int64_t start_position) const
118 {
119 return Async_Reader(file, start_position, get_checkpoint());
120 }
121
122 Async_Reader get_async_reader(int64_t start_position, int64_t until_position) const
123 {
124 return Async_Reader
125 (
126 file,
127 start_position,
128 std::min(until_position, get_checkpoint())
129 );
130 }
131
132 static constexpr uint32_t format_version = 5;
133 };
134}
135
136#endif
virtual int64_t get_size() const
Get the size of the file, or -1 if it is unknown.
void set_position(int64_t position)
bool is_shared() const noexcept
virtual bool equal_to(Buffered_File &destination, int64_t from, int64_t until) const
int64_t get_position() const noexcept
void play_until(Writable &writable, int64_t end)
void one_step(Writable &writable)
static constexpr uint32_t format_version
Readonly_Journal(Journal_Construction_Lock &&lock)
int64_t get_position() const
void replay_with_checkpoint_comments(Writable &writable)
void append_until(Writable &writable, int64_t end)
void replay_log(Writable &writable)
Async_Reader get_async_reader(int64_t start_position, int64_t until_position) const
const Buffered_File & get_file() const
void play_until_checkpoint(Writable &writable)
int64_t get_checkpoint() const
bool equal_to(Readonly_Journal &journal, int64_t until) const
Async_Reader get_async_tail_reader(int64_t start_position) const
void skip_directly_to(int64_t position)
Readonly_Journal(Buffered_File &file)
Definition Blob.h:7
static constexpr int64_t ssize
Definition Header.h:18