Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Public Member Functions | List of all members
joedb::Server_File Class Reference

Directly read file served from joedb_server. More...

#include <joedb/concurrency/Server_File.h>

Inheritance diagram for joedb::Server_File:
Inheritance graph
[legend]
Collaboration diagram for joedb::Server_File:
Collaboration graph
[legend]

Public Member Functions

 Server_File (Channel &channel)
 
int64_t handshake (Readonly_Journal &client_journal, bool content_check) override
 Called during Client construction.
 
int64_t pull (Writable_Journal &client_journal, std::chrono::milliseconds wait) override
 Pull new data from the connection.
 
int64_t lock_pull (Writable_Journal &client_journal, std::chrono::milliseconds wait) override
 Fused lock_pull, executed at the start of a write transaction.
 
int64_t push_until (Readonly_Journal &client_journal, int64_t server_position, int64_t until_position, bool unlock_after) override
 Push new data to the connection.
 
size_t pread (char *data, size_t size, int64_t offset) const override
 
void pwrite (const char *data, size_t size, int64_t offset) override
 
int64_t get_size () const override
 
std::string read_blob_data (Blob blob) const override
 
- Public Member Functions inherited from joedb::Server_Connection
 Server_Connection (Channel &channel)
 
int64_t get_checkpoint (Readonly_Journal &client_journal, std::chrono::milliseconds wait) override
 Get new connection checkpoint without pulling.
 
void unlock () override
 Can be used to cancel a transaction without pushing.
 
- Public Member Functions inherited from joedb::Server_Client
 Server_Client (Channel &channel)
 
void set_log (std::ostream *stream)
 
void set_keep_alive_interval (std::chrono::seconds duration)
 
int64_t get_session_id () const
 
Thread_Safe_Channelget_channel ()
 
void ping ()
 
 ~Server_Client ()
 
- Public Member Functions inherited from joedb::Connection
int64_t push (Readonly_Journal &client_journal, int64_t from_checkpoint, bool unlock_after)
 Shortcut to call push_until until the client checkpoint.
 
virtual ~Connection ()
 
- Public Member Functions inherited from joedb::Buffered_File
 Buffered_File (Open_Mode mode)
 
void flush ()
 
void flush_and_sync ()
 
void exclusive_lock_tail ()
 
void unlock_tail () noexcept
 
bool tail_is_locked () const noexcept
 
void shared_lock_head ()
 
void exclusive_lock_head ()
 
void unlock_head () noexcept
 
bool is_shared () const noexcept
 
bool is_readonly () const noexcept
 
void set_position (int64_t position)
 
int64_t get_position () const noexcept
 
virtual void copy_to (Buffered_File &destination, int64_t start, int64_t size)
 
void copy_to (Buffered_File &destination)
 
template<typename T >
void write (T x)
 
template<typename T >
read ()
 
template<typename T >
void compact_write (T x)
 
template<typename T >
T compact_read ()
 
template<typename T >
T read_strong_type ()
 
void write_reference (Record_Id id)
 
Record_Id read_reference ()
 
void write_string (const std::string &s)
 
std::string read_string ()
 
void write_blob (Blob blob)
 
Blob read_blob ()
 
std::string safe_read_string (int64_t max_size)
 
void write_data (const char *data, size_t n)
 
size_t read_data (char *data, const size_t n)
 
void ignore (const int64_t n)
 
- Public Member Functions inherited from joedb::Sequential_File
void sequential_seek (int64_t new_position)
 
size_t sequential_read (char *data, size_t size)
 
void sequential_write (const char *data, size_t size)
 
int64_t get_position () const
 
- Public Member Functions inherited from joedb::Abstract_File
virtual void sync ()
 
virtual void shared_lock (int64_t start, int64_t size)
 
virtual void exclusive_lock (int64_t start, int64_t size)
 
virtual void unlock (int64_t start, int64_t size) noexcept
 
virtual ~Abstract_File ()=default
 

Additional Inherited Members

- Static Public Attributes inherited from joedb::Buffered_File
static constexpr int64_t last_position = (1ULL << 63) - 1
 
- Protected Member Functions inherited from joedb::Server_Connection
int64_t pull (Writable_Journal *client_journal, std::chrono::milliseconds wait, char pull_type)
 
bool check_matching_content (Readonly_Journal &client_journal, int64_t server_checkpoint)
 
- Protected Member Functions inherited from joedb::Server_Client
void download (Async_Writer &writer, Channel_Lock &lock, int64_t size) const
 
- Protected Member Functions inherited from joedb::Buffered_File
void destructor_flush () noexcept
 
void make_readonly ()
 
void make_writable ()
 
- Static Protected Member Functions inherited from joedb::Connection
static void content_mismatch ()
 
- Protected Attributes inherited from joedb::Server_Client
Thread_Safe_Channel channel
 
std::ostream * log
 
bool connected
 
Buffer< 13 > buffer
 
int64_t session_id
 
bool pullonly_server
 
int64_t server_checkpoint
 

Detailed Description

This class allows reading a remote file via the joedb network protocol. It is convenient for reading blobs from a large remote database without having to download a local replica. This file can also be written to: the head and tail of the file are stored in RAM locally, and can be pushed to the remote server if used in a client.

A demo can be found in write_server_blob.cpp:

#include <iostream>
/// Demonstration of joedb::Server_File
///
/// This demonstrates how to connect to a joedb server to read and write blobs,
/// without downloading a full replica of the database.
static int write_server_blob(int argc, char **argv)
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <port> <blob_string>\n";
std::cerr << "This program will try to connect to a server on localhost.\n";
std::cerr << "Before running this program, start a joedb server with:\n";
std::cerr << "joedb_server -port <port> blobs.joedb\n";
std::cerr << "You can interactively read and write blobs this way:\n";
std::cerr << "joedb_client --nodb server network localhost <port>\n";
return 1;
}
// Connect to the server
// Creating the client: server file serves both as file and connection
// Write blobs with a Client_Lock: keeps the server locked between writes
{
for (int i = 3; --i >= 0;)
{
const joedb::Blob blob = lock.get_journal().write_blob_data(argv[2]);
lock.push();
std::cout << "wrote blob with lock: " << blob.get_position() << '\n';
std::cout << "blob: " << server_file.read_blob_data(blob) << '\n';
}
lock.unlock();
}
// Write blobs with a transaction: lock and unlock for each write
for (int i = 3; --i >= 0;)
{
client.transaction([&blob, argv](joedb::Writable_Journal &journal)
{
blob = journal.write_blob_data(argv[2]);
});
std::cout << "wrote blob with transaction: " << blob.get_position() << '\n';
std::cout << "blob: " << server_file.read_blob_data(blob) << '\n';
}
return 0;
}
int main(int argc, char **argv)
{
return joedb::main_exception_catcher(write_server_blob, argc, argv);
}
int64_t get_position() const noexcept
Definition Blob.h:28
Thread_Safe_Channel channel
Directly read file served from joedb_server.
Definition Server_File.h:23
Blob write_blob_data(const std::string &data) final
int main()
int main_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception from main.

Definition at line 22 of file Server_File.h.

Constructor & Destructor Documentation

◆ Server_File()

joedb::Server_File::Server_File ( Channel channel)

Definition at line 45 of file Server_File.cpp.

Member Function Documentation

◆ get_size()

int64_t joedb::Server_File::get_size ( ) const
inlineoverridevirtual

Reimplemented from joedb::Abstract_File.

Definition at line 77 of file Server_File.h.

◆ handshake()

int64_t joedb::Server_File::handshake ( Readonly_Journal client_journal,
bool  content_check 
)
overridevirtual
Parameters
client_journalmay be used to check matching content
content_checkindicates whether matching content is tested
Return values
server_checkpoint

Reimplemented from joedb::Server_Connection.

Definition at line 76 of file Server_File.cpp.

◆ lock_pull()

int64_t joedb::Server_File::lock_pull ( Writable_Journal client_journal,
std::chrono::milliseconds  wait 
)
overridevirtual
Return values
server_checkpoint

Reimplemented from joedb::Server_Connection.

Definition at line 100 of file Server_File.cpp.

◆ pread()

size_t joedb::Server_File::pread ( char data,
size_t  size,
int64_t  offset 
) const
overridevirtual

Reimplemented from joedb::Abstract_File.

Definition at line 140 of file Server_File.cpp.

◆ pull()

int64_t joedb::Server_File::pull ( Writable_Journal client_journal,
std::chrono::milliseconds  wait 
)
overridevirtual
Parameters
client_journaljournal to pull into
waitduration during which the connection may wait for new data if the pull would otherwise be empty
Return values
server_checkpoint

Reimplemented from joedb::Server_Connection.

Definition at line 89 of file Server_File.cpp.

◆ push_until()

int64_t joedb::Server_File::push_until ( Readonly_Journal client_journal,
int64_t  from_checkpoint,
int64_t  until_checkpoint,
bool  unlock_after 
)
overridevirtual
Return values
server_checkpoint

Reimplemented from joedb::Server_Connection.

Definition at line 111 of file Server_File.cpp.

◆ pwrite()

void joedb::Server_File::pwrite ( const char data,
size_t  size,
int64_t  offset 
)
overridevirtual

Reimplemented from joedb::Abstract_File.

Definition at line 153 of file Server_File.cpp.

◆ read_blob_data()

std::string joedb::Server_File::read_blob_data ( Blob  blob) const
overridevirtual

Reimplemented from joedb::Buffered_File.

Definition at line 170 of file Server_File.cpp.


The documentation for this class was generated from the following files: