From 7a4755d3a40b65286170e08c9c2a109dbbd16b71 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 17 Feb 2016 16:12:38 +0000 Subject: [PATCH 1/4] Fixup after lmdb master resync --- src/blockchain_db/lmdb/db_lmdb.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 5119be3f5..56f4d4c08 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -764,7 +764,7 @@ void BlockchainLMDB::remove_tx_outputs(const crypto::hash& tx_hash, const transa } else { - size_t num_elems = 0; + mdb_size_t num_elems = 0; mdb_cursor_count(cur, &num_elems); mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP); @@ -848,7 +848,7 @@ void BlockchainLMDB::remove_amount_output_index(const uint64_t amount, const uin else if (result) throw0(DB_ERROR("DB error attempting to get an output")); - size_t num_elems = 0; + mdb_size_t num_elems = 0; mdb_cursor_count(cur, &num_elems); mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP); @@ -1777,7 +1777,7 @@ uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount) const else if (result) throw0(DB_ERROR("DB error attempting to get number of outputs of an amount")); - size_t num_elems = 0; + mdb_size_t num_elems = 0; mdb_cursor_count(cur, &num_elems); TXN_POSTFIX_SUCCESS(); @@ -1873,7 +1873,7 @@ std::vector BlockchainLMDB::get_tx_output_indices(const crypto::hash& else if (result) throw0(DB_ERROR("DB error attempting to get an output")); - size_t num_elems = 0; + mdb_size_t num_elems = 0; mdb_cursor_count(cur, &num_elems); mdb_cursor_get(cur, &k, &v, MDB_FIRST_DUP); @@ -1925,7 +1925,7 @@ std::vector BlockchainLMDB::get_tx_amount_output_indices(const crypto: else if (result) throw0(DB_ERROR("DB error attempting to get an output")); - size_t num_elems = 0; + mdb_size_t num_elems = 0; mdb_cursor_count(cur, &num_elems); mdb_cursor_get(cur, &k, &v, MDB_FIRST_DUP); @@ -2441,7 +2441,7 @@ void BlockchainLMDB::get_output_global_indices(const uint64_t& amount, const std else if (result) throw0(DB_ERROR("DB error attempting to get an output")); - size_t num_elems = 0; + mdb_size_t num_elems = 0; mdb_cursor_count(cur, &num_elems); if (max <= 1 && num_elems <= max) throw1(OUTPUT_DNE("Attempting to get an output index by amount and amount index, but output not found")); From 02abe3590dfd67d8d0f0eb8cdcfb14e72b61e1f1 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 7 Jan 2016 18:29:19 +0000 Subject: [PATCH 2/4] Use MDB_PREV_MULTIPLE in get_global_output_indices --- src/blockchain_db/lmdb/db_lmdb.cpp | 51 +++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 56f4d4c08..b43d5742f 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -2475,22 +2475,51 @@ void BlockchainLMDB::get_output_global_indices(const uint64_t& amount, const std LOG_PRINT_L1("Index: " << index << " Elems: " << num_elems << " partial results found for get_output_tx_and_index"); break; } - while (index >= curcount) + if (!curcount && index > num_elems/2) { - TIME_MEASURE_START(db1); - if (mdb_cursor_get(cur, &k, &v, curcount == 0 ? MDB_GET_MULTIPLE : MDB_NEXT_MULTIPLE) != 0) + mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP); + mdb_cursor_get(cur, &k, &v, MDB_PREV); /* kludge to unset C_EOF */ + mdb_cursor_get(cur, &k, &v, MDB_NEXT); + mdb_cursor_get(cur, &k, &v, MDB_GET_MULTIPLE); + + curcount = num_elems; + while(1) { - // allow partial results - result = false; - break; + TIME_MEASURE_START(db1); + int count = v.mv_size / sizeof(uint64_t); + curcount -= count; + if (curcount > index) + { + mdb_cursor_get(cur, &k, &v, MDB_PREV_MULTIPLE); + } else + { + blockstart = curcount; + curcount += count; + break; + } + TIME_MEASURE_FINISH(db1); + t_dbmul += db1; } - int count = v.mv_size / sizeof(uint64_t); + } else + { + while (index >= curcount) + { + TIME_MEASURE_START(db1); + if (mdb_cursor_get(cur, &k, &v, curcount == 0 ? MDB_GET_MULTIPLE : MDB_NEXT_MULTIPLE) != 0) + { + // allow partial results + result = false; + break; + } - blockstart = curcount; - curcount += count; - TIME_MEASURE_FINISH(db1); - t_dbmul += db1; + int count = v.mv_size / sizeof(uint64_t); + + blockstart = curcount; + curcount += count; + TIME_MEASURE_FINISH(db1); + t_dbmul += db1; + } } LOG_PRINT_L3("Records returned: " << curcount << " Index: " << index); From 8860b7497f1f98e2d5ba49aa77e7b390c22b5c4e Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 17 Feb 2016 17:27:50 +0000 Subject: [PATCH 3/4] MDB_VL32 - increase max write txn size --- external/db_drivers/liblmdb/midl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/db_drivers/liblmdb/midl.h b/external/db_drivers/liblmdb/midl.h index ed1d75e36..e16aa0c3c 100644 --- a/external/db_drivers/liblmdb/midl.h +++ b/external/db_drivers/liblmdb/midl.h @@ -61,7 +61,7 @@ typedef MDB_ID *MDB_IDL; * limiting factors: sizeof(ID), thread stack size */ #ifdef MDB_VL32 -#define MDB_IDL_LOGN 10 /* DB_SIZE is 2^10, UM_SIZE is 2^11 */ +#define MDB_IDL_LOGN 14 /* DB_SIZE is 2^14, UM_SIZE is 2^15 */ #else #define MDB_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */ #endif From 9218cad640e51128819d942c71fe70e2e4fba63d Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 17 Feb 2016 19:58:37 +0000 Subject: [PATCH 4/4] Fix cffc411c9025e1d28a8b6e32c53c83ba113d9204 Don't include bdb header unless defined(BERKELEY_DB) --- src/blockchain_utilities/fake_core.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/blockchain_utilities/fake_core.h b/src/blockchain_utilities/fake_core.h index 20a3361b6..2fb5031d3 100644 --- a/src/blockchain_utilities/fake_core.h +++ b/src/blockchain_utilities/fake_core.h @@ -33,7 +33,9 @@ #include "cryptonote_core/blockchain_storage.h" // in-memory DB #include "blockchain_db/blockchain_db.h" #include "blockchain_db/lmdb/db_lmdb.h" +#if defined(BERKELEY_DB) #include "blockchain_db/berkeleydb/db_bdb.h" +#endif using namespace cryptonote;