horizonzy opened a new issue, #3745: URL: https://github.com/apache/bookkeeper/issues/3745
**BUG REPORT** Use v2 protocol to add entry to server. ## The ByteBuf lifecycle in normal case: ### 1. Read from the netty channel **the refCnt is default value 2** ### 2. BookieProtoEncoding decode the request to ParsedAddRequest https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieProtoEncoding.java#L477 https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieProtoEncoding.java#L184-L187 line_186, retain, **the refCnt increase to 4** https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieProtocol.java#L313-L324 line_322, retain, **the refCnt increase to 6** ### 3. Trigger channelRead, and send the request to BookieRequestProcessor. https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieRequestProcessor.java#L618-L648 line_619, wrap the request by WriteEntryProcessor, then line_634, execute the WriteEntryProcessor in the threadPool, it's async, to explain the WriteEntryProcessor detail later. ### 4. BookieProtoEncoding release the ByteBuf https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieProtoEncoding.java#L484 release, **the refCnt decrease to 4.** ### 5. WriteEntryProcessor processPacket https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java#L60-L116 in line_80, invoke BookieImpl#addEntry. https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java#L1080-L1111 line_1093, invoke BookieImpl#addEntryInternal. line_981, invoke Journal#logAddEntry https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java#L981 https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java#L975-L993 line_979, retain, **the refCnt increase to 6**. line_986, wrap the request by QueueEntry, and send it to the queue. https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java#L1109 line_1109 release, **the refCnt decrease to 4** https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java#L105 release, **The refCnt decrease to 2** ### 6. Journal handle the QueueEntry. https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java#L1291 Finally, after journal write the entry to channelBuffer, release, ***The refCnt decrease to 1, it's free** ## There are some abnormal case: ### 1. Bookie is into read-only mode https://github.com/apache/bookkeeper/blob/7b5b6b240ca7551da266903078f2dd2ba2906b96/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java#L61-L71 Before normal case section 5, the ByteBuf refCnt is 4. At line_68, release, **The refCnt decrease to 2**, then return. So memory leak. -- 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]
