mirror of https://gitee.com/bigwinds/arangodb
Fix issue with colleciton/view name conflict checking in cluster. (#6779)
This commit is contained in:
parent
c68c1b7113
commit
ff2ce5c846
|
@ -230,8 +230,8 @@ void ClusterInfo::cleanup() {
|
|||
if (theInstance == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
MUTEX_LOCKER(mutexLocker, theInstance->_planProt.mutex);
|
||||
|
||||
MUTEX_LOCKER(mutexLocker, theInstance->_planProt.mutex);
|
||||
|
||||
TRI_ASSERT(theInstance->_newPlannedViews.empty()); // only non-empty during loadPlan()
|
||||
theInstance->_plannedViews.clear();
|
||||
|
@ -1561,16 +1561,29 @@ int ClusterInfo::createCollectionCoordinator(std::string const& databaseName,
|
|||
{
|
||||
// check if a collection with the same name is already planned
|
||||
loadPlan();
|
||||
|
||||
READ_LOCKER(readLocker, _planProt.lock);
|
||||
AllCollections::const_iterator it = _plannedCollections.find(databaseName);
|
||||
if (it != _plannedCollections.end()) {
|
||||
DatabaseCollections::const_iterator it2 = (*it).second.find(name);
|
||||
{
|
||||
AllCollections::const_iterator it = _plannedCollections.find(databaseName);
|
||||
if (it != _plannedCollections.end()) {
|
||||
DatabaseCollections::const_iterator it2 = (*it).second.find(name);
|
||||
|
||||
if (it2 != (*it).second.end()) {
|
||||
// collection already exists!
|
||||
events::CreateCollection(name, TRI_ERROR_ARANGO_DUPLICATE_NAME);
|
||||
return TRI_ERROR_ARANGO_DUPLICATE_NAME;
|
||||
if (it2 != (*it).second.end()) {
|
||||
// collection already exists!
|
||||
events::CreateCollection(name, TRI_ERROR_ARANGO_DUPLICATE_NAME);
|
||||
return TRI_ERROR_ARANGO_DUPLICATE_NAME;
|
||||
}
|
||||
}
|
||||
} {
|
||||
// check against planned views as well
|
||||
AllViews::const_iterator it = _plannedViews.find(databaseName);
|
||||
if (it != _plannedViews.end()) {
|
||||
DatabaseViews::const_iterator it2 = (*it).second.find(name);
|
||||
|
||||
if (it2 != (*it).second.end()) {
|
||||
// view already exists!
|
||||
events::CreateView(name, TRI_ERROR_ARANGO_DUPLICATE_NAME);
|
||||
return TRI_ERROR_ARANGO_DUPLICATE_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2073,17 +2086,29 @@ int ClusterInfo::createViewCoordinator(
|
|||
{
|
||||
// check if a view with the same name is already planned
|
||||
loadPlan();
|
||||
|
||||
READ_LOCKER(readLocker, _planProt.lock);
|
||||
AllViews::const_iterator it = _plannedViews.find(databaseName);
|
||||
{
|
||||
AllViews::const_iterator it = _plannedViews.find(databaseName);
|
||||
if (it != _plannedViews.end()) {
|
||||
DatabaseViews::const_iterator it2 = (*it).second.find(name);
|
||||
|
||||
if (it != _plannedViews.end()) {
|
||||
DatabaseViews::const_iterator it2 = (*it).second.find(name);
|
||||
if (it2 != (*it).second.end()) {
|
||||
// view already exists!
|
||||
events::CreateView(name, TRI_ERROR_ARANGO_DUPLICATE_NAME);
|
||||
return TRI_ERROR_ARANGO_DUPLICATE_NAME;
|
||||
}
|
||||
}
|
||||
} {
|
||||
// check against planned collections as well
|
||||
AllCollections::const_iterator it = _plannedCollections.find(databaseName);
|
||||
if (it != _plannedCollections.end()) {
|
||||
DatabaseCollections::const_iterator it2 = (*it).second.find(name);
|
||||
|
||||
if (it2 != (*it).second.end()) {
|
||||
// view already exists!
|
||||
events::CreateView(name, TRI_ERROR_ARANGO_DUPLICATE_NAME);
|
||||
return TRI_ERROR_ARANGO_DUPLICATE_NAME;
|
||||
if (it2 != (*it).second.end()) {
|
||||
// collection already exists!
|
||||
events::CreateCollection(name, TRI_ERROR_ARANGO_DUPLICATE_NAME);
|
||||
return TRI_ERROR_ARANGO_DUPLICATE_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3172,11 +3197,11 @@ std::string ClusterInfo::getServerAdvertisedEndpoint(ServerID const& serverID) {
|
|||
|
||||
// _serversAliases is a map-type <Alias, ServerID>
|
||||
auto ita = _serverAliases.find(serverID_);
|
||||
|
||||
|
||||
if (ita != _serverAliases.end()) {
|
||||
serverID_ = (*ita).second;
|
||||
}
|
||||
|
||||
|
||||
// _serversAliases is a map-type <ServerID, std::string>
|
||||
auto it = _serverAdvertisedEndpoints.find(serverID_);
|
||||
if (it != _serverAdvertisedEndpoints.end()) {
|
||||
|
|
|
@ -44,69 +44,6 @@ function ViewSuite () {
|
|||
'use strict';
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad name (empty)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadNameEmpty : function () {
|
||||
try {
|
||||
db._createView("", "arangosearch", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_ILLEGAL_NAME.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad type (none)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadTypeNone : function () {
|
||||
try {
|
||||
db._createView("abc");
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad type (empty)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadTypeEmpty : function () {
|
||||
try {
|
||||
db._createView("abc", "", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad type (non-existent)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadTypeMissing : function () {
|
||||
try {
|
||||
db._createView("abc", "bogus", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad name (duplicate)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadNameDuplicate : function () {
|
||||
try {
|
||||
db._createView("abc", "arangosearch", {});
|
||||
db._createView("abc", "arangosearch", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_DUPLICATE_NAME.code, err.errorNum);
|
||||
var abc = db._view("abc");
|
||||
abc.drop();
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief rename (duplicate)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -140,98 +77,6 @@ function ViewSuite () {
|
|||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get non-existent
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingGetMissing : function () {
|
||||
var abc = db._view("abc");
|
||||
assertEqual(abc, null);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief modify with unacceptable properties
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingModifyUnacceptable : function () {
|
||||
var abc = db._createView("abc", "arangosearch", { "consolidationIntervalMsec": 17 });
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.properties().consolidationIntervalMsec, 17);
|
||||
abc.properties({ "bogus": "junk", "consolidationIntervalMsec": 7 });
|
||||
assertEqual(abc.properties().consolidationIntervalMsec, 7);
|
||||
abc.drop();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create a couple views and then drop them
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testAddDrop : function () {
|
||||
db._dropView("abc");
|
||||
db._dropView("def");
|
||||
db._createView("abc", "arangosearch", { "consolidationIntervalMsec": 10 });
|
||||
db._createView("def", "arangosearch", { "consolidationIntervalMsec": 3 });
|
||||
var abc = db._view("abc");
|
||||
var def = db._view("def");
|
||||
var propA = abc.properties();
|
||||
var propD = def.properties();
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.type(), "arangosearch");
|
||||
assertEqual(propA.consolidationIntervalMsec, 10);
|
||||
assertEqual(def.name(), "def");
|
||||
assertEqual(def.type(), "arangosearch");
|
||||
assertEqual(propD.consolidationIntervalMsec, 3);
|
||||
abc.drop();
|
||||
def.drop();
|
||||
assertNull(db._view("abc"));
|
||||
assertNull(db._view("def"));
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief retrieve empty list of views
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testEmptyList : function () {
|
||||
var views = db._views();
|
||||
assertTrue(Array.isArray(views));
|
||||
assertEqual(views.length, 0);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief retrieve short list of views
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testShortList : function () {
|
||||
var abc = db._createView("abc", "arangosearch", {});
|
||||
assertEqual(abc.name(), "abc");
|
||||
var def = db._createView("def", "arangosearch", {});
|
||||
assertEqual(def.name(), "def");
|
||||
var views = db._views();
|
||||
assertTrue(Array.isArray(views));
|
||||
assertEqual(views.length, 2);
|
||||
assertEqual(abc.name(), views[0].name());
|
||||
assertEqual(def.name(), views[1].name());
|
||||
abc.drop();
|
||||
def.drop();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief modify properties
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testModifyProperties : function () {
|
||||
var abc = db._createView("abc", "arangosearch", { "consolidationIntervalMsec": 10 });
|
||||
var props = abc.properties();
|
||||
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.type(), "arangosearch");
|
||||
assertEqual(props.consolidationIntervalMsec, 10);
|
||||
|
||||
abc.properties({ "consolidationIntervalMsec": 7 });
|
||||
abc = db._view("abc");
|
||||
props = abc.properties();
|
||||
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.type(), "arangosearch");
|
||||
assertEqual(props.consolidationIntervalMsec, 7);
|
||||
|
||||
abc.drop();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief rename view
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
/*jshint globalstrict:false, strict:false */
|
||||
/*global assertEqual, assertTrue, assertEqual, assertNull, assertTypeOf, assertNotEqual, fail */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test the view interface
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2012 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 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Daniel H. Larkin
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var jsunity = require("jsunity");
|
||||
var arangodb = require("@arangodb");
|
||||
var ArangoView = arangodb.ArangoView;
|
||||
var testHelper = require("@arangodb/test-helper").Helper;
|
||||
var db = arangodb.db;
|
||||
var ERRORS = arangodb.errors;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite: view
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function ViewSuite () {
|
||||
'use strict';
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad name (empty)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadNameEmpty : function () {
|
||||
try {
|
||||
db._createView("", "arangosearch", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_ILLEGAL_NAME.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad type (none)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadTypeNone : function () {
|
||||
try {
|
||||
db._createView("abc");
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad type (empty)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadTypeEmpty : function () {
|
||||
try {
|
||||
db._createView("abc", "", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad type (non-existent)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadTypeMissing : function () {
|
||||
try {
|
||||
db._createView("abc", "bogus", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad name (duplicate)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadNameDuplicate : function () {
|
||||
try {
|
||||
db._createView("abc", "arangosearch", {});
|
||||
db._createView("abc", "arangosearch", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_DUPLICATE_NAME.code, err.errorNum);
|
||||
var abc = db._view("abc");
|
||||
abc.drop();
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief bad name (conflict with collection)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingBadNameDuplicateOfCollection : function () {
|
||||
try {
|
||||
db._create("abc");
|
||||
db._createView("abc", "arangosearch", {});
|
||||
fail();
|
||||
} catch (err) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_DUPLICATE_NAME.code, err.errorNum);
|
||||
var abc = db._collection("abc");
|
||||
abc.drop();
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get non-existent
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingGetMissing : function () {
|
||||
var abc = db._view("abc");
|
||||
assertEqual(abc, null);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief modify with unacceptable properties
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testErrorHandlingModifyUnacceptable : function () {
|
||||
var abc = db._createView("abc", "arangosearch", { "consolidationIntervalMsec": 17 });
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.properties().consolidationIntervalMsec, 17);
|
||||
abc.properties({ "bogus": "junk", "consolidationIntervalMsec": 7 });
|
||||
assertEqual(abc.properties().consolidationIntervalMsec, 7);
|
||||
abc.drop();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create a couple views and then drop them
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testAddDrop : function () {
|
||||
db._dropView("abc");
|
||||
db._dropView("def");
|
||||
db._createView("abc", "arangosearch", { "consolidationIntervalMsec": 10 });
|
||||
db._createView("def", "arangosearch", { "consolidationIntervalMsec": 3 });
|
||||
var abc = db._view("abc");
|
||||
var def = db._view("def");
|
||||
var propA = abc.properties();
|
||||
var propD = def.properties();
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.type(), "arangosearch");
|
||||
assertEqual(propA.consolidationIntervalMsec, 10);
|
||||
assertEqual(def.name(), "def");
|
||||
assertEqual(def.type(), "arangosearch");
|
||||
assertEqual(propD.consolidationIntervalMsec, 3);
|
||||
abc.drop();
|
||||
def.drop();
|
||||
assertNull(db._view("abc"));
|
||||
assertNull(db._view("def"));
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief retrieve empty list of views
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testEmptyList : function () {
|
||||
var views = db._views();
|
||||
assertTrue(Array.isArray(views));
|
||||
assertEqual(views.length, 0);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief retrieve short list of views
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testShortList : function () {
|
||||
var abc = db._createView("abc", "arangosearch", {});
|
||||
assertEqual(abc.name(), "abc");
|
||||
var def = db._createView("def", "arangosearch", {});
|
||||
assertEqual(def.name(), "def");
|
||||
var views = db._views();
|
||||
assertTrue(Array.isArray(views));
|
||||
assertEqual(views.length, 2);
|
||||
assertEqual(abc.name(), views[0].name());
|
||||
assertEqual(def.name(), views[1].name());
|
||||
abc.drop();
|
||||
def.drop();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief modify properties
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
testModifyProperties : function () {
|
||||
var abc = db._createView("abc", "arangosearch", { "consolidationIntervalMsec": 10 });
|
||||
var props = abc.properties();
|
||||
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.type(), "arangosearch");
|
||||
assertEqual(props.consolidationIntervalMsec, 10);
|
||||
|
||||
abc.properties({ "consolidationIntervalMsec": 7 });
|
||||
abc = db._view("abc");
|
||||
props = abc.properties();
|
||||
|
||||
assertEqual(abc.name(), "abc");
|
||||
assertEqual(abc.type(), "arangosearch");
|
||||
assertEqual(props.consolidationIntervalMsec, 7);
|
||||
|
||||
abc.drop();
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the test suites
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(ViewSuite);
|
||||
|
||||
return jsunity.done();
|
Loading…
Reference in New Issue