Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
File_Connection.cpp
Go to the documentation of this file.
3
4namespace joedb
5{
6 //////////////////////////////////////////////////////////////////////////
8 //////////////////////////////////////////////////////////////////////////
9 (
10 const Readonly_Journal &client_journal,
11 Content_Check content_check
12 )
13 {
14 if (content_check != Content_Check::none)
15 {
16 const int64_t min = std::min
17 (
18 server_journal.get_checkpoint(),
19 client_journal.get_checkpoint()
20 );
21
22 if (content_check == Content_Check::quick)
23 {
24 if
25 (
26 Journal_Hasher::get_hash(client_journal, min) !=
27 Journal_Hasher::get_hash(server_journal, min)
28 )
29 {
30 content_mismatch();
31 }
32 }
33 else if (content_check == Content_Check::full)
34 {
35 if (!client_journal.equal_to(server_journal, min))
36 content_mismatch();
37 }
38 else
40 }
41
42 return server_journal.get_checkpoint();
43 }
44
45 //////////////////////////////////////////////////////////////////////////
47 //////////////////////////////////////////////////////////////////////////
48 (
49 Lock_Action lock_action,
50 Data_Transfer data_transfer,
51 Writable_Journal &client_journal,
52 std::chrono::milliseconds wait
53 )
54 {
55 if (bool(lock_action))
56 throw Exception("Connected to a read-only journal: can't lock");
57
58 server_journal.pull();
59
60 if (bool(data_transfer))
61 client_journal.pull_from(server_journal);
62
63 return server_journal.get_checkpoint();
64 }
65
66 //////////////////////////////////////////////////////////////////////////
68 //////////////////////////////////////////////////////////////////////////
69 (
70 const Readonly_Journal &client_journal,
71 const int64_t from,
72 const int64_t until,
73 Unlock_Action unlock_action
74 )
75 {
76 throw Exception("Connected to a read-only journal: can't push");
77 }
78
79 //////////////////////////////////////////////////////////////////////////
81 //////////////////////////////////////////////////////////////////////////
82 (
83 Lock_Action lock_action,
84 Data_Transfer data_transfer,
85 Writable_Journal &client_journal,
86 std::chrono::milliseconds wait
87 )
88 {
89 if (bool(lock_action))
90 get_journal().lock_pull();
91 else
92 get_journal().pull();
93
94 if (bool(data_transfer))
95 client_journal.pull_from(server_journal);
96
97 return server_journal.get_checkpoint();
98 }
99
100 //////////////////////////////////////////////////////////////////////////
102 //////////////////////////////////////////////////////////////////////////
103 (
104 const Readonly_Journal &client_journal,
105 const int64_t from,
106 const int64_t until,
107 Unlock_Action unlock_action
108 )
109 {
110 if (!get_journal().is_locked())
111 get_journal().lock_pull();
112
113 if (from != server_journal.get_checkpoint())
114 throw Exception("push error: conflict");
115 get_journal().pull_from(client_journal, until);
116
117 if (bool(unlock_action))
118 get_journal().unlock();
119
120 return server_journal.get_checkpoint();
121 }
122
123 //////////////////////////////////////////////////////////////////////////
125 //////////////////////////////////////////////////////////////////////////
126 {
127 get_journal().unlock();
128 }
129
130 //////////////////////////////////////////////////////////////////////////
132 //////////////////////////////////////////////////////////////////////////
133 {
134 get_journal().unlock();
135 }
136}
void unlock() override
Unlock the connection.
int64_t push(const Readonly_Journal &client_journal, const int64_t from, const int64_t until, 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.
static SHA_256::Hash get_hash(const Readonly_Journal &journal, int64_t checkpoint)
int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait) override
Pull from the connection.
int64_t handshake(const Readonly_Journal &client_journal, Content_Check content_check) override
Called during Client construction.
int64_t push(const Readonly_Journal &client_journal, const int64_t from, const int64_t until, Unlock_Action unlock_action) override
Push new data to the connection.
Data_Transfer
Definition Connection.h:27
Lock_Action
Definition Connection.h:34
Content_Check
Definition Connection.h:19
Unlock_Action
Definition Connection.h:41
#define JOEDB_RELEASE_ASSERT(x)
Definition assert.h:24
Definition Blob.h:7