Skip to content

Commit

Permalink
Merge pull request #819 from skalenetwork/v3.18.0
Browse files Browse the repository at this point in the history
V3.18.0 to develop
  • Loading branch information
kladkogex authored Oct 24, 2023
2 parents 5a9b85d + ef26c4a commit 79d6b7f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
24 changes: 20 additions & 4 deletions db/CacheLevelDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion db/CacheLevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
};


Expand Down
29 changes: 16 additions & 13 deletions node/NodeGettersSetters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 79d6b7f

Please sign in to comment.