From 915b0817efff746ffd266512bdf9e50466e020c6 Mon Sep 17 00:00:00 2001 From: Yan Zhao Date: Tue, 26 Jul 2022 17:18:16 +0800 Subject: [PATCH] avoid init WriteSet when waitForWriteSetMs < 0. (#3325) ### Motivation Avoid init WriteSet when waitForWriteSetMs < 0. And LedgerHandleAdv didn't recycle WriteSet. --- .../bookkeeper/client/LedgerHandle.java | 28 +++++++++++-------- .../bookkeeper/client/LedgerHandleAdv.java | 12 ++++++-- 2 files changed, 25 insertions(+), 15 deletions(-) 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 4d9090e5897..4b1a20c25ec 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 @@ -878,13 +878,15 @@ CompletableFuture readEntriesInternalAsync(long firstEntry, // Naturally one of the solutions would be to submit smaller batches and in this case // current implementation will prevent next batch from starting when bookie is // unresponsive thus helpful enough. - DistributionSchedule.WriteSet ws = distributionSchedule.getWriteSet(firstEntry); - try { - if (!waitForWritable(ws, ws.size() - 1, clientCtx.getConf().waitForWriteSetMs)) { - op.allowFailFastOnUnwritableChannel(); + if (clientCtx.getConf().waitForWriteSetMs >= 0) { + DistributionSchedule.WriteSet ws = distributionSchedule.getWriteSet(firstEntry); + try { + if (!waitForWritable(ws, ws.size() - 1, clientCtx.getConf().waitForWriteSetMs)) { + op.allowFailFastOnUnwritableChannel(); + } + } finally { + ws.recycle(); } - } finally { - ws.recycle(); } if (isHandleWritable()) { @@ -1343,13 +1345,15 @@ public String toString() { return; } - DistributionSchedule.WriteSet ws = distributionSchedule.getWriteSet(op.getEntryId()); - try { - if (!waitForWritable(ws, 0, clientCtx.getConf().waitForWriteSetMs)) { - op.allowFailFastOnUnwritableChannel(); + if (clientCtx.getConf().waitForWriteSetMs >= 0) { + DistributionSchedule.WriteSet ws = distributionSchedule.getWriteSet(op.getEntryId()); + try { + if (!waitForWritable(ws, 0, clientCtx.getConf().waitForWriteSetMs)) { + op.allowFailFastOnUnwritableChannel(); + } + } finally { + ws.recycle(); } - } finally { - ws.recycle(); } try { diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java index d7550617275..1320fc0fd28 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java @@ -263,9 +263,15 @@ public String toString() { return; } - if (!waitForWritable(distributionSchedule.getWriteSet(op.getEntryId()), - 0, clientCtx.getConf().waitForWriteSetMs)) { - op.allowFailFastOnUnwritableChannel(); + if (clientCtx.getConf().waitForWriteSetMs >= 0) { + DistributionSchedule.WriteSet ws = distributionSchedule.getWriteSet(op.getEntryId()); + try { + if (!waitForWritable(ws, 0, clientCtx.getConf().waitForWriteSetMs)) { + op.allowFailFastOnUnwritableChannel(); + } + } finally { + ws.recycle(); + } } try {