Use MDB_PREV_MULTIPLE

in get_global_output_indices
This commit is contained in:
Howard Chu 2016-01-07 18:29:19 +00:00
parent 7a4755d3a4
commit 02abe3590d
1 changed files with 40 additions and 11 deletions

View File

@ -2475,6 +2475,34 @@ 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"); LOG_PRINT_L1("Index: " << index << " Elems: " << num_elems << " partial results found for get_output_tx_and_index");
break; break;
} }
if (!curcount && index > num_elems/2)
{
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)
{
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;
}
} else
{
while (index >= curcount) while (index >= curcount)
{ {
TIME_MEASURE_START(db1); TIME_MEASURE_START(db1);
@ -2492,6 +2520,7 @@ void BlockchainLMDB::get_output_global_indices(const uint64_t& amount, const std
TIME_MEASURE_FINISH(db1); TIME_MEASURE_FINISH(db1);
t_dbmul += db1; t_dbmul += db1;
} }
}
LOG_PRINT_L3("Records returned: " << curcount << " Index: " << index); LOG_PRINT_L3("Records returned: " << curcount << " Index: " << index);
TIME_MEASURE_START(db2); TIME_MEASURE_START(db2);