File tree Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Original file line number Diff line number Diff line change 6
6
7
7
#include < logging.h>
8
8
#include < random.h>
9
+ #include < span.h>
10
+ #include < streams.h>
9
11
#include < tinyformat.h>
10
12
#include < util/fs.h>
11
13
#include < util/fs_helpers.h>
23
25
#include < leveldb/helpers/memenv/memenv.h>
24
26
#include < leveldb/iterator.h>
25
27
#include < leveldb/options.h>
28
+ #include < leveldb/slice.h>
26
29
#include < leveldb/status.h>
30
+ #include < leveldb/write_batch.h>
27
31
#include < memory>
28
32
#include < optional>
29
33
@@ -132,6 +136,22 @@ static leveldb::Options GetOptions(size_t nCacheSize)
132
136
return options;
133
137
}
134
138
139
+ void CDBBatch::WriteImpl (Span<const std::byte> ssKey, CDataStream& ssValue)
140
+ {
141
+ leveldb::Slice slKey (CharCast (ssKey.data ()), ssKey.size ());
142
+ ssValue.Xor (dbwrapper_private::GetObfuscateKey (parent));
143
+ leveldb::Slice slValue (CharCast (ssValue.data ()), ssValue.size ());
144
+ batch.Put (slKey, slValue);
145
+ // LevelDB serializes writes as:
146
+ // - byte: header
147
+ // - varint: key length (1 byte up to 127B, 2 bytes up to 16383B, ...)
148
+ // - byte[]: key
149
+ // - varint: value length
150
+ // - byte[]: value
151
+ // The formula below assumes the key and value are both less than 16k.
152
+ size_estimate += 3 + (slKey.size () > 127 ) + slKey.size () + (slValue.size () > 127 ) + slValue.size ();
153
+ }
154
+
135
155
CDBWrapper::CDBWrapper (const DBParams& params)
136
156
: m_name{fs::PathToString (params.path .stem ())}, m_path{params.path }, m_is_memory{params.memory_only }
137
157
{
Original file line number Diff line number Diff line change @@ -97,6 +97,8 @@ class CDBBatch
97
97
98
98
size_t size_estimate{0 };
99
99
100
+ void WriteImpl (Span<const std::byte> ssKey, CDataStream& ssValue);
101
+
100
102
public:
101
103
/* *
102
104
* @param[in] _parent CDBWrapper that this batch is to be submitted to
@@ -113,23 +115,10 @@ class CDBBatch
113
115
void Write (const K& key, const V& value)
114
116
{
115
117
ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE);
116
- ssKey << key;
117
- leveldb::Slice slKey (CharCast (ssKey.data ()), ssKey.size ());
118
-
119
118
ssValue.reserve (DBWRAPPER_PREALLOC_VALUE_SIZE);
119
+ ssKey << key;
120
120
ssValue << value;
121
- ssValue.Xor (dbwrapper_private::GetObfuscateKey (parent));
122
- leveldb::Slice slValue (CharCast (ssValue.data ()), ssValue.size ());
123
-
124
- batch.Put (slKey, slValue);
125
- // LevelDB serializes writes as:
126
- // - byte: header
127
- // - varint: key length (1 byte up to 127B, 2 bytes up to 16383B, ...)
128
- // - byte[]: key
129
- // - varint: value length
130
- // - byte[]: value
131
- // The formula below assumes the key and value are both less than 16k.
132
- size_estimate += 3 + (slKey.size () > 127 ) + slKey.size () + (slValue.size () > 127 ) + slValue.size ();
121
+ WriteImpl (ssKey, ssValue);
133
122
ssKey.clear ();
134
123
ssValue.clear ();
135
124
}
You can’t perform that action at this time.
0 commit comments