This is an automated email from the ASF dual-hosted git repository.
ShannonDing pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 51cd8baec8 [ISSUE #11589] Fix PerfCounter maximum for zero-duration
samples (#11590)
51cd8baec8 is described below
commit 51cd8baec872445cbf68deb8f120cd5a6a0fcb5e
Author: NANASHIdl <[email protected]>
AuthorDate: Mon Nov 23 22:44:16 2026 +0800
[ISSUE #11589] Fix PerfCounter maximum for zero-duration samples (#11590)
---
.../apache/rocketmq/store/util/PerfCounter.java | 2 +-
.../rocketmq/store/util/PerfCounterTest.java | 40 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git
a/store/src/main/java/org/apache/rocketmq/store/util/PerfCounter.java
b/store/src/main/java/org/apache/rocketmq/store/util/PerfCounter.java
index 99649398a8..3a9059d426 100644
--- a/store/src/main/java/org/apache/rocketmq/store/util/PerfCounter.java
+++ b/store/src/main/java/org/apache/rocketmq/store/util/PerfCounter.java
@@ -189,7 +189,7 @@ public class PerfCounter {
}
public int getMax() {
- for (int i = count.length - 1; i > 0; i--) {
+ for (int i = count.length - 1; i >= 0; i--) {
if (count[i].get() > 0) {
return convert(i);
}
diff --git
a/store/src/test/java/org/apache/rocketmq/store/util/PerfCounterTest.java
b/store/src/test/java/org/apache/rocketmq/store/util/PerfCounterTest.java
new file mode 100644
index 0000000000..80224322be
--- /dev/null
+++ b/store/src/test/java/org/apache/rocketmq/store/util/PerfCounterTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.store.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class PerfCounterTest {
+ @Test
+ public void testMaxWithOnlyZeroCostSamples() {
+ PerfCounter counter = new PerfCounter();
+ counter.flow(0);
+
+ assertEquals(0, counter.getMax());
+ }
+
+ @Test
+ public void testMaxWithZeroAndPositiveCosts() {
+ PerfCounter counter = new PerfCounter();
+ counter.flow(7);
+ counter.flow(0);
+
+ assertEquals(7, counter.getMax());
+ }
+}