@@ -38,6 +38,18 @@ bool DestroyDB(const std::string& path_str)
38
38
return leveldb::DestroyDB (path_str, {}).ok ();
39
39
}
40
40
41
+ /* * Handle database error by throwing dbwrapper_error exception.
42
+ */
43
+ static void HandleError (const leveldb::Status& status)
44
+ {
45
+ if (status.ok ())
46
+ return ;
47
+ const std::string errmsg = " Fatal LevelDB error: " + status.ToString ();
48
+ LogPrintf (" %s\n " , errmsg);
49
+ LogPrintf (" You can use -debug=leveldb to get more complete diagnostic messages\n " );
50
+ throw dbwrapper_error (errmsg);
51
+ }
52
+
41
53
class CBitcoinLevelDBLogger : public leveldb ::Logger {
42
54
public:
43
55
// This code is adapted from posix_logger.h, which is why it is using vsprintf.
@@ -199,7 +211,7 @@ CDBWrapper::CDBWrapper(const DBParams& params)
199
211
if (params.wipe_data ) {
200
212
LogPrintf (" Wiping LevelDB in %s\n " , fs::PathToString (params.path ));
201
213
leveldb::Status result = leveldb::DestroyDB (fs::PathToString (params.path ), options);
202
- dbwrapper_private:: HandleError (result);
214
+ HandleError (result);
203
215
}
204
216
TryCreateDirectories (params.path );
205
217
LogPrintf (" Opening LevelDB in %s\n " , fs::PathToString (params.path ));
@@ -209,7 +221,7 @@ CDBWrapper::CDBWrapper(const DBParams& params)
209
221
// on Windows it converts from UTF-8 to UTF-16 before calling ::CreateFileW
210
222
// (see env_posix.cc and env_windows.cc).
211
223
leveldb::Status status = leveldb::DB::Open (options, fs::PathToString (params.path ), &pdb);
212
- dbwrapper_private:: HandleError (status);
224
+ HandleError (status);
213
225
LogPrintf (" Opened LevelDB successfully\n " );
214
226
215
227
if (params.options .force_compact ) {
@@ -260,7 +272,7 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
260
272
mem_before = DynamicMemoryUsage () / 1024.0 / 1024 ;
261
273
}
262
274
leveldb::Status status = pdb->Write (fSync ? syncoptions : writeoptions, &batch.m_impl_batch ->batch );
263
- dbwrapper_private:: HandleError (status);
275
+ HandleError (status);
264
276
if (log_memory) {
265
277
double mem_after = DynamicMemoryUsage () / 1024.0 / 1024 ;
266
278
LogPrint (BCLog::LEVELDB, " WriteBatch memory usage: db=%s, before=%.1fMiB, after=%.1fMiB\n " ,
@@ -308,7 +320,7 @@ std::optional<std::string> CDBWrapper::ReadImpl(Span<const std::byte> ssKey) con
308
320
if (status.IsNotFound ())
309
321
return std::nullopt;
310
322
LogPrintf (" LevelDB read failure: %s\n " , status.ToString ());
311
- dbwrapper_private:: HandleError (status);
323
+ HandleError (status);
312
324
}
313
325
return strValue;
314
326
}
@@ -323,7 +335,7 @@ bool CDBWrapper::ExistsImpl(Span<const std::byte> ssKey) const
323
335
if (status.IsNotFound ())
324
336
return false ;
325
337
LogPrintf (" LevelDB read failure: %s\n " , status.ToString ());
326
- dbwrapper_private:: HandleError (status);
338
+ HandleError (status);
327
339
}
328
340
return true ;
329
341
}
@@ -371,16 +383,6 @@ void CDBIterator::Next() { m_impl_iter->iter->Next(); }
371
383
372
384
namespace dbwrapper_private {
373
385
374
- void HandleError (const leveldb::Status& status)
375
- {
376
- if (status.ok ())
377
- return ;
378
- const std::string errmsg = " Fatal LevelDB error: " + status.ToString ();
379
- LogPrintf (" %s\n " , errmsg);
380
- LogPrintf (" You can use -debug=leveldb to get more complete diagnostic messages\n " );
381
- throw dbwrapper_error (errmsg);
382
- }
383
-
384
386
const std::vector<unsigned char >& GetObfuscateKey (const CDBWrapper &w)
385
387
{
386
388
return w.obfuscate_key ;
0 commit comments