This is an automated email from the ASF dual-hosted git repository. yong pushed a commit to branch branch-4.15 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit 2d40a7c3b608c7fa66909307570f274a7a47e24c Author: Yan Zhao <[email protected]> AuthorDate: Tue Jul 26 17:18:16 2022 +0800 avoid init WriteSet when waitForWriteSetMs < 0. (#3325) ### Motivation Avoid init WriteSet when waitForWriteSetMs < 0. And LedgerHandleAdv didn't recycle WriteSet. (cherry picked from commit cb70194be62ba8110a9dba316f53b9760b6a8fc0) --- .../org/apache/bookkeeper/client/LedgerHandle.java | 28 ++++++++++++---------- .../apache/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 bead7d1072..316cc7d32d 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 @@ -883,13 +883,15 @@ public class LedgerHandle implements WriteHandle { // 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()) { @@ -1348,13 +1350,15 @@ public class LedgerHandle implements WriteHandle { 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 d755061727..1320fc0fd2 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 class LedgerHandleAdv extends LedgerHandle implements WriteAdvHandle { 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 {
