Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc committed Mar 29, 2023
1 parent 8b8ec82 commit 921158f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ public CompletableFuture<List<SnapshotSegment>> getBucketSnapshotSegment(long bu

@Override
public CompletableFuture<Long> getBucketSnapshotLength(long bucketId) {
return openLedger(bucketId).thenApply(ledgerHandle -> {
long length = ledgerHandle.getLength();
closeLedger(ledgerHandle);
return length;
});
return openLedger(bucketId).thenApply(LedgerHandle::getLength);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ private void afterCreateImmutableBucket(Pair<ImmutableBucket, DelayedIndex> immu
CompletableFuture<Long> future = createFuture.handle((bucketId, ex) -> {
if (ex == null) {
immutableBucket.setSnapshotSegments(null);
immutableBucket.asyncUpdateSnapshotLength();
log.info("[{}] Creat bucket snapshot finish, bucketKey: {}", dispatcher.getName(),
immutableBucket.bucketKey());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ Pair<ImmutableBucket, DelayedIndex> createImmutableBucketAndAsyncPersistent(
Pair<ImmutableBucket, DelayedIndex> result = Pair.of(bucket, lastDelayedIndex);

CompletableFuture<Long> future = asyncSaveBucketSnapshot(bucket,
bucketSnapshotMetadata, bucketSnapshotSegments).thenCompose(__ ->
bucket.asyncUpdateSnapshotLength().exceptionally(ex -> null)
);
bucketSnapshotMetadata, bucketSnapshotSegments);
bucket.setSnapshotCreateFuture(future);

return result;
Expand Down

0 comments on commit 921158f

Please sign in to comment.