You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "coderzc (via GitHub)" <gi...@apache.org> on 2023/04/19 13:39:41 UTC

[GitHub] [pulsar] coderzc opened a new pull request, #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

coderzc opened a new pull request, #20117:
URL: https://github.com/apache/pulsar/pull/20117

   PIP: #16763 
   
   ### Motivation
   
   https://github.com/apache/pulsar/pull/20111#pullrequestreview-1386658536
   
   ### Modifications
   
   Cache this ledger in BookkeeperBucketSnapshotStorage
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: <!-- ENTER URL HERE -->
   
   <!--
   After opening this PR, the build in apache/pulsar will fail and instructions will
   be provided for opening a PR in the PR author's forked repository.
   
   apache/pulsar pull requests should be first tested in your own fork since the 
   apache/pulsar CI based on GitHub Actions has constrained resources and quota.
   GitHub Actions provides separate quota for pull requests that are executed in 
   a forked repository.
   
   The tests will be run in the forked repository until all PR review comments have
   been handled, the tests pass and the PR is approved by a reviewer.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao closed pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao closed pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage
URL: https://github.com/apache/pulsar/pull/20117


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#discussion_r1169403388


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BookkeeperBucketSnapshotStorage.java:
##########
@@ -172,12 +157,25 @@ private CompletableFuture<LedgerHandle> createLedger(String bucketKey, String to
                     if (rc != BKException.Code.OK) {
                         future.completeExceptionally(bkException("Create ledger", rc, -1));
                     } else {
+                        ledgerHandleCache.put(handle.getId(), handle);

Review Comment:
   You shouldn't close it if you want to cache a writable ledger handle.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#discussion_r1169404069


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BookkeeperBucketSnapshotStorage.java:
##########
@@ -172,12 +157,25 @@ private CompletableFuture<LedgerHandle> createLedger(String bucketKey, String to
                     if (rc != BKException.Code.OK) {
                         future.completeExceptionally(bkException("Create ledger", rc, -1));
                     } else {
+                        ledgerHandleCache.put(handle.getId(), handle);

Review Comment:
   I don't suggest caching this handle here. since you want the bucket(ledger) to be immutable, you should close it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#issuecomment-1513995286

   > @coderzc we're in code freeze for 3.0. Is this a blocker or fixing a regression from 2.11 ? Otherwise I suggest to move this to 3.1 milestone.
   
   OK, it can be moved to 3.1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc merged pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc merged PR #20117:
URL: https://github.com/apache/pulsar/pull/20117


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#discussion_r1169404912


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BookkeeperBucketSnapshotStorage.java:
##########
@@ -172,12 +157,25 @@ private CompletableFuture<LedgerHandle> createLedger(String bucketKey, String to
                     if (rc != BKException.Code.OK) {
                         future.completeExceptionally(bkException("Create ledger", rc, -1));
                     } else {
+                        ledgerHandleCache.put(handle.getId(), handle);
                         future.complete(handle);
                     }
                 }, null, metadata);
         return future;
     }
 
+    private CompletableFuture<LedgerHandle> getLedgerHandle(Long ledgerId) {
+        LedgerHandle ledgerHandle = ledgerHandleCache.get(ledgerId);

Review Comment:
   There is a race condition, you should consider use `compute` here.
   
   case: read - if -modify



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#discussion_r1169917134


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BookkeeperBucketSnapshotStorage.java:
##########
@@ -186,6 +178,10 @@ private CompletableFuture<LedgerHandle> openLedger(Long ledgerId) {
                 LedgerPassword,
                 (rc, handle, ctx) -> {
                     if (rc != BKException.Code.OK) {
+                        ledgerHandleFutureCache.remove(ledgerId, future);

Review Comment:
   If the future is complete like sync, may it cause a deadlock?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on code in PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#discussion_r1169409460


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BookkeeperBucketSnapshotStorage.java:
##########
@@ -172,12 +157,25 @@ private CompletableFuture<LedgerHandle> createLedger(String bucketKey, String to
                     if (rc != BKException.Code.OK) {
                         future.completeExceptionally(bkException("Create ledger", rc, -1));
                     } else {
+                        ledgerHandleCache.put(handle.getId(), handle);

Review Comment:
   It makes sense to don't caching this handle here. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#discussion_r1169402611


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/bucket/BookkeeperBucketSnapshotStorage.java:
##########
@@ -66,45 +69,27 @@ public CompletableFuture<Long> createBucketSnapshot(SnapshotMetadata snapshotMet
 
     @Override
     public CompletableFuture<SnapshotMetadata> getBucketSnapshotMetadata(long bucketId) {
-        return openLedger(bucketId).thenCompose(ledgerHandle -> {
-            CompletableFuture<SnapshotMetadata> snapshotFuture =
-                    getLedgerEntry(ledgerHandle, 0, 0)
-                            .thenApply(entryEnumeration -> parseSnapshotMetadataEntry(entryEnumeration.nextElement()));
-
-            snapshotFuture.whenComplete((__, e) -> closeLedger(ledgerHandle));
-
-            return snapshotFuture;
-        });
+        return getLedgerHandle(bucketId).thenCompose(ledgerHandle -> getLedgerEntry(ledgerHandle, 0, 0)
+                .thenApply(entryEnumeration -> parseSnapshotMetadataEntry(entryEnumeration.nextElement())));
     }
 
     @Override
     public CompletableFuture<List<SnapshotSegment>> getBucketSnapshotSegment(long bucketId, long firstSegmentEntryId,
                                                                              long lastSegmentEntryId) {
-        return openLedger(bucketId).thenCompose(ledgerHandle -> {
-            CompletableFuture<List<SnapshotSegment>> parseFuture =
-                    getLedgerEntry(ledgerHandle, firstSegmentEntryId, lastSegmentEntryId)
-                            .thenApply(this::parseSnapshotSegmentEntries);
-
-            parseFuture.whenComplete((__, e) -> closeLedger(ledgerHandle));
-
-            return parseFuture;
-        });
+        return getLedgerHandle(bucketId).thenCompose(
+                ledgerHandle -> getLedgerEntry(ledgerHandle, firstSegmentEntryId, lastSegmentEntryId)
+                        .thenApply(this::parseSnapshotSegmentEntries));
     }
 
     @Override
     public CompletableFuture<Long> getBucketSnapshotLength(long bucketId) {
-        return openLedger(bucketId).thenCompose(ledgerHandle -> {
-            CompletableFuture<Long> lengthFuture =
-                    CompletableFuture.completedFuture(ledgerHandle.getLength());
-
-            lengthFuture.whenComplete((__, e) -> closeLedger(ledgerHandle));
-
-            return lengthFuture;
-        });
+        return getLedgerHandle(bucketId).thenCompose(
+                ledgerHandle -> CompletableFuture.completedFuture(ledgerHandle.getLength()));
     }
 
     @Override
     public CompletableFuture<Void> deleteBucketSnapshot(long bucketId) {
+        ledgerHandleCache.remove(bucketId);

Review Comment:
   We should close this handle here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on pull request #20117: [improve][broker] Cache LedgerHandle in BookkeeperBucketSnapshotStorage

Posted by "cbornet (via GitHub)" <gi...@apache.org>.
cbornet commented on PR #20117:
URL: https://github.com/apache/pulsar/pull/20117#issuecomment-1513502265

   @coderzc we're in code freeze for 3.0. Is this a blocker or fixing a regression from 2.11 ? Otherwise I suggest to move this to 3.1 milestone.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org