[Feature](resource-group) Support drop resource group (#18873)
This commit is contained in:
@ -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.
|
||||
|
||||
package org.apache.doris.analysis;
|
||||
|
||||
import org.apache.doris.catalog.Env;
|
||||
import org.apache.doris.common.ErrorCode;
|
||||
import org.apache.doris.common.ErrorReport;
|
||||
import org.apache.doris.common.FeNameFormat;
|
||||
import org.apache.doris.common.UserException;
|
||||
import org.apache.doris.mysql.privilege.PrivPredicate;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
public class DropResourceGroupStmt extends DdlStmt {
|
||||
private boolean ifExists;
|
||||
private String resourceGroupName;
|
||||
|
||||
public DropResourceGroupStmt(boolean ifExists, String resourceGroupName) {
|
||||
this.ifExists = ifExists;
|
||||
this.resourceGroupName = resourceGroupName;
|
||||
}
|
||||
|
||||
public boolean isIfExists() {
|
||||
return ifExists;
|
||||
}
|
||||
|
||||
public String getResourceGroupName() {
|
||||
return resourceGroupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analyze(Analyzer analyzer) throws UserException {
|
||||
super.analyze(analyzer);
|
||||
|
||||
// check auth
|
||||
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
|
||||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
|
||||
}
|
||||
|
||||
FeNameFormat.checkResourceGroupName(resourceGroupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSql() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("DROP ");
|
||||
sb.append("RESOURCE GROUP '").append(resourceGroupName).append("' ");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -83,6 +83,7 @@ import org.apache.doris.persist.DropDbInfo;
|
||||
import org.apache.doris.persist.DropInfo;
|
||||
import org.apache.doris.persist.DropLinkDbAndUpdateDbInfo;
|
||||
import org.apache.doris.persist.DropPartitionInfo;
|
||||
import org.apache.doris.persist.DropResourceGroupOperationLog;
|
||||
import org.apache.doris.persist.DropResourceOperationLog;
|
||||
import org.apache.doris.persist.DropSqlBlockRuleOperationLog;
|
||||
import org.apache.doris.persist.GlobalVarPersistInfo;
|
||||
@ -807,6 +808,11 @@ public class JournalEntity implements Writable {
|
||||
isRead = true;
|
||||
break;
|
||||
}
|
||||
case OperationType.OP_DROP_RESOURCE_GROUP: {
|
||||
data = DropResourceGroupOperationLog.read(in);
|
||||
isRead = true;
|
||||
break;
|
||||
}
|
||||
case OperationType.OP_ALTER_LIGHT_SCHEMA_CHANGE: {
|
||||
data = AlterLightSchemaChangeInfo.read(in);
|
||||
isRead = true;
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
// 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.persist;
|
||||
|
||||
import org.apache.doris.common.io.Text;
|
||||
import org.apache.doris.common.io.Writable;
|
||||
import org.apache.doris.persist.gson.GsonUtils;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* For resource group drop
|
||||
*/
|
||||
public class DropResourceGroupOperationLog implements Writable {
|
||||
@SerializedName(value = "id")
|
||||
private long id;
|
||||
|
||||
public DropResourceGroupOperationLog(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput out) throws IOException {
|
||||
Text.writeString(out, GsonUtils.GSON.toJson(this));
|
||||
}
|
||||
|
||||
public static DropResourceGroupOperationLog read(DataInput in) throws IOException {
|
||||
return GsonUtils.GSON.fromJson(Text.readString(in), DropResourceGroupOperationLog.class);
|
||||
}
|
||||
}
|
||||
@ -1012,6 +1012,12 @@ public class EditLog {
|
||||
env.getResourceGroupMgr().replayCreateResourceGroup(resourceGroup);
|
||||
break;
|
||||
}
|
||||
case OperationType.OP_DROP_RESOURCE_GROUP: {
|
||||
final DropResourceGroupOperationLog operationLog =
|
||||
(DropResourceGroupOperationLog) journal.getData();
|
||||
env.getResourceGroupMgr().replayDropResourceGroup(operationLog);
|
||||
break;
|
||||
}
|
||||
case OperationType.OP_INIT_EXTERNAL_TABLE: {
|
||||
// Do nothing.
|
||||
break;
|
||||
@ -1562,6 +1568,10 @@ public class EditLog {
|
||||
logEdit(OperationType.OP_CREATE_RESOURCE_GROUP, resourceGroup);
|
||||
}
|
||||
|
||||
public void logDropResourceGroup(DropResourceGroupOperationLog operationLog) {
|
||||
logEdit(OperationType.OP_DROP_RESOURCE_GROUP, operationLog);
|
||||
}
|
||||
|
||||
public void logAlterStoragePolicy(StoragePolicy storagePolicy) {
|
||||
logEdit(OperationType.OP_ALTER_STORAGE_POLICY, storagePolicy);
|
||||
}
|
||||
|
||||
@ -283,6 +283,7 @@ public class OperationType {
|
||||
|
||||
// resource group 410 ~ 419
|
||||
public static final short OP_CREATE_RESOURCE_GROUP = 410;
|
||||
public static final short OP_DROP_RESOURCE_GROUP = 411;
|
||||
|
||||
/**
|
||||
* Get opcode name by op code.
|
||||
|
||||
@ -83,6 +83,7 @@ import org.apache.doris.analysis.DropFunctionStmt;
|
||||
import org.apache.doris.analysis.DropMaterializedViewStmt;
|
||||
import org.apache.doris.analysis.DropPolicyStmt;
|
||||
import org.apache.doris.analysis.DropRepositoryStmt;
|
||||
import org.apache.doris.analysis.DropResourceGroupStmt;
|
||||
import org.apache.doris.analysis.DropResourceStmt;
|
||||
import org.apache.doris.analysis.DropRoleStmt;
|
||||
import org.apache.doris.analysis.DropSqlBlockRuleStmt;
|
||||
@ -262,6 +263,8 @@ public class DdlExecutor {
|
||||
env.getResourceMgr().dropResource((DropResourceStmt) ddlStmt);
|
||||
} else if (ddlStmt instanceof CreateResourceGroupStmt) {
|
||||
env.getResourceGroupMgr().createResourceGroup((CreateResourceGroupStmt) ddlStmt);
|
||||
} else if (ddlStmt instanceof DropResourceGroupStmt) {
|
||||
env.getResourceGroupMgr().dropResourceGroup((DropResourceGroupStmt) ddlStmt);
|
||||
} else if (ddlStmt instanceof CreateDataSyncJobStmt) {
|
||||
CreateDataSyncJobStmt createSyncJobStmt = (CreateDataSyncJobStmt) ddlStmt;
|
||||
SyncJobManager syncJobMgr = env.getSyncJobManager();
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
package org.apache.doris.resource.resourcegroup;
|
||||
|
||||
import org.apache.doris.analysis.CreateResourceGroupStmt;
|
||||
import org.apache.doris.analysis.DropResourceGroupStmt;
|
||||
import org.apache.doris.catalog.Env;
|
||||
import org.apache.doris.common.Config;
|
||||
import org.apache.doris.common.DdlException;
|
||||
@ -27,6 +28,7 @@ import org.apache.doris.common.io.Writable;
|
||||
import org.apache.doris.common.proc.BaseProcResult;
|
||||
import org.apache.doris.common.proc.ProcNodeInterface;
|
||||
import org.apache.doris.common.proc.ProcResult;
|
||||
import org.apache.doris.persist.DropResourceGroupOperationLog;
|
||||
import org.apache.doris.persist.gson.GsonPostProcessable;
|
||||
import org.apache.doris.persist.gson.GsonUtils;
|
||||
import org.apache.doris.thrift.TPipelineResourceGroup;
|
||||
@ -149,6 +151,35 @@ public class ResourceGroupMgr implements Writable, GsonPostProcessable {
|
||||
LOG.info("Create resource group success: {}", resourceGroup);
|
||||
}
|
||||
|
||||
public void dropResourceGroup(DropResourceGroupStmt stmt) throws DdlException {
|
||||
if (!Config.enable_resource_group) {
|
||||
throw new DdlException("unsupported feature now, coming soon.");
|
||||
}
|
||||
|
||||
String resourceGroupName = stmt.getResourceGroupName();
|
||||
if (resourceGroupName == DEFAULT_GROUP_NAME) {
|
||||
throw new DdlException("Dropping default resource group " + resourceGroupName + " is not allowed");
|
||||
}
|
||||
|
||||
writeLock();
|
||||
try {
|
||||
if (!nameToResourceGroup.containsKey(resourceGroupName)) {
|
||||
if (stmt.isIfExists()) {
|
||||
return;
|
||||
}
|
||||
throw new DdlException("Resource group " + resourceGroupName + " does not exist");
|
||||
}
|
||||
ResourceGroup resourceGroup = nameToResourceGroup.get(resourceGroupName);
|
||||
long groupId = resourceGroup.getId();
|
||||
idToResourceGroup.remove(groupId);
|
||||
nameToResourceGroup.remove(resourceGroupName);
|
||||
Env.getCurrentEnv().getEditLog().logDropResourceGroup(new DropResourceGroupOperationLog(groupId));
|
||||
} finally {
|
||||
writeUnlock();
|
||||
}
|
||||
LOG.info("Drop resource group success: {}", resourceGroupName);
|
||||
}
|
||||
|
||||
public void replayCreateResourceGroup(ResourceGroup resourceGroup) {
|
||||
writeLock();
|
||||
try {
|
||||
@ -159,6 +190,21 @@ public class ResourceGroupMgr implements Writable, GsonPostProcessable {
|
||||
}
|
||||
}
|
||||
|
||||
public void replayDropResourceGroup(DropResourceGroupOperationLog operationLog) {
|
||||
long id = operationLog.getId();
|
||||
writeLock();
|
||||
try {
|
||||
if (!idToResourceGroup.containsKey(id)) {
|
||||
return;
|
||||
}
|
||||
ResourceGroup resourceGroup = idToResourceGroup.get(id);
|
||||
nameToResourceGroup.remove(resourceGroup.getName());
|
||||
idToResourceGroup.remove(id);
|
||||
} finally {
|
||||
writeUnlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<List<String>> getResourcesInfo() {
|
||||
return procNode.fetchResult().getRows();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user