You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2017/11/30 05:53:12 UTC

[GitHub] jiazhai closed pull request #786: Issue 765: Add `isClosed()` to ReadHandle

jiazhai closed pull request #786: Issue 765: Add `isClosed()` to ReadHandle
URL: https://github.com/apache/bookkeeper/pull/786
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
index 51efefd07..ca6cb8999 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
@@ -356,8 +356,9 @@ public void asyncClose(CloseCallback cb, Object ctx) {
     }
 
     /**
-     * Has the ledger been closed?
+     * {@inheritDoc}
      */
+    @Override
     public synchronized boolean isClosed() {
         return metadata.isClosed();
     }
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/api/ReadHandle.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/api/ReadHandle.java
index 4227e82f2..505e19c59 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/api/ReadHandle.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/api/ReadHandle.java
@@ -115,6 +115,20 @@
      */
     long getLength();
 
+    /**
+     * Returns whether the ledger is sealed or not.
+     *
+     * <p>A ledger is sealed when either the client explicitly closes it ({@link WriteHandle#close()} or
+     * {@link WriteAdvHandle#close()}) or another client explicitly open and recovery it
+     * {@link OpenBuilder#withRecovery(boolean)}.
+     *
+     * <p>This method only checks the metadata cached locally. The metadata can be not update-to-date because
+     * the metadata notification is delayed.
+     *
+     * @return true if the ledger is sealed, otherwise false.
+     */
+    boolean isClosed();
+
     /**
      * Asynchronous read specific entry and the latest last add confirmed.
      * If the next entryId is less than known last add confirmed, the call will read next entry directly.
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/api/BookKeeperApiTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/api/BookKeeperApiTest.java
index cefbe804c..408a2f697 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/api/BookKeeperApiTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/api/BookKeeperApiTest.java
@@ -24,6 +24,8 @@
 import static org.apache.bookkeeper.common.concurrent.FutureUtils.result;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import io.netty.buffer.Unpooled;
 import java.nio.ByteBuffer;
@@ -177,6 +179,31 @@ public void testOpenLedgerDigestUnmatched() throws Exception {
         }
     }
 
+    @Test
+    public void testOpenLedgerNoSealed() throws Exception {
+        try (WriteHandle writer
+            = result(newCreateLedgerOp()
+                .withEnsembleSize(3)
+                .withWriteQuorumSize(3)
+                .withAckQuorumSize(2)
+                .withPassword(password)
+                .execute())) {
+            long lId = writer.getId();
+            // write data and populate LastAddConfirmed
+            result(writer.append(ByteBuffer.wrap(data)));
+            result(writer.append(ByteBuffer.wrap(data)));
+
+            try (ReadHandle reader
+                = result(newOpenLedgerOp()
+                    .withPassword(password)
+                    .withRecovery(false)
+                    .withLedgerId(lId)
+                    .execute())) {
+                assertFalse(reader.isClosed());
+            }
+        }
+    }
+
     @Test
     public void testOpenLedgerRead() throws Exception {
         long lId;
@@ -199,6 +226,7 @@ public void testOpenLedgerRead() throws Exception {
             .withRecovery(false)
             .withLedgerId(lId)
             .execute())) {
+            assertTrue(reader.isClosed());
             assertEquals(2, reader.getLastAddConfirmed());
             assertEquals(3 * data.length, reader.getLength());
             assertEquals(2, result(reader.readLastAddConfirmed()).intValue());
@@ -236,6 +264,7 @@ public void testOpenLedgerWithRecovery() throws Exception {
                 .withRecovery(true)
                 .withLedgerId(lId)
                 .execute())) {
+                assertTrue(reader.isClosed());
                 assertEquals(1L, reader.getLastAddConfirmed());
             }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services