From b6df2002e6d252a16a39b790dcce072967fa7e82 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Wed, 26 Apr 2017 10:13:35 +0200 Subject: [PATCH 1/2] Port 3.1 fixes to devel, update tests. --- .../cluster-sync-test-noncluster-spec.js | 64 +++++++++++++++++-- 1 file changed, 58 insertions(+), 6 deletions(-) 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 dab1433a8d..6c54731718 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 @@ -805,6 +805,58 @@ describe('Cluster sync', function() { db._useDatabase('test'); expect(db._collection('s100001').isLeader()).to.equal(true); }); + it('should kill any unplanned server from current', function() { + let collection = db._create('s100001'); + collection.assumeLeadership(); + collection.addFollower('test'); + collection.addFollower('test2'); + let plan = { + test: { + "100001": { + "deleted": false, + "doCompact": true, + "id": "100001", + "indexBuckets": 8, + "indexes": [ + { + "fields": [ + "_key" + ], + "id": "0", + "sparse": false, + "type": "primary", + "unique": true + } + ], + "isSystem": false, + "isVolatile": false, + "journalSize": 1048576, + "keyOptions": { + "allowUserKeys": true, + "type": "traditional" + }, + "name": "testi", + "numberOfShards": 1, + "replicationFactor": 2, + "shardKeys": [ + "_key" + ], + "shards": { + "s100001": [ + "repltest", + "test2", + ] + }, + "status": 2, + "type": 2, + "waitForSync": false + } + } + }; + cluster.executePlanForCollections(plan); + db._useDatabase('test'); + expect(collection.getFollowers()).to.deep.equal(['test2']); + }); }); describe('Update current database', function() { beforeEach(function() { @@ -972,7 +1024,7 @@ describe('Cluster sync', function() { let collection = db._create('testi', props); let current = { }; - let result = cluster.updateCurrentForCollections({}, current); + let result = cluster.updateCurrentForCollections({}, {}, current); expect(Object.keys(result)).to.have.lengthOf(0); }); it('should not delete any collections for which we are not a leader locally', function() { @@ -983,7 +1035,7 @@ describe('Cluster sync', function() { }, } }; - let result = cluster.updateCurrentForCollections({}, current); + let result = cluster.updateCurrentForCollections({}, {}, current); expect(Object.keys(result)).to.have.lengthOf(0); }); it('should resign leadership for which we are no more leader locally', function() { @@ -996,7 +1048,7 @@ describe('Cluster sync', function() { }, } }; - let result = cluster.updateCurrentForCollections({}, current); + 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/servers') @@ -1016,7 +1068,7 @@ describe('Cluster sync', function() { }, } }; - let result = cluster.updateCurrentForCollections({}, current); + 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') @@ -1033,7 +1085,7 @@ describe('Cluster sync', function() { }, } }; - let result = cluster.updateCurrentForCollections({}, current); + 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') @@ -1051,7 +1103,7 @@ describe('Cluster sync', function() { }, } }; - let result = cluster.updateCurrentForCollections({}, current); + 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') From 96615132e45737dbc5a74e78bfd9aff838be6fc6 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Wed, 26 Apr 2017 10:19:05 +0200 Subject: [PATCH 2/2] Port 3.1 fixes to devel, new test. --- .../shell-distributeShardsLike-cluster.js | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 js/server/tests/shell/shell-distributeShardsLike-cluster.js diff --git a/js/server/tests/shell/shell-distributeShardsLike-cluster.js b/js/server/tests/shell/shell-distributeShardsLike-cluster.js new file mode 100644 index 0000000000..36ea0f3059 --- /dev/null +++ b/js/server/tests/shell/shell-distributeShardsLike-cluster.js @@ -0,0 +1,95 @@ +/*jshint globalstrict:false, strict:false */ +/*global fail, assertEqual */ + +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2017 ArangoDB GmbH, Cologne, Germany +/// Copyright 2010-2017 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Max Neunhoeffer +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); +var arangodb = require("@arangodb"); +var errors = require("internal").errors; + +var db = arangodb.db; + +function DistributeShardsLikeSuite() { + 'use strict'; + var cn1 = "UnitTestsDistributeShardsLike1"; + var cn2 = "UnitTestsDistributeShardsLike2"; + var cn3 = "UnitTestsDistributeShardsLike3"; + + return { + setUp: function() { + db._drop(cn2); + db._drop(cn3); + db._drop(cn1); + }, + + tearDown: function() { + db._drop(cn2); + db._drop(cn3); + db._drop(cn1); + }, + + testPointToEmpty: function() { + try { + db._create(cn1, {numberOfShards: 2, distributeShardsLike: cn2}); + fail(); + } + catch (err) { + require("internal").print("FUXX:", JSON.stringify(err)); + assertEqual(errors.ERROR_CLUSTER_UNKNOWN_DISTRIBUTESHARDSLIKE.code, + err.errorNum); + } + }, + + testAvoidChain: function() { + db._create(cn1, {numberOfShards: 2}); + db._create(cn2, {numberOfShards: 2, distributeShardsLike: cn1}); + try { + db._create(cn3, {numberOfShards: 2, distributeShardsLike: cn2}); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_CLUSTER_CHAIN_OF_DISTRIBUTESHARDSLIKE.code, + err.errorNum); + } + }, + + testPreventDrop: function() { + db._create(cn1, {numberOfShards: 2}); + db._create(cn2, {numberOfShards: 2, distributeShardsLike: cn1}); + db._create(cn3, {numberOfShards: 2, distributeShardsLike: cn1}); + try { + db._drop(cn1); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_CLUSTER_MUST_NOT_DROP_COLL_OTHER_DISTRIBUTESHARDSLIKE.code, + err.errorNum); + } + } + }; +} + +jsunity.run(DistributeShardsLikeSuite); +return jsunity.done(); +