hangc0276 commented on code in PR #4867:
URL: https://github.com/apache/bookkeeper/pull/4867#discussion_r4749903468


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessorV3.java:
##########
@@ -267,6 +266,7 @@ protected ReadResponse getReadResponse() {
 
     @Override
     public void run() {
+        requestProcessor.onReadRequestStart(requestHandler.ctx().channel());

Review Comment:
   `run()` can execute more than once for one request, and with this change 
each execution acquires a read permit while only one release happens. 
`LongPollReadEntryProcessorV3` extends this class and inherits `run()`; when 
its wait ends (LAC update or timer) `scheduleDeferredRead` does 
`longPollThreadPool.submit(this)`, so `run()` runs a second time. The first run 
returns from `executeOp()` without sending a response, and the single 
`onReadRequestFinish()` happens when the response is finally sent. Before this 
PR the start call was in the constructor, which runs once.
   
   Effect: with `maxReadsInProgressLimit > 0`, every long poll that waits and 
resumes leaks one permit; once they add up to the limit, every later read 
blocks in `acquireUninterruptibly`. Even without a limit, `trackReadRequest()` 
is counted twice per `untrackReadRequest()`.
   
   Reproduced with the existing `LongPollReadEntryProcessorV3Test` setup 
(timeout 1 ms, the timer resumes the processor):
   ```
   verify(requestProcessor, times(1)).onReadRequestStart(any(Channel.class))
   -> Wanted 1 time ... But was 2 times
   ```
   A long-poll request with no wait starts once (control passes). Suggest 
making the start once per processor, e.g. a `permitAcquired` flag checked here 
(or an override in the long-poll subclass that skips it when resumed).



##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java:
##########
@@ -51,10 +51,15 @@ public static ReadEntryProcessor create(ReadRequest request,
         rep.init(request, requestHandler, requestProcessor);
         rep.fenceThreadPool = fenceThreadPool;
         rep.throttleReadResponses = throttleReadResponses;
-        requestProcessor.onReadRequestStart(requestHandler.ctx().channel());
         return rep;
     }
 
+    @Override
+    public void run() {
+        requestProcessor.onReadRequestStart(requestHandler.ctx().channel());

Review Comment:
   Two things about moving the blocking start call onto a worker thread:
   
   1. `BookieRequestProcessor.onReadRequestStart` also does 
`channel.config().setAutoRead(false)`, blocks, then `setAutoRead(true)`. That 
was written for the channel's single event-loop thread, which can only be 
blocked on one read at a time. Now several read-pool threads can be blocked on 
the same channel. With one permit held and two reads from one channel waiting, 
releasing one permit lets one waiter proceed and set autoread back to true 
while the other is still blocked (`TestBookieRequestProcessor`-style test: `one 
read is still waiting for a permit, so autoread must stay off`; the 
single-waiter control passes). Backpressure on the socket is lost while the 
semaphore is still exhausted. This is bounded by the read queue limits, so I 
see it as a nit. Counting the blocked reads per channel and re-enabling 
autoread only when the last one proceeds would keep the old behavior.
   
   2. Nothing in the tests calls this method: I removed this 
`onReadRequestStart` line and every test in `ReadEntryProcessorTest`, including 
the new one, still passed. Same for the call in `ReadEntryProcessorV3.run()`. A 
test that runs the processor and verifies `onReadRequestStart` is called once 
(and `onReadRequestFinish` once for the response) would pin the new location.



##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java:
##########
@@ -51,10 +51,15 @@ public static ReadEntryProcessor create(ReadRequest request,
         rep.init(request, requestHandler, requestProcessor);
         rep.fenceThreadPool = fenceThreadPool;
         rep.throttleReadResponses = throttleReadResponses;
-        requestProcessor.onReadRequestStart(requestHandler.ctx().channel());
         return rep;
     }
 
+    @Override
+    public void run() {

Review Comment:
   Config note (traced by reading, not run): when `threadPool` is null in 
`BookieRequestProcessor` (`numReadWorkerThreads = 0`, see lines 536-537 and 
694-695), the read is run inline with `read.run()` on the Netty IO thread. With 
this change `run()` begins with the blocking permit acquire, so in that 
configuration the IO thread still blocks when permits are exhausted, which is 
the situation the description sets out to fix. The fix covers configurations 
with a read pool only. If that is intended, a line in the description or code 
comment would help; otherwise the acquire would need to move off the IO thread 
in that mode too.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to