zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1335117 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ bookkeeper-server/src/main/java/org/apache/bookkeeper/util/
Date Mon, 07 May 2012 16:48:08 GMT
Author: ivank
Date: Mon May  7 16:48:07 2012
New Revision: 1335117

URL: http://svn.apache.org/viewvc?rev=1335117&view=rev
Log:
BOOKKEEPER-232: AsyncBK tests failing (umamaheswararao via ivank)

Added:
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCache.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCacheImpl.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Mon May  7 16:48:07 2012
@@ -92,6 +92,8 @@ Trunk (unreleased changes)
 
         BOOKKEEPER-231: ZKUtil.killServer not closing the FileTxnSnapLog from ZK. (Uma Maheswara
Rao G via sijie)
 
+        BOOKKEEPER-232: AsyncBK tests failing (umamaheswararao via ivank)
+
       hedwig-client/
 
         BOOKKEEPER-217: NPE in hedwig client when enable DEBUG (sijie via ivank)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java
Mon May  7 16:48:07 2012
@@ -38,13 +38,13 @@ import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.util.IOUtils;
 
 /**
  * This class manages the writing of the bookkeeper entries. All the new
@@ -437,9 +437,14 @@ public class EntryLogger {
         // since logChannel is buffered channel, do flush when shutting down
         try {
             flush();
+            logChannel.getFileChannel().close();
         } catch (IOException ie) {
             // we have no idea how to avoid io exception during shutting down, so just ignore
it
             LOG.error("Error flush entry log during shutting down, which may cause entry
log corrupted.", ie);
+        } finally {
+            if (logChannel.getFileChannel().isOpen()) {
+                IOUtils.close(LOG, logChannel.getFileChannel());
+            }
         }
     }
 

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
Mon May  7 16:48:07 2012
@@ -68,6 +68,11 @@ class InterleavedLedgerStorage implement
         // also compaction will write entries again to entry log file
         gcThread.shutdown();
         entryLogger.shutdown();
+        try {
+            ledgerCache.close();
+        } catch (IOException e) {
+            LOG.error("Error while closing the ledger cache", e);
+        }
     }
 
     @Override

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
Mon May  7 16:48:07 2012
@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlocki
 
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback;
+import org.apache.bookkeeper.util.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -449,11 +450,10 @@ class Journal extends Thread {
     public void run() {
         LinkedList<QueueEntry> toFlush = new LinkedList<QueueEntry>();
         ByteBuffer lenBuff = ByteBuffer.allocate(4);
+        JournalChannel logFile = null;
         try {
             long logId = 0;
-            JournalChannel logFile = null;
             BufferedChannel bc = null;
-            long nextPrealloc = 0;
             long lastFlushPosition = 0;
 
             QueueEntry qe = null;
@@ -515,8 +515,12 @@ class Journal extends Thread {
                 toFlush.add(qe);
                 qe = null;
             }
+            logFile.close();
+            logFile = null;
         } catch (Exception e) {
             LOG.warn("Journal exits when shutting down", e);
+        } finally {
+            IOUtils.close(LOG, logFile);
         }
     }
 

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
Mon May  7 16:48:07 2012
@@ -23,6 +23,7 @@ package org.apache.bookkeeper.bookie;
 
 import java.util.Arrays;
 
+import java.io.Closeable;
 import java.io.File;
 import java.io.RandomAccessFile;
 import java.io.IOException;
@@ -36,7 +37,7 @@ import org.slf4j.LoggerFactory;
  * Simple wrapper around FileChannel to add versioning
  * information to the file.
  */
-class JournalChannel {
+class JournalChannel implements Closeable {
     static Logger LOG = LoggerFactory.getLogger(JournalChannel.class);
 
     final FileChannel fc;
@@ -151,7 +152,7 @@ class JournalChannel {
         return fc.read(dst);
     }
 
-    void close() throws IOException {
+    public void close() throws IOException {
         fc.close();
     }
 }
\ No newline at end of file

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCache.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCache.java?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCache.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCache.java
Mon May  7 16:48:07 2012
@@ -21,6 +21,7 @@
 
 package org.apache.bookkeeper.bookie;
 
+import java.io.Closeable;
 import java.io.IOException;
 
 /**
@@ -28,7 +29,7 @@ import java.io.IOException;
  * an entry log file. It does user level caching to more efficiently manage disk
  * head scheduling.
  */
-interface LedgerCache {
+interface LedgerCache extends Closeable {
     void setMasterKey(long ledgerId, byte[] masterKey) throws IOException;
     byte[] readMasterKey(long ledgerId) throws IOException, BookieException;
     boolean ledgerExists(long ledgerId) throws IOException;

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCacheImpl.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCacheImpl.java?rev=1335117&r1=1335116&r2=1335117&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCacheImpl.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerCacheImpl.java
Mon May  7 16:48:07 2012
@@ -33,6 +33,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.Map.Entry;
 
 import org.apache.bookkeeper.meta.LedgerManager;
 import org.apache.bookkeeper.conf.ServerConfiguration;
@@ -760,4 +761,14 @@ public class LedgerCacheImpl implements 
             }
         };
     }
+
+    @Override
+    public void close() throws IOException {
+        for (Entry<Long, FileInfo> fileInfo : fileInfoCache.entrySet()) {
+            FileInfo value = fileInfo.getValue();
+            if (value != null) {
+                value.close(true);
+            }
+        }
+    }
 }

Added: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java?rev=1335117&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
(added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
Mon May  7 16:48:07 2012
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.util;
+
+import java.io.IOException;
+
+import org.slf4j.Logger;
+
+/**
+ * An utility class for I/O related functionality.
+ */
+public class IOUtils {
+
+    /**
+     * Close the Closeable objects and <b>ignore</b> any {@link IOException}
or
+     * null pointers. Must only be used for cleanup in exception handlers.
+     * 
+     * @param log
+     *            the log to record problems to at debug level. Can be null.
+     * @param closeables
+     *            the objects to close
+     */
+    public static void close(Logger log, java.io.Closeable... closeables) {
+        for (java.io.Closeable c : closeables) {
+            if (c != null) {
+                try {
+                    c.close();
+                } catch (IOException e) {
+                    if (log != null && log.isDebugEnabled()) {
+                        log.debug("Exception in closing " + c, e);
+                    }
+                }
+            }
+        }
+    }
+
+}



Mime
View raw message