1
0
Fork 0

Introduce getCollectionId, use it in a few places.

This commit is contained in:
Max Neunhoeffer 2016-02-19 23:48:34 +01:00
parent 393ac7e753
commit ed29fd9d60
4 changed files with 48 additions and 38 deletions

View File

@ -107,7 +107,7 @@ class AqlTransaction : public Transaction {
int processCollectionCoordinator(arangodb::aql::Collection* collection) {
TRI_voc_cid_t cid =
this->resolver()->getCollectionIdCluster(collection->getName());
this->resolver()->getCollectionId(collection->getName());
return this->addCollection(cid, collection->getName().c_str(),
collection->accessType);

View File

@ -51,7 +51,9 @@ class CollectionNameResolver {
public:
//////////////////////////////////////////////////////////////////////////////
/// @brief look up a collection id for a collection name (local case)
/// @brief look up a collection id for a collection name (local case),
/// use this if you know you are on a single server or on a DBserver
/// and need to look up a local collection name (or shard name).
//////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t getCollectionIdLocal(std::string const& name) const {
@ -69,6 +71,47 @@ class CollectionNameResolver {
return 0;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief look up a cluster collection id for a cluster collection name,
/// only use this is in cluster mode on a coordinator or DBserver, in both
/// cases the name is resolved as a cluster wide collection name and the
/// cluster wide collection id is returned.
//////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t getCollectionIdCluster(std::string const& name) const {
if (!ServerState::instance()->isRunningInCluster()) {
return getCollectionIdLocal(name);
}
if (name[0] >= '0' && name[0] <= '9') {
// name is a numeric id
return (TRI_voc_cid_t)arangodb::basics::StringUtils::uint64(name);
}
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> cinfo =
ci->getCollection(DatabaseID(_vocbase->_name), name);
if (cinfo->empty()) {
return 0;
}
return cinfo->id();
}
//////////////////////////////////////////////////////////////////////////////
/// @brief look up a collection id for a collection name, this is the
/// default one to use, which will usually do the right thing. On a
/// single server or DBserver it will use the local lookup and on a
/// coordinator it will use the cluster wide lookup.
//////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t getCollectionId(std::string const& name) const {
if (!ServerState::instance()->isRunningInCluster() ||
ServerState::instance()->isDBServer()) {
return getCollectionIdLocal(name);
}
return getCollectionIdCluster(name);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief look up a collection type for a collection name (local case)
//////////////////////////////////////////////////////////////////////////////
@ -109,29 +152,6 @@ class CollectionNameResolver {
return collection;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief look up a cluster collection id for a cluster collection name
//////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t getCollectionIdCluster(std::string const& name) const {
if (!ServerState::instance()->isRunningInCluster()) {
return getCollectionIdLocal(name);
}
if (name[0] >= '0' && name[0] <= '9') {
// name is a numeric id
return (TRI_voc_cid_t)arangodb::basics::StringUtils::uint64(name);
}
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> cinfo =
ci->getCollection(DatabaseID(_vocbase->_name), name);
if (cinfo->empty()) {
return 0;
}
return cinfo->id();
}
//////////////////////////////////////////////////////////////////////////////
/// @brief look up a cluster collection type for a cluster collection name on
/// the

View File

@ -70,12 +70,7 @@ class SingleCollectionTransaction : public Transaction {
_accessType(accessType) {
// add the (sole) collection
if (setupState() == TRI_ERROR_NO_ERROR) {
if (ServerState::instance()->isCoordinator()) {
_cid = this->resolver()->getCollectionIdCluster(name);
} else {
_cid = this->resolver()->getCollectionIdLocal(name);
}
_cid = this->resolver()->getCollectionId(name);
this->addCollection(_cid, _accessType);
}
}

View File

@ -949,13 +949,8 @@ class Transaction {
return _setupState;
}
if (!_isReal) {
return addCollection(this->resolver()->getCollectionIdCluster(name),
name.c_str(), type);
}
return addCollection(this->resolver()->getCollectionIdLocal(name), name.c_str(),
type);
return addCollection(this->resolver()->getCollectionId(name),
name.c_str(), type);
}
//////////////////////////////////////////////////////////////////////////////