From 3fda764bbd8d05172af97d591250d3c080ec5a4b Mon Sep 17 00:00:00 2001 From: Peter John Bushnell Date: Fri, 4 Oct 2024 12:57:58 +0100 Subject: [PATCH] logdvmstate flush DB to disk (#3083) --- src/dfi/rpc_accounts.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 345e73d19f..51f4f53b3a 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3559,10 +3559,16 @@ UniValue logdvmstate(const JSONRPCRequest &request) { } .Check(request); + const auto fileSize = request.params[0].isNull() ? 1 : request.params[0].get_int64(); + if (fileSize <= 0) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Size must be more then zero"); + } + LOCK(cs_main); // Flush any pending changes to the DB. Not always written to disk. pcustomcsview->Flush(); + pcustomcsDB->Flush(); // Get the CDBWrapper instance from CCustomCSView auto db = pcustomcsview->GetStorage().GetStorageLevelDB()->GetDB(); @@ -3570,11 +3576,6 @@ UniValue logdvmstate(const JSONRPCRequest &request) { // Create a CDBIterator auto pcursor = db->NewIterator(leveldb::ReadOptions()); - const auto fileSize = request.params[0].isNull() ? 1 : request.params[0].get_int64(); - if (fileSize <= 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Size must be more then zero"); - } - const size_t MAX_FILE_SIZE = fileSize * 1024 * 1048576; // 1MB = 1048576 bytes fs::path dumpsDir = GetDataDir() / "dumps"; @@ -3617,6 +3618,10 @@ UniValue logdvmstate(const JSONRPCRequest &request) { // Iterate over all key-value pairs while (pcursor->Valid()) { + if (ShutdownRequested()) { + break; + } + // Get the key and value slices auto keySlice = pcursor->GetKey(); auto valueSlice = pcursor->GetValue();