mirror of https://gitee.com/bigwinds/arangodb
add alternative to ClusterInfo::getCollection() that doesn't throw (#7339)
This commit is contained in:
parent
8703615acd
commit
05a7d4e96e
|
@ -1229,8 +1229,8 @@ AstNode* Ast::createNodeWithCollections(AstNode const* collections, arangodb::Co
|
||||||
|
|
||||||
// We want to tolerate that a collection name is given here
|
// We want to tolerate that a collection name is given here
|
||||||
// which does not exist, if only for some unit tests:
|
// which does not exist, if only for some unit tests:
|
||||||
try {
|
auto coll = ci->getCollectionNT(_query->vocbase().name(), name);
|
||||||
auto coll = ci->getCollection(_query->vocbase().name(), name);
|
if (coll != nullptr) {
|
||||||
auto names = coll->realNames();
|
auto names = coll->realNames();
|
||||||
|
|
||||||
for (auto const& n : names) {
|
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);
|
LogicalDataSource::Category const* shardsCategory = injectDataSourceInQuery(*_query, resolver, AccessMode::Type::READ, false, shardsNameRef);
|
||||||
TRI_ASSERT(shardsCategory == LogicalCollection::category());
|
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);
|
LogicalDataSource::Category const* category = injectDataSourceInQuery(*_query, resolver, AccessMode::Type::READ, false, nameRef);
|
||||||
if (category == LogicalCollection::category()) {
|
if (category == LogicalCollection::category()) {
|
||||||
if (ss->isCoordinator()) {
|
if (ss->isCoordinator()) {
|
||||||
try {
|
auto c = ci->getCollectionNT(_query->vocbase().name(), name);
|
||||||
auto c = ci->getCollection(_query->vocbase().name(), name);
|
if (c != nullptr) {
|
||||||
auto const& names = c->realNames();
|
auto const& names = c->realNames();
|
||||||
|
|
||||||
for (auto const& n : names) {
|
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);
|
LogicalDataSource::Category const* shardsCategory = injectDataSourceInQuery(*_query, resolver, AccessMode::Type::READ, false, shardsNameRef);
|
||||||
TRI_ASSERT(shardsCategory == LogicalCollection::category());
|
TRI_ASSERT(shardsCategory == LogicalCollection::category());
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} // else { TODO Should we really not react? }
|
||||||
// TODO Should we really not react?
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_COLLECTION_TYPE_MISMATCH, nameRef.toString() + " is required to be a collection.");
|
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
|
// We want to tolerate that a collection name is given here
|
||||||
// which does not exist, if only for some unit tests:
|
// which does not exist, if only for some unit tests:
|
||||||
try {
|
auto coll = ci->getCollectionNT(_query->vocbase().name(), name);
|
||||||
auto coll = ci->getCollection(_query->vocbase().name(), name);
|
if (coll != nullptr) {
|
||||||
auto names = coll->realNames();
|
auto names = coll->realNames();
|
||||||
|
|
||||||
for (auto const& n : names) {
|
for (auto const& n : names) {
|
||||||
_query->addCollection(n, isExclusive ? AccessMode::Type::EXCLUSIVE : AccessMode::Type::WRITE);
|
_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();
|
auto ci = ClusterInfo::instance();
|
||||||
// We want to tolerate that a collection name is given here
|
// We want to tolerate that a collection name is given here
|
||||||
// which does not exist, if only for some unit tests:
|
// which does not exist, if only for some unit tests:
|
||||||
try {
|
auto coll = ci->getCollectionNT(_query->vocbase().name(), name.toString());
|
||||||
auto coll = ci->getCollection(_query->vocbase().name(), name.toString());
|
if (coll != nullptr) {
|
||||||
|
|
||||||
if (coll->isSmart()) {
|
if (coll->isSmart()) {
|
||||||
// add names of underlying smart-edge collections
|
// add names of underlying smart-edge collections
|
||||||
for (auto const& n : coll->realNames()) {
|
for (auto const& n : coll->realNames()) {
|
||||||
_query->addCollection(n, accessType);
|
_query->addCollection(n, accessType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (...) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3876,14 +3870,13 @@ void Ast::extractCollectionsFromGraph(AstNode const* graphNode) {
|
||||||
auto ci = ClusterInfo::instance();
|
auto ci = ClusterInfo::instance();
|
||||||
|
|
||||||
for (const auto& n : eColls) {
|
for (const auto& n : eColls) {
|
||||||
try {
|
auto c = ci->getCollection(_query->vocbase().name(), n);
|
||||||
auto c = ci->getCollection(_query->vocbase().name(), n);
|
if (c != nullptr) {
|
||||||
auto names = c->realNames();
|
auto names = c->realNames();
|
||||||
|
|
||||||
for (auto const& name : names) {
|
for (auto const& name : names) {
|
||||||
_query->addCollection(name, AccessMode::Type::READ);
|
_query->addCollection(name, AccessMode::Type::READ);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1016,6 +1016,18 @@ void ClusterInfo::loadCurrent() {
|
||||||
|
|
||||||
std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
|
std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
|
||||||
DatabaseID const& databaseID, CollectionID const& collectionID) {
|
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;
|
int tries = 0;
|
||||||
|
|
||||||
if (!_planProt.isValid) {
|
if (!_planProt.isValid) {
|
||||||
|
@ -1046,9 +1058,12 @@ std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
|
||||||
// must load collections outside the lock
|
// must load collections outside the lock
|
||||||
loadPlan();
|
loadPlan();
|
||||||
}
|
}
|
||||||
THROW_ARANGO_EXCEPTION_MESSAGE(
|
return nullptr;
|
||||||
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
|
}
|
||||||
"Collection not found: " + collectionID + " in database " + databaseID);
|
|
||||||
|
std::string ClusterInfo::getCollectionNotFoundMsg (
|
||||||
|
DatabaseID const& databaseID, CollectionID const& collectionID) {
|
||||||
|
return "Collection not found: " + collectionID + " in database " + databaseID;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -313,15 +313,31 @@ class ClusterInfo {
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief ask about a collection
|
/// @brief ask about a collection
|
||||||
/// If it is not found in the cache, the cache is reloaded once. The second
|
/// Throwing version, deprecated.
|
||||||
/// 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
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
virtual std::shared_ptr<LogicalCollection> getCollection(DatabaseID const&,
|
virtual std::shared_ptr<LogicalCollection> getCollection(DatabaseID const&,
|
||||||
CollectionID 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
|
/// @brief ask about all collections of a database
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -726,12 +726,10 @@ int revisionOnCoordinator(std::string const& dbname,
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
rid = 0;
|
rid = 0;
|
||||||
|
|
||||||
|
@ -799,12 +797,10 @@ int warmupOnCoordinator(std::string const& dbname,
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, cid);
|
||||||
collinfo = ci->getCollection(dbname, cid);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
// If we get here, the sharding attributes are not only _key, therefore
|
// If we get here, the sharding attributes are not only _key, therefore
|
||||||
// we have to contact everybody:
|
// 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:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
// If we get here, the sharding attributes are not only _key, therefore
|
// If we get here, the sharding attributes are not only _key, therefore
|
||||||
// we have to contact everybody:
|
// 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:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, cname);
|
||||||
collinfo = ci->getCollection(dbname, cname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
auto shards = collinfo->shardIds();
|
auto shards = collinfo->shardIds();
|
||||||
std::vector<ClusterCommRequest> requests;
|
std::vector<ClusterCommRequest> requests;
|
||||||
|
@ -982,12 +974,10 @@ int selectivityEstimatesOnCoordinator(
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
auto shards = collinfo->shardIds();
|
auto shards = collinfo->shardIds();
|
||||||
std::vector<ClusterCommRequest> requests;
|
std::vector<ClusterCommRequest> requests;
|
||||||
|
@ -1107,12 +1097,10 @@ Result createDocumentOnCoordinator(
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
auto collid = std::to_string(collinfo->id());
|
auto collid = std::to_string(collinfo->id());
|
||||||
|
|
||||||
|
|
||||||
|
@ -1253,12 +1241,10 @@ int deleteDocumentOnCoordinator(
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
bool useDefaultSharding = collinfo->usesDefaultShardKeys();
|
bool useDefaultSharding = collinfo->usesDefaultShardKeys();
|
||||||
auto collid = std::to_string(collinfo->id());
|
auto collid = std::to_string(collinfo->id());
|
||||||
bool useMultiple = slice.isArray();
|
bool useMultiple = slice.isArray();
|
||||||
|
@ -1486,12 +1472,10 @@ int truncateCollectionOnCoordinator(std::string const& dbname,
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
// Some stuff to prepare cluster-intern requests:
|
// Some stuff to prepare cluster-intern requests:
|
||||||
// We have to contact everybody:
|
// We have to contact everybody:
|
||||||
|
@ -1545,12 +1529,10 @@ int getDocumentOnCoordinator(
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
std::shared_ptr<LogicalCollection> collinfo;
|
||||||
try {
|
collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
if (collinfo == nullptr) {
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
auto collid = std::to_string(collinfo->id());
|
auto collid = std::to_string(collinfo->id());
|
||||||
|
|
||||||
|
|
|
@ -673,10 +673,8 @@ bool SynchronizeShard::first() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicalCollection> ci;
|
auto ci = clusterInfo->getCollectionNT(database, planId);
|
||||||
try { // ci->getCollection can throw
|
if (ci == nullptr) {
|
||||||
ci = clusterInfo->getCollection(database, planId);
|
|
||||||
} catch(...) {
|
|
||||||
auto const endTime = system_clock::now();
|
auto const endTime = system_clock::now();
|
||||||
std::stringstream msg;
|
std::stringstream msg;
|
||||||
msg << "exception in getCollection, " << database << "/"
|
msg << "exception in getCollection, " << database << "/"
|
||||||
|
@ -688,7 +686,6 @@ bool SynchronizeShard::first() {
|
||||||
_result.reset(TRI_ERROR_FAILED, msg.str());
|
_result.reset(TRI_ERROR_FAILED, msg.str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(ci != nullptr);
|
|
||||||
|
|
||||||
std::string const cid = std::to_string(ci->id());
|
std::string const cid = std::to_string(ci->id());
|
||||||
std::shared_ptr<CollectionInfoCurrent> cic =
|
std::shared_ptr<CollectionInfoCurrent> cic =
|
||||||
|
|
|
@ -653,9 +653,13 @@ static void JS_GetCollectionInfoClusterInfo(
|
||||||
"getCollectionInfo(<database-id>, <collection-id>)");
|
"getCollectionInfo(<database-id>, <collection-id>)");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
|
auto databaseID = TRI_ObjectToString(args[0]);
|
||||||
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
|
auto collectionID = TRI_ObjectToString(args[1]);
|
||||||
TRI_ASSERT(ci != nullptr);
|
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",
|
std::unordered_set<std::string> ignoreKeys{"allowUserKeys",
|
||||||
"avoidServers",
|
"avoidServers",
|
||||||
|
@ -720,9 +724,13 @@ static void JS_GetCollectionInfoCurrentClusterInfo(
|
||||||
|
|
||||||
ShardID shardID = TRI_ObjectToString(args[2]);
|
ShardID shardID = TRI_ObjectToString(args[2]);
|
||||||
|
|
||||||
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
|
auto databaseID = TRI_ObjectToString(args[0]);
|
||||||
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
|
auto collectionID = TRI_ObjectToString(args[1]);
|
||||||
TRI_ASSERT(ci != nullptr);
|
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);
|
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||||
// First some stuff from Plan for which Current does not make sense:
|
// 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]);
|
CollectionID collectionId = TRI_ObjectToString(args[0]);
|
||||||
auto& vocbase = GetContextVocBase(isolate);
|
auto& vocbase = GetContextVocBase(isolate);
|
||||||
auto ci = ClusterInfo::instance();
|
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;
|
bool usesDefaultShardingAttributes;
|
||||||
|
|
||||||
res = collInfo->getResponsibleShard(builder.slice(), documentIsComplete, shardId, usesDefaultShardingAttributes);
|
res = collInfo->getResponsibleShard(builder.slice(), documentIsComplete, shardId, usesDefaultShardingAttributes);
|
||||||
|
|
|
@ -98,28 +98,18 @@ int ClusterTransactionCollection::use(int nestingLevel) {
|
||||||
return TRI_ERROR_SHUTTING_DOWN;
|
return TRI_ERROR_SHUTTING_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
_collection = ci->getCollectionNT(_transaction->vocbase().name(), std::to_string(_cid));
|
||||||
_collection = ci->getCollection(_transaction->vocbase().name(), std::to_string(_cid));
|
|
||||||
if (_collection) {
|
|
||||||
if (!_transaction->hasHint(transaction::Hints::Hint::LOCK_NEVER) &&
|
|
||||||
!_transaction->hasHint(transaction::Hints::Hint::NO_USAGE_LOCK)) {
|
|
||||||
// use and usage-lock
|
|
||||||
LOG_TRX(_transaction, nestingLevel) << "using collection " << _cid;
|
|
||||||
_usageLocked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(...) {}
|
|
||||||
|
|
||||||
if (_collection == nullptr) {
|
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;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TRI_ASSERT(_collection != nullptr);
|
if (!_transaction->hasHint(transaction::Hints::Hint::LOCK_NEVER) &&
|
||||||
|
!_transaction->hasHint(transaction::Hints::Hint::NO_USAGE_LOCK)) {
|
||||||
|
// use and usage-lock
|
||||||
|
LOG_TRX(_transaction, nestingLevel) << "using collection " << _cid;
|
||||||
|
_usageLocked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (AccessMode::isWriteOrExclusive(_accessType) && !isLocked()) {
|
if (AccessMode::isWriteOrExclusive(_accessType) && !isLocked()) {
|
||||||
// r/w lock the collection
|
// r/w lock the collection
|
||||||
|
|
|
@ -53,13 +53,10 @@ int rotateActiveJournalOnAllDBServers(std::string const& dbname,
|
||||||
}
|
}
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
auto collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
try {
|
if (collinfo == nullptr) {
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
std::string const baseUrl = "/_db/" + basics::StringUtils::urlEncode(dbname)
|
std::string const baseUrl = "/_db/" + basics::StringUtils::urlEncode(dbname)
|
||||||
+ "/_api/collection/";
|
+ "/_api/collection/";
|
||||||
|
|
|
@ -52,14 +52,10 @@ Result recalculateCountsOnAllDBServers(std::string const& dbname,
|
||||||
}
|
}
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
auto collinfo = ci->getCollectionNT(dbname, collname);
|
||||||
try {
|
if (collinfo == nullptr) {
|
||||||
collinfo = ci->getCollection(dbname, collname);
|
|
||||||
} catch (...) {
|
|
||||||
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
TRI_ASSERT(collinfo != nullptr);
|
|
||||||
|
|
||||||
|
|
||||||
std::string const baseUrl = "/_db/" + basics::StringUtils::urlEncode(dbname)
|
std::string const baseUrl = "/_db/" + basics::StringUtils::urlEncode(dbname)
|
||||||
+ "/_api/collection/";
|
+ "/_api/collection/";
|
||||||
|
|
|
@ -256,14 +256,11 @@ std::shared_ptr<LogicalCollection> GraphManager::getCollectionByName(
|
||||||
const TRI_vocbase_t& vocbase, std::string const& name) {
|
const TRI_vocbase_t& vocbase, std::string const& name) {
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
// try looking up the collection by name then
|
// try looking up the collection by name then
|
||||||
try {
|
if (arangodb::ServerState::instance()->isRunningInCluster()) {
|
||||||
if (arangodb::ServerState::instance()->isRunningInCluster()) {
|
|
||||||
ClusterInfo* ci = ClusterInfo::instance();
|
ClusterInfo* ci = ClusterInfo::instance();
|
||||||
return ci->getCollection(vocbase.name(), name);
|
return ci->getCollectionNT(vocbase.name(), name);
|
||||||
} else {
|
} else {
|
||||||
return vocbase.lookupCollection(name);
|
return vocbase.lookupCollection(name);
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,18 +57,12 @@ RestStatus RestIndexHandler::execute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogicalCollection* RestIndexHandler::collection(
|
std::shared_ptr<LogicalCollection> RestIndexHandler::collection(std::string const& cName) {
|
||||||
std::string const& cName, std::shared_ptr<LogicalCollection>& coll) {
|
|
||||||
if (!cName.empty()) {
|
if (!cName.empty()) {
|
||||||
if (ServerState::instance()->isCoordinator()) {
|
if (ServerState::instance()->isCoordinator()) {
|
||||||
try {
|
return ClusterInfo::instance()->getCollectionNT(_vocbase.name(), cName);
|
||||||
coll = ClusterInfo::instance()->getCollection(_vocbase.name(), cName);
|
|
||||||
|
|
||||||
return coll.get();
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return _vocbase.lookupCollection(cName).get();
|
return _vocbase.lookupCollection(cName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +74,6 @@ LogicalCollection* RestIndexHandler::collection(
|
||||||
// //////////////////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
RestStatus RestIndexHandler::getIndexes() {
|
RestStatus RestIndexHandler::getIndexes() {
|
||||||
std::shared_ptr<LogicalCollection> tmpColl;
|
|
||||||
std::vector<std::string> const& suffixes = _request->suffixes();
|
std::vector<std::string> const& suffixes = _request->suffixes();
|
||||||
if (suffixes.empty()) {
|
if (suffixes.empty()) {
|
||||||
// .............................................................................
|
// .............................................................................
|
||||||
|
@ -89,7 +82,7 @@ RestStatus RestIndexHandler::getIndexes() {
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
std::string cName = _request->value("collection", found);
|
std::string cName = _request->value("collection", found);
|
||||||
LogicalCollection* coll = collection(cName, tmpColl);
|
auto coll = collection(cName);
|
||||||
if (coll == nullptr) {
|
if (coll == nullptr) {
|
||||||
generateError(rest::ResponseCode::NOT_FOUND,
|
generateError(rest::ResponseCode::NOT_FOUND,
|
||||||
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
||||||
|
@ -103,7 +96,7 @@ RestStatus RestIndexHandler::getIndexes() {
|
||||||
bool withLinks = _request->parsedValue("withLinks", false);
|
bool withLinks = _request->parsedValue("withLinks", false);
|
||||||
|
|
||||||
VPackBuilder indexes;
|
VPackBuilder indexes;
|
||||||
Result res = methods::Indexes::getAll(coll, flags, withLinks, indexes);
|
Result res = methods::Indexes::getAll(coll.get(), flags, withLinks, indexes);
|
||||||
if (!res.ok()) {
|
if (!res.ok()) {
|
||||||
generateError(rest::ResponseCode::BAD, res.errorNumber(),
|
generateError(rest::ResponseCode::BAD, res.errorNumber(),
|
||||||
res.errorMessage());
|
res.errorMessage());
|
||||||
|
@ -132,7 +125,7 @@ RestStatus RestIndexHandler::getIndexes() {
|
||||||
// .............................................................................
|
// .............................................................................
|
||||||
|
|
||||||
std::string const& cName = suffixes[0];
|
std::string const& cName = suffixes[0];
|
||||||
LogicalCollection* coll = collection(cName, tmpColl);
|
auto coll = collection(cName);
|
||||||
if (coll == nullptr) {
|
if (coll == nullptr) {
|
||||||
generateError(rest::ResponseCode::NOT_FOUND,
|
generateError(rest::ResponseCode::NOT_FOUND,
|
||||||
TRI_ERROR_ARANGO_DATA_SOURCE_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));
|
b.add(VPackValue(cName + TRI_INDEX_HANDLE_SEPARATOR_CHR + iid));
|
||||||
|
|
||||||
VPackBuilder output;
|
VPackBuilder output;
|
||||||
Result res = methods::Indexes::getIndex(coll, b.slice(), output);
|
Result res = methods::Indexes::getIndex(coll.get(), b.slice(), output);
|
||||||
if (res.ok()) {
|
if (res.ok()) {
|
||||||
VPackBuilder b;
|
VPackBuilder b;
|
||||||
b.openObject();
|
b.openObject();
|
||||||
|
@ -184,8 +177,7 @@ RestStatus RestIndexHandler::createIndex() {
|
||||||
return RestStatus::DONE;
|
return RestStatus::DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicalCollection> tmpColl;
|
auto coll = collection(cName);
|
||||||
LogicalCollection* coll = collection(cName, tmpColl);
|
|
||||||
if (coll == nullptr) {
|
if (coll == nullptr) {
|
||||||
generateError(rest::ResponseCode::NOT_FOUND,
|
generateError(rest::ResponseCode::NOT_FOUND,
|
||||||
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
||||||
|
@ -202,7 +194,7 @@ RestStatus RestIndexHandler::createIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
VPackBuilder output;
|
VPackBuilder output;
|
||||||
Result res = methods::Indexes::ensureIndex(coll, body, true, output);
|
Result res = methods::Indexes::ensureIndex(coll.get(), body, true, output);
|
||||||
if (res.ok()) {
|
if (res.ok()) {
|
||||||
VPackSlice created = output.slice().get("isNewlyCreated");
|
VPackSlice created = output.slice().get("isNewlyCreated");
|
||||||
auto r = created.isBool() && created.getBool() ? rest::ResponseCode::CREATED
|
auto r = created.isBool() && created.getBool() ? rest::ResponseCode::CREATED
|
||||||
|
@ -240,8 +232,7 @@ RestStatus RestIndexHandler::dropIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& cName = suffixes[0];
|
std::string const& cName = suffixes[0];
|
||||||
std::shared_ptr<LogicalCollection> tmpColl;
|
auto coll = collection(cName);
|
||||||
LogicalCollection* coll = collection(cName, tmpColl);
|
|
||||||
if (coll == nullptr) {
|
if (coll == nullptr) {
|
||||||
generateError(rest::ResponseCode::NOT_FOUND,
|
generateError(rest::ResponseCode::NOT_FOUND,
|
||||||
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
||||||
|
@ -252,7 +243,7 @@ RestStatus RestIndexHandler::dropIndex() {
|
||||||
VPackBuilder idBuilder;
|
VPackBuilder idBuilder;
|
||||||
idBuilder.add(VPackValue(cName + TRI_INDEX_HANDLE_SEPARATOR_CHR + iid));
|
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()) {
|
if (res.ok()) {
|
||||||
VPackBuilder b;
|
VPackBuilder b;
|
||||||
b.openObject();
|
b.openObject();
|
||||||
|
|
|
@ -44,8 +44,7 @@ class RestIndexHandler : public arangodb::RestVocbaseBaseHandler {
|
||||||
RestStatus createIndex();
|
RestStatus createIndex();
|
||||||
RestStatus dropIndex();
|
RestStatus dropIndex();
|
||||||
|
|
||||||
LogicalCollection* collection(std::string const& cName,
|
std::shared_ptr<LogicalCollection> collection(std::string const& cName);
|
||||||
std::shared_ptr<LogicalCollection>& coll);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1724,13 +1724,10 @@ Result RestReplicationHandler::processRestoreIndexesCoordinator(
|
||||||
|
|
||||||
// in a cluster, we only look up by name:
|
// in a cluster, we only look up by name:
|
||||||
ClusterInfo* ci = ClusterInfo::instance();
|
ClusterInfo* ci = ClusterInfo::instance();
|
||||||
std::shared_ptr<LogicalCollection> col;
|
std::shared_ptr<LogicalCollection> col = ci->getCollectionNT(dbName, name);
|
||||||
|
if (col == nullptr) {
|
||||||
try {
|
return {TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
|
||||||
col = ci->getCollection(dbName, name);
|
ClusterInfo::getCollectionNotFoundMsg(dbName, name)};
|
||||||
} catch (...) {
|
|
||||||
std::string errorMsg = "could not find collection '" + name + "'";
|
|
||||||
return {TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND, errorMsg};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_ASSERT(col != nullptr);
|
TRI_ASSERT(col != nullptr);
|
||||||
|
|
|
@ -2696,10 +2696,8 @@ OperationResult transaction::Methods::countCoordinator(
|
||||||
}
|
}
|
||||||
|
|
||||||
// First determine the collection ID from the name:
|
// First determine the collection ID from the name:
|
||||||
std::shared_ptr<LogicalCollection> collinfo;
|
auto collinfo = ci->getCollectionNT(vocbase().name(), collectionName);
|
||||||
try {
|
if (collinfo == nullptr) {
|
||||||
collinfo = ci->getCollection(vocbase().name(), collectionName);
|
|
||||||
} catch (...) {
|
|
||||||
return OperationResult(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
return OperationResult(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,18 +118,10 @@ TRI_voc_cid_t CollectionNameResolver::getCollectionIdCluster(
|
||||||
// We have to look up the collection info:
|
// We have to look up the collection info:
|
||||||
auto* ci = ClusterInfo::instance();
|
auto* ci = ClusterInfo::instance();
|
||||||
|
|
||||||
try {
|
auto const cinfo = (ci) ? ci->getCollectionNT(_vocbase.name(), name) : nullptr;
|
||||||
auto const cinfo = ci->getCollection(_vocbase.name(), name);
|
|
||||||
|
|
||||||
if (cinfo) {
|
if (cinfo != nullptr) {
|
||||||
return cinfo->id();
|
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);
|
auto const vinfo = ci->getView(_vocbase.name(), name);
|
||||||
|
@ -149,18 +141,9 @@ std::shared_ptr<LogicalCollection> CollectionNameResolver::getCollectionStructCl
|
||||||
return getCollectionStruct(name);
|
return getCollectionStruct(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// We have to look up the collection info:
|
||||||
// We have to look up the collection info:
|
ClusterInfo* ci = ClusterInfo::instance();
|
||||||
ClusterInfo* ci = ClusterInfo::instance();
|
return (ci) ? ci->getCollectionNT(_vocbase.name(), name) : nullptr;
|
||||||
auto cinfo = ci->getCollection(_vocbase.name(), name);
|
|
||||||
|
|
||||||
TRI_ASSERT(cinfo != nullptr);
|
|
||||||
|
|
||||||
return cinfo;
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -267,11 +250,10 @@ std::string CollectionNameResolver::getCollectionNameCluster(
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
|
|
||||||
while (tries++ < 2) {
|
while (tries++ < 2) {
|
||||||
try {
|
auto ci = ClusterInfo::instance()->getCollectionNT(
|
||||||
auto ci = ClusterInfo::instance()->getCollection(
|
|
||||||
_vocbase.name(), arangodb::basics::StringUtils::itoa(cid)
|
_vocbase.name(), arangodb::basics::StringUtils::itoa(cid)
|
||||||
);
|
);
|
||||||
|
if (ci != nullptr) {
|
||||||
name = ci->name();
|
name = ci->name();
|
||||||
{
|
{
|
||||||
WRITE_LOCKER(locker, _idLock);
|
WRITE_LOCKER(locker, _idLock);
|
||||||
|
@ -279,7 +261,8 @@ std::string CollectionNameResolver::getCollectionNameCluster(
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
} catch (...) {
|
}
|
||||||
|
else {
|
||||||
// most likely collection not found. now try again
|
// most likely collection not found. now try again
|
||||||
ClusterInfo::instance()->flush();
|
ClusterInfo::instance()->flush();
|
||||||
}
|
}
|
||||||
|
@ -315,19 +298,17 @@ std::string CollectionNameResolver::localNameLookup(TRI_voc_cid_t cid) const {
|
||||||
|
|
||||||
// DBserver case of a shard:
|
// DBserver case of a shard:
|
||||||
if (collection && collection->planId() != collection->id()) {
|
if (collection && collection->planId() != collection->id()) {
|
||||||
try {
|
collection = ClusterInfo::instance()->getCollectionNT(collection->vocbase().name(),
|
||||||
collection = ClusterInfo::instance()->getCollection(
|
std::to_string(collection->planId()));
|
||||||
collection->vocbase().name(), std::to_string(collection->planId())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
return UNKNOWN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// can be empty, if collection unknown
|
// can be empty, if collection unknown
|
||||||
return collection && !collection->name().empty()
|
if ((collection == nullptr) || (collection->name().empty())) {
|
||||||
? collection->name() : UNKNOWN;
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return collection->name();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicalDataSource> CollectionNameResolver::getDataSource(
|
std::shared_ptr<LogicalDataSource> CollectionNameResolver::getDataSource(
|
||||||
|
@ -374,17 +355,9 @@ std::shared_ptr<LogicalDataSource> CollectionNameResolver::getDataSource(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
ptr = (ci) ? ci->getCollectionNT(_vocbase.name(), nameOrId) : nullptr;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ptr) {
|
if (ptr == nullptr) {
|
||||||
ptr = ci->getView(_vocbase.name(), nameOrId);
|
ptr = ci->getView(_vocbase.name(), nameOrId);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
|
@ -82,16 +82,10 @@ std::shared_ptr<arangodb::LogicalCollection> GetCollectionFromArgument(
|
||||||
v8::Handle<v8::Value> const val
|
v8::Handle<v8::Value> const val
|
||||||
) {
|
) {
|
||||||
if (arangodb::ServerState::instance()->isCoordinator()) {
|
if (arangodb::ServerState::instance()->isCoordinator()) {
|
||||||
try {
|
auto* ci = arangodb::ClusterInfo::instance();
|
||||||
auto* ci = arangodb::ClusterInfo::instance();
|
|
||||||
|
|
||||||
return ci
|
return ci
|
||||||
? ci->getCollection(vocbase.name(), TRI_ObjectToString(val)) : nullptr;
|
? ci->getCollectionNT(vocbase.name(), TRI_ObjectToString(val)) : nullptr;
|
||||||
} catch (...) {
|
|
||||||
// NOOP
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr; // not found
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// number
|
// number
|
||||||
|
@ -2063,12 +2057,13 @@ static void JS_StatusVocbaseCol(
|
||||||
if (ServerState::instance()->isCoordinator()) {
|
if (ServerState::instance()->isCoordinator()) {
|
||||||
auto& databaseName = collection->vocbase().name();
|
auto& databaseName = collection->vocbase().name();
|
||||||
|
|
||||||
try {
|
auto ci = ClusterInfo::instance()->getCollectionNT(
|
||||||
auto ci = ClusterInfo::instance()->getCollection(
|
|
||||||
databaseName, std::to_string(collection->id())
|
databaseName, std::to_string(collection->id())
|
||||||
);
|
);
|
||||||
|
if (ci != nullptr) {
|
||||||
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->status()));
|
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));
|
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()) {
|
if (ServerState::instance()->isCoordinator()) {
|
||||||
auto& databaseName = collection->vocbase().name();
|
auto& databaseName = collection->vocbase().name();
|
||||||
|
|
||||||
try {
|
auto ci = ClusterInfo::instance()->getCollectionNT(
|
||||||
auto ci = ClusterInfo::instance()->getCollection(
|
|
||||||
databaseName, std::to_string(collection->id())
|
databaseName, std::to_string(collection->id())
|
||||||
);
|
);
|
||||||
|
if (ci != nullptr) {
|
||||||
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->type()));
|
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->type()));
|
||||||
} catch (...) {
|
}
|
||||||
|
else {
|
||||||
TRI_V8_RETURN(v8::Number::New(isolate, (int)(collection->type())));
|
TRI_V8_RETURN(v8::Number::New(isolate, (int)(collection->type())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1396,18 +1396,13 @@ static void MapGetVocBase(v8::Local<v8::String> const name,
|
||||||
|
|
||||||
std::shared_ptr<arangodb::LogicalCollection> collection;
|
std::shared_ptr<arangodb::LogicalCollection> collection;
|
||||||
|
|
||||||
try {
|
if (ServerState::instance()->isCoordinator()) {
|
||||||
if (ServerState::instance()->isCoordinator()) {
|
auto* ci = arangodb::ClusterInfo::instance();
|
||||||
auto* ci = arangodb::ClusterInfo::instance();
|
if (ci) {
|
||||||
|
collection = ci->getCollectionNT(vocbase.name(), std::string(key));
|
||||||
collection = ci
|
|
||||||
? ci->getCollection(vocbase.name(), std::string(key)) : nullptr;
|
|
||||||
} else {
|
|
||||||
collection = vocbase.lookupCollection(std::string(key));
|
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} else {
|
||||||
// do not propagate exception from here
|
collection = vocbase.lookupCollection(std::string(key));
|
||||||
TRI_V8_RETURN(v8::Handle<v8::Value>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection == nullptr) {
|
if (collection == nullptr) {
|
||||||
|
|
|
@ -140,21 +140,24 @@ Result methods::Collections::lookup(TRI_vocbase_t* vocbase,
|
||||||
|
|
||||||
if (ServerState::instance()->isCoordinator()) {
|
if (ServerState::instance()->isCoordinator()) {
|
||||||
try {
|
try {
|
||||||
auto coll = ClusterInfo::instance()->getCollection(vocbase->name(), name);
|
auto coll = ClusterInfo::instance()->getCollectionNT(vocbase->name(), name);
|
||||||
|
|
||||||
// check authentication after ensuring the collection exists
|
|
||||||
if (exec != nullptr &&
|
|
||||||
!exec->canUseCollection(vocbase->name(), coll->name(),
|
|
||||||
auth::Level::RO)) {
|
|
||||||
return Result(TRI_ERROR_FORBIDDEN,
|
|
||||||
"No access to collection '" + name + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (coll) {
|
if (coll) {
|
||||||
|
// check authentication after ensuring the collection exists
|
||||||
|
if (exec != nullptr &&
|
||||||
|
!exec->canUseCollection(vocbase->name(), coll->name(),
|
||||||
|
auth::Level::RO)) {
|
||||||
|
return Result(TRI_ERROR_FORBIDDEN,
|
||||||
|
"No access to collection '" + name + "'");
|
||||||
|
}
|
||||||
|
|
||||||
func(coll);
|
func(coll);
|
||||||
|
|
||||||
return Result();
|
return Result();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return Result(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
|
||||||
|
}
|
||||||
} catch (basics::Exception const& ex) {
|
} catch (basics::Exception const& ex) {
|
||||||
return Result(ex.code(), ex.what());
|
return Result(ex.code(), ex.what());
|
||||||
} catch (std::exception const& ex) {
|
} catch (std::exception const& ex) {
|
||||||
|
|
Loading…
Reference in New Issue