From cbce9f1f65a3bca9c373577178d6e6447d09dc90 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 14 Jul 2018 23:00:09 +0000 Subject: [PATCH] WIP debugging why leveldb iterator is broke --- src/main.cpp | 14 +++++++++++--- src/txdb.cpp | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08d2e522..15d74adb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -590,10 +590,18 @@ CBlockTreeDB *pblocktree = NULL; int64_t komodo_snapshot() { + fprintf(stderr,"komodo_snapshot\n"); int64_t total = -1; - if ( pblocktree != 0 ) - total = pblocktree->Snapshot(); - else fprintf(stderr,"null pblocktree start with -addressindex=true\n"); + if (fAddressIndex) { + if ( pblocktree != 0 ) { + 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); } diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..fa3766faf 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,18 +402,31 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); - pcursor->SeekToFirst(); + //boost::scoped_ptr pcursor(pdb->NewIterator(leveldb::ReadOptions()) ); + //boost::scoped_ptr pcursor(db->NewIterator()); + fprintf(stderr,"Snapshot\n"); + + //pcursor->SeekToFirst(); + pcursor->SeekToLast(); + fprintf(stderr,"SeekToLast\n"); + fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { + fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); + fprintf(stderr,"about to try\n"); try { leveldb::Slice slKey = pcursor->key(); + fprintf(stderr,"made slice\n"); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); + fprintf(stderr,"made ssKey\n"); CAddressIndexKey indexKey; ssKey >> chType; + fprintf(stderr,"made chType\n"); ssKey >> indexKey; + fprintf(stderr,"made indexKey\n"); fprintf(stderr,"chType.%d\n",chType); if ( chType == DB_ADDRESSINDEX ) { @@ -428,12 +441,13 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Next(); + pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } } else { break; } } catch (const std::exception& e) { + fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } }