1
0
Fork 0

Add failover actions to coordinator in cluster case.

This commit is contained in:
Max Neunhoeffer 2015-10-30 16:16:09 +01:00 committed by Frank Celler
parent e2eadd8239
commit 92dbff9fdb
1 changed files with 30 additions and 12 deletions

View File

@ -786,9 +786,19 @@ function cleanupCurrentCollections (plannedCollections) {
function handleCollectionChanges (plan) { function handleCollectionChanges (plan) {
var plannedCollections = getByPrefix3d(plan, "Plan/Collections/"); var plannedCollections = getByPrefix3d(plan, "Plan/Collections/");
createLocalCollections(plannedCollections); var ok = true;
dropLocalCollections(plannedCollections);
cleanupCurrentCollections(plannedCollections); try {
createLocalCollections(plannedCollections);
dropLocalCollections(plannedCollections);
cleanupCurrentCollections(plannedCollections);
}
catch (err) {
console.error("Caught error in handleCollectionChanges: " +
JSON.stringify(err));
ok = false;
}
return ok;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -802,8 +812,9 @@ function setupReplication () {
var rep = require("org/arangodb/replication"); var rep = require("org/arangodb/replication");
var dbs = db._listDatabases(); var dbs = db._listDatabases();
var i; var i;
try { var ok = true;
for (i = 0; i < dbs.length; i++) { for (i = 0; i < dbs.length; i++) {
try {
var database = dbs[i]; var database = dbs[i];
console.debug("Checking replication of database "+database); console.debug("Checking replication of database "+database);
db._useDatabase(database); db._useDatabase(database);
@ -812,21 +823,25 @@ function setupReplication () {
if (state.state.running === false) { if (state.state.running === false) {
var endpoint = ArangoClusterInfo.getServerEndpoint( var endpoint = ArangoClusterInfo.getServerEndpoint(
ArangoServerState.idOfPrimary()); ArangoServerState.idOfPrimary());
var config = { "endpoint": endpoint, "includeSystem": false }; var config = { "endpoint": endpoint, "includeSystem": false,
rep.applier.properties(config); "incremental": false, "autoStart": true,
"requireFromPresent": true};
console.info("Starting synchronization..."); console.info("Starting synchronization...");
var res = rep.sync(config); var res = rep.sync(config);
console.info("Last log tick: "+res.lastLogTick+ console.info("Last log tick: "+res.lastLogTick+
", starting replication..."); ", starting replication...");
rep.applier.properties(config);
var res2 = rep.applier.start(res.lastLogTick); var res2 = rep.applier.start(res.lastLogTick);
console.info("Result of replication start: "+res2); console.info("Result of replication start: "+res2);
} }
} }
} catch (err) {
catch (err) { console.error("Could not set up replication for database ", database);
db._useDatabase("_system"); ok = false;
}
} }
db._useDatabase("_system"); db._useDatabase("_system");
return ok;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -920,14 +935,17 @@ function handleChanges (plan, current) {
} }
handleDatabaseChanges(plan, current); handleDatabaseChanges(plan, current);
var success;
if (role === "PRIMARY" || role === "COORDINATOR") { if (role === "PRIMARY" || role === "COORDINATOR") {
// Note: This is only ever called for DBservers (primary and secondary), // Note: This is only ever called for DBservers (primary and secondary),
// we keep the coordinator case here just in case... // we keep the coordinator case here just in case...
handleCollectionChanges(plan, current); success = handleCollectionChanges(plan, current);
} }
else { else {
setupReplication(); success = setupReplication();
} }
return success;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////