migrateDirtyDBtoRealDB: fix the script not trusting length, and directly iterating on dirtyDB tuples
Fixes #2214.pull/4002/head
parent
d155b792e9
commit
94921b53fd
|
@ -11,7 +11,7 @@ require("ep_etherpad-lite/node_modules/npm").load({}, function(er,npm) {
|
||||||
|
|
||||||
|
|
||||||
var settings = require("ep_etherpad-lite/node/utils/Settings");
|
var settings = require("ep_etherpad-lite/node/utils/Settings");
|
||||||
var dirty = require("../src/node_modules/dirty")('var/dirty.db');
|
var dirty = require("../src/node_modules/dirty");
|
||||||
var ueberDB = require("../src/node_modules/ueberdb2");
|
var ueberDB = require("../src/node_modules/ueberdb2");
|
||||||
var log4js = require("../src/node_modules/log4js");
|
var log4js = require("../src/node_modules/log4js");
|
||||||
var dbWrapperSettings = {
|
var dbWrapperSettings = {
|
||||||
|
@ -19,25 +19,31 @@ require("ep_etherpad-lite/node_modules/npm").load({}, function(er,npm) {
|
||||||
"writeInterval": 0 // Write directly to the database, don't buffer
|
"writeInterval": 0 // Write directly to the database, don't buffer
|
||||||
};
|
};
|
||||||
var db = new ueberDB.database(settings.dbType, settings.dbSettings, dbWrapperSettings, log4js.getLogger("ueberDB"));
|
var db = new ueberDB.database(settings.dbType, settings.dbSettings, dbWrapperSettings, log4js.getLogger("ueberDB"));
|
||||||
|
var i = 0;
|
||||||
|
var length = 0;
|
||||||
|
|
||||||
db.init(function() {
|
db.init(function() {
|
||||||
console.log("Waiting for dirtyDB to parse its file.");
|
console.log("Waiting for dirtyDB to parse its file.");
|
||||||
dirty.on("load", function(length) {
|
dirty = dirty('var/dirty.db').on("load", function() {
|
||||||
console.log("Loaded " + length + " records, processing now.");
|
dirty.forEach(function(){
|
||||||
var remaining = length;
|
length++;
|
||||||
dirty.forEach(function(key, value) {
|
});
|
||||||
db.set(key, value, function(error) {
|
console.log(`Found ${length} records, processing now.`);
|
||||||
if (typeof error != 'undefined') {
|
|
||||||
console.log("Unexpected result handling: ", key, value, " was: ", error);
|
dirty.forEach(async function(key, value) {
|
||||||
}
|
let error = await db.set(key, value);
|
||||||
remaining -= 1;
|
console.log(`Wrote record ${i}`);
|
||||||
var oldremaining = remaining;
|
i++;
|
||||||
if ((oldremaining % 100) == 0) {
|
|
||||||
console.log("Records not yet flushed to database: ", remaining);
|
if (i === length) {
|
||||||
}
|
console.log("finished, just clearing up for a bit...");
|
||||||
});
|
setTimeout(function() {
|
||||||
|
process.exit(0);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
console.log("Please wait for all records to flush to database, then kill this process.");
|
console.log("Please wait for all records to flush to database, then kill this process.");
|
||||||
});
|
});
|
||||||
|
console.log("done?")
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue