1
0
Fork 0

add alternative to ClusterInfo::getCollection() that doesn't throw (#7339)

This commit is contained in:
Wilfried Goesgens 2018-11-20 16:05:57 +01:00 committed by Jan
parent 8703615acd
commit 05a7d4e96e
18 changed files with 172 additions and 224 deletions

View File

@ -1229,8 +1229,8 @@ AstNode* Ast::createNodeWithCollections(AstNode const* collections, arangodb::Co
// We want to tolerate that a collection name is given here
// which does not exist, if only for some unit tests:
try {
auto coll = ci->getCollection(_query->vocbase().name(), name);
auto coll = ci->getCollectionNT(_query->vocbase().name(), name);
if (coll != nullptr) {
auto names = coll->realNames();
for (auto const& n : names) {
@ -1238,7 +1238,6 @@ AstNode* Ast::createNodeWithCollections(AstNode const* collections, arangodb::Co
LogicalDataSource::Category const* shardsCategory = injectDataSourceInQuery(*_query, resolver, AccessMode::Type::READ, false, shardsNameRef);
TRI_ASSERT(shardsCategory == LogicalCollection::category());
}
} catch (...) {
}
}
}
@ -1268,8 +1267,8 @@ AstNode* Ast::createNodeCollectionList(AstNode const* edgeCollections, Collectio
LogicalDataSource::Category const* category = injectDataSourceInQuery(*_query, resolver, AccessMode::Type::READ, false, nameRef);
if (category == LogicalCollection::category()) {
if (ss->isCoordinator()) {
try {
auto c = ci->getCollection(_query->vocbase().name(), name);
auto c = ci->getCollectionNT(_query->vocbase().name(), name);
if (c != nullptr) {
auto const& names = c->realNames();
for (auto const& n : names) {
@ -1277,9 +1276,7 @@ AstNode* Ast::createNodeCollectionList(AstNode const* edgeCollections, Collectio
LogicalDataSource::Category const* shardsCategory = injectDataSourceInQuery(*_query, resolver, AccessMode::Type::READ, false, shardsNameRef);
TRI_ASSERT(shardsCategory == LogicalCollection::category());
}
} catch (...) {
// TODO Should we really not react?
}
} // else { TODO Should we really not react? }
}
} else {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_COLLECTION_TYPE_MISMATCH, nameRef.toString() + " is required to be a collection.");
@ -1729,14 +1726,13 @@ void Ast::injectBindParameters(
// We want to tolerate that a collection name is given here
// which does not exist, if only for some unit tests:
try {
auto coll = ci->getCollection(_query->vocbase().name(), name);
auto coll = ci->getCollectionNT(_query->vocbase().name(), name);
if (coll != nullptr) {
auto names = coll->realNames();
for (auto const& n : names) {
_query->addCollection(n, isExclusive ? AccessMode::Type::EXCLUSIVE : AccessMode::Type::WRITE);
}
} catch (...) {
}
}
}
@ -3832,16 +3828,14 @@ AstNode* Ast::createNodeCollectionNoValidation(StringRef const& name,
auto ci = ClusterInfo::instance();
// We want to tolerate that a collection name is given here
// which does not exist, if only for some unit tests:
try {
auto coll = ci->getCollection(_query->vocbase().name(), name.toString());
auto coll = ci->getCollectionNT(_query->vocbase().name(), name.toString());
if (coll != nullptr) {
if (coll->isSmart()) {
// add names of underlying smart-edge collections
for (auto const& n : coll->realNames()) {
_query->addCollection(n, accessType);
}
}
} catch (...) {
}
}
@ -3876,14 +3870,13 @@ void Ast::extractCollectionsFromGraph(AstNode const* graphNode) {
auto ci = ClusterInfo::instance();
for (const auto& n : eColls) {
try {
auto c = ci->getCollection(_query->vocbase().name(), n);
if (c != nullptr) {
auto names = c->realNames();
for (auto const& name : names) {
_query->addCollection(name, AccessMode::Type::READ);
}
} catch (...) {
}
}
}

View File

@ -1016,6 +1016,18 @@ void ClusterInfo::loadCurrent() {
std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
DatabaseID const& databaseID, CollectionID const& collectionID) {
auto c = getCollectionNT(databaseID, collectionID);
if (c == nullptr) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
getCollectionNotFoundMsg(collectionID, databaseID));
}
else {
return c;
}
}
std::shared_ptr<LogicalCollection> ClusterInfo::getCollectionNT(
DatabaseID const& databaseID, CollectionID const& collectionID) {
int tries = 0;
if (!_planProt.isValid) {
@ -1046,9 +1058,12 @@ std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
// must load collections outside the lock
loadPlan();
}
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
"Collection not found: " + collectionID + " in database " + databaseID);
return nullptr;
}
std::string ClusterInfo::getCollectionNotFoundMsg (
DatabaseID const& databaseID, CollectionID const& collectionID) {
return "Collection not found: " + collectionID + " in database " + databaseID;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -313,15 +313,31 @@ class ClusterInfo {
//////////////////////////////////////////////////////////////////////////////
/// @brief ask about a collection
/// If it is not found in the cache, the cache is reloaded once. The second
/// argument can be a collection ID or a collection name (both cluster-wide).
/// if the collection is not found afterwards, this method will throw an
/// exception
/// Throwing version, deprecated.
//////////////////////////////////////////////////////////////////////////////
virtual std::shared_ptr<LogicalCollection> getCollection(DatabaseID const&,
CollectionID const&);
//////////////////////////////////////////////////////////////////////////////
/// @brief ask about a collection
/// If it is not found in the cache, the cache is reloaded once. The second
/// argument can be a collection ID or a collection name (both cluster-wide).
/// if the collection is not found afterwards, this method will throw an
/// exception
/// will not throw but return nullptr if the collection isn't found.
//////////////////////////////////////////////////////////////////////////////
virtual std::shared_ptr<LogicalCollection> getCollectionNT(DatabaseID const&,
CollectionID const&);
//////////////////////////////////////////////////////////////////////////////
/// Format error message for TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND
//////////////////////////////////////////////////////////////////////////////
static std::string getCollectionNotFoundMsg(DatabaseID const&,
CollectionID const&);
//////////////////////////////////////////////////////////////////////////////
/// @brief ask about all collections of a database
//////////////////////////////////////////////////////////////////////////////

View File

@ -726,12 +726,10 @@ int revisionOnCoordinator(std::string const& dbname,
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
rid = 0;
@ -799,12 +797,10 @@ int warmupOnCoordinator(std::string const& dbname,
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, cid);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, cid);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
// If we get here, the sharding attributes are not only _key, therefore
// we have to contact everybody:
@ -846,12 +842,10 @@ int figuresOnCoordinator(std::string const& dbname, std::string const& collname,
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
// If we get here, the sharding attributes are not only _key, therefore
// we have to contact everybody:
@ -917,12 +911,10 @@ int countOnCoordinator(std::string const& dbname, std::string const& cname,
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, cname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, cname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
auto shards = collinfo->shardIds();
std::vector<ClusterCommRequest> requests;
@ -982,12 +974,10 @@ int selectivityEstimatesOnCoordinator(
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
auto shards = collinfo->shardIds();
std::vector<ClusterCommRequest> requests;
@ -1107,12 +1097,10 @@ Result createDocumentOnCoordinator(
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
auto collid = std::to_string(collinfo->id());
@ -1253,12 +1241,10 @@ int deleteDocumentOnCoordinator(
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
bool useDefaultSharding = collinfo->usesDefaultShardKeys();
auto collid = std::to_string(collinfo->id());
bool useMultiple = slice.isArray();
@ -1486,12 +1472,10 @@ int truncateCollectionOnCoordinator(std::string const& dbname,
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
// Some stuff to prepare cluster-intern requests:
// We have to contact everybody:
@ -1545,12 +1529,10 @@ int getDocumentOnCoordinator(
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
auto collid = std::to_string(collinfo->id());

View File

@ -673,10 +673,8 @@ bool SynchronizeShard::first() {
return false;
}
std::shared_ptr<LogicalCollection> ci;
try { // ci->getCollection can throw
ci = clusterInfo->getCollection(database, planId);
} catch(...) {
auto ci = clusterInfo->getCollectionNT(database, planId);
if (ci == nullptr) {
auto const endTime = system_clock::now();
std::stringstream msg;
msg << "exception in getCollection, " << database << "/"
@ -688,7 +686,6 @@ bool SynchronizeShard::first() {
_result.reset(TRI_ERROR_FAILED, msg.str());
return false;
}
TRI_ASSERT(ci != nullptr);
std::string const cid = std::to_string(ci->id());
std::shared_ptr<CollectionInfoCurrent> cic =

View File

@ -653,9 +653,13 @@ static void JS_GetCollectionInfoClusterInfo(
"getCollectionInfo(<database-id>, <collection-id>)");
}
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
TRI_ASSERT(ci != nullptr);
auto databaseID = TRI_ObjectToString(args[0]);
auto collectionID = TRI_ObjectToString(args[1]);
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollectionNT(databaseID, collectionID);
if (ci == nullptr) {
TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
ClusterInfo::getCollectionNotFoundMsg(databaseID, collectionID));
}
std::unordered_set<std::string> ignoreKeys{"allowUserKeys",
"avoidServers",
@ -720,9 +724,13 @@ static void JS_GetCollectionInfoCurrentClusterInfo(
ShardID shardID = TRI_ObjectToString(args[2]);
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
TRI_ASSERT(ci != nullptr);
auto databaseID = TRI_ObjectToString(args[0]);
auto collectionID = TRI_ObjectToString(args[1]);
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollectionNT(databaseID, collectionID);
if (ci == nullptr) {
TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
ClusterInfo::getCollectionNotFoundMsg(databaseID, collectionID));
}
v8::Handle<v8::Object> result = v8::Object::New(isolate);
// First some stuff from Plan for which Current does not make sense:
@ -841,7 +849,12 @@ static void JS_GetResponsibleShardClusterInfo(
CollectionID collectionId = TRI_ObjectToString(args[0]);
auto& vocbase = GetContextVocBase(isolate);
auto ci = ClusterInfo::instance();
auto collInfo = ci->getCollection(vocbase.name(), collectionId);
auto collInfo = ci->getCollectionNT(vocbase.name(), collectionId);
if (collInfo == nullptr) {
TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
ClusterInfo::getCollectionNotFoundMsg(vocbase.name(), collectionId));
}
bool usesDefaultShardingAttributes;
res = collInfo->getResponsibleShard(builder.slice(), documentIsComplete, shardId, usesDefaultShardingAttributes);

View File

@ -98,9 +98,11 @@ int ClusterTransactionCollection::use(int nestingLevel) {
return TRI_ERROR_SHUTTING_DOWN;
}
try {
_collection = ci->getCollection(_transaction->vocbase().name(), std::to_string(_cid));
if (_collection) {
_collection = ci->getCollectionNT(_transaction->vocbase().name(), std::to_string(_cid));
if (_collection == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
if (!_transaction->hasHint(transaction::Hints::Hint::LOCK_NEVER) &&
!_transaction->hasHint(transaction::Hints::Hint::NO_USAGE_LOCK)) {
// use and usage-lock
@ -108,18 +110,6 @@ int ClusterTransactionCollection::use(int nestingLevel) {
_usageLocked = true;
}
}
} catch(...) {}
if (_collection == nullptr) {
int res = TRI_errno();
if (res == TRI_ERROR_ARANGO_COLLECTION_NOT_LOADED) {
return res;
}
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
}
TRI_ASSERT(_collection != nullptr);
if (AccessMode::isWriteOrExclusive(_accessType) && !isLocked()) {
// r/w lock the collection

View File

@ -53,13 +53,10 @@ int rotateActiveJournalOnAllDBServers(std::string const& dbname,
}
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
auto collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
std::string const baseUrl = "/_db/" + basics::StringUtils::urlEncode(dbname)
+ "/_api/collection/";

View File

@ -52,14 +52,10 @@ Result recalculateCountsOnAllDBServers(std::string const& dbname,
}
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
auto collinfo = ci->getCollectionNT(dbname, collname);
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
std::string const baseUrl = "/_db/" + basics::StringUtils::urlEncode(dbname)
+ "/_api/collection/";

View File

@ -256,15 +256,12 @@ std::shared_ptr<LogicalCollection> GraphManager::getCollectionByName(
const TRI_vocbase_t& vocbase, std::string const& name) {
if (!name.empty()) {
// try looking up the collection by name then
try {
if (arangodb::ServerState::instance()->isRunningInCluster()) {
ClusterInfo* ci = ClusterInfo::instance();
return ci->getCollection(vocbase.name(), name);
return ci->getCollectionNT(vocbase.name(), name);
} else {
return vocbase.lookupCollection(name);
}
} catch (...) {
}
}
return nullptr;

View File

@ -57,18 +57,12 @@ RestStatus RestIndexHandler::execute() {
}
}
LogicalCollection* RestIndexHandler::collection(
std::string const& cName, std::shared_ptr<LogicalCollection>& coll) {
std::shared_ptr<LogicalCollection> RestIndexHandler::collection(std::string const& cName) {
if (!cName.empty()) {
if (ServerState::instance()->isCoordinator()) {
try {
coll = ClusterInfo::instance()->getCollection(_vocbase.name(), cName);
return coll.get();
} catch (...) {
}
return ClusterInfo::instance()->getCollectionNT(_vocbase.name(), cName);
} else {
return _vocbase.lookupCollection(cName).get();
return _vocbase.lookupCollection(cName);
}
}
@ -80,7 +74,6 @@ LogicalCollection* RestIndexHandler::collection(
// //////////////////////////////////////////////////////////////////////////////
RestStatus RestIndexHandler::getIndexes() {
std::shared_ptr<LogicalCollection> tmpColl;
std::vector<std::string> const& suffixes = _request->suffixes();
if (suffixes.empty()) {
// .............................................................................
@ -89,7 +82,7 @@ RestStatus RestIndexHandler::getIndexes() {
bool found = false;
std::string cName = _request->value("collection", found);
LogicalCollection* coll = collection(cName, tmpColl);
auto coll = collection(cName);
if (coll == nullptr) {
generateError(rest::ResponseCode::NOT_FOUND,
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
@ -103,7 +96,7 @@ RestStatus RestIndexHandler::getIndexes() {
bool withLinks = _request->parsedValue("withLinks", false);
VPackBuilder indexes;
Result res = methods::Indexes::getAll(coll, flags, withLinks, indexes);
Result res = methods::Indexes::getAll(coll.get(), flags, withLinks, indexes);
if (!res.ok()) {
generateError(rest::ResponseCode::BAD, res.errorNumber(),
res.errorMessage());
@ -132,7 +125,7 @@ RestStatus RestIndexHandler::getIndexes() {
// .............................................................................
std::string const& cName = suffixes[0];
LogicalCollection* coll = collection(cName, tmpColl);
auto coll = collection(cName);
if (coll == nullptr) {
generateError(rest::ResponseCode::NOT_FOUND,
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
@ -144,7 +137,7 @@ RestStatus RestIndexHandler::getIndexes() {
b.add(VPackValue(cName + TRI_INDEX_HANDLE_SEPARATOR_CHR + iid));
VPackBuilder output;
Result res = methods::Indexes::getIndex(coll, b.slice(), output);
Result res = methods::Indexes::getIndex(coll.get(), b.slice(), output);
if (res.ok()) {
VPackBuilder b;
b.openObject();
@ -184,8 +177,7 @@ RestStatus RestIndexHandler::createIndex() {
return RestStatus::DONE;
}
std::shared_ptr<LogicalCollection> tmpColl;
LogicalCollection* coll = collection(cName, tmpColl);
auto coll = collection(cName);
if (coll == nullptr) {
generateError(rest::ResponseCode::NOT_FOUND,
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
@ -202,7 +194,7 @@ RestStatus RestIndexHandler::createIndex() {
}
VPackBuilder output;
Result res = methods::Indexes::ensureIndex(coll, body, true, output);
Result res = methods::Indexes::ensureIndex(coll.get(), body, true, output);
if (res.ok()) {
VPackSlice created = output.slice().get("isNewlyCreated");
auto r = created.isBool() && created.getBool() ? rest::ResponseCode::CREATED
@ -240,8 +232,7 @@ RestStatus RestIndexHandler::dropIndex() {
}
std::string const& cName = suffixes[0];
std::shared_ptr<LogicalCollection> tmpColl;
LogicalCollection* coll = collection(cName, tmpColl);
auto coll = collection(cName);
if (coll == nullptr) {
generateError(rest::ResponseCode::NOT_FOUND,
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
@ -252,7 +243,7 @@ RestStatus RestIndexHandler::dropIndex() {
VPackBuilder idBuilder;
idBuilder.add(VPackValue(cName + TRI_INDEX_HANDLE_SEPARATOR_CHR + iid));
Result res = methods::Indexes::drop(coll, idBuilder.slice());
Result res = methods::Indexes::drop(coll.get(), idBuilder.slice());
if (res.ok()) {
VPackBuilder b;
b.openObject();

View File

@ -44,8 +44,7 @@ class RestIndexHandler : public arangodb::RestVocbaseBaseHandler {
RestStatus createIndex();
RestStatus dropIndex();
LogicalCollection* collection(std::string const& cName,
std::shared_ptr<LogicalCollection>& coll);
std::shared_ptr<LogicalCollection> collection(std::string const& cName);
};
}

View File

@ -1724,13 +1724,10 @@ Result RestReplicationHandler::processRestoreIndexesCoordinator(
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<LogicalCollection> col;
try {
col = ci->getCollection(dbName, name);
} catch (...) {
std::string errorMsg = "could not find collection '" + name + "'";
return {TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND, errorMsg};
std::shared_ptr<LogicalCollection> col = ci->getCollectionNT(dbName, name);
if (col == nullptr) {
return {TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
ClusterInfo::getCollectionNotFoundMsg(dbName, name)};
}
TRI_ASSERT(col != nullptr);

View File

@ -2696,10 +2696,8 @@ OperationResult transaction::Methods::countCoordinator(
}
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(vocbase().name(), collectionName);
} catch (...) {
auto collinfo = ci->getCollectionNT(vocbase().name(), collectionName);
if (collinfo == nullptr) {
return OperationResult(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
}

View File

@ -118,19 +118,11 @@ TRI_voc_cid_t CollectionNameResolver::getCollectionIdCluster(
// We have to look up the collection info:
auto* ci = ClusterInfo::instance();
try {
auto const cinfo = ci->getCollection(_vocbase.name(), name);
auto const cinfo = (ci) ? ci->getCollectionNT(_vocbase.name(), name) : nullptr;
if (cinfo) {
if (cinfo != nullptr) {
return cinfo->id();
}
} catch (basics::Exception const& ex) {
// FIXME by some reason 'ClusterInfo::getCollection' throws exception
// in case if collection is not found, ignore error
if (ex.code() != TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND) {
throw;
}
}
auto const vinfo = ci->getView(_vocbase.name(), name);
@ -149,18 +141,9 @@ std::shared_ptr<LogicalCollection> CollectionNameResolver::getCollectionStructCl
return getCollectionStruct(name);
}
try {
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
auto cinfo = ci->getCollection(_vocbase.name(), name);
TRI_ASSERT(cinfo != nullptr);
return cinfo;
} catch (...) {
}
return nullptr;
return (ci) ? ci->getCollectionNT(_vocbase.name(), name) : nullptr;
}
//////////////////////////////////////////////////////////////////////////////
@ -267,11 +250,10 @@ std::string CollectionNameResolver::getCollectionNameCluster(
int tries = 0;
while (tries++ < 2) {
try {
auto ci = ClusterInfo::instance()->getCollection(
auto ci = ClusterInfo::instance()->getCollectionNT(
_vocbase.name(), arangodb::basics::StringUtils::itoa(cid)
);
if (ci != nullptr) {
name = ci->name();
{
WRITE_LOCKER(locker, _idLock);
@ -279,7 +261,8 @@ std::string CollectionNameResolver::getCollectionNameCluster(
}
return name;
} catch (...) {
}
else {
// most likely collection not found. now try again
ClusterInfo::instance()->flush();
}
@ -315,19 +298,17 @@ std::string CollectionNameResolver::localNameLookup(TRI_voc_cid_t cid) const {
// DBserver case of a shard:
if (collection && collection->planId() != collection->id()) {
try {
collection = ClusterInfo::instance()->getCollection(
collection->vocbase().name(), std::to_string(collection->planId())
);
}
catch (...) {
return UNKNOWN;
}
collection = ClusterInfo::instance()->getCollectionNT(collection->vocbase().name(),
std::to_string(collection->planId()));
}
// can be empty, if collection unknown
return collection && !collection->name().empty()
? collection->name() : UNKNOWN;
if ((collection == nullptr) || (collection->name().empty())) {
return UNKNOWN;
}
else {
return collection->name();
}
}
std::shared_ptr<LogicalDataSource> CollectionNameResolver::getDataSource(
@ -374,17 +355,9 @@ std::shared_ptr<LogicalDataSource> CollectionNameResolver::getDataSource(
}
try {
try {
ptr = ci->getCollection(_vocbase.name(), nameOrId);
} catch (basics::Exception const& ex) {
// FIXME by some reason 'ClusterInfo::getCollection' throws exception
// in case if collection is not found, ignore error
if (ex.code() != TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND) {
throw;
}
}
ptr = (ci) ? ci->getCollectionNT(_vocbase.name(), nameOrId) : nullptr;
if (!ptr) {
if (ptr == nullptr) {
ptr = ci->getView(_vocbase.name(), nameOrId);
}
} catch (...) {

View File

@ -82,16 +82,10 @@ std::shared_ptr<arangodb::LogicalCollection> GetCollectionFromArgument(
v8::Handle<v8::Value> const val
) {
if (arangodb::ServerState::instance()->isCoordinator()) {
try {
auto* ci = arangodb::ClusterInfo::instance();
return ci
? ci->getCollection(vocbase.name(), TRI_ObjectToString(val)) : nullptr;
} catch (...) {
// NOOP
}
return nullptr; // not found
? ci->getCollectionNT(vocbase.name(), TRI_ObjectToString(val)) : nullptr;
}
// number
@ -2063,12 +2057,13 @@ static void JS_StatusVocbaseCol(
if (ServerState::instance()->isCoordinator()) {
auto& databaseName = collection->vocbase().name();
try {
auto ci = ClusterInfo::instance()->getCollection(
auto ci = ClusterInfo::instance()->getCollectionNT(
databaseName, std::to_string(collection->id())
);
if (ci != nullptr) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->status()));
} catch (...) {
}
else {
TRI_V8_RETURN(v8::Number::New(isolate, (int)TRI_VOC_COL_STATUS_DELETED));
}
}
@ -2144,12 +2139,13 @@ static void JS_TypeVocbaseCol(v8::FunctionCallbackInfo<v8::Value> const& args) {
if (ServerState::instance()->isCoordinator()) {
auto& databaseName = collection->vocbase().name();
try {
auto ci = ClusterInfo::instance()->getCollection(
auto ci = ClusterInfo::instance()->getCollectionNT(
databaseName, std::to_string(collection->id())
);
if (ci != nullptr) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->type()));
} catch (...) {
}
else {
TRI_V8_RETURN(v8::Number::New(isolate, (int)(collection->type())));
}
}

View File

@ -1396,19 +1396,14 @@ static void MapGetVocBase(v8::Local<v8::String> const name,
std::shared_ptr<arangodb::LogicalCollection> collection;
try {
if (ServerState::instance()->isCoordinator()) {
auto* ci = arangodb::ClusterInfo::instance();
collection = ci
? ci->getCollection(vocbase.name(), std::string(key)) : nullptr;
if (ci) {
collection = ci->getCollectionNT(vocbase.name(), std::string(key));
}
} else {
collection = vocbase.lookupCollection(std::string(key));
}
} catch (...) {
// do not propagate exception from here
TRI_V8_RETURN(v8::Handle<v8::Value>());
}
if (collection == nullptr) {
if (*key == '_') {

View File

@ -140,8 +140,9 @@ Result methods::Collections::lookup(TRI_vocbase_t* vocbase,
if (ServerState::instance()->isCoordinator()) {
try {
auto coll = ClusterInfo::instance()->getCollection(vocbase->name(), name);
auto coll = ClusterInfo::instance()->getCollectionNT(vocbase->name(), name);
if (coll) {
// check authentication after ensuring the collection exists
if (exec != nullptr &&
!exec->canUseCollection(vocbase->name(), coll->name(),
@ -150,11 +151,13 @@ Result methods::Collections::lookup(TRI_vocbase_t* vocbase,
"No access to collection '" + name + "'");
}
if (coll) {
func(coll);
return Result();
}
else {
return Result(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
}
} catch (basics::Exception const& ex) {
return Result(ex.code(), ex.what());
} catch (std::exception const& ex) {