From dbfe62fd664f23915a51c807cd2d1432eb2bddd8 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Tue, 10 Jun 2014 14:32:57 +0200 Subject: [PATCH] TRI_SelectByExample now uses copies of master pointers. --- arangod/V8Server/v8-query.cpp | 20 ++++++++++---------- arangod/VocBase/document-collection.cpp | 6 +++--- arangod/VocBase/document-collection.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index e74724379d..0cc6c354c2 100644 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -1880,16 +1880,22 @@ static v8::Handle JS_ByExampleQuery (v8::Arguments const& argv) { v8::Handle documents = v8::Array::New(); result->Set(v8::String::New("documents"), documents); - // ............................................................................. + // ........................................................................... // inside a read transaction - // ............................................................................. + // ........................................................................... trx.lockRead(); // find documents by example - vector filtered + vector filtered = TRI_SelectByExample(trx.trxCollection(), n, pids, values); + trx.finish(res); + + // ........................................................................... + // outside a read transaction + // ........................................................................... + // convert to list of shaped jsons size_t total = filtered.size(); size_t count = 0; @@ -1903,7 +1909,7 @@ static v8::Handle JS_ByExampleQuery (v8::Arguments const& argv) { if (s < e) { for (size_t j = s; j < e; ++j) { - TRI_doc_mptr_t* mptr = filtered[j]; + TRI_doc_mptr_copy_t* mptr = &filtered[j]; v8::Handle doc = WRAP_SHAPED_JSON(trx, col->_cid, mptr); @@ -1918,12 +1924,6 @@ static v8::Handle JS_ByExampleQuery (v8::Arguments const& argv) { } } - trx.finish(res); - - // ............................................................................. - // outside a write transaction - // ............................................................................. - result->Set(v8::String::New("total"), v8::Integer::New((int32_t) total)); result->Set(v8::String::New("count"), v8::Integer::New((int32_t) count)); diff --git a/arangod/VocBase/document-collection.cpp b/arangod/VocBase/document-collection.cpp index 2ee63df588..db448c5c6d 100644 --- a/arangod/VocBase/document-collection.cpp +++ b/arangod/VocBase/document-collection.cpp @@ -5483,7 +5483,7 @@ static bool IsExampleMatch (TRI_transaction_collection_t*, //////////////////////////////////////////////////////////////////////////////// -std::vector TRI_SelectByExample ( +std::vector TRI_SelectByExample ( TRI_transaction_collection_t* trxCollection, size_t length, TRI_shape_pid_t* pids, @@ -5494,7 +5494,7 @@ std::vector TRI_SelectByExample ( TRI_shaper_t* shaper = document->_shaper; // use filtered to hold copies of the master pointer - std::vector filtered; + std::vector filtered; // do a full scan TRI_doc_mptr_t** ptr = (TRI_doc_mptr_t**) (document->_primaryIndex._table); @@ -5502,7 +5502,7 @@ std::vector TRI_SelectByExample ( for (; ptr < end; ++ptr) { if (*ptr != nullptr && IsExampleMatch(trxCollection, shaper, *ptr, length, pids, values)) { - filtered.push_back(*ptr); + filtered.push_back(**ptr); } } return filtered; diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h index a0d8938035..c3a5c00094 100644 --- a/arangod/VocBase/document-collection.h +++ b/arangod/VocBase/document-collection.h @@ -986,7 +986,7 @@ struct TRI_index_s* TRI_EnsureFulltextIndexDocumentCollection (TRI_document_coll /// @brief executes a select-by-example query //////////////////////////////////////////////////////////////////////////////// -std::vector TRI_SelectByExample ( +std::vector TRI_SelectByExample ( struct TRI_transaction_collection_s*, size_t, TRI_shape_pid_t*,