zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1132682 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ bookkeepe...
Date Mon, 06 Jun 2011 15:49:38 GMT
Author: fpj
Date: Mon Jun  6 15:49:38 2011
New Revision: 1132682

URL: http://svn.apache.org/viewvc?rev=1132682&view=rev
Log:
BOOKKEEPER-22: Exception in LedgerCache causes addEntry request to fail (fpj via fpj)


Added:
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerCacheTest.java
Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    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/client/MacDigestManager.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1132682&r1=1132681&r2=1132682&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Mon Jun  6 15:49:38 2011
@@ -13,3 +13,5 @@ BUGFIXES:
   BOOKKEEPER-1: Static variable makes tests fail (fpj via ivank)
 
   BOOKKEEPER-19: BookKeeper doesn't support more than 2Gig of memory (ivan via fpj)
+
+  BOOKEEPER-22: Exception in LedgerCache causes addEntry request to fail (fpj via fpj)

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=1132682&r1=1132681&r2=1132682&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 Jun  6 15:49:38 2011
@@ -423,7 +423,7 @@ public class LedgerCache {
                     Iterator<Map.Entry<Long, LedgerEntryPage>> it = map.entrySet().iterator();
                     LedgerEntryPage lep = it.next().getValue();
                     while((lep.inUse() || !lep.isClean())) {
-                        if (it.hasNext()) {
+                        if (!it.hasNext()) {
                             continue outerLoop;
                         }
                         lep = it.next().getValue();

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/MacDigestManager.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/MacDigestManager.java?rev=1132682&r1=1132681&r2=1132682&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/MacDigestManager.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/MacDigestManager.java
Mon Jun  6 15:49:38 2011
@@ -25,7 +25,7 @@ import java.security.NoSuchAlgorithmExce
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 
-class MacDigestManager extends DigestManager {
+public class MacDigestManager extends DigestManager {
     public static String DIGEST_ALGORITHM = "SHA-1";
     public static String KEY_ALGORITHM = "HmacSHA1";
     Mac mac;

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java?rev=1132682&r1=1132681&r2=1132682&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/NIOServerFactory.java
Mon Jun  6 15:49:38 2011
@@ -120,12 +120,11 @@ public class NIOServerFactory extends Th
                 }
                 selected.clear();
             } catch (Exception e) {
-                LOG.warn(e);
+                LOG.warn("Exception in server socket loop: " + ss.socket().getInetAddress(),
e);
             }
         }
-        LOG.debug("NIOServerCnxn factory exitedloop.");
+        LOG.info("NIOServerCnxn factory exitedloop.");
         clear();
-        // System.exit(0);
     }
 
     /**

Added: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerCacheTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerCacheTest.java?rev=1132682&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerCacheTest.java
(added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerCacheTest.java
Mon Jun  6 15:49:38 2011
@@ -0,0 +1,131 @@
+/*
+ *
+ * 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.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.security.GeneralSecurityException;
+
+import org.apache.bookkeeper.bookie.Bookie;
+import org.apache.bookkeeper.bookie.BookieException;
+import org.apache.bookkeeper.bookie.LedgerEntryPage;
+import org.apache.bookkeeper.client.MacDigestManager;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.log4j.Logger;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests writing to concurrent ledgers
+ */
+public class LedgerCacheTest extends TestCase {
+    static Logger LOG = Logger.getLogger(LedgerCacheTest.class);
+    
+    Bookie bookie;
+    File txnDir, ledgerDir;
+    
+    class TestWriteCallback implements WriteCallback {
+        public void writeComplete(int rc, long ledgerId, long entryId, InetSocketAddress
addr, Object ctx){
+            LOG.info("Added entry: " + rc + ", " + ledgerId + ", " + entryId + ", " + addr);
+        }
+    }
+    
+    
+    @Override
+    @Before
+    public void setUp() throws IOException {
+        String txnDirName = System.getProperty("txnDir");
+        if (txnDirName != null) {
+            txnDir = new File(txnDirName);
+        }
+        String ledgerDirName = System.getProperty("ledgerDir");
+        if (ledgerDirName != null) {
+            ledgerDir = new File(ledgerDirName);
+        }
+        File tmpFile = File.createTempFile("book", ".txn", txnDir);
+        tmpFile.delete();
+        txnDir = new File(tmpFile.getParent(), tmpFile.getName()+".dir");
+        txnDir.mkdirs();
+        tmpFile = File.createTempFile("book", ".ledger", ledgerDir);
+        ledgerDir = new File(tmpFile.getParent(), tmpFile.getName()+".dir");
+        ledgerDir.mkdirs();
+        
+        
+        bookie = new Bookie(5000, null, txnDir, new File[] {ledgerDir});   
+    }
+    
+    
+    @Override
+    @After
+    public void tearDown() {
+        try {
+            bookie.shutdown();
+            recursiveDelete(txnDir);
+            recursiveDelete(ledgerDir);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /**
+     * Recursively deletes a directory. This is a duplication of BookieClientTest.
+     * 
+     * @param dir
+     */
+    private static void recursiveDelete(File dir) {
+        File children[] = dir.listFiles();
+        if (children != null) {
+            for (File child : children) {
+                recursiveDelete(child);
+            }
+        }
+        dir.delete();
+    }
+    
+    @Test
+    public void testAddEntryException() 
+    throws GeneralSecurityException, BookieException {
+        /*
+         * Populate ledger cache
+         */
+        try{
+            byte[] masterKey = "blah".getBytes();
+            for( int i = 0; i < 30000; i++){
+                MacDigestManager dm = new MacDigestManager(i, masterKey);
+                ByteBuffer entry = dm.computeDigestAndPackageForSending(0, 0, 10, "0123456789".getBytes()).toByteBuffer();
+                bookie.addEntry(entry, new TestWriteCallback(), null, masterKey);
+            }
+        } catch (IOException e) {
+            LOG.error("Got IOException.", e);
+            fail("Failed to add entry.");
+        }
+    }
+    
+}
\ No newline at end of file



Mime
View raw message