-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[opt](agent-task) Add a daemon thread to clean up agent tasks on dead BEs #57591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // 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.task; | ||
|
|
||
| import org.apache.doris.catalog.Env; | ||
| import org.apache.doris.common.Config; | ||
| import org.apache.doris.common.Status; | ||
| import org.apache.doris.common.util.MasterDaemon; | ||
| import org.apache.doris.system.SystemInfoService; | ||
| import org.apache.doris.thrift.TStatusCode; | ||
|
|
||
| import com.google.common.collect.Maps; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class AgentTaskCleanupDaemon extends MasterDaemon { | ||
| private static final Logger LOG = LogManager.getLogger(AgentTaskCleanupDaemon.class); | ||
|
|
||
| public static final Integer MAX_FAILURE_TIMES = 3; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3 is too small, heartbeat interval is 5 seconds sometimes.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, config in seconds is more readable and understood for users.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But Config.agent_task_health_check_intervals_ms is actually 5minutes by default, >=MAX_FAILURE_TIMES means BE is unavailable more than 10 minutes. |
||
|
|
||
| private final Map<Long, Integer> beInactiveCheckFailures = Maps.newHashMap(); | ||
|
|
||
| public AgentTaskCleanupDaemon() { | ||
| super("agent-task-cleanup", Config.agent_task_health_check_intervals_ms); | ||
| } | ||
|
|
||
| @Override | ||
| protected void runAfterCatalogReady() { | ||
| LOG.info("Begin to clean up inactive agent tasks"); | ||
| SystemInfoService infoService = Env.getCurrentSystemInfo(); | ||
| infoService.getAllClusterBackends(false) | ||
| .forEach(backend -> { | ||
| long id = backend.getId(); | ||
| if (backend.isAlive()) { | ||
| beInactiveCheckFailures.remove(id); | ||
| } else { | ||
| Integer failureTimes = beInactiveCheckFailures.compute(id, (beId, failures) -> { | ||
| int updated = (failures == null ? 1 : failures + 1); | ||
| if (updated >= MAX_FAILURE_TIMES) { | ||
| removeInactiveBeAgentTasks(beId); | ||
| } | ||
| return updated; | ||
| }); | ||
| LOG.info("Check failure on be={}, times={}", failureTimes, failureTimes); | ||
| } | ||
| }); | ||
|
|
||
| LOG.info("Finish to clean up inactive agent tasks"); | ||
| } | ||
|
|
||
| private void removeInactiveBeAgentTasks(Long beId) { | ||
| AgentTaskQueue.removeTask(beId, (agentTask -> { | ||
| String errMsg = "BE down, this agent task is aborted"; | ||
| if (agentTask instanceof PushTask) { | ||
| PushTask task = ((PushTask) agentTask); | ||
| task.countDownLatchWithStatus(beId, agentTask.getTabletId(), new Status(TStatusCode.ABORTED, errMsg)); | ||
| } | ||
| agentTask.setFinished(true); | ||
| agentTask.setErrorCode(TStatusCode.ABORTED); | ||
| agentTask.setErrorMsg(errMsg); | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("BE down, remove agent task: {}", agentTask); | ||
| } | ||
| })); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // 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. | ||
|
|
||
| import org.apache.doris.regression.suite.ClusterOptions | ||
|
|
||
| suite("test_sc_fail_when_be_down", "docker") { | ||
| def options = new ClusterOptions() | ||
| options.cloudMode = false | ||
| options.beNum = 3 | ||
| options.feNum = 2 | ||
| options.enableDebugPoints() | ||
| options.feConfigs += ["agent_task_health_check_intervals_ms=5000"] | ||
|
|
||
| docker(options) { | ||
| GetDebugPoint().clearDebugPointsForAllBEs() | ||
|
|
||
| def tblName = "test_sc_fail_when_be_down" | ||
| sql """ DROP TABLE IF EXISTS ${tblName} """ | ||
| sql """ | ||
| CREATE TABLE IF NOT EXISTS ${tblName} ( | ||
| `k` int NOT NULL, | ||
| `v0` int NOT NULL, | ||
| `v1` int NOT NULL | ||
| ) | ||
| DUPLICATE KEY(`k`) | ||
| DISTRIBUTED BY HASH(`k`) BUCKETS 24 | ||
| PROPERTIES ( | ||
| "replication_allocation" = "tag.location.default: 3" | ||
| ) | ||
| """ | ||
| sql """ INSERT INTO ${tblName} SELECT number, number, number from numbers("number" = "1024") """ | ||
|
|
||
| GetDebugPoint().enableDebugPointForAllBEs("SchemaChangeJob._do_process_alter_tablet.sleep") | ||
| try { | ||
| sql """ ALTER TABLE ${tblName} MODIFY COLUMN v1 VARCHAR(100) """ | ||
| sleep(1000) | ||
| cluster.stopBackends(1, 2) | ||
| sleep(10000) | ||
| def ret = sql """ SHOW ALTER TABLE COLUMN WHERE TableName='test_sc_stuck_when_be_down' ORDER BY createtime DESC LIMIT 1 """ | ||
| println(ret) | ||
| waitForSchemaChangeDone { | ||
| sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tblName}' ORDER BY createtime DESC LIMIT 1 """ | ||
| time 600 | ||
| } | ||
| assertTrue(false) | ||
| } catch (Throwable ignore) { | ||
| // do nothing | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // 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. | ||
|
|
||
| import org.apache.doris.regression.suite.ClusterOptions | ||
|
|
||
| suite("test_sc_success_when_be_down", "docker") { | ||
| def options = new ClusterOptions() | ||
| options.cloudMode = false | ||
| options.beNum = 3 | ||
| options.feNum = 2 | ||
| options.enableDebugPoints() | ||
| options.feConfigs += ["agent_task_health_check_intervals_ms=5000"] | ||
|
|
||
| docker(options) { | ||
| GetDebugPoint().clearDebugPointsForAllBEs() | ||
|
|
||
| def tblName = "test_sc_success_when_be_down" | ||
| sql """ DROP TABLE IF EXISTS ${tblName} """ | ||
| sql """ | ||
| CREATE TABLE IF NOT EXISTS ${tblName} ( | ||
| `k` int NOT NULL, | ||
| `v0` int NOT NULL, | ||
| `v1` int NOT NULL | ||
| ) | ||
| DUPLICATE KEY(`k`) | ||
| DISTRIBUTED BY HASH(`k`) BUCKETS 24 | ||
| PROPERTIES ( | ||
| "replication_allocation" = "tag.location.default: 3" | ||
| ) | ||
| """ | ||
| sql """ INSERT INTO ${tblName} SELECT number, number, number from numbers("number" = "1024") """ | ||
|
|
||
| GetDebugPoint().enableDebugPointForAllBEs("SchemaChangeJob._do_process_alter_tablet.sleep") | ||
| sql """ ALTER TABLE ${tblName} MODIFY COLUMN v0 VARCHAR(100) """ | ||
| sleep(3000) | ||
| cluster.stopBackends(1) | ||
| waitForSchemaChangeDone { | ||
| sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tblName}' ORDER BY createtime DESC LIMIT 1 """ | ||
| time 600 | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.