mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 20:19:34 +00:00
Update db_bdb.cpp
This commit is contained in:
parent
4b7ad2b0a7
commit
dbbc457836
1 changed files with 68 additions and 68 deletions
|
@ -1425,31 +1425,31 @@ void BlockchainBDB::get_output_tx_and_index(const uint64_t& amount,
|
||||||
max = index;
|
max = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ??? might be a bug, don't always treat as uint64_t
|
// ??? might be a bug, don't always treat as uint64_t
|
||||||
#define DBT_VALUE(dbt) v.get_size() == sizeof(uint64_t) ? \
|
#define DBT_VALUE(dbt) v.get_size() == sizeof(uint64_t) ? \
|
||||||
*((uint64_t *)v.get_data()) : *((uint32_t *)v.get_data()) \
|
*((uint64_t *)v.get_data()) : *((uint32_t *)v.get_data()) \
|
||||||
|
|
||||||
// get returned keypairs count
|
// get returned keypairs count
|
||||||
#define DB_COUNT_RECORDS(dbt, cnt) \
|
#define DB_COUNT_RECORDS(dbt, cnt) \
|
||||||
do { \
|
do { \
|
||||||
uint32_t *_p = (uint32_t *) ((uint8_t *)(dbt)->data + \
|
uint32_t *_p = (uint32_t *) ((uint8_t *)(dbt)->data + \
|
||||||
(dbt)->ulen - sizeof(uint32_t)); \
|
(dbt)->ulen - sizeof(uint32_t)); \
|
||||||
cnt = 0; \
|
cnt = 0; \
|
||||||
while(*_p != (uint32_t) -1) { \
|
while(*_p != (uint32_t) -1) { \
|
||||||
_p -= 2; \
|
_p -= 2; \
|
||||||
++cnt; \
|
++cnt; \
|
||||||
} \
|
} \
|
||||||
} while(0); \
|
} while(0); \
|
||||||
|
|
||||||
Dbt_copy<uint64_t> k(amount);
|
Dbt_copy<uint64_t> k(amount);
|
||||||
Dbt_copy<uint64_t> v;
|
Dbt_copy<uint64_t> v;
|
||||||
uint64_t buflen = 0;
|
uint64_t buflen = 0;
|
||||||
uint64_t t_dbmul = 0;
|
uint64_t t_dbmul = 0;
|
||||||
uint64_t t_dbscan = 0;
|
uint64_t t_dbscan = 0;
|
||||||
TIME_MEASURE_START(db2);
|
TIME_MEASURE_START(db2);
|
||||||
if(max <= 1)
|
if(max <= 1)
|
||||||
{
|
{
|
||||||
for (const uint64_t& index : offsets)
|
for (const uint64_t& index : offsets)
|
||||||
{
|
{
|
||||||
TIME_MEASURE_START(t_seek);
|
TIME_MEASURE_START(t_seek);
|
||||||
|
|
||||||
|
@ -1481,28 +1481,28 @@ void BlockchainBDB::get_output_tx_and_index(const uint64_t& amount,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// setup a 256KB minimum buffer size
|
// setup a 256KB minimum buffer size
|
||||||
uint32_t pagesize = 256 * 1024;
|
uint32_t pagesize = 256 * 1024;
|
||||||
|
|
||||||
// Retrieve only a suitable portion of the kvp data, up to somewhere near
|
// Retrieve only a suitable portion of the kvp data, up to somewhere near
|
||||||
// the maximum offset value being retrieved
|
// the maximum offset value being retrieved
|
||||||
buflen = (max + 1) * 4 * sizeof(uint64_t);
|
buflen = (max + 1) * 4 * sizeof(uint64_t);
|
||||||
buflen = ((buflen / pagesize) + ((buflen % pagesize) > 0 ? 1 : 0)) * pagesize;
|
buflen = ((buflen / pagesize) + ((buflen % pagesize) > 0 ? 1 : 0)) * pagesize;
|
||||||
bool singlebuff = buflen <= BUFFER_LENGTH;
|
bool singlebuff = buflen <= BUFFER_LENGTH;
|
||||||
buflen = buflen < BUFFER_LENGTH ? buflen : BUFFER_LENGTH;
|
buflen = buflen < BUFFER_LENGTH ? buflen : BUFFER_LENGTH;
|
||||||
|
|
||||||
Dbt data;
|
Dbt data;
|
||||||
data.set_data(m_buffer);
|
data.set_data(m_buffer);
|
||||||
data.set_ulen(buflen);
|
data.set_ulen(buflen);
|
||||||
data.set_size(buflen);
|
data.set_size(buflen);
|
||||||
data.set_flags(DB_DBT_USERMEM);
|
data.set_flags(DB_DBT_USERMEM);
|
||||||
|
|
||||||
uint32_t curcount = 0;
|
uint32_t curcount = 0;
|
||||||
uint32_t blockstart = 0;
|
uint32_t blockstart = 0;
|
||||||
for (const uint64_t& index : offsets)
|
for (const uint64_t& index : offsets)
|
||||||
{
|
{
|
||||||
// fixme! for whatever reason, the first call to DB_MULTIPLE | DB_SET does not
|
// fixme! for whatever reason, the first call to DB_MULTIPLE | DB_SET does not
|
||||||
// retrieve the first value.
|
// retrieve the first value.
|
||||||
if(index <= 1)
|
if(index <= 1)
|
||||||
{
|
{
|
||||||
auto result = cur->get(&k, &v, DB_SET);
|
auto result = cur->get(&k, &v, DB_SET);
|
||||||
|
@ -1521,40 +1521,40 @@ void BlockchainBDB::get_output_tx_and_index(const uint64_t& amount,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while(index >= curcount)
|
while(index >= curcount)
|
||||||
{
|
{
|
||||||
TIME_MEASURE_START(t_db1);
|
TIME_MEASURE_START(t_db1);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cur->get(&k, &data, DB_MULTIPLE | (curcount == 0 ? DB_SET : DB_NEXT_DUP));
|
cur->get(&k, &data, DB_MULTIPLE | (curcount == 0 ? DB_SET : DB_NEXT_DUP));
|
||||||
blockstart = curcount;
|
blockstart = curcount;
|
||||||
// skip counting if using single buffer, it actually adds some overhead on some systems.
|
// skip counting if using single buffer, it actually adds some overhead on some systems.
|
||||||
if(!singlebuff)
|
if(!singlebuff)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
DB_COUNT_RECORDS((DBT *) &data, count);
|
DB_COUNT_RECORDS((DBT *) &data, count);
|
||||||
curcount += count;
|
curcount += count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
LOG_PRINT_L0("DB_EXCEPTION: " << e.what());
|
LOG_PRINT_L0("DB_EXCEPTION: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME_MEASURE_FINISH(t_db1);
|
TIME_MEASURE_FINISH(t_db1);
|
||||||
t_dbmul += t_db1;
|
t_dbmul += t_db1;
|
||||||
if(singlebuff)
|
if(singlebuff)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_PRINT_L1("Records returned: " << curcount << " Index: " << index);
|
LOG_PRINT_L1("Records returned: " << curcount << " Index: " << index);
|
||||||
TIME_MEASURE_START(t_db2);
|
TIME_MEASURE_START(t_db2);
|
||||||
DBT *pdata = (DBT *) &data;
|
DBT *pdata = (DBT *) &data;
|
||||||
|
|
||||||
uint8_t *value;
|
uint8_t *value;
|
||||||
uint64_t dlen = 0;
|
uint64_t dlen = 0;
|
||||||
|
|
||||||
void *pbase = ((uint8_t *)(pdata->data)) + pdata->ulen - sizeof(uint32_t);
|
void *pbase = ((uint8_t *)(pdata->data)) + pdata->ulen - sizeof(uint32_t);
|
||||||
uint32_t *p = (uint32_t *) pbase;
|
uint32_t *p = (uint32_t *) pbase;
|
||||||
if (*p == (uint32_t) -1)
|
if (*p == (uint32_t) -1)
|
||||||
{
|
{
|
||||||
|
@ -1574,9 +1574,9 @@ void BlockchainBDB::get_output_tx_and_index(const uint64_t& amount,
|
||||||
v = dlen == sizeof(uint64_t) ? *((uint64_t *) value)
|
v = dlen == sizeof(uint64_t) ? *((uint64_t *) value)
|
||||||
: *((uint32_t *) value);
|
: *((uint32_t *) value);
|
||||||
}
|
}
|
||||||
TIME_MEASURE_FINISH(t_db2);
|
TIME_MEASURE_FINISH(t_db2);
|
||||||
t_dbscan += t_db2;
|
t_dbscan += t_db2;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t glob_index = DBT_VALUE(v);
|
uint64_t glob_index = DBT_VALUE(v);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue