From 2a4cd3f5b21000c7f1c6c5346491082729dc43d1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 3 Oct 2023 13:12:30 +0100 Subject: [PATCH 1/4] SKALED-1482 fix db usage call --- node/NodeGettersSetters.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/node/NodeGettersSetters.cpp b/node/NodeGettersSetters.cpp index 1eb55c00..cddebdeb 100644 --- a/node/NodeGettersSetters.cpp +++ b/node/NodeGettersSetters.cpp @@ -381,19 +381,19 @@ uint64_t Node::getInternalInfoDBSize() const { map< string, uint64_t > Node::getDBUsage() const { map< string, uint64_t > ret; - ret["blocks.db_disk_usage"] = getBlockDB()->getActiveDBSize(); - ret["block_proposal.db_disk_usage"] = getBlockProposalDB()->getActiveDBSize(); - ret["block_sigshare.db_disk_usage"] = getBlockSigShareDB()->getActiveDBSize(); - ret["consensus_state.db_disk_usage"] = getConsensusStateDB()->getActiveDBSize(); - ret["da_proof.db_disk_usage"] = getDaProofDB()->getActiveDBSize(); - ret["da_sigshare.db_disk_usage"] = getDaSigShareDB()->getActiveDBSize(); - ret["incoming_msg.db_disk_usage"] = getIncomingMsgDB()->getActiveDBSize(); - ret["interna_info.db_disk_usage"] = getInternalInfoDB()->getActiveDBSize(); - ret["outgoing_msg.db_disk_usage"] = getOutgoingMsgDB()->getActiveDBSize(); - ret["price.db_disk_usage"] = getPriceDB()->getActiveDBSize(); - ret["proposal_hash.db_disk_usage"] = getProposalHashDB()->getActiveDBSize(); - ret["proposal_vector.db_disk_usage"] = getProposalVectorDB()->getActiveDBSize(); - ret["random.db_disk_usage"] = getRandomDB()->getActiveDBSize(); + ret["blocks.db_disk_usage"] = getBlockDB()->getMemoryUsed(); + ret["block_proposal.db_disk_usage"] = getBlockProposalDB()->getMemoryUsed(); + ret["block_sigshare.db_disk_usage"] = getBlockSigShareDB()->getMemoryUsed(); + ret["consensus_state.db_disk_usage"] = getConsensusStateDB()->getMemoryUsed(); + ret["da_proof.db_disk_usage"] = getDaProofDB()->getMemoryUsed(); + ret["da_sigshare.db_disk_usage"] = getDaSigShareDB()->getMemoryUsed(); + ret["incoming_msg.db_disk_usage"] = getIncomingMsgDB()->getMemoryUsed(); + ret["interna_info.db_disk_usage"] = getInternalInfoDB()->getMemoryUsed(); + ret["outgoing_msg.db_disk_usage"] = getOutgoingMsgDB()->getMemoryUsed(); + ret["price.db_disk_usage"] = getPriceDB()->getMemoryUsed(); + ret["proposal_hash.db_disk_usage"] = getProposalHashDB()->getMemoryUsed(); + ret["proposal_vector.db_disk_usage"] = getProposalVectorDB()->getMemoryUsed(); + ret["random.db_disk_usage"] = getRandomDB()->getMemoryUsed(); return ret; } From 76badd71a0a06fd3935a6ce0b1d4a9b9a02adb91 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 4 Oct 2023 17:42:31 +0100 Subject: [PATCH 2/4] 1482 use getFullDBSize to get occupied storage space in bytes --- db/CacheLevelDB.cpp | 16 ++++++++++++++++ db/CacheLevelDB.h | 3 +++ node/NodeGettersSetters.cpp | 29 ++++++++++++++++------------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/db/CacheLevelDB.cpp b/db/CacheLevelDB.cpp index 384b6af2..49565d82 100644 --- a/db/CacheLevelDB.cpp +++ b/db/CacheLevelDB.cpp @@ -735,3 +735,19 @@ uint64_t CacheLevelDB::getMemoryUsed() { } return totalMemory; } + +uint64_t CacheLevelDB::getFullDBSize() { + uint64_t totalSize = 0; + + boost::filesystem::path dbPath( dirname ); + + boost::filesystem::recursive_directory_iterator directory_it( dbPath ), end; + while ( directory_it != end ) { + if ( boost::filesystem::is_regular_file( *directory_it ) ) { + totalSize += boost::filesystem::file_size( *directory_it ); + } + ++directory_it; + } + + return totalSize; +} diff --git a/db/CacheLevelDB.h b/db/CacheLevelDB.h index 98f10813..fb4b068e 100644 --- a/db/CacheLevelDB.h +++ b/db/CacheLevelDB.h @@ -163,6 +163,9 @@ class CacheLevelDB { void checkForDeadLockRead( const char* _functionName ); uint64_t getMemoryUsed(); + + // get the occupied storage space by the db in bytes + uint64_t getFullDBSize(); }; diff --git a/node/NodeGettersSetters.cpp b/node/NodeGettersSetters.cpp index cddebdeb..4f0356bc 100644 --- a/node/NodeGettersSetters.cpp +++ b/node/NodeGettersSetters.cpp @@ -381,19 +381,22 @@ uint64_t Node::getInternalInfoDBSize() const { map< string, uint64_t > Node::getDBUsage() const { map< string, uint64_t > ret; - ret["blocks.db_disk_usage"] = getBlockDB()->getMemoryUsed(); - ret["block_proposal.db_disk_usage"] = getBlockProposalDB()->getMemoryUsed(); - ret["block_sigshare.db_disk_usage"] = getBlockSigShareDB()->getMemoryUsed(); - ret["consensus_state.db_disk_usage"] = getConsensusStateDB()->getMemoryUsed(); - ret["da_proof.db_disk_usage"] = getDaProofDB()->getMemoryUsed(); - ret["da_sigshare.db_disk_usage"] = getDaSigShareDB()->getMemoryUsed(); - ret["incoming_msg.db_disk_usage"] = getIncomingMsgDB()->getMemoryUsed(); - ret["interna_info.db_disk_usage"] = getInternalInfoDB()->getMemoryUsed(); - ret["outgoing_msg.db_disk_usage"] = getOutgoingMsgDB()->getMemoryUsed(); - ret["price.db_disk_usage"] = getPriceDB()->getMemoryUsed(); - ret["proposal_hash.db_disk_usage"] = getProposalHashDB()->getMemoryUsed(); - ret["proposal_vector.db_disk_usage"] = getProposalVectorDB()->getMemoryUsed(); - ret["random.db_disk_usage"] = getRandomDB()->getMemoryUsed(); + + // use getFullDBSize() to get memory used by the entire db + // not only the active one + ret["blocks.db_disk_usage"] = getBlockDB()->getFullDBSize(); + ret["block_proposal.db_disk_usage"] = getBlockProposalDB()->getFullDBSize(); + ret["block_sigshare.db_disk_usage"] = getBlockSigShareDB()->getFullDBSize(); + ret["consensus_state.db_disk_usage"] = getConsensusStateDB()->getFullDBSize(); + ret["da_proof.db_disk_usage"] = getDaProofDB()->getFullDBSize(); + ret["da_sigshare.db_disk_usage"] = getDaSigShareDB()->getFullDBSize(); + ret["incoming_msg.db_disk_usage"] = getIncomingMsgDB()->getFullDBSize(); + ret["internal_info.db_disk_usage"] = getInternalInfoDB()->getFullDBSize(); + ret["outgoing_msg.db_disk_usage"] = getOutgoingMsgDB()->getFullDBSize(); + ret["price.db_disk_usage"] = getPriceDB()->getFullDBSize(); + ret["proposal_hash.db_disk_usage"] = getProposalHashDB()->getFullDBSize(); + ret["proposal_vector.db_disk_usage"] = getProposalVectorDB()->getFullDBSize(); + ret["random.db_disk_usage"] = getRandomDB()->getFullDBSize(); return ret; } From 452f8fdd9f2a81d712d46859f23864d07a965037 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 4 Oct 2023 17:50:41 +0100 Subject: [PATCH 3/4] 1482 add comments --- node/NodeGettersSetters.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/NodeGettersSetters.cpp b/node/NodeGettersSetters.cpp index 4f0356bc..4969f6df 100644 --- a/node/NodeGettersSetters.cpp +++ b/node/NodeGettersSetters.cpp @@ -382,7 +382,7 @@ uint64_t Node::getInternalInfoDBSize() const { map< string, uint64_t > Node::getDBUsage() const { map< string, uint64_t > ret; - // use getFullDBSize() to get memory used by the entire db + // use getFullDBSize() to get storage used by the entire db // not only the active one ret["blocks.db_disk_usage"] = getBlockDB()->getFullDBSize(); ret["block_proposal.db_disk_usage"] = getBlockProposalDB()->getFullDBSize(); From dce10c3221362a7e19a0f49ca7dee275095e89ff Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 9 Oct 2023 11:12:38 +0100 Subject: [PATCH 4/4] 1482 fix naming --- db/CacheLevelDB.cpp | 20 ++++++++++---------- db/CacheLevelDB.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/db/CacheLevelDB.cpp b/db/CacheLevelDB.cpp index 49565d82..eb56573e 100644 --- a/db/CacheLevelDB.cpp +++ b/db/CacheLevelDB.cpp @@ -57,7 +57,7 @@ using namespace leveldb; string CacheLevelDB::index2Path( uint64_t index ) { - return dirname + "/db." + to_string( index ); + return dirName + "/db." + to_string( index ); } string CacheLevelDB::createKey( const block_id _blockId, uint64_t _counter ) { @@ -371,14 +371,14 @@ CacheLevelDB::CacheLevelDB( Schain* _sChain, string& _dirName, string& _prefix, this->prefix = _prefix; this->totalSigners = _sChain->getTotalSigners(); this->requiredSigners = _sChain->getRequiredSigners(); - this->dirname = _dirName + "/" + _prefix; + this->dirName = _dirName + "/" + _prefix; this->maxDBSize = _maxDBSize; this->options = _options; this->readOptions.fill_cache = false; this->writeOptions.sync = true; this->isDuplicateAddOK = _isDuplicateAddOK; - boost::filesystem::path path( dirname ); + boost::filesystem::path path( dirName ); boost::filesystem::create_directory( path ); highestDBIndex = findMaxMinDBIndex().first; @@ -435,7 +435,7 @@ pair< uint64_t, uint64_t > CacheLevelDB::findMaxMinDBIndex() { vector< path > dirs; vector< uint64_t > indices; - copy( directory_iterator( path( dirname ) ), directory_iterator(), back_inserter( dirs ) ); + copy( directory_iterator( path( dirName ) ), directory_iterator(), back_inserter( dirs ) ); sort( dirs.begin(), dirs.end() ); size_t offset = string( "db." ).size(); @@ -739,14 +739,14 @@ uint64_t CacheLevelDB::getMemoryUsed() { uint64_t CacheLevelDB::getFullDBSize() { uint64_t totalSize = 0; - boost::filesystem::path dbPath( dirname ); + boost::filesystem::path dbPath( dirName ); - boost::filesystem::recursive_directory_iterator directory_it( dbPath ), end; - while ( directory_it != end ) { - if ( boost::filesystem::is_regular_file( *directory_it ) ) { - totalSize += boost::filesystem::file_size( *directory_it ); + boost::filesystem::recursive_directory_iterator directoryIt( dbPath ), end; + while ( directoryIt != end ) { + if ( boost::filesystem::is_regular_file( *directoryIt ) ) { + totalSize += boost::filesystem::file_size( *directoryIt ); } - ++directory_it; + ++directoryIt; } return totalSize; diff --git a/db/CacheLevelDB.h b/db/CacheLevelDB.h index fb4b068e..567d6742 100644 --- a/db/CacheLevelDB.h +++ b/db/CacheLevelDB.h @@ -55,7 +55,7 @@ class CacheLevelDB { node_id nodeId = 0; string prefix; - string dirname; + string dirName; uint64_t maxDBSize = 0; uint64_t totalSigners = 0; uint64_t requiredSigners = 0;