Joedb 9.6.2
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, int64_t file_size);
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:
35
39
40 void reset_context();
41
43 std::string safe_read_string();
44
45 #define TYPE_MACRO(cpp_type, return_type, type_id, read_method, W)\
46 void read_vector_of_##type_id(cpp_type *data, size_t size);
47 #include "joedb/TYPE_MACRO.h"
48
49 enum class operation_t: uint8_t
50 {
51 create_table = 0x01,
52 drop_table = 0x02,
53 add_field = 0x03,
54 drop_field = 0x04,
55 insert_into = 0x05,
56 delete_from = 0x06,
57 update = 0x07, // deprecated
58 append = 0x08,
59 update_last = 0x09, // deprecated
60 comment = 0x0a,
61 timestamp = 0x0b,
62 rename_table = 0x0c,
63 rename_field = 0x0d,
64 valid_data = 0x0e,
65 insert_vector = 0x0f,
66 custom = 0x10,
67 update_vector = 0x11, // deprecated
68 update_next = 0x12, // deprecated
69 blob = 0x13,
70 delete_vector = 0x14,
71 updates = 0x80,
72 #define TYPE_MACRO(t, rt, type_id, r, w)\
73 update_##type_id,\
74 update_last_##type_id,\
75 update_next_##type_id,\
76 update_vector_##type_id,
77 #include "joedb/TYPE_MACRO.h"
78 };
79
80 public:
82
85 {
86 }
87
92
93 int64_t get_position() const {return file.get_position();}
94 int64_t get_checkpoint() const {return checkpoint_position;}
96 bool is_empty() const {return file.get_size() == Header::ssize;}
97 bool is_shared() const {return file.is_shared();}
98 int64_t pull();
99 const Buffered_File &get_file() const {return file;}
100 void replay_log(Writable &writable);
102 void rewind();
103 void one_step(Writable &writable);
104 void play_until(Writable &writable, int64_t end);
105 void raw_play_until(Writable &writable, int64_t end);
107 {
109 }
111 {
113 }
114 void skip_directly_to(int64_t position)
115 {
116 file.set_position(position);
117 }
118 bool equal_to(Readonly_Journal &journal, int64_t from, int64_t until) const
119 {
120 return file.equal_to(journal.file, from, until);
121 }
122
123 Async_Reader get_async_tail_reader(int64_t start_position) const
124 {
125 return Async_Reader(file, start_position, get_checkpoint());
126 }
127
128 Async_Reader get_async_reader(int64_t start_position, int64_t until_position) const
129 {
130 return Async_Reader
131 (
132 file,
133 start_position,
134 std::min(until_position, get_checkpoint())
135 );
136 }
137
138 static constexpr uint32_t format_version = 5;
139 };
140}
141
142#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
int64_t get_hard_checkpoint() const
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)
bool equal_to(Readonly_Journal &journal, int64_t from, int64_t until) const
void replay_log(Writable &writable)
void raw_play_until(Writable &writable, int64_t end)
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)
void raw_play_until_checkpoint(Writable &writable)
int64_t get_checkpoint() 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