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 9cea6f76b8 improve(store): make disk-full diagnostics actionable 
(#11559)
9cea6f76b8 is described below

commit 9cea6f76b8c73ea8bfc5b2153792538aa6dd1e57
Author: Chuanpo We <[email protected]>
AuthorDate: Mon Nov 23 22:57:58 2026 +0800

    improve(store): make disk-full diagnostics actionable (#11559)
    
    When the commitlog volume goes above the disk threshold the broker marks the
    message store read-only and producers get CODE: 14, but nothing in the logs
    says why:
    
      - broker.log prints "message store is not writeable, so putMessage is
        forbidden 16", where 16 is the raw RunningFlags bit value;
      - store.log prints the measured ratio but not the effective threshold;
      - a diskSpaceWarningLevelRatio outside [0.35, 0.90] is silently clamped, 
so
        an operator may believe the configured value is in effect when it is 
not.
    
    Changes:
    
      - RunningFlags#getFlagBitsString() renders the bits as readable names
        (DISK_FULL, NOT_READABLE|DISK_FULL, ...) and keeps getFlagBits() intact.
      - HookUtils#checkBeforePutMessage logs both the numeric value and the 
names,
        so existing greps on the number keep working.
      - DefaultMessageStore logs the clamp once, with the allowed range and the
        effective value, and prints the effective threshold next to the measured
        ratio when it marks the disk full.
      - Add RunningFlagsTest covering the empty, single, multiple and cleared 
cases.
    
    No behaviour change: the clamp produces the same values as before, and only
    log output and a new accessor are added.
    
    Co-authored-by: Chuanpo We <[email protected]>
---
 .../org/apache/rocketmq/broker/util/HookUtils.java |  4 +-
 .../apache/rocketmq/store/DefaultMessageStore.java | 30 ++++++++---
 .../org/apache/rocketmq/store/RunningFlags.java    | 26 +++++++++
 .../apache/rocketmq/store/RunningFlagsTest.java    | 62 ++++++++++++++++++++++
 4 files changed, 114 insertions(+), 8 deletions(-)

diff --git 
a/broker/src/main/java/org/apache/rocketmq/broker/util/HookUtils.java 
b/broker/src/main/java/org/apache/rocketmq/broker/util/HookUtils.java
index 06eb90b6ea..277952ef5f 100644
--- a/broker/src/main/java/org/apache/rocketmq/broker/util/HookUtils.java
+++ b/broker/src/main/java/org/apache/rocketmq/broker/util/HookUtils.java
@@ -76,7 +76,9 @@ public class HookUtils {
         if 
(!brokerController.getMessageStore().getRunningFlags().isWriteable()) {
             long value = PRINT_TIMES.getAndIncrement();
             if ((value % 50000) == 0) {
-                LOG.warn("message store is not writeable, so putMessage is 
forbidden " + 
brokerController.getMessageStore().getRunningFlags().getFlagBits());
+                LOG.warn("message store is not writeable, so putMessage is 
forbidden, flagBits={}, flags={}",
+                    
brokerController.getMessageStore().getRunningFlags().getFlagBits(),
+                    
brokerController.getMessageStore().getRunningFlags().getFlagBitsString());
             }
 
             return new 
PutMessageResult(PutMessageStatus.SERVICE_NOT_AVAILABLE, null);
diff --git 
a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java 
b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
index aa54e735f0..88cd5222bf 100644
--- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
+++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java
@@ -53,6 +53,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.Supplier;
@@ -2310,11 +2311,21 @@ public class DefaultMessageStore implements 
MessageStore {
     class CleanCommitLogService {
 
         private final static int MAX_MANUAL_DELETE_FILE_TIMES = 20;
+
+        /**
+         * Allowed range of {@code diskSpaceWarningLevelRatio}. A configured 
value outside this range is
+         * silently replaced, which is why the effective value is logged once 
when it happens.
+         */
+        static final double MIN_DISK_SPACE_WARNING_LEVEL_RATIO = 0.35;
+        static final double MAX_DISK_SPACE_WARNING_LEVEL_RATIO = 0.90;
+
         private final String diskSpaceWarningLevelRatio =
             System.getProperty("rocketmq.broker.diskSpaceWarningLevelRatio", 
"");
 
         private final String diskSpaceCleanForciblyRatio =
             System.getProperty("rocketmq.broker.diskSpaceCleanForciblyRatio", 
"");
+
+        private final AtomicBoolean warningLevelRatioClampedWarned = new 
AtomicBoolean(false);
         private long lastRedeleteTimestamp = 0;
 
         private final AtomicInteger manualDeleteFileSeveralTimes = new 
AtomicInteger();
@@ -2331,14 +2342,18 @@ public class DefaultMessageStore implements 
MessageStore {
                 finalDiskSpaceWarningLevelRatio = 
Double.parseDouble(diskSpaceWarningLevelRatio);
             }
 
-            if (finalDiskSpaceWarningLevelRatio > 0.90) {
-                finalDiskSpaceWarningLevelRatio = 0.90;
-            }
-            if (finalDiskSpaceWarningLevelRatio < 0.35) {
-                finalDiskSpaceWarningLevelRatio = 0.35;
+            boolean outOfRange = finalDiskSpaceWarningLevelRatio < 
MIN_DISK_SPACE_WARNING_LEVEL_RATIO
+                || finalDiskSpaceWarningLevelRatio > 
MAX_DISK_SPACE_WARNING_LEVEL_RATIO;
+            double clampedRatio = 
Math.min(Math.max(finalDiskSpaceWarningLevelRatio,
+                MIN_DISK_SPACE_WARNING_LEVEL_RATIO), 
MAX_DISK_SPACE_WARNING_LEVEL_RATIO);
+            if (outOfRange && 
warningLevelRatioClampedWarned.compareAndSet(false, true)) {
+                DefaultMessageStore.LOGGER.warn("diskSpaceWarningLevelRatio={} 
is out of the allowed range [{}, {}], "
+                        + "so it is clamped to {}; the store is marked 
read-only once the disk usage exceeds {}",
+                    finalDiskSpaceWarningLevelRatio, 
MIN_DISK_SPACE_WARNING_LEVEL_RATIO,
+                    MAX_DISK_SPACE_WARNING_LEVEL_RATIO, clampedRatio, 
clampedRatio);
             }
 
-            return finalDiskSpaceWarningLevelRatio;
+            return clampedRatio;
         }
 
         double getDiskSpaceCleanForciblyRatio() {
@@ -2457,7 +2472,8 @@ public class DefaultMessageStore implements MessageStore {
                 boolean diskFull = 
DefaultMessageStore.this.runningFlags.getAndMakeDiskFull();
                 if (diskFull) {
                     DefaultMessageStore.LOGGER.error("physic disk maybe full 
soon " + minPhysicRatio +
-                        ", so mark disk full, storePathPhysic=" + 
minStorePath);
+                        ", so mark disk full, storePathPhysic=" + minStorePath 
+
+                        ", diskSpaceWarningLevelRatio=" + 
getDiskSpaceWarningLevelRatio());
                 }
 
                 cleanImmediately = true;
diff --git a/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java 
b/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java
index f415487bd5..8bf66d06e5 100644
--- a/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java
+++ b/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java
@@ -41,6 +41,32 @@ public class RunningFlags {
         return flagBits;
     }
 
+    /**
+     * Render the current flag bits as readable names, e.g. {@code DISK_FULL} 
or
+     * {@code NOT_READABLE|DISK_FULL}, so that a log line is actionable 
without looking up the
+     * constants. Returns {@code NONE} when no bit is set.
+     */
+    public String getFlagBitsString() {
+        StringBuilder sb = new StringBuilder();
+        appendFlag(sb, NOT_READABLE_BIT, "NOT_READABLE");
+        appendFlag(sb, NOT_WRITEABLE_BIT, "NOT_WRITEABLE");
+        appendFlag(sb, WRITE_LOGICS_QUEUE_ERROR_BIT, 
"WRITE_LOGICS_QUEUE_ERROR");
+        appendFlag(sb, WRITE_INDEX_FILE_ERROR_BIT, "WRITE_INDEX_FILE_ERROR");
+        appendFlag(sb, DISK_FULL_BIT, "DISK_FULL");
+        appendFlag(sb, FENCED_BIT, "FENCED");
+        appendFlag(sb, LOGIC_DISK_FULL_BIT, "LOGIC_DISK_FULL");
+        return sb.length() == 0 ? "NONE" : sb.toString();
+    }
+
+    private void appendFlag(StringBuilder sb, int bit, String flagName) {
+        if ((this.flagBits & bit) != 0) {
+            if (sb.length() > 0) {
+                sb.append('|');
+            }
+            sb.append(flagName);
+        }
+    }
+
     public boolean getAndMakeReadable() {
         boolean result = this.isReadable();
         if (!result) {
diff --git 
a/store/src/test/java/org/apache/rocketmq/store/RunningFlagsTest.java 
b/store/src/test/java/org/apache/rocketmq/store/RunningFlagsTest.java
new file mode 100644
index 0000000000..20e62b3e81
--- /dev/null
+++ b/store/src/test/java/org/apache/rocketmq/store/RunningFlagsTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class RunningFlagsTest {
+
+    @Test
+    public void testNoFlagIsRenderedAsNone() {
+        RunningFlags runningFlags = new RunningFlags();
+        assertEquals(0, runningFlags.getFlagBits());
+        assertEquals("NONE", runningFlags.getFlagBitsString());
+        assertTrue(runningFlags.isWriteable());
+        assertTrue(runningFlags.isReadable());
+    }
+
+    @Test
+    public void testDiskFullIsRenderedAsName() {
+        RunningFlags runningFlags = new RunningFlags();
+        assertTrue(runningFlags.getAndMakeDiskFull());
+        assertEquals(1 << 4, runningFlags.getFlagBits());
+        assertEquals("DISK_FULL", runningFlags.getFlagBitsString());
+        assertFalse(runningFlags.isWriteable());
+    }
+
+    @Test
+    public void testMultipleFlagsAreJoined() {
+        RunningFlags runningFlags = new RunningFlags();
+        runningFlags.getAndMakeDiskFull();
+        runningFlags.getAndMakeNotReadable();
+        assertEquals("NOT_READABLE|DISK_FULL", 
runningFlags.getFlagBitsString());
+    }
+
+    @Test
+    public void testDiskFullFlagCanBeCleared() {
+        RunningFlags runningFlags = new RunningFlags();
+        runningFlags.getAndMakeDiskFull();
+        assertFalse(runningFlags.getAndMakeDiskOK());
+        assertEquals("NONE", runningFlags.getFlagBitsString());
+        assertTrue(runningFlags.isWriteable());
+    }
+}

Reply via email to