From 8da8c7801594cc86bf8c594dc658ad5be1194572 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Tue, 7 Aug 2012 15:00:19 +0000 Subject: [PATCH] SOLR-3685: cloud sometimes skipped peersync attempt due to flags not being cleared when no updates were buffered during replication git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1370297 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/solr/search/ValueSourceParser.java | 19 +++++++++++++++++++ .../org/apache/solr/update/UpdateLog.java | 2 +- .../apache/solr/search/QueryEqualityTest.java | 5 +++++ .../org/apache/solr/search/TestRecovery.java | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java index 74ee84742d4..ff28e3decdb 100755 --- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java +++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java @@ -107,6 +107,25 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin { return new LiteralValueSource(fp.parseArg()); } }); + addParser("threadid", new ValueSourceParser() { + @Override + public ValueSource parse(FunctionQParser fp) throws ParseException { + return new LongConstValueSource(Thread.currentThread().getId()); + } + }); + addParser("sleep", new ValueSourceParser() { + @Override + public ValueSource parse(FunctionQParser fp) throws ParseException { + int ms = fp.parseInt(); + ValueSource source = fp.parseValueSource(); + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return source; + } + }); addParser("rord", new ValueSourceParser() { @Override public ValueSource parse(FunctionQParser fp) throws ParseException { diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.java index ac444370212..490c371eda6 100644 --- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java +++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java @@ -1048,6 +1048,7 @@ public class UpdateLog implements PluginInfoInitialized { try { cancelApplyBufferUpdate = false; if (state != State.BUFFERING) return null; + operationFlags &= ~FLAG_GAP; // handle case when no log was even created because no updates // were received. @@ -1057,7 +1058,6 @@ public class UpdateLog implements PluginInfoInitialized { } tlog.incref(); state = State.APPLYING_BUFFERED; - operationFlags &= ~FLAG_GAP; } finally { versionInfo.unblockUpdates(); } diff --git a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java index 5c79a2d1335..d00dbf20ed8 100644 --- a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java +++ b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java @@ -648,6 +648,11 @@ public class QueryEqualityTest extends SolrTestCaseJ4 { "foo_i"); } + public void testTestFuncs() throws Exception { + assertFuncEquals("sleep(1,5)", "sleep(1,5)"); + assertFuncEquals("threadid()", "threadid()"); + } + /** * this test does not assert anything itself, it simply toggles a static * boolean informing an @AfterClass method to assert that every default diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.java index 6282573492f..e2efbf33a2c 100644 --- a/solr/core/src/test/org/apache/solr/search/TestRecovery.java +++ b/solr/core/src/test/org/apache/solr/search/TestRecovery.java @@ -559,7 +559,22 @@ public class TestRecovery extends SolrTestCaseJ4 { assertTrue((ulog.getStartingOperation() & UpdateLog.FLAG_GAP) == 0); + ulog.bufferUpdates(); + // simulate receiving no updates + ulog.applyBufferedUpdates(); + updateJ(jsonAdd(sdoc("id","Q7", "_version_","117")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER)); // do another add to make sure flags are back to normal + req.close(); + h.close(); + createCore(); + + req = req(); + uhandler = req.getCore().getUpdateHandler(); + ulog = uhandler.getUpdateLog(); + + assertTrue((ulog.getStartingOperation() & UpdateLog.FLAG_GAP) == 0); // check flags on Q7 + + logReplayFinish.acquire(); assertEquals(UpdateLog.State.ACTIVE, ulog.getState()); // leave each test method in a good state } finally { DirectUpdateHandler2.commitOnClose = true;