WIP debugging why leveldb iterator is broke

This commit is contained in:
Duke Leto
2018-07-14 23:00:09 +00:00
parent 8a7c025aae
commit cbce9f1f65
2 changed files with 27 additions and 5 deletions

View File

@@ -590,10 +590,18 @@ CBlockTreeDB *pblocktree = NULL;
int64_t komodo_snapshot() int64_t komodo_snapshot()
{ {
fprintf(stderr,"komodo_snapshot\n");
int64_t total = -1; int64_t total = -1;
if ( pblocktree != 0 ) if (fAddressIndex) {
total = pblocktree->Snapshot(); if ( pblocktree != 0 ) {
else fprintf(stderr,"null pblocktree start with -addressindex=true\n"); total = pblocktree->Snapshot();
} else {
fprintf(stderr,"null pblocktree start with -addressindex=true\n");
}
} else {
fprintf(stderr,"getsnapshot requires -addressindex=true\n");
}
fprintf(stderr,"total=%li\n", total);
return(total); return(total);
} }

View File

@@ -402,18 +402,31 @@ int64_t CBlockTreeDB::Snapshot()
{ {
char chType; int64_t total = -1; std::string address; char chType; int64_t total = -1; std::string address;
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator()); boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
pcursor->SeekToFirst(); //boost::scoped_ptr<leveldb::Iterator> pcursor(pdb->NewIterator(leveldb::ReadOptions()) );
//boost::scoped_ptr<leveldb::Iterator> pcursor(db->NewIterator());
fprintf(stderr,"Snapshot\n");
//pcursor->SeekToFirst();
pcursor->SeekToLast();
fprintf(stderr,"SeekToLast\n");
fprintf(stderr,"pcursor iterate\n"); fprintf(stderr,"pcursor iterate\n");
while (pcursor->Valid()) while (pcursor->Valid())
{ {
fprintf(stderr,"pcursor valid\n");
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
fprintf(stderr,"about to try\n");
try try
{ {
leveldb::Slice slKey = pcursor->key(); leveldb::Slice slKey = pcursor->key();
fprintf(stderr,"made slice\n");
CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION);
fprintf(stderr,"made ssKey\n");
CAddressIndexKey indexKey; CAddressIndexKey indexKey;
ssKey >> chType; ssKey >> chType;
fprintf(stderr,"made chType\n");
ssKey >> indexKey; ssKey >> indexKey;
fprintf(stderr,"made indexKey\n");
fprintf(stderr,"chType.%d\n",chType); fprintf(stderr,"chType.%d\n",chType);
if ( chType == DB_ADDRESSINDEX ) if ( chType == DB_ADDRESSINDEX )
{ {
@@ -428,12 +441,13 @@ int64_t CBlockTreeDB::Snapshot()
total = (int64_t)nValue; total = (int64_t)nValue;
else total += (int64_t)nValue; else total += (int64_t)nValue;
//addressIndex.push_back(make_pair(indexKey, nValue)); //addressIndex.push_back(make_pair(indexKey, nValue));
pcursor->Next(); pcursor->Prev();
} catch (const std::exception& e) { } catch (const std::exception& e) {
return error("failed to get address index value"); return error("failed to get address index value");
} }
} else { break; } } else { break; }
} catch (const std::exception& e) { } catch (const std::exception& e) {
fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what());
break; break;
} }
} }