From 4742a3ee3422156796350083a8d18bb8238e4684 Mon Sep 17 00:00:00 2001 From: Lijia Liu Date: Tue, 28 Oct 2025 09:58:39 +0800 Subject: [PATCH] [fix](cloud) Skip tablet report when CloudTabletRebalancer is not inited (#56989) Issue Number: close #56583 --------- Co-authored-by: liutang123 --- .../apache/doris/cloud/catalog/CloudEnv.java | 4 ++ .../cloud/catalog/CloudTabletRebalancer.java | 7 +++ .../cloud/master/CloudReportHandler.java | 4 ++ .../cloud/master/CloudReportHandlerTest.java | 63 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 fe/fe-core/src/test/java/org/apache/doris/cloud/master/CloudReportHandlerTest.java diff --git a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java index a0bf8ae31b890a..7c992394797211 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java +++ b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java @@ -96,6 +96,10 @@ public CloudTabletRebalancer getCloudTabletRebalancer() { return this.cloudTabletRebalancer; } + public boolean isRebalancerInited() { + return this.cloudTabletRebalancer.isInited(); + } + public CloudUpgradeMgr getCloudUpgradeMgr() { return this.upgradeMgr; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.java b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.java index 1b4a9d6e042ab0..d8d6b712b2ea45 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.java @@ -104,6 +104,8 @@ public class CloudTabletRebalancer extends MasterDaemon { private boolean tableBalanced = true; + private volatile boolean inited = false; + private LinkedBlockingQueue> tabletsMigrateTasks = new LinkedBlockingQueue>(); private Map tabletToInfightTask = new HashMap<>(); @@ -254,6 +256,7 @@ protected void runAfterCatalogReady() { performBalancing(); checkDecommissionState(clusterToBes); + inited = true; LOG.info("finished to rebalancer. cost: {} ms", (System.currentTimeMillis() - start)); } @@ -1297,4 +1300,8 @@ private List batchUpdateCloudReplicaInfoEditlogs(List backendTablets, long start = System.currentTimeMillis(); LOG.info("backend[{}] have {} tablet(s), {} need deal tablet(s). report version: {}", backendId, numTablets, backendTablets.size(), backendReportVersion); + if (!((CloudEnv) Env.getCurrentEnv()).isRebalancerInited()) { + LOG.warn("TabletRebalancer has not been initialized, so skip do report for {}", backendId); + return; + } // current be useful Set tabletIdsInFe = ((CloudEnv) Env.getCurrentEnv()).getCloudTabletRebalancer() .getSnapshotTabletsInPrimaryAndSecondaryByBeId(backendId); diff --git a/fe/fe-core/src/test/java/org/apache/doris/cloud/master/CloudReportHandlerTest.java b/fe/fe-core/src/test/java/org/apache/doris/cloud/master/CloudReportHandlerTest.java new file mode 100644 index 00000000000000..5af6d35c5f9647 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/cloud/master/CloudReportHandlerTest.java @@ -0,0 +1,63 @@ +// 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.cloud.master; + +import org.apache.doris.catalog.Env; +import org.apache.doris.cloud.catalog.CloudEnv; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; +import mockit.Verifications; +import org.junit.Test; + +import java.util.HashMap; + +public class CloudReportHandlerTest { + + @Mocked + private CloudEnv mockCloudEnv; + + @Test + public void testTabletReportWhenTabletRebalancerNotInitialized() { + new MockUp() { + @Mock + public Env getCurrentEnv() { + return mockCloudEnv; + } + }; + new Expectations() { + { + mockCloudEnv.isRebalancerInited(); + result = false; + } + }; + + CloudReportHandler handler = new CloudReportHandler(); + handler.tabletReport(1001L, new HashMap<>(), new HashMap<>(), 1L, 10L); + // If the tabletRebalancer is not initialized, + // the tabletReport should not call mockCloudEnv.getCurrentSystemInfo + new Verifications() { + { + mockCloudEnv.getCurrentSystemInfo(); + times = 0; + } + }; + } +}