You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by iv...@apache.org on 2013/06/21 19:26:37 UTC
svn commit: r1495513 - in /zookeeper/bookkeeper/trunk: CHANGES.txt
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShutdownTest.java
Author: ivank
Date: Fri Jun 21 17:26:37 2013
New Revision: 1495513
URL: http://svn.apache.org/r1495513
Log:
BOOKKEEPER-313: Bookkeeper shutdown call from Bookie thread is not shutting down server (vinay via ivank)
Added:
zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShutdownTest.java
Modified:
zookeeper/bookkeeper/trunk/CHANGES.txt
zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1495513&r1=1495512&r2=1495513&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Fri Jun 21 17:26:37 2013
@@ -32,6 +32,8 @@ Trunk (unreleased changes)
BOOKKEEPER-619: Bookie should not create local cookie files if zookeeper is uninitialized (ivank)
+ BOOKKEEPER-313: Bookkeeper shutdown call from Bookie thread is not shutting down server (vinay via ivank)
+
bookkeeper-server:
BOOKKEEPER-567: ReadOnlyBookieTest hangs on shutdown (sijie via ivank)
Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java?rev=1495513&r1=1495512&r2=1495513&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java (original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java Fri Jun 21 17:26:37 2013
@@ -674,6 +674,10 @@ public class Bookie extends Thread {
*/
@VisibleForTesting
public void transitionToReadOnlyMode() {
+ if (shuttingdown == true) {
+ return;
+ }
+
if (!readOnly.compareAndSet(false, true)) {
return;
}
@@ -793,19 +797,18 @@ public class Bookie extends Thread {
// Triggering the Bookie shutdown in its own thread,
// because shutdown can be called from sync thread which would be
// interrupted by shutdown call.
+ AtomicBoolean shutdownTriggered = new AtomicBoolean(false);
void triggerBookieShutdown(final int exitCode) {
- Thread shutdownThread = new Thread() {
+ if (!shutdownTriggered.compareAndSet(false, true)) {
+ return;
+ }
+ LOG.info("Triggering shutdown of Bookie-{} with exitCode {}",
+ conf.getBookiePort(), exitCode);
+ new Thread("BookieShutdownTrigger") {
public void run() {
Bookie.this.shutdown(exitCode);
}
- };
- shutdownThread.start();
- try {
- shutdownThread.join();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- LOG.debug("InterruptedException while waiting for shutdown. Not a problem!!");
- }
+ }.start();
}
// provided a public shutdown method for other caller
@@ -820,16 +823,12 @@ public class Bookie extends Thread {
try {
if (running) { // avoid shutdown twice
// the exitCode only set when first shutdown usually due to exception found
+ LOG.info("Shutting down Bookie-{} with exitCode {}",
+ conf.getBookiePort(), exitCode);
this.exitCode = exitCode;
// mark bookie as in shutting down progress
shuttingdown = true;
- // Shutdown the ZK client
- if(zk != null) zk.close();
-
- //Shutdown disk checker
- ledgerDirsManager.shutdown();
-
// Shutdown journal
journal.shutdown();
this.join();
@@ -845,7 +844,15 @@ public class Bookie extends Thread {
} catch (IOException ie) {
LOG.error("Failed to close active ledger manager : ", ie);
}
- // setting running to false here, so watch thread in bookie server know it only after bookie shut down
+
+ //Shutdown disk checker
+ ledgerDirsManager.shutdown();
+
+ // Shutdown the ZK client
+ if(zk != null) zk.close();
+
+ // setting running to false here, so watch thread
+ // in bookie server know it only after bookie shut down
running = false;
}
} catch (InterruptedException ie) {
Added: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShutdownTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShutdownTest.java?rev=1495513&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShutdownTest.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShutdownTest.java Fri Jun 21 17:26:37 2013
@@ -0,0 +1,71 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.bookie;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.junit.Test;
+
+public class BookieShutdownTest extends BookKeeperClusterTestCase {
+
+ public BookieShutdownTest() {
+ super(1);
+ }
+
+ /**
+ * Test whether Bookie can be shutdown when the call comes inside bookie thread.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBookieShutdownFromBookieThread() throws Exception {
+ ServerConfiguration conf = bsConfs.get(0);
+ killBookie(0);
+ final CountDownLatch latch = new CountDownLatch(1);
+ final CountDownLatch shutdownComplete = new CountDownLatch(1);
+ Bookie bookie = new Bookie(conf) {
+ @Override
+ public void run() {
+ try {
+ latch.await();
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ triggerBookieShutdown(ExitCode.BOOKIE_EXCEPTION);
+ }
+
+ @Override
+ synchronized int shutdown(int exitCode) {
+ super.shutdown(exitCode);
+ shutdownComplete.countDown();
+ return exitCode;
+ }
+ };
+ bookie.start();
+ // after 1 sec stop .
+ Thread.sleep(1000);
+ latch.countDown();
+ shutdownComplete.await(5000, TimeUnit.MILLISECONDS);
+ }
+}