1
0
Fork 0

Fix waitForSyncRepl.

This commit is contained in:
Max Neunhoeffer 2017-01-26 10:47:03 +01:00
parent 15ab287a23
commit fe1b10e6af
1 changed files with 55 additions and 28 deletions

View File

@ -1913,34 +1913,48 @@ function supervisionState () {
// / @brief wait for synchronous replication to settle // / @brief wait for synchronous replication to settle
// ///////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
function waitForSyncReplOneCollection (dbName, collName) { function checkForSyncReplOneCollection (dbName, collName) {
console.debug('waitForSyncRepl:', dbName, collName);
try { try {
var count = 60; let cinfo = global.ArangoClusterInfo.getCollectionInfo(dbName, collName);
while (--count > 0) { let shards = Object.keys(cinfo.shards);
var cinfo = global.ArangoClusterInfo.getCollectionInfo(dbName, collName); let ccinfo = shards.map(function (s) {
var shards = Object.keys(cinfo.shards);
var ccinfo = shards.map(function (s) {
return global.ArangoClusterInfo.getCollectionInfoCurrent(dbName, return global.ArangoClusterInfo.getCollectionInfoCurrent(dbName,
collName, s).servers; collName, s).servers;
}); });
console.debug('waitForSyncRepl', dbName, collName, shards, cinfo.shards, ccinfo); console.debug('checkForSyncReplOneCollection:', dbName, collName, shards,
var ok = true; cinfo.shards, ccinfo);
for (var i = 0; i < shards.length; ++i) { let ok = true;
for (let i = 0; i < shards.length; ++i) {
if (cinfo.shards[shards[i]].length !== ccinfo[i].length) { if (cinfo.shards[shards[i]].length !== ccinfo[i].length) {
ok = false; ok = false;
} }
} }
if (ok) { if (ok) {
console.debug('waitForSyncRepl: OK:', dbName, collName, shards); console.debug('checkForSyncReplOneCollection: OK:', dbName, collName,
shards);
return true;
}
console.debug('checkForSyncReplOneCollection: not yet:', dbName, collName,
shards);
return false;
} catch (err) {
console.error('checkForSyncReplOneCollection: exception:', dbName, collName,
JSON.stringify(err));
}
return false;
}
function waitForSyncReplOneCollection (dbName, collName) {
console.debug('waitForSyncRepl:', dbName, collName);
let count = 60;
while (--count > 0) {
let ok = checkForSyncReplOneCollection(dbName, collName);
if (ok) {
return true; return true;
} }
require('internal').wait(1); require('internal').wait(1);
} }
} catch (err) { console.warn('waitForSyncReplOneCollection:', dbName, collName, ': BAD');
console.warn('waitForSyncRepl:', dbName, collName, ': exception', JSON.stringify(err));
}
console.warn('waitForSyncRepl:', dbName, collName, ': BAD');
return false; return false;
} }
@ -1948,11 +1962,24 @@ function waitForSyncRepl (dbName, collList) {
if (!isCoordinator()) { if (!isCoordinator()) {
return true; return true;
} }
var ok = true; let n = collList.length;
for (var i = 0; i < collList.length; ++i) { let count = 10 * n; // wait for up to 10 * collList.length seconds
ok = waitForSyncReplOneCollection(dbName, collList[i].name()) && ok; let ok = [...Array(n)].map(v => false);
while (--count > 0) {
let allOk = true;
for (var i = 0; i < n; ++i) {
if (!ok[i]) {
ok[i] = checkForSyncReplOneCollection(dbName, collList[i].name());
allOk = allOk && ok[i];
} }
return ok; }
if (allOk) {
return true;
}
require('internal').wait(1);
}
console.warn('waitForSyncRepl: timeout:', dbName, collList);
return false;
} }
exports.bootstrapDbServers = bootstrapDbServers; exports.bootstrapDbServers = bootstrapDbServers;