From cec7d79fc2307ff25b7dac4da9502fc833f5f20a Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Wed, 5 Oct 2016 13:00:43 +0200 Subject: [PATCH 1/2] Added a new error code if a collection is not smart (EE only) --- js/common/bootstrap/errors.js | 1 + lib/Basics/errors.dat | 7 +++++++ lib/Basics/voc-errors.cpp | 1 + lib/Basics/voc-errors.h | 12 ++++++++++++ 4 files changed, 21 insertions(+) diff --git a/js/common/bootstrap/errors.js b/js/common/bootstrap/errors.js index ee0342ed79..3ab22357f4 100644 --- a/js/common/bootstrap/errors.js +++ b/js/common/bootstrap/errors.js @@ -258,6 +258,7 @@ "ERROR_SERVICE_MOUNTPOINT_CONFLICT" : { "code" : 3011, "message" : "mountpoint already in use" }, "ERROR_MODULE_NOT_FOUND" : { "code" : 3100, "message" : "cannot locate module" }, "ERROR_MODULE_FAILURE" : { "code" : 3103, "message" : "failed to invoke module" }, + "ERROR_NO_SMART_COLLECTION" : { "code" : 4000, "message" : "collection is not smart" }, "ERROR_DISPATCHER_IS_STOPPING" : { "code" : 21001, "message" : "dispatcher stopped" }, "ERROR_QUEUE_UNKNOWN" : { "code" : 21002, "message" : "named queue does not exist" }, "ERROR_QUEUE_FULL" : { "code" : 21003, "message" : "named queue is full" } diff --git a/lib/Basics/errors.dat b/lib/Basics/errors.dat index e5ac1b0189..9d72efd678 100755 --- a/lib/Basics/errors.dat +++ b/lib/Basics/errors.dat @@ -360,6 +360,13 @@ ERROR_SERVICE_MOUNTPOINT_CONFLICT,3011,"mountpoint already in use","A service ha ERROR_MODULE_NOT_FOUND,3100,"cannot locate module","The module path could not be resolved." ERROR_MODULE_FAILURE,3103,"failed to invoke module","Failed to invoke the module in its context." + +################################################################################ +## Enterprise errors +################################################################################ + +ERROR_NO_SMART_COLLECTION,4000,"collection is not smart","The requested collection needs to be smart, but it ain't" + ################################################################################ ## Dispatcher errors ################################################################################ diff --git a/lib/Basics/voc-errors.cpp b/lib/Basics/voc-errors.cpp index d242393100..d4b16d8076 100644 --- a/lib/Basics/voc-errors.cpp +++ b/lib/Basics/voc-errors.cpp @@ -254,6 +254,7 @@ void TRI_InitializeErrorMessages () { REG_ERROR(ERROR_SERVICE_MOUNTPOINT_CONFLICT, "mountpoint already in use"); REG_ERROR(ERROR_MODULE_NOT_FOUND, "cannot locate module"); REG_ERROR(ERROR_MODULE_FAILURE, "failed to invoke module"); + REG_ERROR(ERROR_NO_SMART_COLLECTION, "collection is not smart"); REG_ERROR(ERROR_DISPATCHER_IS_STOPPING, "dispatcher stopped"); REG_ERROR(ERROR_QUEUE_UNKNOWN, "named queue does not exist"); REG_ERROR(ERROR_QUEUE_FULL, "named queue is full"); diff --git a/lib/Basics/voc-errors.h b/lib/Basics/voc-errors.h index 6a7031c068..691bcba22f 100644 --- a/lib/Basics/voc-errors.h +++ b/lib/Basics/voc-errors.h @@ -605,6 +605,8 @@ /// The module path could not be resolved. /// - 3103: @LIT{failed to invoke module} /// Failed to invoke the module in its context. +/// - 4000: @LIT{collection is not smart} +/// The requested collection needs to be smart, but it ain't /// - 21001: @LIT{dispatcher stopped} /// Will be returned if a shutdown is in progress. /// - 21002: @LIT{named queue does not exist} @@ -3195,6 +3197,16 @@ void TRI_InitializeErrorMessages (); #define TRI_ERROR_MODULE_FAILURE (3103) +//////////////////////////////////////////////////////////////////////////////// +/// @brief 4000: ERROR_NO_SMART_COLLECTION +/// +/// collection is not smart +/// +/// The requested collection needs to be smart, but it ain't +//////////////////////////////////////////////////////////////////////////////// + +#define TRI_ERROR_NO_SMART_COLLECTION (4000) + //////////////////////////////////////////////////////////////////////////////// /// @brief 21001: ERROR_DISPATCHER_IS_STOPPING /// From a6dbda8bddd5cd96027baa091bc72aa37c562415 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Wed, 5 Oct 2016 13:01:27 +0200 Subject: [PATCH 2/2] Made index creation enterprise ready. --- arangod/Cluster/ClusterInfo.cpp | 11 ++- arangod/V8Server/v8-vocindex.cpp | 116 ++++++++++++++++--------------- arangod/V8Server/v8-vocindex.h | 12 +++- 3 files changed, 80 insertions(+), 59 deletions(-) diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 2ef3647ec4..d032dd84cd 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -1687,7 +1687,12 @@ int ClusterInfo::ensureIndexCoordinator( loadPlan(); - TRI_ASSERT(*numberOfShards > 0); + if (*numberOfShards == 0) { + errorMsg = *errMsg; + resultBuilder = *resBuilder; + loadCurrent(); + return TRI_ERROR_NO_ERROR; + } { CONDITION_LOCKER(locker, agencyCallback->_cv); @@ -1902,6 +1907,10 @@ int ClusterInfo::dropIndexCoordinator(std::string const& databaseName, // load our own cache: loadPlan(); + if (*numberOfShards == 0) { + loadCurrent(); + return TRI_ERROR_NO_ERROR; + } { MUTEX_LOCKER(guard, *numberOfShardsMutex); diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 7f970044d1..fbbb211b77 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -448,15 +448,11 @@ static int EnhanceIndexJson(v8::FunctionCallbackInfo const& args, /// @brief ensures an index, coordinator case //////////////////////////////////////////////////////////////////////////////// -int EnsureIndexCoordinator( - LogicalCollection const* collection, VPackSlice const slice, bool create, - VPackBuilder& resultBuilder, std::string& errorMsg) { - TRI_ASSERT(collection != nullptr); +int EnsureIndexCoordinator(std::string const& databaseName, + std::string const& cid, + VPackSlice const slice, bool create, + VPackBuilder& resultBuilder, std::string& errorMsg) { TRI_ASSERT(!slice.isNone()); - - std::string const databaseName(collection->dbName()); - std::string const cid = collection->cid_as_string(); - return ClusterInfo::instance()->ensureIndexCoordinator( databaseName, cid, slice, create, &arangodb::Index::Compare, resultBuilder, errorMsg, 360.0); @@ -604,9 +600,13 @@ static void EnsureIndex(v8::FunctionCallbackInfo const& args, VPackBuilder resultBuilder; std::string errorMsg; #ifdef USE_ENTERPRISE - int res = EnsureIndexCoordinatorEnterprise(collection, slice, create, resultBuilder, errorMsg); + int res = EnsureIndexCoordinatorEnterprise(collection, slice, create, + resultBuilder, errorMsg); #else - int res = EnsureIndexCoordinator(collection, slice, create, resultBuilder, errorMsg); + std::string const databaseName(collection->dbName()); + std::string const cid = collection->cid_as_string(); + int res = EnsureIndexCoordinator(databaseName, cid, slice, create, + resultBuilder, errorMsg); #endif if (res != TRI_ERROR_NO_ERROR) { TRI_V8_THROW_EXCEPTION_MESSAGE(res, errorMsg); @@ -728,54 +728,15 @@ static void JS_LookupIndexVocbaseCol( /// @brief drops an index, coordinator case //////////////////////////////////////////////////////////////////////////////// -static void DropIndexCoordinator( - v8::FunctionCallbackInfo const& args, - arangodb::LogicalCollection const* collection, v8::Handle const val) { - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); - - std::string collectionName; - TRI_idx_iid_t iid = 0; - - // extract the index identifier from a string - if (val->IsString() || val->IsStringObject() || val->IsNumber()) { - if (!IsIndexHandle(val, collectionName, iid)) { - TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_INDEX_HANDLE_BAD); - } - } - - // extract the index identifier from an object - else if (val->IsObject()) { - TRI_GET_GLOBALS(); - - v8::Handle obj = val->ToObject(); - TRI_GET_GLOBAL_STRING(IdKey); - v8::Handle iidVal = obj->Get(IdKey); - - if (!IsIndexHandle(iidVal, collectionName, iid)) { - TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_INDEX_HANDLE_BAD); - } - } - - if (!collectionName.empty()) { - CollectionNameResolver resolver(collection->vocbase()); - - if (!EqualCollection(&resolver, collectionName, collection)) { - TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_CROSS_COLLECTION_REQUEST); - } - } - - std::string const databaseName(collection->dbName()); - std::string const cid = collection->cid_as_string(); +int DropIndexCoordinator( + std::string const& databaseName, + std::string const& cid, + TRI_idx_iid_t const iid) { std::string errorMsg; - int res = ClusterInfo::instance()->dropIndexCoordinator(databaseName, cid, - iid, errorMsg, 0.0); + return ClusterInfo::instance()->dropIndexCoordinator(databaseName, cid, + iid, errorMsg, 0.0); - if (res == TRI_ERROR_NO_ERROR) { - TRI_V8_RETURN_TRUE(); - } - TRI_V8_RETURN_FALSE(); } //////////////////////////////////////////////////////////////////////////////// @@ -801,8 +762,49 @@ static void JS_DropIndexVocbaseCol( } if (ServerState::instance()->isCoordinator()) { - DropIndexCoordinator(args, collection, args[0]); - return; + std::string collectionName; + TRI_idx_iid_t iid = 0; + v8::Handle const val = args[0]; + + // extract the index identifier from a string + if (val->IsString() || val->IsStringObject() || val->IsNumber()) { + if (!IsIndexHandle(val, collectionName, iid)) { + TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_INDEX_HANDLE_BAD); + } + } + + // extract the index identifier from an object + else if (val->IsObject()) { + TRI_GET_GLOBALS(); + + v8::Handle obj = val->ToObject(); + TRI_GET_GLOBAL_STRING(IdKey); + v8::Handle iidVal = obj->Get(IdKey); + + if (!IsIndexHandle(iidVal, collectionName, iid)) { + TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_INDEX_HANDLE_BAD); + } + } + + if (!collectionName.empty()) { + CollectionNameResolver resolver(collection->vocbase()); + + if (!EqualCollection(&resolver, collectionName, collection)) { + TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_CROSS_COLLECTION_REQUEST); + } + } + +#ifdef USE_ENTERPRISE + int res = DropIndexCoordinatorEnterprise(collection, iid); +#else + std::string const databaseName(collection->dbName()); + std::string const cid = collection->cid_as_string(); + int res = DropIndexCoordinator(databaseName, cid, iid); +#endif + if (res == TRI_ERROR_NO_ERROR) { + TRI_V8_RETURN_TRUE(); + } + TRI_V8_RETURN_FALSE(); } READ_LOCKER(readLocker, collection->vocbase()->_inventoryLock); diff --git a/arangod/V8Server/v8-vocindex.h b/arangod/V8Server/v8-vocindex.h index 3b9adeea39..426dfc82b5 100644 --- a/arangod/V8Server/v8-vocindex.h +++ b/arangod/V8Server/v8-vocindex.h @@ -61,7 +61,7 @@ std::unique_ptr CreateCollectionCoordinatorEnterpri arangodb::velocypack::Slice parameters); #endif -int EnsureIndexCoordinator(arangodb::LogicalCollection const* collection, +int EnsureIndexCoordinator(std::string const& dbName, std::string const& cid, arangodb::velocypack::Slice const slice, bool create, arangodb::velocypack::Builder& resultBuilder, std::string& errorMessage); @@ -73,4 +73,14 @@ int EnsureIndexCoordinatorEnterprise( arangodb::velocypack::Builder& resultBuilder, std::string& errorMessage); #endif +int DropIndexCoordinator( + std::string const& databaseName, + std::string const& cid, + TRI_idx_iid_t const iid); + +#ifdef USE_ENTERPRISE +int DropIndexCoordinatorEnterprise( + arangodb::LogicalCollection const* collection, TRI_idx_iid_t const iid); +#endif + #endif