morningman commented on code in PR #69848:
URL: https://github.com/apache/doris/pull/69848#discussion_r4419694162


##########
fe/fe-core/src/main/java/org/apache/doris/changelog/ChangelogIvmMonitor.java:
##########
@@ -0,0 +1,113 @@
+// 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.doris.changelog;
+
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.util.MasterDaemon;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Samples the changelog, the table streams and the IVM materialized views on 
the Master FE for monitoring.
+ *
+ * <p>Each round builds an immutable {@link ChangelogIvmMonitorSnapshot} and 
replaces the previous one at once, so
+ * that /metrics renders the state from the snapshot instead of computing it 
while being scraped. A round that fails
+ * keeps the previous snapshot, whose sample time then shows its age, and 
counts the failure.
+ */
+public class ChangelogIvmMonitor extends MasterDaemon {
+    private static final Logger LOG = 
LogManager.getLogger(ChangelogIvmMonitor.class);
+
+    // The monitor checks every second whether 
changelog_ivm_monitor_interval_seconds has passed since its last
+    // round, so that a change of the interval applies at once: a daemon 
sleeping its own interval would only see
+    // the change once the old interval is over.
+    private static final long CHECK_INTERVAL_MS = 1000L;
+
+    // only read and written by the daemon thread
+    private long lastRoundMs = 0;
+
+    // null before the first round completes, and while the monitor is disabled
+    private volatile ChangelogIvmMonitorSnapshot snapshot;
+    private final AtomicLong sampleFailures = new AtomicLong();
+
+    public ChangelogIvmMonitor() {
+        super("changelog-ivm-monitor", CHECK_INTERVAL_MS);
+    }
+
+    public static boolean isEnabled() {
+        return Config.enable_feature_changelog && 
Config.enable_changelog_ivm_monitor;
+    }
+
+    @Override
+    protected void runAfterCatalogReady() {
+        if (!isEnabled()) {

Review Comment:
   The mechanism is right, but the snapshot exported in either case is never 
older than the one a monitor that was never disabled would export at that 
moment.
   
   - The monitor checks the flag every second. A disable that lasts until the 
next check drops the snapshot, and after re-enabling, the series are missing 
until a round completes. That is what dropping it is for: after a long disable, 
the first round can take a while, and a snapshot hours old must not be exported 
in the meantime (`testRoundsFollowTheIntervalAndStopWhileDisabled`).
   - What the daemon does not see is a toggle shorter than one check, or a 
disable during a walk that is undone before the next check. The snapshot 
exported afterwards is then the latest round, taken before the disable or 
finishing as it happened, and 
`doris_fe_changelog_ivm_monitor_last_sample_timestamp_seconds` says when it was 
taken. Nothing in it comes from a disabled period.
   - While the monitor is disabled, nothing is exported: the visitor checks 
`isEnabled()`, and the next check drops the snapshot.
   - A check of the flag before publishing would not cover either case, since 
both checks see it on. An enable generation needs a callback on the config 
(`ConfHandler`) for a window of under a second with no observable difference.
   
   So I'm keeping it as it is.
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to