Radiancebobo opened a new pull request, #25310:
URL: https://github.com/apache/pulsar/pull/25310

    ### Motivation                                                              
                                   
      
     When clients and brokers have clock skew, delayed message delivery can 
behave incorrectly. For example:        
     - If a client's clock is 5 minutes behind the server and uses 
`deliverAfter(3min)`, the message may be
     delivered immediately instead of after 3 minutes
     - If a client's clock is 5 minutes ahead, the message may be delivered 5 
minutes later than intended
   
     This happens because the broker uses the client-provided `deliverAtTime` 
timestamp directly, which is
     calculated based on the client's clock.
   
     ### Modifications
   
     - Modified `PersistentDispatcherMultipleConsumers.trackDelayedDelivery()` 
to recalculate delivery time based on
      server clock
     - Modified 
`PersistentDispatcherMultipleConsumersClassic.trackDelayedDelivery()` with the 
same logic
     - The fix calculates the relative delay (`deliverAtTime - publishTime`) 
and adds it to the current server time
     - Falls back to original behavior when `publishTime` is missing or when 
`relativeDelay <= 0`
     - Added comprehensive unit tests in `TrackDelayedDeliveryClockSkewTest` 
covering various clock skew scenarios
   
     ### Verifying this change
   
     This change added tests and can be verified as follows:
   
     - Added unit tests `TrackDelayedDeliveryClockSkewTest` with 7 test cases:
       - `testDeliverAfterWithClientClockBehindServer` - verifies correct 
behavior when client clock is behind
       - `testDeliverAfterWithClientClockAheadOfServer` - verifies correct 
behavior when client clock is ahead
       - `testFallbackWhenNoPublishTime` - verifies fallback when publishTime 
is missing
       - `testFallbackWhenRelativeDelayNegative` - verifies fallback for 
abnormal data
       - `testNoDeliverAtTime` - verifies normal non-delayed messages
       - `testNoClockSkew` - verifies behavior with synchronized clocks
       - `testClassicDispatcherClockSkewRecalculation` - verifies Classic 
dispatcher has same behavior
   
     ### Does this pull request potentially affect one of the following parts:
   
     - [ ] 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-not-needed` - This is an internal bug fix that doesn't require 
documentation changes


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