Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logdvmstate flush DB to disk #3083

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/dfi/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3559,22 +3559,23 @@ 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();

// 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";
Expand Down Expand Up @@ -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();
Expand Down
Loading