Skip to content

Commit f40a903

Browse files
github-actions[bot]liutang123liutang123
authored
branch-4.0: [fix](cloud) Skip tablet report when CloudTabletRebalancer is not inited #56989 (#57394)
Cherry-picked from #56989 Co-authored-by: Lijia Liu <[email protected]> Co-authored-by: liutang123 <[email protected]>
1 parent cb0746d commit f40a903

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public CloudTabletRebalancer getCloudTabletRebalancer() {
9696
return this.cloudTabletRebalancer;
9797
}
9898

99+
public boolean isRebalancerInited() {
100+
return this.cloudTabletRebalancer.isInited();
101+
}
102+
99103
public CloudUpgradeMgr getCloudUpgradeMgr() {
100104
return this.upgradeMgr;
101105
}

fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public class CloudTabletRebalancer extends MasterDaemon {
104104

105105
private boolean tableBalanced = true;
106106

107+
private volatile boolean inited = false;
108+
107109
private LinkedBlockingQueue<Pair<Long, Long>> tabletsMigrateTasks = new LinkedBlockingQueue<Pair<Long, Long>>();
108110

109111
private Map<InfightTablet, InfightTask> tabletToInfightTask = new HashMap<>();
@@ -254,6 +256,7 @@ protected void runAfterCatalogReady() {
254256
performBalancing();
255257

256258
checkDecommissionState(clusterToBes);
259+
inited = true;
257260
LOG.info("finished to rebalancer. cost: {} ms", (System.currentTimeMillis() - start));
258261
}
259262

@@ -1297,4 +1300,8 @@ private List<UpdateCloudReplicaInfo> batchUpdateCloudReplicaInfoEditlogs(List<Up
12971300
}
12981301
return rets;
12991302
}
1303+
1304+
public boolean isInited() {
1305+
return inited;
1306+
}
13001307
}

fe/fe-core/src/main/java/org/apache/doris/cloud/master/CloudReportHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public void tabletReport(long backendId, Map<Long, TTablet> backendTablets,
4242
long start = System.currentTimeMillis();
4343
LOG.info("backend[{}] have {} tablet(s), {} need deal tablet(s). report version: {}",
4444
backendId, numTablets, backendTablets.size(), backendReportVersion);
45+
if (!((CloudEnv) Env.getCurrentEnv()).isRebalancerInited()) {
46+
LOG.warn("TabletRebalancer has not been initialized, so skip do report for {}", backendId);
47+
return;
48+
}
4549
// current be useful
4650
Set<Long> tabletIdsInFe = ((CloudEnv) Env.getCurrentEnv()).getCloudTabletRebalancer()
4751
.getSnapshotTabletsInPrimaryAndSecondaryByBeId(backendId);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.cloud.master;
19+
20+
import org.apache.doris.catalog.Env;
21+
import org.apache.doris.cloud.catalog.CloudEnv;
22+
23+
import mockit.Expectations;
24+
import mockit.Mock;
25+
import mockit.MockUp;
26+
import mockit.Mocked;
27+
import mockit.Verifications;
28+
import org.junit.Test;
29+
30+
import java.util.HashMap;
31+
32+
public class CloudReportHandlerTest {
33+
34+
@Mocked
35+
private CloudEnv mockCloudEnv;
36+
37+
@Test
38+
public void testTabletReportWhenTabletRebalancerNotInitialized() {
39+
new MockUp<Env>() {
40+
@Mock
41+
public Env getCurrentEnv() {
42+
return mockCloudEnv;
43+
}
44+
};
45+
new Expectations() {
46+
{
47+
mockCloudEnv.isRebalancerInited();
48+
result = false;
49+
}
50+
};
51+
52+
CloudReportHandler handler = new CloudReportHandler();
53+
handler.tabletReport(1001L, new HashMap<>(), new HashMap<>(), 1L, 10L);
54+
// If the tabletRebalancer is not initialized,
55+
// the tabletReport should not call mockCloudEnv.getCurrentSystemInfo
56+
new Verifications() {
57+
{
58+
mockCloudEnv.getCurrentSystemInfo();
59+
times = 0;
60+
}
61+
};
62+
}
63+
}

0 commit comments

Comments
 (0)