Joedb 9.5.0
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
8namespace joedb
9{
10 /// @ingroup journal
12 {
13 private:
14 void generic_update
15 (
16 Table_Id table_id,
17 Record_Id record_id,
18 Field_Id field_id,
19 operation_t operation
20 );
21
22 public:
24
27 {
28 }
29
34
39
40 int64_t pull_from(const Readonly_Journal &journal, int64_t until);
41 int64_t pull_from(const Readonly_Journal &journal)
42 {
43 return pull_from(journal, journal.get_checkpoint());
44 }
45
46 int64_t ahead_of_checkpoint() const noexcept;
47
48 void flush() final {file.flush();}
49
50 int64_t get_position() const override {return file.get_position();}
51 void start_writing(int64_t position) override;
52 void soft_checkpoint_at(int64_t position) override;
53 void hard_checkpoint_at(int64_t position) override;
54
55 void create_table(const std::string &name) final;
56 void drop_table(Table_Id table_id) final;
57
58 void rename_table
59 (
60 Table_Id table_id,
61 const std::string &name
62 ) final;
63
64 void add_field
65 (
66 Table_Id table_id,
67 const std::string &name,
68 Type type
69 ) final;
70
71 void drop_field
72 (
73 Table_Id table_id,
74 Field_Id field_id
75 ) final;
76
77 void rename_field
78 (
79 Table_Id table_id,
80 Field_Id field_id,
81 const std::string &name
82 ) final;
83
84 void custom(const std::string &name) final;
85 void comment(const std::string &comment) final;
86 void timestamp(int64_t timestamp) final;
87 void valid_data() final;
88
89 void insert_into(Table_Id table_id, Record_Id record_id) final;
90 void delete_from(Table_Id table_id, Record_Id record_id) final;
91
92 void insert_vector
93 (
94 Table_Id table_id,
95 Record_Id record_id,
96 size_t size
97 ) final;
98
99 void delete_vector
100 (
101 Table_Id table_id,
102 Record_Id record_id,
103 size_t size
104 ) final;
105
106 #define TYPE_MACRO(type, return_type, type_id, read_method, write_method)\
107 void update_##type_id\
108 (\
109 Table_Id table_id,\
110 Record_Id record_id,\
111 Field_Id field_id,\
112 return_type value\
113 ) final;\
114 void update_vector_##type_id\
115 (\
116 Table_Id table_id,\
117 Record_Id record_id,\
118 Field_Id field_id,\
119 size_t size,\
120 const type *value\
121 ) final;
122 #include "joedb/TYPE_MACRO.h"
123
124 bool wants_blob_data() const final {return true;}
125 Blob write_blob(const std::string &data) final;
126
131
132 void lock_pull();
133 bool is_locked() const {return file.tail_is_locked();}
134 void unlock() noexcept;
135
136 ~Writable_Journal() override;
137 };
138
140 {
141 private:
142 Writable_Journal &journal;
143
144 public:
145 Journal_Lock(Writable_Journal &journal): journal(journal)
146 {
147 if (journal.get_position() > journal.get_checkpoint())
148 throw Exception("locking journal with uncheckpointed data");
149 journal.lock_pull();
150 }
151
152 Journal_Lock(const Journal_Lock &lock) = delete;
153 Journal_Lock &operator=(const Journal_Lock &lock) = delete;
154
156 {
157 journal.unlock();
158 }
159 };
160}
161
162#endif
void set_position(int64_t position)
bool tail_is_locked() const noexcept
int64_t get_position() 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() const
int64_t pull_from(const Readonly_Journal &journal, int64_t until)
void hard_checkpoint_at(int64_t position) override
void soft_checkpoint_at(int64_t position) override
bool wants_blob_data() const final
int64_t ahead_of_checkpoint() const noexcept
Writable_Journal(Buffered_File &file)
Blob write_blob(const std::string &data) final
void start_writing(int64_t position) override
int64_t get_position() const override
int64_t pull_from(const Readonly_Journal &journal)
Writable_Journal(Journal_Construction_Lock &&lock)
Async_Writer get_async_tail_writer()
Definition Blob.h:7