3pacccccc opened a new pull request, #25053:
URL: https://github.com/apache/pulsar/pull/25053

   ### Motivation
   Currently, `txnMetaMap.size()` is used to determine if a new transaction can 
be added and for metrics reporting. However, `txnMetaMap` is a 
`ConcurrentSkipListMap`, and calling `size()` is an O(n) operation, which can 
consume significant system resources, especially under high transaction loads.
   
   This PR replaces the use of `txnMetaMap.size()` with a dedicated atomic 
counter (`onGoingTxnCount`) to track the number of ongoing transactions in 
constant time (O(1)). This improves performance and reduces overhead in 
transaction management.
   ### Modifications
   1. Introduced a `LongAdder` field `onGoingTxnCount` in 
`MLTransactionMetadataStore` to maintain the ongoing transaction count.
   2. Updated all relevant methods to increment/decrement the counter when 
transactions are added or removed.
   3. Refactored test cases to use `getOnGoingTxnCount()` instead of accessing 
the map via reflection, improving test clarity and maintainability.
   4. Ensured metrics and coordinator stats now use the atomic counter instead 
of `txnMetaMap.size()`.
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### Documentation
   - [ ] `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/3pacccccc/pulsar/pull/34
   


-- 
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