1
0
Fork 0

Merge branch 'generic-col-types' of https://github.com/arangodb/arangodb into generic-col-types

This commit is contained in:
jsteemann 2016-09-02 08:13:49 +02:00
commit a6697636ed
8 changed files with 92 additions and 79 deletions

View File

@ -657,7 +657,6 @@ std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
}
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND,
"Collection not found: " + collectionID);
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -563,12 +563,13 @@ int revisionOnCoordinator(std::string const& dbname,
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
rid = 0;
@ -634,12 +635,13 @@ int figuresOnCoordinator(std::string const& dbname, std::string const& collname,
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
// If we get here, the sharding attributes are not only _key, therefore
// we have to contact everybody:
@ -700,12 +702,13 @@ int countOnCoordinator(std::string const& dbname, std::string const& collname,
result = 0;
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
auto shards = collinfo->shardIds();
std::vector<ClusterCommRequest> requests;
@ -768,12 +771,13 @@ int createDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
std::string const collid = collinfo->cid_as_string();
std::unordered_map<
@ -902,11 +906,13 @@ int deleteDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
bool useDefaultSharding = collinfo->usesDefaultShardKeys();
std::string collid = collinfo->cid_as_string();
bool useMultiple = slice.isArray();
@ -1128,12 +1134,13 @@ int truncateCollectionOnCoordinator(std::string const& dbname,
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
// Some stuff to prepare cluster-intern requests:
// We have to contact everybody:
@ -1183,11 +1190,14 @@ int getDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo == nullptr) {
std::shared_ptr<LogicalCollection> collinfo;
try {
collinfo = ci->getCollection(dbname, collname);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(collinfo != nullptr);
std::string collid = collinfo->cid_as_string();
// If _key is the one and only sharding attribute, we can do this quickly,
@ -1436,10 +1446,7 @@ static void insertIntoShardMap(
// First determine the collection ID from the name:
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, splitId[0]);
if (collinfo == nullptr) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND,
"Collection not found: " + splitId[0]);
}
std::string collid = collinfo->cid_as_string();
if (collinfo->usesDefaultShardKeys()) {
// We only need add one resp. shard

View File

@ -676,9 +676,7 @@ static void JS_GetCollectionInfoClusterInfo(
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
if (ci == nullptr) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
}
TRI_ASSERT(ci != nullptr);
v8::Handle<v8::Object> result = v8::Object::New(isolate);
std::string const cid = ci->cid_as_string();

View File

@ -1653,12 +1653,13 @@ int RestReplicationHandler::processRestoreCollectionCoordinator(
std::string dbName = _vocbase->name();
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
// drop an existing collection if it exists
if (col != nullptr) {
try {
// in a cluster, we only look up by name:
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
// drop an existing collection if it exists
if (dropExisting) {
int res = ci->dropCollectionCoordinator(dbName, col->cid_as_string(),
errorMsg, 0.0);
@ -1686,6 +1687,7 @@ int RestReplicationHandler::processRestoreCollectionCoordinator(
return res;
}
} catch (...) {
}
// now re-create the collection
@ -1975,12 +1977,14 @@ int RestReplicationHandler::processRestoreIndexesCoordinator(
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
if (col == nullptr) {
std::shared_ptr<LogicalCollection> col;
try {
col = ci->getCollection(dbName, name);
} catch (...) {
errorMsg = "could not find collection '" + name + "'";
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
TRI_ASSERT(col != nullptr);
int res = TRI_ERROR_NO_ERROR;
for (VPackSlice const& idxDef : VPackArrayIterator(indexes)) {
@ -2484,9 +2488,10 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator() {
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
if (col == nullptr) {
std::shared_ptr<LogicalCollection> col;
try {
col = ci->getCollection(dbName, name);
} catch (...) {
generateError(rest::ResponseCode::BAD,
TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
return;

View File

@ -77,11 +77,13 @@ TRI_voc_cid_t CollectionNameResolver::getCollectionIdCluster(
return cid;
}
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
auto cinfo = ci->getCollection(_vocbase->name(), name);
if (cinfo != nullptr) {
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->cid();
} catch (...) {
}
return 0;
}
@ -162,11 +164,13 @@ TRI_col_type_e CollectionNameResolver::getCollectionTypeCluster(
arangodb::basics::StringUtils::uint64(name))));
}
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
auto cinfo = ci->getCollection(_vocbase->name(), name);
if (cinfo != nullptr) {
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->type();
} catch(...) {
}
return TRI_COL_TYPE_UNKNOWN;
}

View File

@ -173,13 +173,13 @@ static int ParseDocumentOrDocumentHandle(v8::Isolate* isolate,
// name
if (ServerState::instance()->isCoordinator()) {
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<LogicalCollection> col =
ci->getCollection(vocbase->name(), collectionName);
if (col == nullptr) {
// collection not found
try {
std::shared_ptr<LogicalCollection> col =
ci->getCollection(vocbase->name(), collectionName);
collection = new LogicalCollection(col);
} catch (...) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
collection = new LogicalCollection(col);
} else {
collection = resolver->getCollectionStruct(collectionName);
}
@ -2200,14 +2200,14 @@ static void JS_StatusVocbaseCol(
if (ServerState::instance()->isCoordinator()) {
std::string const databaseName(collection->dbName());
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(databaseName,
collection->cid_as_string());
if (ci == nullptr) {
try {
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(databaseName,
collection->cid_as_string());
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->getStatusLocked()));
} catch (...) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)TRI_VOC_COL_STATUS_DELETED));
}
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->getStatusLocked()));
}
// fallthru intentional
@ -2362,14 +2362,13 @@ static void JS_TypeVocbaseCol(v8::FunctionCallbackInfo<v8::Value> const& args) {
if (ServerState::instance()->isCoordinator()) {
std::string const databaseName = collection->dbName();
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(databaseName,
collection->cid_as_string());
if (ci == nullptr) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)collection->type()));
} else {
try {
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(databaseName,
collection->cid_as_string());
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->type()));
} catch (...) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)collection->type()));
}
}
// fallthru intentional
@ -2521,15 +2520,14 @@ static void JS_CollectionVocbase(
if (ServerState::instance()->isCoordinator()) {
std::string const name = TRI_ObjectToString(val);
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(vocbase->name(), name);
if (ci == nullptr) {
try {
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(vocbase->name(), name);
collection = new LogicalCollection(ci);
} catch (...) {
// not found
TRI_V8_RETURN_NULL();
}
collection = new LogicalCollection(ci);
} else {
collection = GetCollectionFromArgument(vocbase, val);
}

View File

@ -1890,6 +1890,7 @@ static void MapGetVocBase(v8::Local<v8::String> const name,
}
} catch (...) {
// do not propagate exception from here
TRI_V8_RETURN(v8::Handle<v8::Value>());
}
if (collection == nullptr) {

View File

@ -764,9 +764,9 @@ static void CreateCollectionCoordinator(
if (otherCid != 0) {
std::string otherCidString
= arangodb::basics::StringUtils::itoa(otherCid);
std::shared_ptr<LogicalCollection> collInfo =
ci->getCollection(databaseName, otherCidString);
if (collInfo != nullptr) {
try {
std::shared_ptr<LogicalCollection> collInfo =
ci->getCollection(databaseName, otherCidString);
auto shards = collInfo->shardIds();
auto shardList = ci->getShardList(otherCidString);
for (auto const& s : *shardList) {
@ -777,6 +777,7 @@ static void CreateCollectionCoordinator(
}
}
}
} catch (...) {
}
}
}