From 2476cf71469e82d015a3da5f400b0cdf0735fc58 Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Thu, 26 Jan 2017 13:58:34 +0100 Subject: [PATCH] Fix drop and add reporting in agency current --- js/server/modules/@arangodb/cluster.js | 6 +- .../cluster-sync-test-noncluster-spec.js | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/js/server/modules/@arangodb/cluster.js b/js/server/modules/@arangodb/cluster.js index 4affa24122..27057bad8a 100644 --- a/js/server/modules/@arangodb/cluster.js +++ b/js/server/modules/@arangodb/cluster.js @@ -59,6 +59,9 @@ var isEqual = function(object, other) { } if (Array.isArray(object)) { + if (object.length !== other.length) { + return false; + } return object.every((value, index) => { return isEqual(value, other[index]); }); @@ -674,6 +677,7 @@ function createIndexes(collection, plannedIndexes) { return localId(plannedIndex) === index.id; }).length === 0; }); + return indexesToDelete.reduce((errors, index) => { console.debug("dropping index '%s/%s': %s", collection._dbName, @@ -1010,8 +1014,8 @@ function updateCurrentForCollections(localErrors, currentCollections) { let shardInfo = localCollections[shard]; if (shardInfo.isLeader) { let localCollectionInfo = assembleLocalCollectionInfo(shardInfo, localErrors[shard] || {}); - let currentCollectionInfo = fetchKey(currentCollections, database, shardInfo.planId, shard); + if (!isEqual(localCollectionInfo, currentCollectionInfo)) { trx[curCollections + database + '/' + shardInfo.planId + '/' + shardInfo.name] = { op: 'set', diff --git a/js/server/tests/cluster-sync/cluster-sync-test-noncluster-spec.js b/js/server/tests/cluster-sync/cluster-sync-test-noncluster-spec.js index 7e92a0fad4..dab1433a8d 100644 --- a/js/server/tests/cluster-sync/cluster-sync-test-noncluster-spec.js +++ b/js/server/tests/cluster-sync/cluster-sync-test-noncluster-spec.js @@ -1118,5 +1118,60 @@ describe('Cluster sync', function() { .that.has.deep.property('new.indexes.1.error') .equals(true); }); + it('should report deleted indexes', function() { + let current = { + testung: { + 888111: { + testi : { "error" : false, "errorMessage" : "", "errorNum" : 0, "indexes" : [ { "id" : "0", "type" : "primary", "fields" : [ "_key" ], "selectivityEstimate" : 1, "unique" : true, "sparse" : false }, + { + "fields": [ + "test" + ], + "id": "testi", + "selectivityEstimate": 1, + "sparse": false, + "type": "hash", + "unique": false + } + ], "servers" : [ "repltest" ] } + }, + } + }; + + let props = { planId: '888111' }; + let collection = db._create('testi', props); + collection.assumeLeadership(); + let result = cluster.updateCurrentForCollections({}, current); + expect(result).to.be.an('object'); + expect(Object.keys(result)).to.have.lengthOf(1); + expect(result).to.have.property('/arango/Current/Collections/testung/888111/testi') + .that.have.property('op', 'set'); + expect(result).to.have.property('/arango/Current/Collections/testung/888111/testi') + .that.has.deep.property('new.indexes') + .that.has.lengthOf(1); + }); + it('should report added indexes', function() { + let current = { + testung: { + 888111: { + testi : { "error" : false, "errorMessage" : "", "errorNum" : 0, "indexes" : [ { "id" : "0", "type" : "primary", "fields" : [ "_key" ], "selectivityEstimate" : 1, "unique" : true, "sparse" : false }, + ], "servers" : [ "repltest" ] } + }, + } + }; + + let props = { planId: '888111' }; + let collection = db._create('testi', props); + collection.assumeLeadership(); + collection.ensureIndex({type: "hash", fields: ["test"]}); + let result = cluster.updateCurrentForCollections({}, current); + expect(result).to.be.an('object'); + expect(Object.keys(result)).to.have.lengthOf(1); + expect(result).to.have.property('/arango/Current/Collections/testung/888111/testi') + .that.have.property('op', 'set'); + expect(result).to.have.property('/arango/Current/Collections/testung/888111/testi') + .that.has.deep.property('new.indexes') + .that.has.lengthOf(2); + }); }); });