You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bo...@apache.org on 2022/08/30 08:51:07 UTC

[pulsar] branch branch-2.10 updated: [fix][broker]ManagedLedger metrics fail cause of zero period (#17257)

This is an automated email from the ASF dual-hosted git repository.

bogong pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.10 by this push:
     new bb8693a967e [fix][broker]ManagedLedger metrics fail cause of zero period (#17257)
bb8693a967e is described below

commit bb8693a967ecd909cc2f78a2c485628e877955d4
Author: fengyubiao <yu...@streamnative.io>
AuthorDate: Tue Aug 30 16:45:08 2022 +0800

    [fix][broker]ManagedLedger metrics fail cause of zero period (#17257)
    
    ### Motivation
    
    `ManagedLedgerMBeanImpl` will execute method `refreshStats` immediately after it is created, but if `refreshStats` is executed too fast, will throws `IllegalArgumentException`.
    
    - `refreshStats` execute immediately
    https://github.com/apache/pulsar/blob/fd9489771959f3e722656e4b70d4bd891a13f690/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java#L198-L199
    
    - throw `IllegalArgumentException` if executed too fast
    https://github.com/apache/pulsar/blob/1de80e0684ec5c13b6edcd217af62d74d8677f04/pulsar-common/src/main/java/org/apache/pulsar/common/stats/Rate.java#L62-L64
    
    `ManagedLedgerMBeanImpl.refreshStats` will immediatelly execute after create
    
    ### Modifications
    
    Skip refreshing stats, just like `ManagedLedgerFactoryMBeanImpl.refreshStats`
    
    https://github.com/apache/pulsar/blob/1de80e0684ec5c13b6edcd217af62d74d8677f04/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryMBeanImpl.java#L38-L44
    (cherry picked from commit 1d1f75e4131332c360d7ef0132ddf257feaed940)
---
 .../org/apache/bookkeeper/mledger/impl/ManagedLedgerMBeanImpl.java    | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerMBeanImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerMBeanImpl.java
index f13aa2aa2e8..42e79167f92 100644
--- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerMBeanImpl.java
+++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerMBeanImpl.java
@@ -63,6 +63,10 @@ public class ManagedLedgerMBeanImpl implements ManagedLedgerMXBean {
 
     public void refreshStats(long period, TimeUnit unit) {
         double seconds = unit.toMillis(period) / 1000.0;
+        if (seconds <= 0.0) {
+            // skip refreshing stats
+            return;
+        }
         addEntryOps.calculateRate(seconds);
         addEntryWithReplicasOps.calculateRate(seconds);
         addEntryOpsFailed.calculateRate(seconds);