Skip to content

Commit

Permalink
#1588 move batchCHunkSize to class field
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Jan 18, 2024
1 parent b8cdd8d commit ac6490e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions libdevcore/LevelDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace db {

unsigned c_maxOpenLeveldbFiles = 25;

const size_t LevelDB::BATCH_CHUNK_SIZE = 10000;

namespace {
inline leveldb::Slice toLDBSlice( Slice _slice ) {
return leveldb::Slice( _slice.data(), _slice.size() );
Expand Down Expand Up @@ -281,8 +283,7 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const {
return hash;
}

void LevelDB::hashBasePartially(
secp256k1_sha256_t* ctx, std::string& lastHashedKey, size_t batchSize ) const {
void LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const {
std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) );
if ( it == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
Expand All @@ -293,7 +294,7 @@ void LevelDB::hashBasePartially(
else
it->SeekToFirst();

for ( size_t counter = 0; it->Valid() && counter < batchSize; it->Next() ) {
for ( size_t counter = 0; it->Valid() && counter < BATCH_CHUNK_SIZE; it->Next() ) {
std::string keyTmp = it->key().ToString();
std::string valueTmp = it->value().ToString();
// HACK! For backward compatibility! When snapshot could happen between update of two nodes
Expand Down
5 changes: 3 additions & 2 deletions libdevcore/LevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class LevelDB : public DatabaseFace {
h256 hashBase() const override;
h256 hashBaseWithPrefix( char _prefix ) const;

void hashBasePartially(
secp256k1_sha256_t* ctx, std::string& lastHashedKey, size_t batchSize = 10000 ) const;
void hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const;

void doCompaction() const;

Expand All @@ -79,6 +78,8 @@ class LevelDB : public DatabaseFace {
leveldb::WriteOptions const m_writeOptions;
leveldb::Options m_options;
boost::filesystem::path const m_path;

static const size_t BATCH_CHUNK_SIZE;
};

} // namespace db
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libweb3core/LevelDBHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( hash ) {
dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(),
dev::db::LevelDB::defaultSnapshotDBOptions() ) );

m_db->hashBasePartially( &dbCtx, lastHashedKey, 10 );
m_db->hashBasePartially( &dbCtx, lastHashedKey );
}

secp256k1_sha256_finalize( &dbCtx, hashPartially.data() );
Expand Down

0 comments on commit ac6490e

Please sign in to comment.