From 2700a6d79df69c00d15cdb1989f5ca1d9cf456df Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Wed, 12 Apr 2017 14:50:55 +0200 Subject: [PATCH] fix rocksdb engine index reporting but break report for mmfiles engine --- arangod/Indexes/Index.cpp | 2 - arangod/RocksDBEngine/RocksDBEdgeIndex.cpp | 35 ++++++++++++++- arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp | 3 ++ arangod/RocksDBEngine/RocksDBVPackIndex.cpp | 3 ++ arangod/V8Server/v8-vocindex.cpp | 44 ++++++++++++++----- arangod/VocBase/PhysicalCollection.cpp | 2 - 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/arangod/Indexes/Index.cpp b/arangod/Indexes/Index.cpp index 6f213f57a5..7406eaa308 100644 --- a/arangod/Indexes/Index.cpp +++ b/arangod/Indexes/Index.cpp @@ -394,9 +394,7 @@ std::string Index::context() const { /// base functionality (called from derived classes) std::shared_ptr Index::toVelocyPack(bool withFigures) const { auto builder = std::make_shared(); - builder->openObject(); toVelocyPack(*builder, withFigures); - builder->close(); return builder; } diff --git a/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp b/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp index 5cf9802b4f..c4801ad5bc 100644 --- a/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBEdgeIndex.cpp @@ -190,11 +190,44 @@ size_t RocksDBEdgeIndex::memory() const { /// @brief return a VelocyPack representation of the index void RocksDBEdgeIndex::toVelocyPack(VPackBuilder& builder, bool withFigures) const { - RocksDBIndex::toVelocyPack(builder, withFigures); + + LOG_TOPIC(ERR, Logger::FIXME) << "EDGE INDEX (" << _directionAttr << ")"; + // skip to + if(_directionAttr == StaticStrings::ToString) + return; + TRI_ASSERT(builder.isOpenArray() || builder.isEmpty()); + + //get data that needs to be modified + VPackBuilder tmpBuilder; + tmpBuilder.openObject(); + RocksDBIndex::toVelocyPack(tmpBuilder, withFigures); + tmpBuilder.close(); + VPackSlice slice = tmpBuilder.slice(); + + builder.openObject(); + for(auto const& item : VPackObjectIterator(slice)){ + //add id + //add type + if (item.key.compareString("fields") == 0){ + // modify fields + builder.add("fields", VPackValue(VPackValueType::Array, false)); + builder.add(VPackValue(StaticStrings::FromString)); + builder.add(VPackValue(StaticStrings::ToString)); + builder.close(); + } else { + // copy other items + auto ref = StringRef(item.key); + builder.add(ref.data(), ref.length(), item.value); + } + } + + // add slectivity estimate // hard-coded builder.add("unique", VPackValue(false)); builder.add("sparse", VPackValue(false)); + + builder.close(); } /// @brief return a VelocyPack representation of the index figures diff --git a/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp b/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp index 87bef71f18..dd22f06533 100644 --- a/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp @@ -275,10 +275,13 @@ size_t RocksDBPrimaryIndex::memory() const { /// @brief return a VelocyPack representation of the index void RocksDBPrimaryIndex::toVelocyPack(VPackBuilder& builder, bool withFigures) const { + TRI_ASSERT(builder.isOpenArray() || builder.isEmpty()); + builder.openObject(); RocksDBIndex::toVelocyPack(builder, withFigures); // hard-coded builder.add("unique", VPackValue(true)); builder.add("sparse", VPackValue(false)); + builder.close(); } /// @brief return a VelocyPack representation of the index figures diff --git a/arangod/RocksDBEngine/RocksDBVPackIndex.cpp b/arangod/RocksDBEngine/RocksDBVPackIndex.cpp index 1eb7a94dd0..f5a366e450 100644 --- a/arangod/RocksDBEngine/RocksDBVPackIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBVPackIndex.cpp @@ -180,9 +180,12 @@ size_t RocksDBVPackIndex::memory() const { /// @brief return a VelocyPack representation of the index void RocksDBVPackIndex::toVelocyPack(VPackBuilder& builder, bool withFigures) const { + TRI_ASSERT(builder.isOpenArray() || builder.isEmpty()); + builder.openObject(); RocksDBIndex::toVelocyPack(builder, withFigures); builder.add("unique", VPackValue(_unique)); builder.add("sparse", VPackValue(_sparse)); + builder.close(); } /// @brief return a VelocyPack representation of the index figures diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 3538c79694..2ac90ae018 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -116,6 +116,21 @@ static v8::Handle IndexRep(v8::Isolate* isolate, return scope.Escape(rep); } +static void IndexRep(v8::Isolate* isolate, std::string const& collectionName, + v8::Handle& array) { + for (size_t i = 0; i < array->Length(); i++) { + v8::Handle tmprep = array->Get(i); + // TODO -- modify rep inplace?! + v8::Handle rep = v8::Handle::Cast(tmprep); + std::string iid = TRI_ObjectToString(rep->Get(TRI_V8_ASCII_STRING("id"))); + std::string const id = + collectionName + TRI_INDEX_HANDLE_SEPARATOR_STR + iid; + LOG_TOPIC(ERR, Logger::FIXME) << "FINAL INDEX ID = " << id; + rep->Set(TRI_V8_ASCII_STRING("id"), TRI_V8_STD_STRING(id)); + array->Set(i, rep); + } +} + //////////////////////////////////////////////////////////////////////////////// /// @brief enhances the json of an index //////////////////////////////////////////////////////////////////////////////// @@ -200,13 +215,14 @@ static void EnsureIndexLocal(v8::FunctionCallbackInfo const& args, } transaction::BuilderLeaser builder(&trx); - builder->openObject(); + // TODO FIXME FOR MMFILES + // builder->openObject(); try { idx->toVelocyPack(*(builder.get()), false); } catch (...) { TRI_V8_THROW_EXCEPTION_MEMORY(); } - builder->close(); + // builder->close(); v8::Handle ret = IndexRep(isolate, collection->name(), builder->slice()); @@ -574,18 +590,26 @@ static void JS_GetIndexesVocbaseCol( trx.finish(res); // READ-LOCK end + builder->clear(); size_t const n = indexes.size(); - v8::Handle result = v8::Array::New(isolate, static_cast(n)); - + builder->openArray(); + VPackBuilder tmpBuilder; for (size_t i = 0; i < n; ++i) { + tmpBuilder.clear(); auto const& idx = indexes[i]; - builder->clear(); - builder->openObject(); - idx->toVelocyPack(*(builder.get()), withFigures); - builder->close(); - result->Set(static_cast(i), - IndexRep(isolate, collectionName, builder->slice())); + // TODO FIXME FOR MMFILES + //builder->openObject(); + idx->toVelocyPack(tmpBuilder, withFigures); + //builder->close(); + if(!tmpBuilder.isEmpty()){ + builder->add(tmpBuilder.slice()); + } } + builder->close(); + v8::Handle objresult = TRI_VPackToV8(isolate, builder->slice()); + v8::Handle result = v8::Handle::Cast(objresult); + + IndexRep(isolate,collectionName,result); TRI_V8_RETURN(result); TRI_V8_TRY_CATCH_END diff --git a/arangod/VocBase/PhysicalCollection.cpp b/arangod/VocBase/PhysicalCollection.cpp index 68f94093c9..784af0c72d 100644 --- a/arangod/VocBase/PhysicalCollection.cpp +++ b/arangod/VocBase/PhysicalCollection.cpp @@ -368,9 +368,7 @@ void PhysicalCollection::getIndexesVPack(VPackBuilder& result, bool withFigures) const { result.openArray(); for (auto const& idx : _indexes) { - result.openObject(); idx->toVelocyPack(result, withFigures); - result.close(); } result.close(); }