[Fix](clean trash) Fix clean trash use agent task (#33912) (#33972)

* [Fix](clean trash) Fix clean trash use agent task (#33912)

* add .h
This commit is contained in:
deardeng
2024-04-22 17:14:21 +08:00
committed by GitHub
parent f6b6c13fb3
commit a050513c91
15 changed files with 760 additions and 39 deletions

View File

@ -94,7 +94,6 @@ import org.apache.doris.clone.TabletChecker;
import org.apache.doris.clone.TabletScheduler;
import org.apache.doris.clone.TabletSchedulerStat;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ClientPool;
import org.apache.doris.common.Config;
import org.apache.doris.common.ConfigBase;
import org.apache.doris.common.ConfigException;
@ -256,11 +255,11 @@ import org.apache.doris.system.SystemInfoService;
import org.apache.doris.system.SystemInfoService.HostInfo;
import org.apache.doris.task.AgentBatchTask;
import org.apache.doris.task.AgentTaskExecutor;
import org.apache.doris.task.CleanTrashTask;
import org.apache.doris.task.CompactionTask;
import org.apache.doris.task.DropReplicaTask;
import org.apache.doris.task.MasterTaskExecutor;
import org.apache.doris.task.PriorityMasterTaskExecutor;
import org.apache.doris.thrift.BackendService;
import org.apache.doris.thrift.TCompressionType;
import org.apache.doris.thrift.TFrontendInfo;
import org.apache.doris.thrift.TGetMetaDBMeta;
@ -5812,25 +5811,13 @@ public class Env {
public void cleanTrash(AdminCleanTrashStmt stmt) {
List<Backend> backends = stmt.getBackends();
AgentBatchTask batchTask = new AgentBatchTask();
for (Backend backend : backends) {
BackendService.Client client = null;
TNetworkAddress address = null;
boolean ok = false;
try {
address = new TNetworkAddress(backend.getHost(), backend.getBePort());
client = ClientPool.backendPool.borrowObject(address);
client.cleanTrash(); // async
ok = true;
} catch (Exception e) {
LOG.warn("trash clean exec error. backend[{}]", backend.getId(), e);
} finally {
if (ok) {
ClientPool.backendPool.returnObject(address, client);
} else {
ClientPool.backendPool.invalidateObject(address, client);
}
}
CleanTrashTask cleanTrashTask = new CleanTrashTask(backend.getId());
batchTask.addTask(cleanTrashTask);
LOG.info("clean trash in be {}, beId {}", backend.getHost(), backend.getId());
}
AgentTaskExecutor.submit(batchTask);
}
public void setPartitionVersion(AdminSetPartitionVersionStmt stmt) throws DdlException {

View File

@ -27,6 +27,7 @@ import org.apache.doris.thrift.TAgentTaskRequest;
import org.apache.doris.thrift.TAlterInvertedIndexReq;
import org.apache.doris.thrift.TAlterTabletReqV2;
import org.apache.doris.thrift.TCheckConsistencyReq;
import org.apache.doris.thrift.TCleanTrashReq;
import org.apache.doris.thrift.TClearAlterTaskRequest;
import org.apache.doris.thrift.TClearTransactionTaskRequest;
import org.apache.doris.thrift.TCloneReq;
@ -392,6 +393,15 @@ public class AgentBatchTask implements Runnable {
tAgentTaskRequest.setGcBinlogReq(request);
return tAgentTaskRequest;
}
case CLEAN_TRASH: {
CleanTrashTask cleanTrashTask = (CleanTrashTask) task;
TCleanTrashReq request = cleanTrashTask.toThrift();
if (LOG.isDebugEnabled()) {
LOG.debug(request.toString());
}
tAgentTaskRequest.setCleanTrashReq(request);
return tAgentTaskRequest;
}
default:
if (LOG.isDebugEnabled()) {
LOG.debug("could not find task type for task [{}]", task);

View File

@ -0,0 +1,37 @@
// 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.thrift.TCleanTrashReq;
import org.apache.doris.thrift.TTaskType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CleanTrashTask extends AgentTask {
private static final Logger LOG = LogManager.getLogger(CleanTrashTask.class);
public CleanTrashTask(long backendId) {
super(null, backendId, TTaskType.CLEAN_TRASH, -1, -1, -1, -1, -1, -1, -1);
}
public TCleanTrashReq toThrift() {
return new TCleanTrashReq();
}
}