diff --git a/db/CacheLevelDB.cpp b/db/CacheLevelDB.cpp index 384b6af2..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(); @@ -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 directoryIt( dbPath ), end; + while ( directoryIt != end ) { + if ( boost::filesystem::is_regular_file( *directoryIt ) ) { + totalSize += boost::filesystem::file_size( *directoryIt ); + } + ++directoryIt; + } + + return totalSize; +} diff --git a/db/CacheLevelDB.h b/db/CacheLevelDB.h index 98f10813..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; @@ -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 1eb55c00..4969f6df 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()->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(); + + // 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(); + 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; }