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

1545 without dos and stats cleanups #2046

Open
wants to merge 309 commits into
base: v4.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
309 commits
Select commit Hold shift + click to select a range
7a9bd1d
1545 improved locking for preseal
kladkogex Jul 19, 2024
45ca874
1545 improved locking for preseal
kladkogex Jul 19, 2024
03d5f07
#1545 state locking
kladkogex Jul 22, 2024
6e5b77b
#1545 state locking
kladkogex Jul 22, 2024
f569004
#1545 state locking
kladkogex Jul 22, 2024
a6538f6
#1545 state locking
kladkogex Jul 22, 2024
d729d01
#1545 state locking
kladkogex Jul 22, 2024
fcf950d
#1545 state locking
kladkogex Jul 22, 2024
cb53e1d
#1545 state locking
kladkogex Jul 22, 2024
42c43e5
#1545 state locking
kladkogex Jul 22, 2024
1115682
#1545 state locking
kladkogex Jul 23, 2024
9c2ea64
#1545 state locking
kladkogex Jul 23, 2024
3ded249
1545 add exception
kladkogex Jul 29, 2024
d1abaa0
1545 add exception
kladkogex Jul 30, 2024
149f4f2
1545 add exception
kladkogex Jul 30, 2024
798b909
1545 add exception
kladkogex Jul 30, 2024
b899b78
1545 add exception
kladkogex Jul 30, 2024
f1e8a6a
1545 fix test
kladkogex Jul 31, 2024
d926a03
1545 fix formatiing
kladkogex Jul 31, 2024
ce283d5
1545 fix formatiing
kladkogex Jul 31, 2024
a1e6282
1545 fix formatiing
kladkogex Jul 31, 2024
9766ddd
1545 fix formatiing
kladkogex Jul 31, 2024
3dcc3b0
1545 fix formatiing
kladkogex Jul 31, 2024
6afc927
1545 fix formatiing
kladkogex Jul 31, 2024
a8dad3a
1545 fix formatiing
kladkogex Aug 1, 2024
3025f31
1545 fix formatiing
kladkogex Aug 1, 2024
f19f5a0
1545 fix formatiing
kladkogex Aug 1, 2024
0e13adb
1545 adding perf test
kladkogex Aug 2, 2024
2f8390b
1545 adding perf test
kladkogex Aug 2, 2024
3d1c761
1545 adding perf test
kladkogex Aug 2, 2024
88a5f0c
1545 adding perf test
kladkogex Aug 3, 2024
5338ba1
1545 adding perf test
kladkogex Aug 3, 2024
0a6f85e
1545 adding perf test
kladkogex Aug 3, 2024
20ff651
1545 adding perf test
kladkogex Aug 3, 2024
cc136cf
1545 adding perf test
kladkogex Aug 3, 2024
43e20a5
1545 adding perf test
kladkogex Aug 3, 2024
c51d958
1545 adding perf test
kladkogex Aug 3, 2024
2c2bbbc
1545 adding perf test
kladkogex Aug 3, 2024
8f846cf
1545 adding perf test
kladkogex Aug 3, 2024
fe2ae46
1545 adding perf test
kladkogex Aug 3, 2024
4be3027
1545 adding perf test
kladkogex Aug 3, 2024
0ec0d38
1545 adding perf test
kladkogex Aug 3, 2024
1b860ca
1545 adding perf test
kladkogex Aug 3, 2024
87aa5e1
1545 adding perf test
kladkogex Aug 3, 2024
fd2f564
1545 adding perf test
kladkogex Aug 3, 2024
ce6ff71
1545 adding perf test
kladkogex Aug 3, 2024
8cfc47f
1545 adding perf test
kladkogex Aug 3, 2024
4692c29
1545 adding perf test
kladkogex Aug 3, 2024
4b4c3e0
1545 Fox cmake
kladkogex Aug 4, 2024
94885ee
1545 Fox cmake
kladkogex Aug 4, 2024
b53f013
1545 Fox cmake
kladkogex Aug 4, 2024
38f64f1
1545 Fox cmake
kladkogex Aug 4, 2024
afa9946
1545 Fox cmake
kladkogex Aug 4, 2024
398a057
1545 Test get balance
kladkogex Aug 4, 2024
152079f
1545 adding raw transaction
kladkogex Aug 5, 2024
4a89bd7
1545 adding raw transaction
kladkogex Aug 5, 2024
8fd1caa
1545 adding raw transaction
kladkogex Aug 5, 2024
2866d3f
1545 adding raw transaction
kladkogex Aug 5, 2024
3d08afd
1545 adding raw transaction
kladkogex Aug 5, 2024
fe8dd7d
1545 removed perf trackr
kladkogex Aug 5, 2024
42f5e8c
1545 removed perf trackr
kladkogex Aug 5, 2024
2e5be99
1545 Skaled config
kladkogex Aug 5, 2024
d1ce088
1545 removed perf trackr
kladkogex Aug 6, 2024
ed99c42
1545 removed perf trackr
kladkogex Aug 6, 2024
60b3244
1545 and account split
kladkogex Aug 6, 2024
af18d0f
1545 and account split
kladkogex Aug 6, 2024
e7a9942
1545 and account split
kladkogex Aug 6, 2024
6bdba6b
1545 and account split
kladkogex Aug 6, 2024
2f30af2
1545 and account split
kladkogex Aug 6, 2024
3851b3b
1545 and account split
kladkogex Aug 6, 2024
d03e8e5
1545 and account split
kladkogex Aug 6, 2024
ee6df1c
1545 and account split
kladkogex Aug 6, 2024
6c5d640
1545 and account split
kladkogex Aug 6, 2024
8f82fd7
1545 and account split
kladkogex Aug 6, 2024
fa35f0a
1545 and account split
kladkogex Aug 6, 2024
9937fe3
1545 and account split
kladkogex Aug 6, 2024
468de19
1545 and account split
kladkogex Aug 6, 2024
7f439f8
1545 and account split
kladkogex Aug 7, 2024
ea7be10
1545 and account split
kladkogex Aug 7, 2024
f93300d
1545 and account split
kladkogex Aug 7, 2024
4b98b1e
1545 and account split
kladkogex Aug 7, 2024
faedb7a
1545 Refactoring libcurl
kladkogex Aug 8, 2024
071ec0e
1545 Refactoring libcurl
kladkogex Aug 8, 2024
5c40e69
1545 Refactoring libcurl
kladkogex Aug 8, 2024
24c8e8d
1545 Refactoring libcurl
kladkogex Aug 8, 2024
448f8b9
1545 Refactoring libcurl
kladkogex Aug 8, 2024
91ec85a
1545 Refactoring libcurl
kladkogex Aug 8, 2024
05898d8
1545 Refactoring libcurl
kladkogex Aug 9, 2024
2ca6f70
1545 Refactoring libcurl
kladkogex Aug 9, 2024
27ab89c
1545 Optimizing TransactionQueue.cpp
kladkogex Aug 9, 2024
11968ad
1545 Optimizing TransactionQueue.cpp
kladkogex Aug 9, 2024
11ff7d3
1545 Optimizing test
kladkogex Aug 10, 2024
2da839b
1545 Optimizing test
kladkogex Aug 10, 2024
294ffda
1545 Optimizing test
kladkogex Aug 10, 2024
ca75e87
1545 Optimizing test
kladkogex Aug 10, 2024
6fb81a7
1545 Optimizing test
kladkogex Aug 10, 2024
27ddb7d
1545 Optimizing test
kladkogex Aug 11, 2024
7aa3339
1545 Optimizing test
kladkogex Aug 11, 2024
97837fa
1545 Optimizing test
kladkogex Aug 11, 2024
a22b7d7
1545 Optimizing test
kladkogex Aug 11, 2024
1e7a1fe
1545 Optimizing test
kladkogex Aug 11, 2024
49f55f3
1545 Optimizing test
kladkogex Aug 11, 2024
a8dcb2a
1545 Optimizing test
kladkogex Aug 11, 2024
3644139
1545 Optimizing test
kladkogex Aug 11, 2024
3630a7b
1545 and account split
kladkogex Aug 12, 2024
2743cc2
1545 and account split
kladkogex Aug 12, 2024
9a8083b
1545 improve test performance
kladkogex Aug 13, 2024
4ed9afc
1545 improve test performance
kladkogex Aug 13, 2024
daf39dd
1545 improve test performance
kladkogex Aug 13, 2024
eb7fd23
1545 improve test performance
kladkogex Aug 13, 2024
c2c67eb
1545 improve test performance
kladkogex Aug 13, 2024
58b9882
1545 improve test performance
kladkogex Aug 13, 2024
1c94524
1545 improve performance
kladkogex Aug 13, 2024
fa471eb
1545 Adding performance tests
kladkogex Aug 13, 2024
30b54d2
1545 Improve locking
kladkogex Aug 13, 2024
c6f23a5
1545 improve test performance
kladkogex Aug 13, 2024
fb5a59b
1545 Improve locks
kladkogex Aug 13, 2024
0ed1850
1545 state locking
kladkogex Aug 29, 2024
4ecc300
1545 Fixing partial transactions
kladkogex Aug 29, 2024
0fc5a30
1545_state_locking Fixing partial transaction receipts
kladkogex Aug 29, 2024
9e78536
1545 partial catchup
kladkogex Sep 4, 2024
91d37da
1545 state locking
kladkogex Sep 5, 2024
9ff801e
1545 Add ERC-20
kladkogex Sep 9, 2024
ada6e57
1545_state_locking adding ERC-20 test
kladkogex Sep 9, 2024
75ef6fa
1545 state locking
kladkogex Sep 9, 2024
07c9cd5
1545 State locking fix timestamp
kladkogex Sep 10, 2024
6a5b5f1
1545 State locking add contract deploy
kladkogex Sep 10, 2024
84bd8bb
1545 State locking add contract deploy
kladkogex Sep 10, 2024
ea69dc4
1545 State locking add contract deploy
kladkogex Sep 11, 2024
c359023
1545 State locking add contract deploy
kladkogex Sep 11, 2024
fcdbd30
1545 State locking add contract deploy
kladkogex Sep 11, 2024
9ddd3ea
1545 State locking add contract deploy
kladkogex Sep 11, 2024
05a234e
1545 State locking add contract deploy
kladkogex Sep 11, 2024
4bd0f2f
1545 State locking add contract deploy
kladkogex Sep 11, 2024
1a4ab58
1545 State locking add contract deploy
kladkogex Sep 12, 2024
f2068a9
Merge branch 'develop' into 1545_state_locking_final
kladkogex Sep 12, 2024
5d8f1f4
1545 Added clang format ignore
kladkogex Sep 12, 2024
6cfcb40
1545 clang format
kladkogex Sep 12, 2024
7fd4900
1545 add clang format ignore
kladkogex Sep 12, 2024
5ebb3ab
1545 add ignore
kladkogex Sep 12, 2024
b8f712f
1545 ignore
kladkogex Sep 12, 2024
4fa20ea
1545 clang-format ignore
kladkogex Sep 12, 2024
a39ab1e
1545 git ignore
kladkogex Sep 12, 2024
277dc9e
1545 fix formatting
kladkogex Sep 12, 2024
b6cc143
1545 fix formatting
kladkogex Sep 12, 2024
5504949
1545 fix formatting
kladkogex Sep 12, 2024
ccdf163
1545 fix formatting
kladkogex Sep 12, 2024
432d4a9
1545 clang format
kladkogex Sep 12, 2024
3ae7286
1545 fix clang-format
kladkogex Sep 12, 2024
8ee156a
1545 clang-format
kladkogex Sep 12, 2024
e8c87f4
1545 fix clang format
kladkogex Sep 12, 2024
41f199d
1545 fix format
kladkogex Sep 12, 2024
470a0cb
1545 fix formatting
kladkogex Sep 12, 2024
5744159
1545 fix formatting
kladkogex Sep 12, 2024
f676bf6
1545 fixed tests and merge
kladkogex Sep 12, 2024
f8b55d8
1545 send erc-20
kladkogex Sep 12, 2024
039b9ed
1545 do erc-20 transfers
kladkogex Sep 12, 2024
c9d1701
1545 ERC-20 tests
kladkogex Sep 12, 2024
f2f04c2
1545 Add ERC-20 test
kladkogex Sep 12, 2024
d761535
1545 remove transaction cache
kladkogex Sep 12, 2024
d4cd772
1545 State locking add contract deploy
kladkogex Sep 12, 2024
79d6ea7
1545 Fixing transaction receipt
kladkogex Sep 12, 2024
6ab597b
1545 Fix partial receipt read/write
kladkogex Sep 23, 2024
97df8c8
1545 Added Type 1 tests
kladkogex Sep 23, 2024
f610b3a
1545 Added type2 test
kladkogex Sep 23, 2024
bbd92e3
1545 Added PoW test for a single node
kladkogex Sep 24, 2024
7f60a1a
1545 state locking
kladkogex Sep 24, 2024
580e6fe
1545 Make error message identical to geth
kladkogex Sep 25, 2024
08d9499
1545 Add MTM mode test
kladkogex Sep 25, 2024
e9211d3
1545 added multi-transaction-mode test
kladkogex Sep 25, 2024
193e9b7
1545 adding multi node tests
kladkogex Sep 26, 2024
bf3cb92
1545 adding 4 node files
kladkogex Sep 26, 2024
68087b5
1545 added 16 node tests
kladkogex Sep 30, 2024
a840871
1545 Add 16 node tests
kladkogex Sep 30, 2024
27d3235
1545 Add 16 node tests
kladkogex Sep 30, 2024
e3ccd55
1545 Remove categories
kladkogex Sep 30, 2024
8b13aad
1545 Remove categories
kladkogex Sep 30, 2024
97ff591
1545 Increase HighWaterMark so tests pass
kladkogex Sep 30, 2024
2d92636
1545 Increase HighWaterMark so tests pass
kladkogex Sep 30, 2024
46fc534
1545 Limit queue size
kladkogex Oct 7, 2024
29bcaff
1545 Limit queue size
kladkogex Oct 7, 2024
31679c3
1545 Fixing stats
kladkogex Oct 7, 2024
5785cad
1545 Fixing stats
kladkogex Oct 7, 2024
c27a0d5
1545 Fixing stats
kladkogex Oct 7, 2024
af4e217
1545 Fixing stats
kladkogex Oct 7, 2024
6aec22b
1545 Fixing stats
kladkogex Oct 7, 2024
419df8a
1545 Fixing stats
kladkogex Oct 7, 2024
ab72ba7
1545 Fixing stats
kladkogex Oct 7, 2024
3f8920e
1545 Fixing stats
kladkogex Oct 7, 2024
4136203
1545 Fixing stats
kladkogex Oct 7, 2024
5bbc5e6
1545 Fixing stats
kladkogex Oct 7, 2024
a04a264
1545 Fixing stats
kladkogex Oct 8, 2024
6409416
1545 Fixing stats
kladkogex Oct 8, 2024
3ee3b48
1545 Fixing stats
kladkogex Oct 9, 2024
d14d59a
1545 Fixing stats
kladkogex Oct 9, 2024
8e87e73
1545 fix clan-format
kladkogex Oct 9, 2024
e507c50
1545 clang-format
kladkogex Oct 9, 2024
41599b2
1545 Clang-format
kladkogex Oct 9, 2024
9d0abc2
1545 Clang-format
kladkogex Oct 9, 2024
865ca5f
Merge branch 'v3.20.0' into 1545_state_locking_final
kladkogex Oct 11, 2024
395c3f4
1545 merge with 3.20
kladkogex Oct 11, 2024
e997209
1545 merge with 3.20
kladkogex Oct 11, 2024
8ddc49c
1545 fix tests
kladkogex Oct 13, 2024
c744f90
1545 fix tests
kladkogex Oct 13, 2024
9ed27f5
1545 Fixing tests
kladkogex Oct 14, 2024
c9a2698
1545 Fixing tests
kladkogex Oct 14, 2024
77bcbe3
1545 Fixing tests
kladkogex Oct 14, 2024
f689751
1545 Fixing tests
kladkogex Oct 14, 2024
b8e9bbb
1545 Fixing tests
kladkogex Oct 15, 2024
fa6ca9a
1545 Fixing tests
kladkogex Nov 5, 2024
f99e3a2
1545 Fixing tests
kladkogex Nov 5, 2024
111eaed
1545 Fixing tests
kladkogex Nov 6, 2024
4b052a6
1545 fix tests
kladkogex Nov 7, 2024
bab09db
1545 Fixing tests
kladkogex Nov 13, 2024
858d770
1545 Fixing tests
kladkogex Nov 13, 2024
d6f5f74
1545 Fixing tests
kladkogex Nov 13, 2024
5bab9c6
1545 Fixing tests
kladkogex Nov 13, 2024
7b0afc7
1545 Fixing tests
kladkogex Nov 13, 2024
fe236ae
1545 Fixing tests
kladkogex Nov 13, 2024
a08d439
1545 Fixing tests
kladkogex Nov 19, 2024
6b9aad6
1545 Fixing tests
kladkogex Nov 19, 2024
3bc2048
1545 Fixing tests
kladkogex Nov 19, 2024
32c6e6c
1545 Fixing tests
kladkogex Nov 19, 2024
d938467
1545 Fixing tests
kladkogex Nov 19, 2024
929e680
1545 Fixing tests
kladkogex Nov 19, 2024
59eb445
1545 Fixing tests
kladkogex Nov 19, 2024
db7817f
1545 Fixing tests
kladkogex Nov 19, 2024
253edec
1545 Fixing tests
kladkogex Nov 20, 2024
c6bd1bb
1545 Fixing tests
kladkogex Nov 20, 2024
b93c3db
1545 Fixing tests
kladkogex Nov 20, 2024
ac34631
1545 Fixing tests
kladkogex Nov 20, 2024
3daf3bf
1545 First pull request
kladkogex Nov 25, 2024
3f6c03f
1545 First pull request
kladkogex Nov 25, 2024
09d589b
1545 First pull request
kladkogex Nov 25, 2024
232ec28
1545 First pull request
kladkogex Nov 25, 2024
f98ed82
Merge branch 'v4.0.0' into 1545_without_dos_and_stats_cleanups
kladkogex Nov 25, 2024
1a307cc
1545 fix formatting
kladkogex Nov 25, 2024
8cfbeac
Merge branch '1545_without_dos_and_stats_cleanups' of github.com:skal…
kladkogex Nov 25, 2024
2ee516e
1545 First pull request
kladkogex Nov 25, 2024
f446af3
1545 First pull request
kladkogex Nov 25, 2024
60e449b
#1545 fix tests after merge
olehnikolaiev Dec 11, 2024
0f0c7f8
1545 Fix test
kladkogex Dec 16, 2024
c6ecf7c
Merge branch '1545_without_dos_and_stats_cleanups' of github.com:skal…
kladkogex Dec 16, 2024
a5a01b2
1545 Fix test
kladkogex Dec 16, 2024
f7bb478
1545 Fix test
kladkogex Dec 16, 2024
e26801e
1545 Fix pull request comment
kladkogex Dec 16, 2024
e40a7d9
1545 Fix pull request comment
kladkogex Dec 16, 2024
c759dc6
1545 Fix pull request comment
kladkogex Dec 16, 2024
742d82b
1545 Fix pull request comment
kladkogex Dec 18, 2024
55c8e71
1545 Fix pull request comment
kladkogex Dec 18, 2024
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
19 changes: 19 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
./test/tools/libtesteth/*
./test/tools/fuzzTesting/*
./test/tools/libtestutils/*
./test/tools/jsontests/*
./test/unittests/external-dependencies/*
./test/unittests/libskutils/*
./test/unittests/libdevcrypto/*
./test/unittests/libethcore/*
./test/unittests/libethereum/*
./test/unittests/libweb3core/*
./test/unittests/libweb3jsonrpc/*
./test/unittests/libtesteth/*
./test/unittests/libdevcore/*
./test/unittests/libethashseal/*
./test/unittests/mapreduce_consensus/*
./test/unittests/libevm/*
./test/unittests/libskale/*
./storage_benchmark/*
./skale-vm/*
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
4.0.0

5 changes: 0 additions & 5 deletions libbatched-io/batched_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ namespace batched_io {

using namespace dev::db;

batched_db::~batched_db() {
// all batches should be either commit()'ted or revert()'ed!
assert( !m_batch );
}

db_operations_face* db_splitter::new_interface() {
assert( this->m_interfaces.size() < 256 );

Expand Down
60 changes: 59 additions & 1 deletion libbatched-io/batched_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "batched_io.h"

#include <libdevcore/DBImpl.h>
#include <libdevcore/LevelDB.h>

#include <shared_mutex>
Expand Down Expand Up @@ -76,7 +77,64 @@ class batched_db : public db_face {
m_db->forEachWithPrefix( _prefix, f );
}

virtual ~batched_db();
virtual ~batched_db() = default;

protected:
void recover() { /*nothing*/
}
};


class read_only_snap_based_batched_db : public db_face {
private:
std::shared_ptr< dev::db::DBImpl > m_db;
std::shared_ptr< dev::db::LevelDBSnap > m_snap;

public:
read_only_snap_based_batched_db(
std::shared_ptr< dev::db::DBImpl > _db, std::shared_ptr< dev::db::LevelDBSnap > _snap ) {
LDB_CHECK( _db );
LDB_CHECK( _snap );
m_db = _db;
m_snap = _snap;
}

bool is_open() const { return !!m_db; };

void insert( dev::db::Slice, dev::db::Slice ) override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

void kill( dev::db::Slice ) override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

void revert() override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

void commit( const std::string& ) override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

// readonly
std::string lookup( dev::db::Slice _key ) const override {
return m_db->lookup( _key, m_snap );
}

bool exists( dev::db::Slice _key ) const override { return m_db->exists( _key, m_snap ); }

void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > _f ) const override {
static std::string emptyString;
return forEachWithPrefix( emptyString, _f );
}

void forEachWithPrefix( std::string& _prefix,
std::function< bool( dev::db::Slice, dev::db::Slice ) > _f ) const override {
m_db->forEachWithPrefix( _prefix, _f, m_snap );
}

virtual ~read_only_snap_based_batched_db() = default;

protected:
void recover() { /*nothing*/
Expand Down
2 changes: 1 addition & 1 deletion libconsensus
Submodule libconsensus updated 0 files
94 changes: 72 additions & 22 deletions libdevcore/LevelDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "LevelDB.h"
#include "Assertions.h"
#include "LevelDBSnap.h"
#include "Log.h"
#include <libdevcore/microprofile.h>

Expand Down Expand Up @@ -144,6 +145,7 @@ void LevelDB::openDBInstanceUnsafe() {

m_db.reset( db );
m_lastDBOpenTimeMs = getCurrentTimeMs();
m_dbReopenId++;
cnote << "LEVELDB_OPENED:TIME_MS:" << m_lastDBOpenTimeMs - startTimeMs;
}
uint64_t LevelDB::getCurrentTimeMs() {
Expand All @@ -159,14 +161,15 @@ LevelDB::~LevelDB() {
}

std::string LevelDB::lookup( Slice _key ) const {
return lookup( _key, nullptr );
}

std::string LevelDB::lookup( Slice _key, const std::shared_ptr< LevelDBSnap >& _snap ) const {
leveldb::Slice const key( _key.data(), _key.size() );
std::string value;

leveldb::Status status;
{
SharedDBGuard readLock( *this );
status = m_db->Get( m_readOptions, key, &value );
}
auto status = getValue( m_readOptions, key, value, _snap );

if ( status.IsNotFound() )
return std::string();

Expand All @@ -175,26 +178,41 @@ std::string LevelDB::lookup( Slice _key ) const {
}

bool LevelDB::exists( Slice _key ) const {
return exists( _key, nullptr );
}

bool LevelDB::exists( Slice _key, const std::shared_ptr< LevelDBSnap >& _snap ) const {
std::string value;
leveldb::Slice const key( _key.data(), _key.size() );
leveldb::Status status;
{
SharedDBGuard lock( *this );
status = m_db->Get( m_readOptions, key, &value );
}

auto status = getValue( m_readOptions, key, value, _snap );

if ( status.IsNotFound() )
return false;

checkStatus( status );
return true;
}

leveldb::Status LevelDB::getValue( leveldb::ReadOptions _readOptions, const leveldb::Slice& _key,
std::string& _value, const std::shared_ptr< LevelDBSnap >& _snap ) const {
SharedDBGuard lock( *this ); // protect so db is not reopened during get call
if ( _snap ) {
// sanity check to make sure that the snap was created for this particular
// db handle
LDB_CHECK( m_dbReopenId == _snap->getParentDbReopenId() );
return _snap->getValue( m_db, _readOptions, _key, _value );
} else {
return m_db->Get( _readOptions, _key, &_value );
}
}

void LevelDB::insert( Slice _key, Slice _value ) {
leveldb::Slice const key( _key.data(), _key.size() );
leveldb::Slice const value( _value.data(), _value.size() );
leveldb::Status status;
{
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during Put() call
status = m_db->Put( m_writeOptions, key, value );
}
checkStatus( status );
Expand Down Expand Up @@ -224,7 +242,7 @@ void LevelDB::commit( std::unique_ptr< WriteBatchFace > _batch ) {
}
leveldb::Status status;
{
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during Write() call
status = m_db->Write( m_writeOptions, &batchPtr->writeBatch() );
}
// Commit happened. This means the keys actually got deleted in LevelDB. Increment key deletes
Expand All @@ -247,17 +265,25 @@ void LevelDB::reopenDataBaseIfNeeded() {
auto currentTimeMs = getCurrentTimeMs();

if ( currentTimeMs - m_lastDBOpenTimeMs >= ( uint64_t ) m_reopenPeriodMs ) {
ExclusiveDBGuard lock( *this );
// releasing unique pointer will cause database destructor to be called that will close db
m_db.reset();
// now open db while holding the exclusive lock
openDBInstanceUnsafe();
reopen();
}
}
void LevelDB::reopen() {
ExclusiveDBGuard lock( *this );
// close all current snaps by passing max lifetime as zero
auto aliveSnaps = m_snapManager.garbageCollectUnusedOldSnaps( m_db, m_dbReopenId, 0 );
LDB_CHECK( aliveSnaps == 0 );

// releasing unique pointer will cause database destructor to be called that will close db
LDB_CHECK( m_db );
m_db.reset();
// now open db while holding the exclusive lock
openDBInstanceUnsafe();
}

void LevelDB::forEach( std::function< bool( Slice, Slice ) > f ) const {
cwarn << "Iterating over the entire LevelDB database: " << this->m_path;
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during iteration
std::unique_ptr< leveldb::Iterator > itr( m_db->NewIterator( m_readOptions ) );
if ( itr == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
Expand All @@ -273,10 +299,22 @@ void LevelDB::forEach( std::function< bool( Slice, Slice ) > f ) const {
}

void LevelDB::forEachWithPrefix(
std::string& _prefix, std::function< bool( Slice, Slice ) > f ) const {
cnote << "Iterating over the LevelDB prefix: " << _prefix;
SharedDBGuard lock( *this );
std::unique_ptr< leveldb::Iterator > itr( m_db->NewIterator( m_readOptions ) );
std::string& _prefix, std::function< bool( Slice, Slice ) > _f ) const {
forEachWithPrefix( _prefix, _f, nullptr );
}

void LevelDB::forEachWithPrefix( std::string& _prefix, std::function< bool( Slice, Slice ) > f,
const std::shared_ptr< LevelDBSnap >& _snap ) const {
SharedDBGuard lock( *this ); // protect so DB is not reopened during iteration

std::unique_ptr< leveldb::Iterator > itr;

if ( _snap ) {
LDB_CHECK( m_dbReopenId == _snap->getParentDbReopenId() );
itr = _snap->getIterator( m_db, m_readOptions );
} else {
itr.reset( m_db->NewIterator( m_readOptions ) );
}
if ( itr == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
}
Expand All @@ -292,6 +330,18 @@ void LevelDB::forEachWithPrefix(
}
}

void LevelDB::createBlockSnap( uint64_t _blockNumber ) {
SharedDBGuard lock( *this ); // protect so db is not reopened during snap creation
m_snapManager.addSnapForBlock( _blockNumber, m_db, m_dbReopenId );
}

std::shared_ptr< LevelDBSnap > LevelDB::getLastBlockSnap() const {
SharedDBGuard lock( *this ); // protect so db is not reopened when while we get snap
auto snap = m_snapManager.getLastBlockSnap();
LDB_CHECK( snap );
return snap;
}

h256 LevelDB::hashBase() const {
SharedDBGuard lock( *this );
std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) );
Expand Down
34 changes: 34 additions & 0 deletions libdevcore/LevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#pragma once

#include "LevelDBSnapManager.h"
#include "db.h"

#include <leveldb/db.h>
Expand All @@ -29,7 +30,17 @@
#include <secp256k1_sha256.h>
#include <shared_mutex>

#define LDB_CHECK( _EXPRESSION_ ) \
if ( !( _EXPRESSION_ ) ) { \
auto __msg__ = std::string( "State check failed::" ) + #_EXPRESSION_ + " " + \
std::string( __FILE__ ) + ":" + std::to_string( __LINE__ ); \
BOOST_THROW_EXCEPTION( dev::db::DatabaseError() << dev::errinfo_comment( __msg__ ) ); \
}

namespace dev::db {

class LevelDBSnap;

class LevelDB : public DatabaseFace {
public:
static leveldb::ReadOptions defaultReadOptions();
Expand Down Expand Up @@ -58,6 +69,18 @@ class LevelDB : public DatabaseFace {
void forEachWithPrefix(
std::string& _prefix, std::function< bool( Slice, Slice ) > f ) const override;

// create a read only snap after blockl processing
void createBlockSnap( uint64_t _blockNumber );

// get block snap for the lasty block
std::shared_ptr< LevelDBSnap > getLastBlockSnap() const;

// perform operations with respect to a particular read only snap
std::string lookup( Slice _key, const std::shared_ptr< LevelDBSnap >& _snap ) const;
bool exists( Slice _key, const std::shared_ptr< LevelDBSnap >& _snap ) const;
void forEachWithPrefix( std::string& _prefix, std::function< bool( Slice, Slice ) > f,
const std::shared_ptr< LevelDBSnap >& _snap ) const;

h256 hashBase() const override;
h256 hashBaseWithPrefix( char _prefix ) const;

Expand All @@ -75,6 +98,14 @@ class LevelDB : public DatabaseFace {

private:
std::unique_ptr< leveldb::DB > m_db;

// stores and manages snap objects
LevelDBSnapManager m_snapManager;
// this is incremented each time this LevelDB instance is reopened
// we reopen states LevelDB every day on archive nodes to avoid
// meta file getting too large
// in other cases LevelDB is never reopened to this stays zero
std::atomic< uint64_t > m_dbReopenId = 0;
leveldb::ReadOptions const m_readOptions;
leveldb::WriteOptions const m_writeOptions;
leveldb::Options m_options;
Expand Down Expand Up @@ -125,6 +156,9 @@ class LevelDB : public DatabaseFace {
};
void openDBInstanceUnsafe();
void reopenDataBaseIfNeeded();
leveldb::Status getValue( leveldb::ReadOptions _readOptions, const leveldb::Slice& _key,
std::string& _value, const std::shared_ptr< LevelDBSnap >& _snap ) const;
void reopen();
};

} // namespace dev::db
Loading
Loading