mirror of https://gitee.com/bigwinds/arangodb
fixed from/to-handling in cluster
This commit is contained in:
parent
4d52ac8c99
commit
c93c952c05
|
@ -494,13 +494,13 @@ Json AqlValue::toJson (triagens::arango::AqlTransaction* trx,
|
||||||
|
|
||||||
if (TRI_IS_EDGE_MARKER(_marker)) {
|
if (TRI_IS_EDGE_MARKER(_marker)) {
|
||||||
// _from
|
// _from
|
||||||
std::string from(trx->resolver()->getCollectionName(TRI_EXTRACT_MARKER_FROM_CID(_marker)));
|
std::string from(trx->resolver()->getCollectionNameCluster(TRI_EXTRACT_MARKER_FROM_CID(_marker)));
|
||||||
from.push_back('/');
|
from.push_back('/');
|
||||||
from.append(TRI_EXTRACT_MARKER_FROM_KEY(_marker));
|
from.append(TRI_EXTRACT_MARKER_FROM_KEY(_marker));
|
||||||
json(TRI_VOC_ATTRIBUTE_FROM, Json(from));
|
json(TRI_VOC_ATTRIBUTE_FROM, Json(from));
|
||||||
|
|
||||||
// _to
|
// _to
|
||||||
std::string to(trx->resolver()->getCollectionName(TRI_EXTRACT_MARKER_TO_CID(_marker)));
|
std::string to(trx->resolver()->getCollectionNameCluster(TRI_EXTRACT_MARKER_TO_CID(_marker)));
|
||||||
to.push_back('/');
|
to.push_back('/');
|
||||||
to.append(TRI_EXTRACT_MARKER_TO_KEY(_marker));
|
to.append(TRI_EXTRACT_MARKER_TO_KEY(_marker));
|
||||||
json(TRI_VOC_ATTRIBUTE_TO, Json(to));
|
json(TRI_VOC_ATTRIBUTE_TO, Json(to));
|
||||||
|
@ -605,13 +605,13 @@ Json AqlValue::extractArrayMember (triagens::arango::AqlTransaction* trx,
|
||||||
return Json(TRI_UNKNOWN_MEM_ZONE, JsonHelper::uint64String(TRI_UNKNOWN_MEM_ZONE, rid));
|
return Json(TRI_UNKNOWN_MEM_ZONE, JsonHelper::uint64String(TRI_UNKNOWN_MEM_ZONE, rid));
|
||||||
}
|
}
|
||||||
else if (strcmp(name, TRI_VOC_ATTRIBUTE_FROM) == 0) {
|
else if (strcmp(name, TRI_VOC_ATTRIBUTE_FROM) == 0) {
|
||||||
std::string from(trx->resolver()->getCollectionName(TRI_EXTRACT_MARKER_FROM_CID(_marker)));
|
std::string from(trx->resolver()->getCollectionNameCluster(TRI_EXTRACT_MARKER_FROM_CID(_marker)));
|
||||||
from.push_back('/');
|
from.push_back('/');
|
||||||
from.append(TRI_EXTRACT_MARKER_FROM_KEY(_marker));
|
from.append(TRI_EXTRACT_MARKER_FROM_KEY(_marker));
|
||||||
return Json(TRI_UNKNOWN_MEM_ZONE, from);
|
return Json(TRI_UNKNOWN_MEM_ZONE, from);
|
||||||
}
|
}
|
||||||
else if (strcmp(name, TRI_VOC_ATTRIBUTE_TO) == 0) {
|
else if (strcmp(name, TRI_VOC_ATTRIBUTE_TO) == 0) {
|
||||||
std::string to(trx->resolver()->getCollectionName(TRI_EXTRACT_MARKER_TO_CID(_marker)));
|
std::string to(trx->resolver()->getCollectionNameCluster(TRI_EXTRACT_MARKER_TO_CID(_marker)));
|
||||||
to.push_back('/');
|
to.push_back('/');
|
||||||
to.append(TRI_EXTRACT_MARKER_TO_KEY(_marker));
|
to.append(TRI_EXTRACT_MARKER_TO_KEY(_marker));
|
||||||
return Json(TRI_UNKNOWN_MEM_ZONE, to);
|
return Json(TRI_UNKNOWN_MEM_ZONE, to);
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "Aql/ExecutionEngine.h"
|
#include "Aql/ExecutionEngine.h"
|
||||||
#include "Basics/StringUtils.h"
|
#include "Basics/StringUtils.h"
|
||||||
#include "Cluster/ClusterInfo.h"
|
#include "Cluster/ClusterInfo.h"
|
||||||
|
#include "Cluster/ClusterMethods.h"
|
||||||
#include "Utils/Exception.h"
|
#include "Utils/Exception.h"
|
||||||
#include "VocBase/document-collection.h"
|
#include "VocBase/document-collection.h"
|
||||||
#include "VocBase/transaction.h"
|
#include "VocBase/transaction.h"
|
||||||
|
@ -80,8 +81,12 @@ Collection::~Collection () {
|
||||||
size_t Collection::count () const {
|
size_t Collection::count () const {
|
||||||
if (numDocuments == UNINITIALIZED) {
|
if (numDocuments == UNINITIALIZED) {
|
||||||
if (ExecutionEngine::isCoordinator()) {
|
if (ExecutionEngine::isCoordinator()) {
|
||||||
/// TODO: determine the proper number of documents in the coordinator case
|
uint64_t result;
|
||||||
numDocuments = 1000;
|
int res = triagens::arango::countOnCoordinator(vocbase->_name, name, result);
|
||||||
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
|
THROW_ARANGO_EXCEPTION_MESSAGE(res, "could not determine number of documents in collection");
|
||||||
|
}
|
||||||
|
numDocuments = static_cast<int64_t>(result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto document = documentCollection();
|
auto document = documentCollection();
|
||||||
|
@ -197,6 +202,29 @@ void Collection::fillIndexes () const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (ExecutionEngine::isDBServer()) {
|
||||||
|
TRI_ASSERT(collection != nullptr);
|
||||||
|
auto document = documentCollection();
|
||||||
|
|
||||||
|
// lookup collection in agency by plan id
|
||||||
|
auto clusterInfo = triagens::arango::ClusterInfo::instance();
|
||||||
|
auto collectionInfo = clusterInfo->getCollection(std::string(vocbase->_name), triagens::basics::StringUtils::itoa(document->_info._planId));
|
||||||
|
if (collectionInfo.get() == nullptr || (*collectionInfo).empty()) {
|
||||||
|
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "collection not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
TRI_json_t const* json = (*collectionInfo).getIndexes();
|
||||||
|
size_t const n = document->_allIndexes._length;
|
||||||
|
indexes.reserve(n);
|
||||||
|
|
||||||
|
// register indexes
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
TRI_json_t const* v = TRI_LookupListJson(json, i);
|
||||||
|
if (v != nullptr) {
|
||||||
|
indexes.emplace_back(new Index(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// local collection
|
// local collection
|
||||||
TRI_ASSERT(collection != nullptr);
|
TRI_ASSERT(collection != nullptr);
|
||||||
|
|
|
@ -288,7 +288,7 @@ int ExecutionBlock::resolve (char const* handle,
|
||||||
std::string const name(handle, p - handle);
|
std::string const name(handle, p - handle);
|
||||||
cid = _trx->resolver()->getCollectionIdCluster(name);
|
cid = _trx->resolver()->getCollectionIdCluster(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid == 0) {
|
if (cid == 0) {
|
||||||
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
@ -803,6 +803,7 @@ IndexRangeBlock::IndexRangeBlock (ExecutionEngine* engine,
|
||||||
_allBoundsConstant(true) {
|
_allBoundsConstant(true) {
|
||||||
|
|
||||||
std::vector<std::vector<RangeInfo>> const& orRanges = en->_ranges;
|
std::vector<std::vector<RangeInfo>> const& orRanges = en->_ranges;
|
||||||
|
TRI_ASSERT(en->_index != nullptr);
|
||||||
|
|
||||||
TRI_ASSERT(orRanges.size() == 1); // OR expressions not yet implemented
|
TRI_ASSERT(orRanges.size() == 1); // OR expressions not yet implemented
|
||||||
|
|
||||||
|
@ -888,7 +889,6 @@ int IndexRangeBlock::initialize () {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IndexRangeBlock::readIndex () {
|
bool IndexRangeBlock::readIndex () {
|
||||||
|
|
||||||
// This is either called from initialize if all bounds are constant,
|
// This is either called from initialize if all bounds are constant,
|
||||||
// in this case it is never called again. If there is at least one
|
// in this case it is never called again. If there is at least one
|
||||||
// variable bound, then readIndex is called once for every item coming
|
// variable bound, then readIndex is called once for every item coming
|
||||||
|
@ -907,6 +907,8 @@ bool IndexRangeBlock::readIndex () {
|
||||||
|
|
||||||
auto en = static_cast<IndexRangeNode const*>(getPlanNode());
|
auto en = static_cast<IndexRangeNode const*>(getPlanNode());
|
||||||
IndexOrCondition const* condition = &en->_ranges;
|
IndexOrCondition const* condition = &en->_ranges;
|
||||||
|
|
||||||
|
TRI_ASSERT(en->_index != nullptr);
|
||||||
|
|
||||||
std::unique_ptr<IndexOrCondition> newCondition;
|
std::unique_ptr<IndexOrCondition> newCondition;
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,14 @@ bool ExecutionEngine::isCoordinator () {
|
||||||
return triagens::arango::ServerState::instance()->isCoordinator();
|
return triagens::arango::ServerState::instance()->isCoordinator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// @brief whether or not we are a db server
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool ExecutionEngine::isDBServer () {
|
||||||
|
return triagens::arango::ServerState::instance()->isDBserver();
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- walker class for ExecutionNode to instanciate
|
// --SECTION-- walker class for ExecutionNode to instanciate
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -78,6 +78,12 @@ namespace triagens {
|
||||||
|
|
||||||
static bool isCoordinator ();
|
static bool isCoordinator ();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// @brief whether or not we are a DB server
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static bool isDBServer ();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// @brief create an execution engine from a plan
|
// @brief create an execution engine from a plan
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1303,7 +1303,8 @@ IndexRangeNode::IndexRangeNode (ExecutionPlan* plan,
|
||||||
_vocbase(plan->getAst()->query()->vocbase()),
|
_vocbase(plan->getAst()->query()->vocbase()),
|
||||||
_collection(plan->getAst()->query()->collections()->get(JsonHelper::checkAndGetStringValue(json.json(),
|
_collection(plan->getAst()->query()->collections()->get(JsonHelper::checkAndGetStringValue(json.json(),
|
||||||
"collection"))),
|
"collection"))),
|
||||||
_outVariable(varFromJson(plan->getAst(), json, "outVariable")),
|
_outVariable(varFromJson(plan->getAst(), json, "outVariable")),
|
||||||
|
_index(nullptr),
|
||||||
_ranges(),
|
_ranges(),
|
||||||
_reverse(false) {
|
_reverse(false) {
|
||||||
|
|
||||||
|
@ -1324,6 +1325,10 @@ IndexRangeNode::IndexRangeNode (ExecutionPlan* plan,
|
||||||
|
|
||||||
_index = _collection->getIndex(iid);
|
_index = _collection->getIndex(iid);
|
||||||
_reverse = JsonHelper::checkAndGetBooleanValue(json.json(), "reverse");
|
_reverse = JsonHelper::checkAndGetBooleanValue(json.json(), "reverse");
|
||||||
|
|
||||||
|
if (_index == nullptr) {
|
||||||
|
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "index not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutionNode::IndexMatch IndexRangeNode::MatchesIndex (IndexMatchVec const& pattern) const {
|
ExecutionNode::IndexMatch IndexRangeNode::MatchesIndex (IndexMatchVec const& pattern) const {
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool empty () const {
|
bool empty () const {
|
||||||
return (0 == _json); //|| (id() == 0);
|
return (nullptr == _json); //|| (id() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -189,11 +189,11 @@ namespace triagens {
|
||||||
TRI_json_t* keyOptions () const {
|
TRI_json_t* keyOptions () const {
|
||||||
TRI_json_t const* keyOptions = triagens::basics::JsonHelper::getArrayElement(_json, "keyOptions");
|
TRI_json_t const* keyOptions = triagens::basics::JsonHelper::getArrayElement(_json, "keyOptions");
|
||||||
|
|
||||||
if (keyOptions != 0) {
|
if (keyOptions != nullptr) {
|
||||||
return TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, keyOptions);
|
return TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, keyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -203,7 +203,7 @@ namespace triagens {
|
||||||
bool allowUserKeys () const {
|
bool allowUserKeys () const {
|
||||||
TRI_json_t const* keyOptions = triagens::basics::JsonHelper::getArrayElement(_json, "keyOptions");
|
TRI_json_t const* keyOptions = triagens::basics::JsonHelper::getArrayElement(_json, "keyOptions");
|
||||||
|
|
||||||
if (keyOptions != 0) {
|
if (keyOptions != nullptr) {
|
||||||
return triagens::basics::JsonHelper::getBooleanValue(keyOptions, "allowUserKeys", true);
|
return triagens::basics::JsonHelper::getBooleanValue(keyOptions, "allowUserKeys", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ namespace triagens {
|
||||||
TRI_json_t* _json = it->second;
|
TRI_json_t* _json = it->second;
|
||||||
b = triagens::basics::JsonHelper::getBooleanValue(_json,
|
b = triagens::basics::JsonHelper::getBooleanValue(_json,
|
||||||
name, false);
|
name, false);
|
||||||
m.insert(make_pair(it->first,b));
|
m.insert(make_pair(it->first, b));
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -539,15 +539,12 @@ namespace triagens {
|
||||||
= triagens::basics::JsonHelper::getArrayElement
|
= triagens::basics::JsonHelper::getArrayElement
|
||||||
(_json, "keyOptions");
|
(_json, "keyOptions");
|
||||||
|
|
||||||
if (keyOptions != 0) {
|
if (keyOptions != nullptr) {
|
||||||
return TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, keyOptions);
|
return TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, keyOptions);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue