sijie commented on a change in pull request #1088: ISSUE #1086 (@bug
W-4146427@) Client-side backpressure in netty (Fixes:
io.netty.util.internal.OutOfDirectMemoryError under continuous heavy load)
URL: https://github.com/apache/bookkeeper/pull/1088#discussion_r170857470
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
##########
@@ -990,6 +1011,78 @@ void asyncRecoveryAddEntry(final byte[] data, final int
offset, final int length
doAsyncAddEntry(op);
}
+ private boolean isWritesetWritable(DistributionSchedule.WriteSet writeSet,
+ long key, int allowedNonWritableCount) {
+ if (allowedNonWritableCount < 0) {
+ allowedNonWritableCount = 0;
+ }
+
+ final int sz = writeSet.size();
+ final int requiredWritable = sz - allowedNonWritableCount;
+
+ int nonWritableCount = 0;
+ for (int i = 0; i < sz; i++) {
+ if
(!bk.getBookieClient().isWritable(metadata.currentEnsemble.get(i), key)) {
+ nonWritableCount++;
+ if (nonWritableCount >= allowedNonWritableCount) {
+ return false;
+ }
+ } else {
+ final int knownWritable = i - nonWritableCount;
+ if (knownWritable >= requiredWritable) {
+ return true;
+ }
+ }
+ }
+ return true;
+ }
+
+ protected boolean waitForWritable(DistributionSchedule.WriteSet writeSet,
long key,
+ int allowedNonWritableCount, long
durationMs) {
+ if (durationMs < 0) {
+ return true;
+ }
+
+ final long startTime = MathUtils.nowInNano();
+ boolean success = true;
+
+ if (durationMs == 0) {
+ success = isWritesetWritable(writeSet, key,
allowedNonWritableCount);
+ } else {
+ int backoff = 1;
+ final Instant deadline = Instant.now().plus(durationMs,
ChronoUnit.MILLIS);
Review comment:
better to move the instant allocation to be after `isWritesetWritable`
check, so we don't need do any object allocation on normal case, where channels
are writable almost all the time. Otherwise line 1053 will become an problem
when the traffic is high.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services