From 21317e16b0dff0801551013a5908a2b65bdacfa1 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 4 Oct 2016 19:05:23 +0200 Subject: [PATCH] Prepared index creation to be enterprise-ready. --- arangod/V8Server/v8-vocindex.cpp | 51 +++++++++++++++----------------- arangod/V8Server/v8-vocindex.h | 13 ++++++++ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 6e48e95edf..7f970044d1 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -448,40 +448,18 @@ static int EnhanceIndexJson(v8::FunctionCallbackInfo const& args, /// @brief ensures an index, coordinator case //////////////////////////////////////////////////////////////////////////////// -static void EnsureIndexCoordinator( - v8::FunctionCallbackInfo const& args, - LogicalCollection const* collection, VPackSlice const slice, bool create) { - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); - +int EnsureIndexCoordinator( + LogicalCollection const* collection, VPackSlice const slice, bool create, + VPackBuilder& resultBuilder, std::string& errorMsg) { TRI_ASSERT(collection != nullptr); TRI_ASSERT(!slice.isNone()); std::string const databaseName(collection->dbName()); std::string const cid = collection->cid_as_string(); - std::string const collectionName(collection->name()); - VPackBuilder resultBuilder; - std::string errorMsg; - int res = ClusterInfo::instance()->ensureIndexCoordinator( + return ClusterInfo::instance()->ensureIndexCoordinator( databaseName, cid, slice, create, &arangodb::Index::Compare, resultBuilder, errorMsg, 360.0); - - if (res != TRI_ERROR_NO_ERROR) { - TRI_V8_THROW_EXCEPTION_MESSAGE(res, errorMsg); - } - - if (resultBuilder.slice().isNone()) { - if (!create) { - // did not find a suitable index - TRI_V8_RETURN_NULL(); - } - - TRI_V8_THROW_EXCEPTION_MEMORY(); - } - - v8::Handle ret = IndexRep(isolate, collectionName, resultBuilder.slice()); - TRI_V8_RETURN(ret); } //////////////////////////////////////////////////////////////////////////////// @@ -623,7 +601,26 @@ static void EnsureIndex(v8::FunctionCallbackInfo const& args, TRI_ASSERT(!slice.isNone()); // ensure an index, coordinator case if (ServerState::instance()->isCoordinator()) { - EnsureIndexCoordinator(args, collection, slice, create); + VPackBuilder resultBuilder; + std::string errorMsg; +#ifdef USE_ENTERPRISE + int res = EnsureIndexCoordinatorEnterprise(collection, slice, create, resultBuilder, errorMsg); +#else + int res = EnsureIndexCoordinator(collection, slice, create, resultBuilder, errorMsg); +#endif + if (res != TRI_ERROR_NO_ERROR) { + TRI_V8_THROW_EXCEPTION_MESSAGE(res, errorMsg); + } + if (resultBuilder.slice().isNone()) { + if (!create) { + // did not find a suitable index + TRI_V8_RETURN_NULL(); + } + + TRI_V8_THROW_EXCEPTION_MEMORY(); + } + v8::Handle ret = IndexRep(isolate, collection->name(), resultBuilder.slice()); + TRI_V8_RETURN(ret); } else { EnsureIndexLocal(args, collection, slice, create); } diff --git a/arangod/V8Server/v8-vocindex.h b/arangod/V8Server/v8-vocindex.h index d2c913839a..3b9adeea39 100644 --- a/arangod/V8Server/v8-vocindex.h +++ b/arangod/V8Server/v8-vocindex.h @@ -60,4 +60,17 @@ std::unique_ptr CreateCollectionCoordinatorEnterpri TRI_col_type_e collectionType, TRI_vocbase_t* vocbase, arangodb::velocypack::Slice parameters); #endif + +int EnsureIndexCoordinator(arangodb::LogicalCollection const* collection, + arangodb::velocypack::Slice const slice, bool create, + arangodb::velocypack::Builder& resultBuilder, + std::string& errorMessage); + +#ifdef USE_ENTERPRISE +int EnsureIndexCoordinatorEnterprise( + arangodb::LogicalCollection const* collection, + arangodb::velocypack::Slice const slice, bool create, + arangodb::velocypack::Builder& resultBuilder, std::string& errorMessage); +#endif + #endif