1#ifndef joedb_Writable_Client_declared
2#define joedb_Writable_Client_declared
23 using T =
decltype(f());
25 if constexpr (std::is_void<T>::value)
63 void emergency_unlock() noexcept
68 Writable_Journal &get_writable_journal()
74 bool use_valid_data =
false;
75 bool use_timestamp =
false;
76 bool use_hard_checkpoint =
false;
81 get_writable_journal().valid_data();
84 get_writable_journal().timestamp(std::time(
nullptr));
86 get_writable_journal().soft_checkpoint();
88 if (use_hard_checkpoint)
89 get_writable_journal().hard_checkpoint();
92 Tail_Exclusive_Lock get_tail_lock()
95 throw Exception(
"pulling when ahead of connection");
97 Tail_Exclusive_Lock lock(get_writable_journal());
101 get_writable_journal(),
110 void start_transaction()
116 get_writable_journal()
138 content_check(content_check)
144 get_writable_journal().touch();
161 std::chrono::milliseconds wait = std::chrono::milliseconds(0)
172 get_writable_journal(),
219 client.start_transaction();
238 if (
client.get_journal_checkpoint() >
client.get_connection_checkpoint())
272 client.connection.unlock();
282 try {
unlock(); }
catch (...) {}
const Tail_Exclusive_Lock journal_lock
void checkpoint_and_push_unlock()
Confirm the transaction right before lock destruction.
void do_checkpoint()
Checkpoint current journal, but do not push yet.
void push_if_ahead()
Push if the journal checkpoint is ahead of the connection checkpoint.
Client_Lock(Writable_Client &client)
void checkpoint_and_push()
Checkpoint current journal, and push to the connection.
void unlock()
Cancel the transaction right before lock destruction.
Client_Lock(const Client_Lock &)=delete
~Client_Lock()
The destructor unlocks the connection if necessary.
Client_Lock & operator=(const Client_Lock &)=delete
virtual void read_journal()
int64_t connection_checkpoint
int64_t get_journal_checkpoint() const
int64_t push(int64_t until, Unlock_Action unlock_action)
Readonly_Journal & journal
virtual int64_t push_if_ahead(int64_t until)=0
int64_t get_connection_checkpoint() const
Client(Readonly_Journal &journal, Connection &connection, Content_Check content_check)
static Connection dummy
Since this class has no internal state, this global variable can be used instead of creating an insta...
virtual void unlock()
Unlock the connection.
static void warning(beman::cstring_view message) noexcept
Writable specialization of Client.
void set_valid_data(bool b)
Automatically write valid_data at every checkpoint (default = false).
void set_hard_checkpoint(bool b)
Use hard checkpoints (default = false).
void set_timestamp(bool b)
Automatically write time stamp at every checkpoint (default = false).
int64_t pull(std::chrono::milliseconds wait=std::chrono::milliseconds(0)) override
Writable_Client(Writable_Journal &journal, Connection &connection=Connection::dummy, Content_Check content_check=Content_Check::fast)
int64_t push_if_ahead(int64_t until) override
#define JOEDB_DEBUG_ASSERT(x)
assertion tested in debug mode