Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Journal.h
Go to the documentation of this file.
1#ifndef joedb_Writable_Journal_declared
2#define joedb_Writable_Journal_declared
3
4#include "joedb/Writable.h"
7#include <limits>
8
9namespace joedb
10{
11 /// @ingroup journal
13 {
14 private:
15 Commit_Level current_commit_level;
16
17 void generic_update
18 (
19 Table_Id table_id,
20 Record_Id record_id,
21 Field_Id field_id,
22 operation_t operation
23 );
24
25 void flush_and_may_sync()
26 {
27 file.flush();
29 file.sync();
30 }
31
32 public:
33 explicit Writable_Journal
34 (
36 Check check,
37 Commit_Level commit_level
38 );
39
40 explicit Writable_Journal
41 (
43 Check check,
44 Commit_Level commit_level
45 );
46
47 explicit Writable_Journal
48 (
50 Check check = Check::all,
52 );
53
58
59 int64_t pull_from
60 (
61 Readonly_Journal &journal,
62 int64_t until_checkpoint = std::numeric_limits<int64_t>::max()
63 );
64
65 int64_t ahead_of_checkpoint() const noexcept;
66
67 void flush() final {file.flush();}
68 void checkpoint(Commit_Level commit_level) final;
69
70 void create_table(const std::string &name) final;
71 void drop_table(Table_Id table_id) final;
72
73 void rename_table
74 (
75 Table_Id table_id,
76 const std::string &name
77 ) final;
78
79 void add_field
80 (
81 Table_Id table_id,
82 const std::string &name,
83 Type type
84 ) final;
85
86 void drop_field
87 (
88 Table_Id table_id,
89 Field_Id field_id
90 ) final;
91
92 void rename_field
93 (
94 Table_Id table_id,
95 Field_Id field_id,
96 const std::string &name
97 ) final;
98
99 void custom(const std::string &name) final;
100 void comment(const std::string &comment) final;
101 void timestamp(int64_t timestamp) final;
102 void valid_data() final;
103 void insert_into(Table_Id table_id, Record_Id record_id) final;
104
105 void insert_vector
106 (
107 Table_Id table_id,
108 Record_Id record_id,
109 size_t size
110 ) final;
111
112 void delete_from(Table_Id table_id, Record_Id record_id) final;
113
114 #define TYPE_MACRO(type, return_type, type_id, read_method, write_method)\
115 void update_##type_id\
116 (\
117 Table_Id table_id,\
118 Record_Id record_id,\
119 Field_Id field_id,\
120 return_type value\
121 ) final;\
122 void update_vector_##type_id\
123 (\
124 Table_Id table_id,\
125 Record_Id record_id,\
126 Field_Id field_id,\
127 size_t size,\
128 const type *value\
129 ) final;
130 #include "joedb/TYPE_MACRO.h"
131
132 bool wants_blob_data() const final {return true;}
133 Blob write_blob_data(const std::string &data) final;
134
139
140 Writable_Journal *get_writable_journal() override {return this;}
141
142 void lock_pull();
143 bool is_locked() const {return file.tail_is_locked();}
144 void unlock() noexcept;
145
146 ~Writable_Journal() override;
147 };
148
150 {
151 private:
152 Writable_Journal &journal;
153
154 public:
155 Journal_Lock(Writable_Journal &journal): journal(journal)
156 {
157 if (journal.get_position() > journal.get_checkpoint_position())
158 throw Exception("locking journal with uncheckpointed data");
159 journal.lock_pull();
160 }
161
162 Journal_Lock(const Journal_Lock &lock) = delete;
163 Journal_Lock &operator=(const Journal_Lock &lock) = delete;
164
166 {
167 journal.unlock();
168 }
169 };
170}
171
172#endif
virtual void sync()
void set_position(int64_t position)
bool tail_is_locked() const noexcept
Journal_Lock(Writable_Journal &journal)
Journal_Lock & operator=(const Journal_Lock &lock)=delete
Journal_Lock(const Journal_Lock &lock)=delete
int64_t get_checkpoint_position() const
Blob write_blob_data(const std::string &data) final
bool wants_blob_data() const final
int64_t ahead_of_checkpoint() const noexcept
Writable_Journal * get_writable_journal() override
int64_t pull_from(Readonly_Journal &journal, int64_t until_checkpoint=std::numeric_limits< int64_t >::max())
void checkpoint(Commit_Level commit_level) final
Async_Writer get_async_tail_writer()
Commit_Level get_default_commit_level() const
Definition Writable.h:57
Definition Blob.h:7
Commit_Level
Definition Writable.h:13