Return-Path: X-Original-To: apmail-lucene-dev-archive@www.apache.org Delivered-To: apmail-lucene-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1F7069D44 for ; Sun, 10 Jun 2012 17:13:03 +0000 (UTC) Received: (qmail 57664 invoked by uid 500); 10 Jun 2012 17:13:01 -0000 Delivered-To: apmail-lucene-dev-archive@lucene.apache.org Received: (qmail 57606 invoked by uid 500); 10 Jun 2012 17:13:01 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 57596 invoked by uid 99); 10 Jun 2012 17:13:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jun 2012 17:13:01 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of dawid.weiss@gmail.com designates 209.85.214.176 as permitted sender) Received: from [209.85.214.176] (HELO mail-ob0-f176.google.com) (209.85.214.176) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jun 2012 17:12:55 +0000 Received: by obbef5 with SMTP id ef5so7281670obb.35 for ; Sun, 10 Jun 2012 10:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=RVOD+fodFZpfC16j/1UDp6KxSkKvOiivd2Bs6dNuD74=; b=HvMZ6NKraRZ8adOdqbg05UT6KCWSPFywpDWeBj+Idv3AierFkqSJy4QqqchXcWa1At TU2Pi1ozIzRNA+IEOgwB2T3Xy0OrlwiCszY8HETbY3yNUQFraRFLG+pnbO1aXcfZiPwX 6nYmrNOvLfMJIXDTKiHz6aJN8qhuYdp2aQ/dyVacitc6p30dXFOl79TuHq+2qSq1Eyk1 3JbMOTA2pFCUaLFKoQ2OyBtsMIX09jo7dn1X7SMkbZLAh12Iy5HFfFc1Xn1t80YOuzfq bvsoIy4C6IbkUln5hKTPgUuthOSgYhErfkB6g1W/VhI3qfo+4vnFmMeisnh5+lUtCnlG 81+g== Received: by 10.50.154.201 with SMTP id vq9mr5248469igb.2.1339348354189; Sun, 10 Jun 2012 10:12:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.42.178.66 with HTTP; Sun, 10 Jun 2012 10:12:14 -0700 (PDT) From: Dawid Weiss Date: Sun, 10 Jun 2012 19:12:14 +0200 Message-ID: Subject: Re: svn commit: r1348623 - in /lucene/dev/branches/branch_4x: ./ dev-tools/ lucene/ lucene/analysis/ lucene/analysis/common/ lucene/analysis/common/src/java/org/apache/lucene/analysis/standard/std31/ lucene/analysis/common/src/java/org/apache/lucene/ To: dev@lucene.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Synchonizer -> Synchronizer? D. On Sun, Jun 10, 2012 at 6:42 PM, wrote: > Author: simonw > Date: Sun Jun 10 16:42:55 2012 > New Revision: 1348623 > > URL: http://svn.apache.org/viewvc?rev=3D1348623&view=3Drev > Log: > LUCENE-4116: fix concurrency test for DWPTStallControl > > Modified: > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/ =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/dev-tools/ =C2=A0 (props chang= ed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/ =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/BUILD.txt =C2=A0 (props= changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/CHANGES.txt =C2=A0 (pro= ps changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.t= xt =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/LICENSE.txt =C2=A0 (pro= ps changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/MIGRATE.txt =C2=A0 (pro= ps changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/NOTICE.txt =C2=A0 (prop= s changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/README.txt =C2=A0 (prop= s changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/analysis/ =C2=A0 (props= changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/analysis/common/ =C2=A0= (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/analysis/common/src/jav= a/org/apache/lucene/analysis/standard/std31/package.html =C2=A0 (props chan= ged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/analysis/common/src/jav= a/org/apache/lucene/analysis/standard/std34/package.html =C2=A0 (props chan= ged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/backwards/ =C2=A0 (prop= s changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/benchmark/ =C2=A0 (prop= s changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/build.xml =C2=A0 (props= changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/common-build.xml =C2=A0= (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/core/ =C2=A0 (props cha= nged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/core/src/java/org/apach= e/lucene/index/DocumentsWriterStallControl.java > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/core/src/test/org/apach= e/lucene/index/TestDocumentsWriterStallControl.java > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/demo/ =C2=A0 (props cha= nged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/facet/ =C2=A0 (props ch= anged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/grouping/ =C2=A0 (props= changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/highlighter/ =C2=A0 (pr= ops changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/ivy-settings.xml =C2=A0= (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/join/ =C2=A0 (props cha= nged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/memory/ =C2=A0 (props c= hanged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/misc/ =C2=A0 (props cha= nged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/module-build.xml =C2=A0= (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/queries/ =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/queryparser/ =C2=A0 (pr= ops changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/sandbox/ =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/site/ =C2=A0 (props cha= nged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/spatial/ =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/suggest/ =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/test-framework/ =C2=A0 = (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/lucene/tools/ =C2=A0 (props ch= anged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/ =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/CHANGES.txt =C2=A0 (props= changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/LICENSE.txt =C2=A0 (props= changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/NOTICE.txt =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/README.txt =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/build.xml =C2=A0 (props c= hanged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/cloud-dev/ =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/common-build.xml =C2=A0 (= props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/contrib/ =C2=A0 (props ch= anged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/core/ =C2=A0 (props chang= ed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/dev-tools/ =C2=A0 (props = changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/example/ =C2=A0 (props ch= anged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/ =C2=A0 (props change= d) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/httpclient-LICENSE-AS= L.txt =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/httpclient-NOTICE.txt= =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/httpcore-LICENSE-ASL.= txt =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/httpcore-NOTICE.txt = =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/httpmime-LICENSE-ASL.= txt =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/lib/httpmime-NOTICE.txt = =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/scripts/ =C2=A0 (props ch= anged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/solrj/ =C2=A0 (props chan= ged) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/test-framework/ =C2=A0 (p= rops changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/testlogging.properties = =C2=A0 (props changed) > =C2=A0 =C2=A0lucene/dev/branches/branch_4x/solr/webapp/ =C2=A0 (props cha= nged) > > Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/l= ucene/index/DocumentsWriterStallControl.java > URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/co= re/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java?rev=3D= 1348623&r1=3D1348622&r2=3D1348623&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/= index/DocumentsWriterStallControl.java (original) > +++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/= index/DocumentsWriterStallControl.java Sun Jun 10 16:42:55 2012 > @@ -39,7 +39,6 @@ import org.apache.lucene.util.ThreadInte > =C2=A0final class DocumentsWriterStallControl { > =C2=A0 @SuppressWarnings("serial") > =C2=A0 private static final class Sync extends AbstractQueuedSynchronizer= { > - =C2=A0 =C2=A0volatile boolean hasBlockedThreads =3D false; // only with= assert > > =C2=A0 =C2=A0 Sync() { > =C2=A0 =C2=A0 =C2=A0 setState(0); > @@ -67,15 +66,10 @@ final class DocumentsWriterStallControl > > =C2=A0 =C2=A0 @Override > =C2=A0 =C2=A0 public int tryAcquireShared(int acquires) { > - =C2=A0 =C2=A0 =C2=A0assert maybeSetHasBlocked(getState()); > =C2=A0 =C2=A0 =C2=A0 return getState() =3D=3D 0 ? 1 : -1; > =C2=A0 =C2=A0 } > > - =C2=A0 =C2=A0// only used for testing > - =C2=A0 =C2=A0private boolean maybeSetHasBlocked(int state) { > - =C2=A0 =C2=A0 =C2=A0hasBlockedThreads |=3D getState() !=3D 0; > - =C2=A0 =C2=A0 =C2=A0return true; > - =C2=A0 =C2=A0} > + > > =C2=A0 =C2=A0 @Override > =C2=A0 =C2=A0 public boolean tryReleaseShared(int newState) { > @@ -130,7 +124,7 @@ final class DocumentsWriterStallControl > =C2=A0 } > > =C2=A0 boolean hasBlocked() { // for tests > - =C2=A0 =C2=A0return sync.hasBlockedThreads; > + =C2=A0 =C2=A0return sync.hasQueuedThreads(); > =C2=A0 } > > =C2=A0 static interface MemoryController { > @@ -138,4 +132,12 @@ final class DocumentsWriterStallControl > =C2=A0 =C2=A0 long flushBytes(); > =C2=A0 =C2=A0 long stallLimitBytes(); > =C2=A0 } > + > + =C2=A0public boolean isHealthy() { > + =C2=A0 =C2=A0return sync.isHealthy(); > + =C2=A0} > + > + =C2=A0public boolean isThreadQueued(Thread t) { > + =C2=A0 =C2=A0return sync.isQueued(t); > + =C2=A0} > =C2=A0} > > Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/l= ucene/index/TestDocumentsWriterStallControl.java > URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/co= re/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java?re= v=3D1348623&r1=3D1348622&r2=3D1348623&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/= index/TestDocumentsWriterStallControl.java (original) > +++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/= index/TestDocumentsWriterStallControl.java Sun Jun 10 16:42:55 2012 > @@ -127,22 +127,19 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 int numStallers =3D atLeast(1); > =C2=A0 =C2=A0 int numReleasers =3D atLeast(1); > =C2=A0 =C2=A0 int numWaiters =3D atLeast(1); > - > - =C2=A0 =C2=A0final CountDownLatch[] latches =3D new CountDownLatch[] { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0new CountDownLatch(numStallers + numReleaser= s), new CountDownLatch(1), > - =C2=A0 =C2=A0 =C2=A0 =C2=A0new CountDownLatch(numWaiters)}; > + =C2=A0 =C2=A0final Synchonizer sync =3D new Synchonizer(numStallers + n= umReleasers, numStallers + numReleasers+numWaiters); > =C2=A0 =C2=A0 Thread[] threads =3D new Thread[numReleasers + numStallers = + numWaiters]; > =C2=A0 =C2=A0 List exceptions =3D =C2=A0Collections.synchroniz= edList(new ArrayList()); > =C2=A0 =C2=A0 for (int i =3D 0; i < numReleasers; i++) { > - =C2=A0 =C2=A0 =C2=A0threads[i] =3D new Updater(stop, checkPoint, ctrl, = latches, true, exceptions); > + =C2=A0 =C2=A0 =C2=A0threads[i] =3D new Updater(stop, checkPoint, ctrl, = sync, true, exceptions); > =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 for (int i =3D numReleasers; i < numReleasers + numStallers= ; i++) { > - =C2=A0 =C2=A0 =C2=A0threads[i] =3D new Updater(stop, checkPoint, ctrl, = latches, false, exceptions); > + =C2=A0 =C2=A0 =C2=A0threads[i] =3D new Updater(stop, checkPoint, ctrl, = sync, false, exceptions); > > =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 for (int i =3D numReleasers + numStallers; i < numReleasers= + numStallers > =C2=A0 =C2=A0 =C2=A0 =C2=A0 + numWaiters; i++) { > - =C2=A0 =C2=A0 =C2=A0threads[i] =3D new Waiter(stop, checkPoint, ctrl, l= atches, exceptions); > + =C2=A0 =C2=A0 =C2=A0threads[i] =3D new Waiter(stop, checkPoint, ctrl, s= ync, exceptions); > > =C2=A0 =C2=A0 } > > @@ -151,7 +148,7 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 for (int i =3D 0; i < iters; i++) { > =C2=A0 =C2=A0 =C2=A0 if (checkPoint.get()) { > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue("timed out waiting for update thr= eads - deadlock?", latches[0].await(10, TimeUnit.SECONDS)); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue("timed out waiting for update thr= eads - deadlock?", sync.updateJoin.await(10, TimeUnit.SECONDS)); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!exceptions.isEmpty()) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (Throwable throwable : exceptions)= { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 throwable.printStackTrace(); > @@ -159,27 +156,38 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fail("got exceptions in threads"); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!ctrl.anyStalledThreads()) { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue( > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"control claims no stal= led threads but waiter seems to be blocked", > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0latches[2].await(10, Ti= meUnit.SECONDS)); > - =C2=A0 =C2=A0 =C2=A0 =C2=A0} > - =C2=A0 =C2=A0 =C2=A0 =C2=A0checkPoint.set(false); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ctrl.hasBlocked() && ctrl.isHealthy()) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assertState(numReleasers, numStallers= , numWaiters, threads, ctrl); > + > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0latches[1].countDown(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0checkPoint.set(false); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0sync.waiter.countDown(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0sync.leftCheckpoint.await(); > =C2=A0 =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 =C2=A0 assertFalse(checkPoint.get()); > + =C2=A0 =C2=A0 =C2=A0assertEquals(0, sync.waiter.getCount()); > =C2=A0 =C2=A0 =C2=A0 if (random().nextInt(2) =3D=3D 0) { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0latches[0] =3D new CountDownLatch(numStaller= s + numReleasers); > - =C2=A0 =C2=A0 =C2=A0 =C2=A0latches[1] =3D new CountDownLatch(1); > - =C2=A0 =C2=A0 =C2=A0 =C2=A0latches[2] =3D new CountDownLatch(numWaiters= ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0sync.reset(numStallers + numReleasers, numSt= allers + numReleasers > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+ numWaiters); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 checkPoint.set(true); > =C2=A0 =C2=A0 =C2=A0 } > > =C2=A0 =C2=A0 } > + =C2=A0 =C2=A0if (!checkPoint.get()) { > + =C2=A0 =C2=A0 =C2=A0sync.reset(numStallers + numReleasers, numStallers = + numReleasers > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+ numWaiters); > + =C2=A0 =C2=A0 =C2=A0checkPoint.set(true); > + =C2=A0 =C2=A0} > > + =C2=A0 =C2=A0assertTrue(sync.updateJoin.await(10, TimeUnit.SECONDS)); > + =C2=A0 =C2=A0assertState(numReleasers, numStallers, numWaiters, threads= , ctrl); > + =C2=A0 =C2=A0checkPoint.set(false); > =C2=A0 =C2=A0 stop.set(true); > - =C2=A0 =C2=A0latches[1].countDown(); > + =C2=A0 =C2=A0sync.waiter.countDown(); > + =C2=A0 =C2=A0sync.leftCheckpoint.await(); > + > > =C2=A0 =C2=A0 for (int i =3D 0; i < threads.length; i++) { > =C2=A0 =C2=A0 =C2=A0 memCtrl.limit =3D 1000; > @@ -196,20 +204,45 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 } > =C2=A0 } > > + =C2=A0private void assertState(int numReleasers, int numStallers, int n= umWaiters, Thread[] threads, DocumentsWriterStallControl ctrl) throws Inter= ruptedException { > + =C2=A0 =C2=A0int millisToSleep =3D 100; > + =C2=A0 =C2=A0while (true) { > + =C2=A0 =C2=A0 =C2=A0if (ctrl.hasBlocked() && ctrl.isHealthy()) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0for (int n =3D numReleasers + numStallers; n= < numReleasers > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+ numStallers + numWaiters; n+= +) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ctrl.isThreadQueued(threads[n])) = { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (millisToSleep < 60000) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thread.sleep(millisToSl= eep); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0millisToSleep *=3D2; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fail("control claims no= stalled threads but waiter seems to be blocked "); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0} else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0} > + > + =C2=A0} > + > =C2=A0 public static class Waiter extends Thread { > - =C2=A0 =C2=A0private CountDownLatch[] latches; > + =C2=A0 =C2=A0private Synchonizer sync; > =C2=A0 =C2=A0 private DocumentsWriterStallControl ctrl; > =C2=A0 =C2=A0 private AtomicBoolean checkPoint; > =C2=A0 =C2=A0 private AtomicBoolean stop; > =C2=A0 =C2=A0 private List exceptions; > > =C2=A0 =C2=A0 public Waiter(AtomicBoolean stop, AtomicBoolean checkPoint, > - =C2=A0 =C2=A0 =C2=A0 =C2=A0DocumentsWriterStallControl ctrl, CountDownL= atch[] latches, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DocumentsWriterStallControl ctrl, Synchonize= r sync, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 List exceptions) { > + =C2=A0 =C2=A0 =C2=A0super("waiter"); > =C2=A0 =C2=A0 =C2=A0 this.stop =3D stop; > =C2=A0 =C2=A0 =C2=A0 this.checkPoint =3D checkPoint; > =C2=A0 =C2=A0 =C2=A0 this.ctrl =3D ctrl; > - =C2=A0 =C2=A0 =C2=A0this.latches =3D latches; > + =C2=A0 =C2=A0 =C2=A0this.sync =3D sync; > =C2=A0 =C2=A0 =C2=A0 this.exceptions =3D exceptions; > =C2=A0 =C2=A0 } > > @@ -218,13 +251,10 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 =C2=A0 =C2=A0 while (!stop.get()) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctrl.waitIfStalled(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (checkPoint.get()) { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CountDownLatch join =3D latche= s[2]; > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CountDownLatch wait =3D latche= s[1]; > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0join.countDown(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue(wait.await(1= 0, TimeUnit.SECONDS)); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue(sync.await()= ); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } catch (InterruptedException e= ) { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.println("[Wa= iter] got interrupted - wait count: " + wait.getCount()); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.println("[Wa= iter] got interrupted - wait count: " + sync.waiter.getCount()); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 throw new ThreadInterrup= tedException(e); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > @@ -238,7 +268,7 @@ public class TestDocumentsWriterStallCon > > =C2=A0 public static class Updater extends Thread { > > - =C2=A0 =C2=A0private CountDownLatch[] latches; > + =C2=A0 =C2=A0private Synchonizer sync; > =C2=A0 =C2=A0 private DocumentsWriterStallControl ctrl; > =C2=A0 =C2=A0 private AtomicBoolean checkPoint; > =C2=A0 =C2=A0 private AtomicBoolean stop; > @@ -246,12 +276,13 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 private List exceptions; > > =C2=A0 =C2=A0 public Updater(AtomicBoolean stop, AtomicBoolean checkPoint= , > - =C2=A0 =C2=A0 =C2=A0 =C2=A0DocumentsWriterStallControl ctrl, CountDownL= atch[] latches, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DocumentsWriterStallControl ctrl, Synchonize= r sync, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 boolean release, List exceptions) = { > + =C2=A0 =C2=A0 =C2=A0super("updater"); > =C2=A0 =C2=A0 =C2=A0 this.stop =3D stop; > =C2=A0 =C2=A0 =C2=A0 this.checkPoint =3D checkPoint; > =C2=A0 =C2=A0 =C2=A0 this.ctrl =3D ctrl; > - =C2=A0 =C2=A0 =C2=A0this.latches =3D latches; > + =C2=A0 =C2=A0 =C2=A0this.sync =3D sync; > =C2=A0 =C2=A0 =C2=A0 this.release =3D release; > =C2=A0 =C2=A0 =C2=A0 this.exceptions =3D exceptions; > =C2=A0 =C2=A0 } > @@ -268,22 +299,24 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctrl.updateStalled(memCtrl); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (checkPoint.get()) { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CountDownLatch join =3D latche= s[0]; > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CountDownLatch wait =3D latche= s[1]; > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0join.countDown(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sync.updateJoin.countDown(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue(wait.await(1= 0, TimeUnit.SECONDS)); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assertTrue(sync.await()= ); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } catch (InterruptedException e= ) { > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.println("[Up= dater] got interrupted - wait count: " + wait.getCount()); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.println("[Up= dater] got interrupted - wait count: " + sync.waiter.getCount()); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 throw new ThreadInterrup= tedException(e); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sync.leftCheckpoint.countDown(= ); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (random().nextBoolean()) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thread.yield(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thread.yield(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 =C2=A0 } catch (Throwable e) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 e.printStackTrace(); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 exceptions.add(e); > =C2=A0 =C2=A0 =C2=A0 } > + =C2=A0 =C2=A0 =C2=A0sync.updateJoin.countDown(); > =C2=A0 =C2=A0 } > > =C2=A0 } > @@ -366,4 +399,25 @@ public class TestDocumentsWriterStallCon > =C2=A0 =C2=A0 } > > =C2=A0 } > + > + =C2=A0private static final class Synchonizer { > + =C2=A0 =C2=A0volatile CountDownLatch waiter; > + =C2=A0 =C2=A0volatile CountDownLatch updateJoin; > + =C2=A0 =C2=A0volatile CountDownLatch leftCheckpoint; > + > + =C2=A0 =C2=A0public Synchonizer(int numUpdater, int numThreads) { > + =C2=A0 =C2=A0 =C2=A0reset(numUpdater, numThreads); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0public void reset(int numUpdaters, int numThreads) { > + =C2=A0 =C2=A0 =C2=A0this.waiter =3D new CountDownLatch(1); > + =C2=A0 =C2=A0 =C2=A0this.updateJoin =3D new CountDownLatch(numUpdaters)= ; > + =C2=A0 =C2=A0 =C2=A0this.leftCheckpoint =3D new CountDownLatch(numUpdat= ers); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0public boolean await() throws InterruptedException { > + =C2=A0 =C2=A0 =C2=A0return waiter.await(10, TimeUnit.SECONDS); > + =C2=A0 =C2=A0} > + > + =C2=A0} > =C2=A0} > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org