zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1492321 - in /zookeeper/bookkeeper/branches/branch-4.2: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ bookkeeper-server/src/test/java/org/apache/bookkeeper/client/
Date Wed, 12 Jun 2013 18:19:28 GMT
Author: ivank
Date: Wed Jun 12 18:19:15 2013
New Revision: 1492321

URL: http://svn.apache.org/r1492321
Log:
BOOKKEEPER-562: Ability to tell if a ledger is closed or not (fpj via ivank)

Modified:
    zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/AsyncCallback.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeper.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java

Modified: zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt?rev=1492321&r1=1492320&r2=1492321&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt (original)
+++ zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt Wed Jun 12 18:19:15 2013
@@ -34,6 +34,11 @@ Release 4.2.2 - Unreleased
 
         BOOKKEEPER-603: Support Boost 1.53 for Hedwig Cpp Client (jiannan via ivank)
 
+    NEW FEATURE:
+
+      BOOKKEEPER-562: Ability to tell if a ledger is closed or not (fpj via ivank)
+
+
 Release 4.2.1 - 2013-02-19
 
   Backward compatible changes:

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/AsyncCallback.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/AsyncCallback.java?rev=1492321&r1=1492320&r2=1492321&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/AsyncCallback.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/AsyncCallback.java
Wed Jun 12 18:19:15 2013
@@ -136,4 +136,16 @@ public interface AsyncCallback {
          */
         void recoverComplete(int rc, Object ctx);
     }
+    
+    public interface IsClosedCallback {
+        /**
+         * Callback definition for isClosed operation
+         *
+         * @param rc
+         *          return code
+         * @param isClosed
+         *          true if ledger is closed
+         */
+        void isClosedComplete(int rc, boolean isClosed, Object ctx);
+    }
 }

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeper.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeper.java?rev=1492321&r1=1492320&r2=1492321&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeper.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeper.java
Wed Jun 12 18:19:15 2013
@@ -29,11 +29,13 @@ import java.util.concurrent.TimeUnit;
 import org.apache.bookkeeper.client.AsyncCallback.CreateCallback;
 import org.apache.bookkeeper.client.AsyncCallback.DeleteCallback;
 import org.apache.bookkeeper.client.AsyncCallback.OpenCallback;
+import org.apache.bookkeeper.client.AsyncCallback.IsClosedCallback;
 import org.apache.bookkeeper.client.BKException.Code;
 import org.apache.bookkeeper.conf.ClientConfiguration;
 import org.apache.bookkeeper.meta.LedgerManager;
 import org.apache.bookkeeper.meta.LedgerManagerFactory;
 import org.apache.bookkeeper.proto.BookieClient;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.util.OrderedSafeExecutor;
 import org.apache.bookkeeper.util.ZkUtils;
 import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase;
@@ -555,6 +557,68 @@ public class BookKeeper {
             throw BKException.create(counter.getrc());
         }
     }
+    
+    /**
+     * Check asynchronously whether the ledger with identifier <i>lId</i>
+     * has been closed.
+     * 
+     * @param lId   ledger identifier
+     * @param cb    callback method
+     */
+    public void asyncIsClosed(long lId, final IsClosedCallback cb, final Object ctx){
+        ledgerManager.readLedgerMetadata(lId, new GenericCallback<LedgerMetadata>(){
+            public void operationComplete(int rc, LedgerMetadata lm){
+                if (rc == BKException.Code.OK) {
+                    cb.isClosedComplete(rc, lm.isClosed(), ctx);
+                } else {
+                    cb.isClosedComplete(rc, false, ctx);
+                }
+            }
+        });
+    }
+    
+    /**
+     * Check whether the ledger with identifier <i>lId</i>
+     * has been closed.
+     * 
+     * @param lId
+     * @return boolean true if ledger has been closed
+     * @throws BKException
+     */
+    public boolean isClosed(long lId)
+    throws BKException, InterruptedException {
+        final class Result {
+            int rc;
+            boolean isClosed;
+            final CountDownLatch notifier = new CountDownLatch(1);
+        }
+
+        final Result result = new Result();
+
+        final IsClosedCallback cb = new IsClosedCallback(){
+            public void isClosedComplete(int rc, boolean isClosed, Object ctx){
+                    result.isClosed = isClosed;
+                    result.rc = rc;
+                    result.notifier.countDown();
+            }
+        };
+
+        /*
+         * Call asynchronous version of isClosed
+         */
+        asyncIsClosed(lId, cb, null);
+        
+        /*
+         * Wait for callback
+         */
+        result.notifier.await();
+        
+        if (result.rc != BKException.Code.OK) {
+            throw BKException.create(result.rc);
+        }
+        
+        return result.isClosed;
+    }
 
     /**
      * Shuts down client.

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java?rev=1492321&r1=1492320&r2=1492321&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
Wed Jun 12 18:19:15 2013
@@ -218,4 +218,24 @@ public class BookKeeperTest extends Base
             assertTrue("Close was not successful", success.get());
         }
     }
+    
+    @Test(timeout=60000)
+    public void testIsClosed() throws Exception {
+        ClientConfiguration conf = new ClientConfiguration()
+        .setZkServers(zkUtil.getZooKeeperConnectString());
+
+        BookKeeper bkc = new BookKeeper(conf);
+        LedgerHandle lh = bkc.createLedger(digestType, "testPasswd".getBytes());
+        Long lId = lh.getId();
+
+        lh.addEntry("000".getBytes());
+        boolean result = bkc.isClosed(lId);
+        Assert.assertTrue("Ledger shouldn't be flagged as closed!",!result);
+
+        lh.close();
+        result = bkc.isClosed(lId);
+        Assert.assertTrue("Ledger should be flagged as closed!",result);
+
+        bkc.close();
+    }
 }



Mime
View raw message