Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Server_File.h
Go to the documentation of this file.
1#ifndef joedb_Server_File_declared
2#define joedb_Server_File_declared
3
7
8namespace joedb
9{
10 /// Directly read file served from joedb_server
11 ///
12 /// This class allows reading a remote file via the joedb network protocol.
13 /// It is convenient for reading blobs from a large remote database without
14 /// having to download a local replica. This file can also be written to:
15 /// the head and tail of the file are stored in RAM locally, and can be
16 /// pushed to the remote server if used in a client.
17 ///
18 /// @include server_file_tutorial.cpp
19 ///
20 /// @ingroup concurrency
22 {
23 private:
24 int64_t tail_offset;
25
26 Memory_File head;
27 Memory_File tail;
28
29 static void write_to_body_error();
30 void write_checkpoint();
31
32 public:
34 (
35 const Connector &connector,
37 );
38
39 //
40 // Connection overrides
41 //
42 int64_t handshake
43 (
44 const Readonly_Journal &client_journal,
45 Content_Check content_check
46 ) override;
47
48 int64_t pull
49 (
50 Lock_Action lock_action,
51 Data_Transfer data_transfer,
52 Writable_Journal &client_journal,
53 std::chrono::milliseconds wait
54 ) override;
55
56 int64_t push
57 (
58 const Readonly_Journal &client_journal,
59 int64_t server_position,
60 int64_t until_position,
61 Unlock_Action unlock_action
62 ) override;
63
64 //
65 // Abstract_File overrides
66 //
67 size_t pread(char *data, size_t size, int64_t offset) const override;
68 void pwrite(const char *data, size_t size, int64_t offset) override;
69 int64_t get_size() const override {return tail_offset + tail.get_size();}
70 };
71}
72
73#endif
Used by Robust_Connection to reconnect after an error.
Definition Connector.h:15
static Logger dummy_logger
Definition Logger.h:14
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
Definition Memory_File.h:27
Server_Connection that automatically reconnects on error
Directly read file served from joedb_server.
Definition Server_File.h:22
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
Definition Server_File.h:69
size_t pread(char *data, size_t size, int64_t offset) const override
Read a range of bytes.
int64_t push(const Readonly_Journal &client_journal, int64_t server_position, int64_t until_position, Unlock_Action unlock_action) override
Push new data to the connection.
int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait) override
Pull from the connection.
void pwrite(const char *data, size_t size, int64_t offset) override
Write a range of bytes. Extend file size if necessary.
int64_t handshake(const Readonly_Journal &client_journal, Content_Check content_check) override
Called during Client construction.
Data_Transfer
Definition Connection.h:28
Lock_Action
Definition Connection.h:35
Content_Check
Definition Connection.h:20
Unlock_Action
Definition Connection.h:42