1
0
Fork 0

Merge branch 'devel' of github.com:arangodb/arangodb into devel

This commit is contained in:
hkernbach 2016-05-24 09:46:28 +02:00
commit 2edb8d0f13
1 changed files with 82 additions and 80 deletions

View File

@ -861,75 +861,29 @@ function cleanupCurrentCollections (plannedCollections, currentCollections,
/// replicated shards) /// replicated shards)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
function synchronizeLocalFollowerCollections (plannedCollections, function synchronizeOneShard(database, shard, planId, leader) {
currentCollections) { // synchronize this shard from the leader
var ourselves = global.ArangoServerState.id(); // this function will throw if anything goes wrong
var db = require("internal").db; const rep = require("@arangodb/replication");
db._useDatabase("_system");
var localDatabases = getLocalDatabases();
var database;
var rep = require("@arangodb/replication");
// iterate over all matching databases
for (database in plannedCollections) {
if (plannedCollections.hasOwnProperty(database)) {
if (localDatabases.hasOwnProperty(database)) {
// switch into other database
db._useDatabase(database);
try {
// iterate over collections of database
var collections = plannedCollections[database];
var collection;
// diff the collections
for (collection in collections) {
if (collections.hasOwnProperty(collection)) {
var collInfo = collections[collection];
var shards = collInfo.shards; // this is the Plan
var shard;
collInfo.planId = collInfo.id;
for (shard in shards) {
if (shards.hasOwnProperty(shard)) {
var pos = shards[shard].indexOf(ourselves);
if (pos > 0) { // found and not in position 0
// found a shard we have to replicate synchronously
// now see whether we are in sync by looking at the
// current entry in the agency:
var inCurrent = lookup4d(currentCollections, database,
collection, shard);
if (inCurrent === undefined ||
! inCurrent.hasOwnProperty("servers") ||
typeof inCurrent.servers !== "object" ||
typeof inCurrent.servers[0] !== "string" ||
inCurrent.servers[0] === "") {
console.debug("Leader has not yet created shard, let's",
"come back later to this shard...");
} else {
if (inCurrent.servers.indexOf(ourselves) === -1) {
// we not in there - must synchronize this shard from
// the leader
console.info("trying to synchronize local shard '%s/%s' for central '%s/%s'", console.info("trying to synchronize local shard '%s/%s' for central '%s/%s'",
database, database,
shard, shard,
database, database,
collInfo.planId); planId);
try { try {
var ep = ArangoClusterInfo.getServerEndpoint( var ep = ArangoClusterInfo.getServerEndpoint(leader);
inCurrent.servers[0]);
// First once without a read transaction: // First once without a read transaction:
var sy = rep.syncCollection(shard, var sy = rep.syncCollection(shard,
{ endpoint: ep, incremental: true, { endpoint: ep, incremental: true,
keepBarrier: true }); keepBarrier: true });
if (sy.error) { if (sy.error) {
console.error("Could not initially synchronize shard ", shard, sy); console.error("Could not initially synchronize shard ", shard, sy);
throw "Initial sync failed";
} else { } else {
if (sy.collections.length == 0 || if (sy.collections.length === 0 ||
sy.collections[0].name != shard) { sy.collections[0].name !== shard) {
cancelBarrier(ep, database, sy.barrierId); cancelBarrier(ep, database, sy.barrierId);
throw "Shard seems to be gone from leader!"; throw "Shard seems to be gone from leader!";
} else { } else {
@ -983,12 +937,60 @@ function synchronizeLocalFollowerCollections (plannedCollections,
} }
catch (err2) { catch (err2) {
console.error("synchronization of local shard '%s/%s' for central '%s/%s' failed: %s", console.error("synchronization of local shard '%s/%s' for central '%s/%s' failed: %s",
database, database, shard, database, planId, JSON.stringify(err2));
shard,
database,
collInfo.planId,
JSON.stringify(err2));
} }
}
function synchronizeLocalFollowerCollections (plannedCollections,
currentCollections) {
var ourselves = global.ArangoServerState.id();
var db = require("internal").db;
db._useDatabase("_system");
var localDatabases = getLocalDatabases();
var database;
// iterate over all matching databases
for (database in plannedCollections) {
if (plannedCollections.hasOwnProperty(database)) {
if (localDatabases.hasOwnProperty(database)) {
// switch into other database
db._useDatabase(database);
try {
// iterate over collections of database
var collections = plannedCollections[database];
var collection;
// diff the collections
for (collection in collections) {
if (collections.hasOwnProperty(collection)) {
var collInfo = collections[collection];
var shards = collInfo.shards; // this is the Plan
var shard;
collInfo.planId = collInfo.id;
for (shard in shards) {
if (shards.hasOwnProperty(shard)) {
var pos = shards[shard].indexOf(ourselves);
if (pos > 0) { // found and not in position 0
// found a shard we have to replicate synchronously
// now see whether we are in sync by looking at the
// current entry in the agency:
var inCurrent = lookup4d(currentCollections, database,
collection, shard);
if (inCurrent === undefined ||
! inCurrent.hasOwnProperty("servers") ||
typeof inCurrent.servers !== "object" ||
typeof inCurrent.servers[0] !== "string" ||
inCurrent.servers[0] === "") {
console.debug("Leader has not yet created shard, let's",
"come back later to this shard...");
} else {
if (inCurrent.servers.indexOf(ourselves) === -1) {
synchronizeOneShard(database, shard, collInfo.planId,
inCurrent.servers[0]);
} }
} }
} }