1#ifndef joedb_Writable_Client_declared
2#define joedb_Writable_Client_declared
25 if constexpr (std::is_void<T>::value)
42 const T result = [&]()
68 bool use_valid_data =
false;
69 bool use_timestamp =
false;
70 bool use_hard_checkpoint =
false;
78 get_writable_journal().
timestamp(std::time(
nullptr));
82 if (use_hard_checkpoint)
86 void start_transaction()
92 get_writable_journal()
122 std::chrono::milliseconds wait = std::chrono::milliseconds(0)
133 get_writable_journal(),
183 client.start_transaction();
246 try {
unlock(); }
catch (...) {}
Lock object that allows writing to a database managed by a joedb::Client.
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.
const Journal_Lock journal_lock
Client_Lock & operator=(const Client_Lock &)=delete
Handle concurrent access to a file with a joedb::Connection.
virtual void read_journal()
int64_t connection_checkpoint
int64_t push(Unlock_Action unlock_action)
int64_t get_journal_checkpoint() const
Readonly_Journal & journal
int64_t get_connection_checkpoint() const
virtual void unlock()
Unlock the connection.
virtual int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait=std::chrono::milliseconds(0))
Pull from the connection.
static void write(const char *message) noexcept
Writable specialization of Client.
void set_valid_data(bool b)
Automatically write valid_data at every checkpoint (default = false)
Writable_Client(Writable_Journal &journal, Connection &connection, Content_Check content_check=Content_Check::quick)
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
int64_t push_if_ahead() override
auto transaction(F transaction)
void timestamp(int64_t timestamp) final
#define JOEDB_DEBUG_ASSERT(x)