From ddb83c8075d21b03cf36a489b65bc11054003fd0 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 30 Mar 2017 14:15:46 +0200 Subject: [PATCH] fixed issue #2404 --- .../RestHandler/RestReplicationHandler.cpp | 12 +++++++-- js/server/tests/dump/dump-setup.js | 7 +++++ js/server/tests/dump/dump.js | 26 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/arangod/RestHandler/RestReplicationHandler.cpp b/arangod/RestHandler/RestReplicationHandler.cpp index 3744ccbea8..380e0967a9 100644 --- a/arangod/RestHandler/RestReplicationHandler.cpp +++ b/arangod/RestHandler/RestReplicationHandler.cpp @@ -1725,6 +1725,8 @@ int RestReplicationHandler::processRestoreIndexes(VPackSlice const& collection, return TRI_ERROR_NO_ERROR; } + int res = TRI_ERROR_NO_ERROR; + READ_LOCKER(readLocker, _vocbase->_inventoryLock); // look up the collection @@ -1737,7 +1739,7 @@ int RestReplicationHandler::processRestoreIndexes(VPackSlice const& collection, transaction::StandaloneContext::Create(_vocbase), collection->cid(), AccessMode::Type::WRITE); - int res = trx.begin(); + res = trx.begin(); if (res != TRI_ERROR_NO_ERROR) { errorMsg = @@ -1765,6 +1767,12 @@ int RestReplicationHandler::processRestoreIndexes(VPackSlice const& collection, } TRI_ASSERT(idx != nullptr); } + + if (res != TRI_ERROR_NO_ERROR) { + return res; + } + res = trx.commit(); + } catch (arangodb::basics::Exception const& ex) { errorMsg = "could not create index: " + std::string(TRI_errno_string(ex.code())); @@ -1772,7 +1780,7 @@ int RestReplicationHandler::processRestoreIndexes(VPackSlice const& collection, errorMsg = "could not create index: unknown error"; } - return TRI_ERROR_NO_ERROR; + return res; } //////////////////////////////////////////////////////////////////////////////// diff --git a/js/server/tests/dump/dump-setup.js b/js/server/tests/dump/dump-setup.js index 6731850195..2bc7dcdab8 100644 --- a/js/server/tests/dump/dump-setup.js +++ b/js/server/tests/dump/dump-setup.js @@ -191,6 +191,13 @@ } catch (err) { } + + c = db._create("UnitTestsDumpPersistent"); + c.ensureIndex({ type: "persistent", fields: ["value"], unique: true }); + + for (i = 0; i < 10000; ++i) { + c.save({ _key: "test" + i, value: i }); + } })(); diff --git a/js/server/tests/dump/dump.js b/js/server/tests/dump/dump.js index 056fbdc4f7..d3e3bba0bd 100644 --- a/js/server/tests/dump/dump.js +++ b/js/server/tests/dump/dump.js @@ -364,6 +364,32 @@ function dumpTestSuite () { assertEqual(1, c.count()); assertTrue(c.exists("foo")); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test persistent +//////////////////////////////////////////////////////////////////////////////// + + testPersistent : function () { + var c = db._collection("UnitTestsDumpPersistent"); + var p = c.properties(); + + assertEqual(2, c.getIndexes().length); + assertEqual("primary", c.getIndexes()[0].type); + assertEqual("persistent", c.getIndexes()[1].type); + assertEqual(10000, c.count()); + + var res = db._query("FOR doc IN " + c.name() + " FILTER doc.value >= 0 RETURN doc").toArray(); + assertEqual(10000, res.length); + + res = db._query("FOR doc IN " + c.name() + " FILTER doc.value >= 5000 RETURN doc").toArray(); + assertEqual(5000, res.length); + + res = db._query("FOR doc IN " + c.name() + " FILTER doc.value >= 9000 RETURN doc").toArray(); + assertEqual(1000, res.length); + + res = db._query("FOR doc IN " + c.name() + " FILTER doc.value >= 10000 RETURN doc").toArray(); + assertEqual(0, res.length); } };