From b249be4bdb0a7e12eae9b9872022402983ee030c Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 4 Jun 2014 10:48:57 -0300 Subject: [PATCH] fixes in upgradev2 script --- lib/BlockDb.js | 30 +++++++++++++++++++++++++++++- lib/TransactionDb.js | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/BlockDb.js b/lib/BlockDb.js index 04b5f1c1..8c8a8f81 100644 --- a/lib/BlockDb.js +++ b/lib/BlockDb.js @@ -393,10 +393,38 @@ BlockDb.prototype._runScript = function(script, cb) { BlockDb.prototype.migrateV02 = function(cb) { var k = 'txb-'; + var dbScript = []; + var c=0; + var c2=0; + var N=50000; this.txDb._db.createReadStream({ start: k, end: k + '~' - }).pipe(db.createWriteStream()).on('close', cb); + }) + .on('data', function(data) { + var k = data.key.split('-'); + var v = data.value.split(':'); + dbScript.push({ + type: 'put', + key: IN_BLK_PREFIX + k[1], + value: data.value, + }); + if (c++>N) { + console.log('\t%dM txs processed', ((c2+=N)/1e6).toFixed(3)); + db.batch(dbScript,function () { + c=0; + dbScript=[]; + }); + } + }) + .on('error', function(err) { + return cb(err); + }) + .on('end', function (){ + return cb(); + }); + + }; BlockDb.prototype.migrateV02cleanup = function(cb) { diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index fe34a592..7a31d493 100644 --- a/lib/TransactionDb.js +++ b/lib/TransactionDb.js @@ -711,7 +711,7 @@ TransactionDb.prototype.migrateV02 = function(cb) { value: v[0], }); if (c++>N) { - console.log('\t%dM txs processed', ((c2+=N)/1e6).toFixed(3)); //TODO + console.log('\t%dM txs outs processed', ((c2+=N)/1e6).toFixed(3)); //TODO db.batch(dbScript,function () { c=0; dbScript=[];