Joedb 9.5.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:
33 Server_File(const Connector &connector, std::ostream *log = nullptr);
34
35 //
36 // Connection overrides
37 //
38 int64_t handshake
39 (
40 const Readonly_Journal &client_journal,
41 Content_Check content_check
42 ) override;
43
44 int64_t pull
45 (
46 Lock_Action lock_action,
47 Data_Transfer data_transfer,
48 Writable_Journal &client_journal,
49 std::chrono::milliseconds wait
50 ) override;
51
52 int64_t push
53 (
54 const Readonly_Journal &client_journal,
55 int64_t server_position,
56 int64_t until_position,
57 Unlock_Action unlock_action
58 ) override;
59
60 //
61 // Abstract_File overrides
62 //
63 size_t pread(char *data, size_t size, int64_t offset) const override;
64 void pwrite(const char *data, size_t size, int64_t offset) override;
65 int64_t get_size() const override {return tail_offset + tail.get_size();}
66 };
67}
68
69#endif
Used by Robust_Connection to reconnect after an error.
Definition Connector.h:14
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
Definition Memory_File.h:24
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:65
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:27
Lock_Action
Definition Connection.h:34
Content_Check
Definition Connection.h:19
Unlock_Action
Definition Connection.h:41
Definition Blob.h:7