This is an automated email from the ASF dual-hosted git repository.
zhaijia pushed a commit to branch branch-4.6
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/branch-4.6 by this push:
new b0f2ab3 ISSUE #765: Add `isClosed()` to ReadHandle
b0f2ab3 is described below
commit b0f2ab3aa1273789864ff9f9c02f4d058e92adaa
Author: Sijie Guo <[email protected]>
AuthorDate: Thu Nov 30 13:52:58 2017 +0800
ISSUE #765: Add `isClosed()` to ReadHandle
Descriptions of the changes in this PR:
add `isClosed` to ReadHandle, so distributedlog can use this for
implementing readers.
Author: Sijie Guo <[email protected]>
Reviewers: Jia Zhai <None>
This closes #786 from sijie/is_sealed, closes #765
(cherry picked from commit 64650cfc3fc2f25393c71252341a37a03db5be15)
Signed-off-by: Jia Zhai <[email protected]>
---
.../org/apache/bookkeeper/client/LedgerHandle.java | 3 ++-
.../apache/bookkeeper/client/api/ReadHandle.java | 14 +++++++++++
.../bookkeeper/client/api/BookKeeperApiTest.java | 29 ++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
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 51efefd..ca6cb89 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 class LedgerHandle implements WriteHandle {
}
/**
- * 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 4227e82..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
@@ -116,6 +116,20 @@ public interface ReadHandle extends Handle {
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.
* If the next entryId is ahead of known last add confirmed, the call will
issue a long poll read
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 cefbe80..408a2f6 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 com.google.common.base.Charsets.UTF_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;
@@ -178,6 +180,31 @@ public class BookKeeperApiTest extends
MockBookKeeperTestCase {
}
@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;
try (WriteHandle writer
@@ -199,6 +226,7 @@ public class BookKeeperApiTest extends
MockBookKeeperTestCase {
.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 class BookKeeperApiTest extends
MockBookKeeperTestCase {
.withRecovery(true)
.withLedgerId(lId)
.execute())) {
+ assertTrue(reader.isClosed());
assertEquals(1L, reader.getLastAddConfirmed());
}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].