1
0
Fork 0

Merge branch 'devel' of https://github.com/arangodb/arangodb into devel

This commit is contained in:
Jan Steemann 2016-04-21 18:04:17 +02:00
commit e6b6221b0d
2 changed files with 80 additions and 44 deletions

View File

@ -828,14 +828,14 @@ int createDocumentOnCoordinator(
TRI_ASSERT(it.second.size() == 1); TRI_ASSERT(it.second.size() == 1);
auto idx = it.second.front(); auto idx = it.second.front();
if (idx.second.empty()) { if (idx.second.empty()) {
body = std::make_shared<std::string>(std::move(slice.toJson())); body = std::make_shared<std::string>(slice.toJson());
} else { } else {
reqBuilder.clear(); reqBuilder.clear();
reqBuilder.openObject(); reqBuilder.openObject();
TRI_SanitizeObject(slice, reqBuilder); TRI_SanitizeObject(slice, reqBuilder);
reqBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(idx.second)); reqBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(idx.second));
reqBuilder.close(); reqBuilder.close();
body = std::make_shared<std::string>(std::move(reqBuilder.slice().toJson())); body = std::make_shared<std::string>(reqBuilder.slice().toJson());
} }
} else { } else {
reqBuilder.clear(); reqBuilder.clear();
@ -851,7 +851,7 @@ int createDocumentOnCoordinator(
} }
} }
reqBuilder.close(); reqBuilder.close();
body = std::make_shared<std::string>(std::move(reqBuilder.slice().toJson())); body = std::make_shared<std::string>(reqBuilder.slice().toJson());
} }
auto headersCopy = auto headersCopy =
std::make_unique<std::map<std::string, std::string>>(headers); std::make_unique<std::map<std::string, std::string>>(headers);
@ -998,7 +998,7 @@ int deleteDocumentOnCoordinator(
for (auto const& it : shardMap) { for (auto const& it : shardMap) {
if (!useMultiple) { if (!useMultiple) {
TRI_ASSERT(it.second.size() == 1); TRI_ASSERT(it.second.size() == 1);
body = std::make_shared<std::string>(std::move(slice.toJson())); body = std::make_shared<std::string>(slice.toJson());
} else { } else {
reqBuilder.clear(); reqBuilder.clear();
reqBuilder.openArray(); reqBuilder.openArray();
@ -1006,7 +1006,7 @@ int deleteDocumentOnCoordinator(
reqBuilder.add(slice.at(idx)); reqBuilder.add(slice.at(idx));
} }
reqBuilder.close(); reqBuilder.close();
body = std::make_shared<std::string>(std::move(reqBuilder.slice().toJson())); body = std::make_shared<std::string>(reqBuilder.slice().toJson());
} }
auto headersCopy = auto headersCopy =
std::make_unique<std::map<std::string, std::string>>(*headers); std::make_unique<std::map<std::string, std::string>>(*headers);
@ -1050,7 +1050,7 @@ int deleteDocumentOnCoordinator(
// end // end
// if (!skipped) => insert NOT_FOUND // if (!skipped) => insert NOT_FOUND
auto body = std::make_shared<std::string>(std::move(slice.toJson())); auto body = std::make_shared<std::string>(slice.toJson());
auto shardList = ci->getShardList(collid); auto shardList = ci->getShardList(collid);
for (auto const& shard : *shardList) { for (auto const& shard : *shardList) {
auto headersCopy = auto headersCopy =
@ -1277,7 +1277,7 @@ int getDocumentOnCoordinator(
reqBuilder.add(slice.at(idx)); reqBuilder.add(slice.at(idx));
} }
reqBuilder.close(); reqBuilder.close();
body = std::make_shared<std::string>(std::move(reqBuilder.slice().toJson())); body = std::make_shared<std::string>(reqBuilder.slice().toJson());
// We send to Babies endpoint // We send to Babies endpoint
cc->asyncRequest("", coordTransactionID, "shard:" + it.first, reqType, cc->asyncRequest("", coordTransactionID, "shard:" + it.first, reqType,
baseUrl + StringUtils::urlEncode(it.first) + optsUrlPart, baseUrl + StringUtils::urlEncode(it.first) + optsUrlPart,
@ -1332,7 +1332,7 @@ int getDocumentOnCoordinator(
nullptr, headersCopy, nullptr, 60.0); nullptr, headersCopy, nullptr, 60.0);
} }
} else { } else {
auto body = std::make_shared<std::string>(std::move(slice.toJson())); auto body = std::make_shared<std::string>(slice.toJson());
for (auto const& shard : *shardList) { for (auto const& shard : *shardList) {
auto headersCopy = auto headersCopy =
std::make_unique<std::map<std::string, std::string>>(*headers); std::make_unique<std::map<std::string, std::string>>(*headers);
@ -1795,7 +1795,7 @@ int modifyDocumentOnCoordinator(
std::make_unique<std::map<std::string, std::string>>(*headers); std::make_unique<std::map<std::string, std::string>>(*headers);
if (!useMultiple) { if (!useMultiple) {
TRI_ASSERT(it.second.size() == 1); TRI_ASSERT(it.second.size() == 1);
body = std::make_shared<std::string>(std::move(slice.toJson())); body = std::make_shared<std::string>(slice.toJson());
// We send to single endpoint // We send to single endpoint
cc->asyncRequest("", coordTransactionID, "shard:" + it.first, reqType, cc->asyncRequest("", coordTransactionID, "shard:" + it.first, reqType,
@ -1810,7 +1810,7 @@ int modifyDocumentOnCoordinator(
reqBuilder.add(slice.at(idx)); reqBuilder.add(slice.at(idx));
} }
reqBuilder.close(); reqBuilder.close();
body = std::make_shared<std::string>(std::move(reqBuilder.slice().toJson())); body = std::make_shared<std::string>(reqBuilder.slice().toJson());
// We send to Babies endpoint // We send to Babies endpoint
cc->asyncRequest("", coordTransactionID, "shard:" + it.first, reqType, cc->asyncRequest("", coordTransactionID, "shard:" + it.first, reqType,
baseUrl + StringUtils::urlEncode(it.first) + optsUrlPart, baseUrl + StringUtils::urlEncode(it.first) + optsUrlPart,
@ -1848,7 +1848,7 @@ int modifyDocumentOnCoordinator(
// Not all shard keys are known in all documents. // Not all shard keys are known in all documents.
// We contact all shards with the complete body and ignore NOT_FOUND // We contact all shards with the complete body and ignore NOT_FOUND
auto body = std::make_shared<std::string>(std::move(slice.toJson())); auto body = std::make_shared<std::string>(slice.toJson());
auto shardList = ci->getShardList(collid); auto shardList = ci->getShardList(collid);
if (!useMultiple) { if (!useMultiple) {
for (auto const& shard : *shardList) { for (auto const& shard : *shardList) {

View File

@ -46,17 +46,25 @@ static OperationResult FetchDocumentById(arangodb::Transaction* trx,
std::string const& id, std::string const& id,
VPackBuilder& builder, VPackBuilder& builder,
OperationOptions& options) { OperationOptions& options) {
std::vector<std::string> parts = size_t pos = id.find('/');
arangodb::basics::StringUtils::split(id, "/"); if (pos == std::string::npos) {
TRI_ASSERT(parts.size() == 2); TRI_ASSERT(false);
trx->addCollectionAtRuntime(parts[0]); return OperationResult(TRI_ERROR_INTERNAL);
}
if (id.find('/', pos + 1) != std::string::npos) {
TRI_ASSERT(false);
return OperationResult(TRI_ERROR_INTERNAL);
}
std::string col = id.substr(0, pos);
trx->addCollectionAtRuntime(col);
builder.clear(); builder.clear();
builder.openObject(); builder.openObject();
builder.add(VPackValue(TRI_VOC_ATTRIBUTE_KEY)); builder.add(VPackValue(TRI_VOC_ATTRIBUTE_KEY));
builder.add(VPackValue(parts[1])); builder.add(VPackValue(id.substr(pos + 1)));
builder.close(); builder.close();
OperationResult opRes = trx->document(parts[0], builder.slice(), options); OperationResult opRes = trx->document(col, builder.slice(), options);
if (opRes.failed() && opRes.code != TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) { if (opRes.failed() && opRes.code != TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) {
THROW_ARANGO_EXCEPTION(opRes.code); THROW_ARANGO_EXCEPTION(opRes.code);
@ -418,10 +426,19 @@ bool BasicOptions::matchesEdge(VPackSlice edge) const {
return true; return true;
} }
auto id = _trx->extractIdString(edge); std::string id = _trx->extractIdString(edge);
std::vector<std::string> parts = arangodb::basics::StringUtils::split(id, "/"); size_t pos = id.find('/');
TRI_ASSERT(parts.size() == 2); // We have a real ID
auto it = _edgeFilter.find(parts[0]); if (pos == std::string::npos) {
// no / contained in _id!
return false;
}
if (id.find('/', pos + 1) != std::string::npos) {
// multiple / contained in _id!
return false;
}
auto it = _edgeFilter.find(id.substr(0, pos));
if (it == _edgeFilter.end()) { if (it == _edgeFilter.end()) {
// This collection does not have any object that can match. // This collection does not have any object that can match.
@ -474,26 +491,35 @@ bool NeighborsOptions::matchesVertex(std::string const& id) const {
return true; return true;
} }
std::vector<std::string> parts = size_t pos = id.find('/');
arangodb::basics::StringUtils::split(id, "/"); if (pos == std::string::npos) {
TRI_ASSERT(parts.size() == 2); TRI_ASSERT(false);
return false;
}
if (id.find('/', pos + 1) != std::string::npos) {
TRI_ASSERT(false);
return false;
}
std::string col = id.substr(0, pos);
// If there are explicitly marked collections check them. // If there are explicitly marked collections check them.
if (!_explicitCollections.empty()) { if (!_explicitCollections.empty()) {
// If the current collection is not stored the result is invalid // If the current collection is not stored the result is invalid
if (_explicitCollections.find(parts[0]) == _explicitCollections.end()) { if (_explicitCollections.find(col) == _explicitCollections.end()) {
return false; return false;
} }
} }
std::string key = id.substr(pos + 1);
VPackBuilder tmp; VPackBuilder tmp;
tmp.openObject(); tmp.openObject();
tmp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(parts[1])); tmp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key));
tmp.close(); tmp.close();
OperationOptions opOpts; OperationOptions opOpts;
OperationResult opRes = _trx->document(parts[0], tmp.slice(), opOpts); OperationResult opRes = _trx->document(col, tmp.slice(), opOpts);
if (opRes.failed()) { if (opRes.failed()) {
return false; return false;
} }
return BasicOptions::matchesVertex(parts[0], parts[1], opRes.slice()); return BasicOptions::matchesVertex(col, key, opRes.slice());
} }
@ -533,21 +559,31 @@ std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch(
auto edgeFilterClosure = [&opts](VPackSlice edge) auto edgeFilterClosure = [&opts](VPackSlice edge)
-> bool { return opts.matchesEdge(edge); }; -> bool { return opts.matchesEdge(edge); };
auto vertexFilterClosure = auto vertexFilterClosure = [&opts](std::string const& v) -> bool {
[&opts](std::string const& v) -> bool { size_t pos = v.find('/');
// TODO: this closure needs to be optimized
std::vector<std::string> parts = arangodb::basics::StringUtils::split(v, "/"); if (pos == std::string::npos) {
VPackBuilder tmp; // no / contained in _id!
tmp.openObject(); return false;
tmp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(parts[1])); }
tmp.close(); if (v.find('/', pos + 1) != std::string::npos) {
OperationOptions opOpts; // multiple / contained in _id!
OperationResult opRes = opts.trx()->document(parts[0], tmp.slice(), opOpts); return false;
if (opRes.failed()) { }
return false; std::string col = v.substr(0, pos);
} std::string key = v.substr(pos + 1);
return opts.matchesVertex(parts[0], parts[1], opRes.slice());
}; VPackBuilder tmp;
tmp.openObject();
tmp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key));
tmp.close();
OperationOptions opOpts;
OperationResult opRes = opts.trx()->document(col, tmp.slice(), opOpts);
if (opRes.failed()) {
return false;
}
return opts.matchesVertex(col, key, opRes.slice());
};
MultiCollectionEdgeExpander forwardExpander( MultiCollectionEdgeExpander forwardExpander(
forward, collectionInfos, edgeFilterClosure, vertexFilterClosure); forward, collectionInfos, edgeFilterClosure, vertexFilterClosure);