poorbarcode opened a new pull request, #19404: URL: https://github.com/apache/pulsar/pull/19404
### Motivation #### 1. Issue `totalSize` of managed ledger is less than `0` <img width="1058" alt="dump_totalSize_of_ml_less_than_0" src="https://user-images.githubusercontent.com/25195800/216346276-1ed939c0-c16d-4d56-bc44-c79e41c98cbf.png"> ---- #### 2. Analizy Before writing to BK, `OpAddEntry` records the size of the data to `dataLength`, but if the data is changed by `ManagedLedgerInterceptor.processPayloadBeforeLedgerWrite`, the field `dataLength` of `OpAddEntry` is not changed, which will cause the field `totalSize` and `currentLedgerSize` of managed ledger to be incorrect. For example: 1. write data `[1]`, before write BK record the data size by `OpAddEntry.dataLength`. 1-1. now `OpAddEntry.dataLength` is `1`. 2. reset `data` of OpAddEntry to `[1,2,3...21]` by `ManagedLedgerInterceptor.processPayloadBeforeLedgerWrite`. 2-1. now the actual size of data is `21`, but `OpAddEntry.dataLength` still is `1`. 3. do write BK and switch the ledger 3-1. Create ledger info and put it into `ML.ledgers`, the size of ledger info is `21`. 4. trim ledgers 4-1. `ML.totalSize -= ledgerInfo.size`, then the `totalSize` of ML is `1-21 = -20` ---- #### 3.Reproduce You can reproduce this issue by test `testTotalSizeCorrectIfHasInterceptor` and `testCurrentLedgerSizeCorrectIfHasInterceptor` ---- ### Modifications Correct variables `OpAddEntry.dataLength` and `ML.currentLedgerSize` after executing `ManagedLedgerInterceptor.processPayloadBeforeLedgerWrite` ### Documentation <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. --> - [ ] `doc` <!-- Your PR contains doc changes. --> - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later --> - [x] `doc-not-needed` <!-- Your PR changes do not impact docs --> - [ ] `doc-complete` <!-- Docs have been already added --> ### Matching PR in forked repository PR in forked repository: - https://github.com/poorbarcode/pulsar/pull/62 -- 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]
