6
6
#include < string.h>
7
7
#include < map>
8
8
9
+ #ifndef DNSDIST
10
+ #include < lmdb.h>
11
+ #include " ../../pdns/gettime.hh"
12
+ #endif
13
+
9
14
using std::string;
10
15
using std::runtime_error;
11
16
using std::tuple;
@@ -16,6 +21,56 @@ static string MDBError(int rc)
16
21
return mdb_strerror (rc);
17
22
}
18
23
24
+ #ifndef DNSDIST
25
+
26
+ namespace LMDBLS {
27
+ // this also returns a pointer to the string's data. Do not hold on to it too long!
28
+ LSheader* LSassertFixedHeaderSize (std::string_view val) {
29
+ // cerr<<"val.size()="<<val.size()<<endl;
30
+ if (val.size () < LS_MIN_HEADER_SIZE) {
31
+ throw std::runtime_error (" LSheader too short" );
32
+ }
33
+
34
+ return (LSheader*)val.data ();
35
+ }
36
+
37
+ size_t LScheckHeaderAndGetSize (std::string_view val, size_t datasize) {
38
+ LSheader* lsh = LSassertFixedHeaderSize (val);
39
+
40
+ if (lsh->d_version != 0 ) {
41
+ throw std::runtime_error (" LSheader has wrong version (not zero)" );
42
+ }
43
+
44
+ size_t headersize = LS_MIN_HEADER_SIZE;
45
+
46
+ headersize += ntohs (lsh->d_numextra ) * LS_BLOCK_SIZE;
47
+
48
+ if (val.size () < headersize) {
49
+ throw std::runtime_error (" LSheader too short for promised extra data" );
50
+ }
51
+
52
+ if (datasize && val.size () < (headersize+datasize)) {
53
+ throw std::runtime_error (" Trailing data after LSheader has wrong size" );
54
+ }
55
+
56
+ return headersize;
57
+ }
58
+
59
+ size_t LScheckHeaderAndGetSize (const MDBOutVal *val, size_t datasize) {
60
+ return LScheckHeaderAndGetSize (val->getNoStripHeader <string_view>(), datasize);
61
+ }
62
+
63
+ bool LSisDeleted (std::string_view val) {
64
+ LSheader* lsh = LSassertFixedHeaderSize (val);
65
+
66
+ return (lsh->d_flags & LS_FLAG_DELETED) != 0 ;
67
+ }
68
+
69
+ bool s_flag_deleted{false };
70
+ }
71
+
72
+ #endif /* #ifndef DNSDIST */
73
+
19
74
MDBDbi::MDBDbi (MDB_env* env, MDB_txn* txn, const string_view dbname, int flags)
20
75
{
21
76
// A transaction that uses this function must finish (either commit or abort) before any other transaction in the process may use this function.
@@ -184,6 +239,13 @@ MDB_txn *MDBRWTransactionImpl::openRWTransaction(MDBEnv *env, MDB_txn *parent, i
184
239
MDBRWTransactionImpl::MDBRWTransactionImpl (MDBEnv* parent, int flags):
185
240
MDBRWTransactionImpl(parent, openRWTransaction(parent, nullptr , flags))
186
241
{
242
+ #ifndef DNSDIST
243
+ struct timespec tp;
244
+
245
+ gettime (&tp, true );
246
+
247
+ d_txtime = tp.tv_sec * 1E9 + tp.tv_nsec ;
248
+ #endif
187
249
}
188
250
189
251
MDBRWTransactionImpl::~MDBRWTransactionImpl ()
@@ -301,9 +363,10 @@ MDBRWCursor MDBRWTransactionImpl::getRWCursor(const MDBDbi& dbi)
301
363
MDB_cursor *cursor;
302
364
int rc= mdb_cursor_open (d_txn, dbi, &cursor);
303
365
if (rc) {
304
- throw std::runtime_error (" Error creating RO cursor: " +std::string (mdb_strerror (rc)));
366
+ throw std::runtime_error (" Error creating RW cursor: " +std::string (mdb_strerror (rc)));
305
367
}
306
- return MDBRWCursor (d_rw_cursors, cursor);
368
+
369
+ return MDBRWCursor (d_rw_cursors, cursor, d_txn, d_txtime);
307
370
}
308
371
309
372
MDBRWCursor MDBRWTransactionImpl::getCursor (const MDBDbi &dbi)
0 commit comments