mirror of https://gitee.com/bigwinds/arangodb
First current tests
This commit is contained in:
parent
d869325add
commit
b56621a01b
|
@ -1348,6 +1348,7 @@ static void JS_EnableSyncReplicationDebug(
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerState::instance()->setInitialized();
|
ServerState::instance()->setInitialized();
|
||||||
|
ServerState::instance()->setId("repltest");
|
||||||
AgencyComm::syncReplDebug = true;
|
AgencyComm::syncReplDebug = true;
|
||||||
TRI_V8_TRY_CATCH_END
|
TRI_V8_TRY_CATCH_END
|
||||||
}
|
}
|
||||||
|
|
|
@ -1197,25 +1197,28 @@ function executePlanForDatabases(plannedDatabases) {
|
||||||
// / @brief updateCurrentForDatabases
|
// / @brief updateCurrentForDatabases
|
||||||
// /////////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function updateCurrentForDatabases(localErrors, current) {
|
function updateCurrentForDatabases(localErrors, currentDatabases) {
|
||||||
let ourselves = global.ArangoServerState.id();
|
let ourselves = global.ArangoServerState.id();
|
||||||
|
|
||||||
function makeAddDatabaseAgencyOperation(payload, trx) {
|
function makeAddDatabaseAgencyOperation(payload) {
|
||||||
trx[0][curDatabases + payload.name + '/' + ourselves] =
|
let create = {};
|
||||||
|
create[curDatabases + payload.name + '/' + ourselves] =
|
||||||
{op: 'set', new: payload};
|
{op: 'set', new: payload};
|
||||||
|
return create;
|
||||||
};
|
};
|
||||||
|
|
||||||
function makeDropDatabaseAgencyOperation(name, trx) {
|
function makeDropDatabaseAgencyOperation(name) {
|
||||||
trx[0][curDatabases + name + '/' + ourselves] = {'op':'delete'};
|
let drop = {};
|
||||||
|
drop[curDatabases + name + '/' + ourselves] = {'op':'delete'};
|
||||||
|
return drop;
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = require('internal').db;
|
let db = require('internal').db;
|
||||||
db._useDatabase('_system');
|
db._useDatabase('_system');
|
||||||
|
|
||||||
let localDatabases = getLocalDatabases();
|
let localDatabases = getLocalDatabases();
|
||||||
let currentDatabases = current.Databases;
|
|
||||||
let name;
|
let name;
|
||||||
let trx = [{}]; // Here we collect all write operations
|
let trx = {}; // Here we collect all write operations
|
||||||
|
|
||||||
// Add entries that we have but that are not in Current:
|
// Add entries that we have but that are not in Current:
|
||||||
for (name in localDatabases) {
|
for (name in localDatabases) {
|
||||||
|
@ -1223,9 +1226,9 @@ function updateCurrentForDatabases(localErrors, current) {
|
||||||
if (!currentDatabases.hasOwnProperty(name) ||
|
if (!currentDatabases.hasOwnProperty(name) ||
|
||||||
!currentDatabases[name].hasOwnProperty(ourselves)) {
|
!currentDatabases[name].hasOwnProperty(ourselves)) {
|
||||||
console.debug("adding entry in Current for database '%s'", name);
|
console.debug("adding entry in Current for database '%s'", name);
|
||||||
makeAddDatabaseAgencyOperation({error: false, errorNum: 0, name: name,
|
trx = Object.assign(trx, makeAddDatabaseAgencyOperation({error: false, errorNum: 0, name: name,
|
||||||
id: localDatabases[name].id,
|
id: localDatabases[name].id,
|
||||||
errorMessage: ""}, trx);
|
errorMessage: ""}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1239,7 +1242,7 @@ function updateCurrentForDatabases(localErrors, current) {
|
||||||
if (currentDatabases[name].hasOwnProperty(ourselves)) {
|
if (currentDatabases[name].hasOwnProperty(ourselves)) {
|
||||||
// we are entered for a database that we don't have locally
|
// we are entered for a database that we don't have locally
|
||||||
console.debug("cleaning up entry for unknown database '%s'", name);
|
console.debug("cleaning up entry for unknown database '%s'", name);
|
||||||
makeDropDatabaseAgencyOperation(name, trx);
|
trx = Object.assign(trx, makeDropDatabaseAgencyOperation(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1247,12 +1250,10 @@ function updateCurrentForDatabases(localErrors, current) {
|
||||||
|
|
||||||
// Finally, report any errors that might have been produced earlier when
|
// Finally, report any errors that might have been produced earlier when
|
||||||
// we were trying to execute the Plan:
|
// we were trying to execute the Plan:
|
||||||
for (name in localErrors) {
|
Object.keys(localErrors).forEach(name => {
|
||||||
if (localErrors.hasOwnProperty(name)) {
|
console.debug("reporting error to Current about database '%s'", name);
|
||||||
console.debug("reporting error to Current about database '%s'", name);
|
trx = Object.assign(trx, makeAddDatabaseAgencyOperation(localErrors[name]));
|
||||||
makeAddDatabaseAgencyOperation(localErrors[name], trx);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return trx;
|
return trx;
|
||||||
}
|
}
|
||||||
|
@ -1268,7 +1269,8 @@ function migrateAnyServer(plan, current) {
|
||||||
// diff current and local and prepare agency transactions or whatever
|
// diff current and local and prepare agency transactions or whatever
|
||||||
// to update current. will report the errors created locally to the agency
|
// to update current. will report the errors created locally to the agency
|
||||||
let trx = updateCurrentForDatabases(localErrors, current);
|
let trx = updateCurrentForDatabases(localErrors, current);
|
||||||
if (Object.keys(trx[0]).length !== 0) {
|
if (Object.keys(trx).length !== 0) {
|
||||||
|
trx = [trx];
|
||||||
trx[0][curVersion] = {op: 'increment'};
|
trx[0][curVersion] = {op: 'increment'};
|
||||||
// TODO: reduce timeout when we can:
|
// TODO: reduce timeout when we can:
|
||||||
try {
|
try {
|
||||||
|
@ -1939,3 +1941,5 @@ exports.waitForSyncRepl = waitForSyncRepl;
|
||||||
|
|
||||||
exports.executePlanForDatabases = executePlanForDatabases;
|
exports.executePlanForDatabases = executePlanForDatabases;
|
||||||
exports.executePlanForCollections = executePlanForCollections;
|
exports.executePlanForCollections = executePlanForCollections;
|
||||||
|
exports.updateCurrentForDatabases = updateCurrentForDatabases;
|
||||||
|
exports.updateCurrentForCollections = updateCurrentForCollections;
|
||||||
|
|
|
@ -32,11 +32,11 @@ const expect = require('chai').expect;
|
||||||
const ArangoCollection = require('@arangodb/arango-collection').ArangoCollection;
|
const ArangoCollection = require('@arangodb/arango-collection').ArangoCollection;
|
||||||
|
|
||||||
describe('Cluster sync', function() {
|
describe('Cluster sync', function() {
|
||||||
describe('Databaseplan to local', function() {
|
before(function() {
|
||||||
before(function() {
|
require('@arangodb/sync-replication-debug').setup();
|
||||||
require('@arangodb/sync-replication-debug').setup();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
describe('Databaseplan to local', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
db._databases().forEach(database => {
|
db._databases().forEach(database => {
|
||||||
if (database !== '_system') {
|
if (database !== '_system') {
|
||||||
|
@ -141,7 +141,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 3,
|
"status": 3,
|
||||||
|
@ -192,7 +192,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -244,7 +244,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -419,7 +419,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
""
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -481,7 +481,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -531,7 +531,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"Möter": [
|
"Möter": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -579,7 +579,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 3,
|
"status": 3,
|
||||||
|
@ -627,7 +627,7 @@ describe('Cluster sync', function() {
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"the leader-leader",
|
"the leader-leader",
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -674,7 +674,7 @@ describe('Cluster sync', function() {
|
||||||
],
|
],
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -724,7 +724,7 @@ describe('Cluster sync', function() {
|
||||||
"shards": {
|
"shards": {
|
||||||
"s100001": [
|
"s100001": [
|
||||||
"old-leader",
|
"old-leader",
|
||||||
"",
|
"repltest",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"status": 2,
|
"status": 2,
|
||||||
|
@ -734,7 +734,7 @@ describe('Cluster sync', function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let errors = cluster.executePlanForCollections(plan);
|
let errors = cluster.executePlanForCollections(plan);
|
||||||
plan.test['100001'].shards['s100001'] = [""];
|
plan.test['100001'].shards['s100001'] = ["repltest"];
|
||||||
cluster.executePlanForCollections(plan);
|
cluster.executePlanForCollections(plan);
|
||||||
db._useDatabase('test');
|
db._useDatabase('test');
|
||||||
expect(db._collection('s100001').isLeader()).to.equal(true);
|
expect(db._collection('s100001').isLeader()).to.equal(true);
|
||||||
|
@ -749,9 +749,32 @@ describe('Cluster sync', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should report a new database', function() {
|
it('should report a new database', function() {
|
||||||
let Current = {
|
db._createDatabase('testi');
|
||||||
Databases: {},
|
let current = {
|
||||||
|
_system: {
|
||||||
|
repltest: {
|
||||||
|
id: 1,
|
||||||
|
name: '_system',
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
let result = cluster.updateCurrentForDatabases({}, current);
|
||||||
|
expect(result).to.have.property('/arango/Current/Databases/testi/repltest');
|
||||||
|
expect(result['/arango/Current/Databases/testi/repltest']).to.have.property('op', 'set');
|
||||||
|
expect(result['/arango/Current/Databases/testi/repltest']).to.have.deep.property('new.name', 'testi');
|
||||||
|
});
|
||||||
|
it('should not do anything if there is nothing to do', function() {
|
||||||
|
let current = {
|
||||||
|
_system: {
|
||||||
|
repltest: {
|
||||||
|
id: 1,
|
||||||
|
name: '_system',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let result = cluster.updateCurrentForDatabases({}, current);
|
||||||
|
|
||||||
|
expect(Object.keys(result)).to.have.lengthOf(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue