Skip to content

Commit

Permalink
[Enhancement] (nereids)implement adminCheckTabletsCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
rijeshkp committed Nov 29, 2024
1 parent db3a3ec commit cd33a9b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ unsupportedCancelStatement

supportedAdminStatement
: ADMIN SHOW REPLICA DISTRIBUTION FROM baseTableRef #adminShowReplicaDistribution
| ADMIN CHECK tabletList properties=propertyClause? #adminCheckTablets
;

supportedRecoverStatement
Expand All @@ -492,7 +493,6 @@ unsupportedAdminStatement
| ADMIN COMPACT TABLE baseTableRef wildWhere? #adminCompactTable
| ADMIN SET (FRONTEND | (ALL FRONTENDS)) CONFIG
(LEFT_PAREN propertyItemList RIGHT_PAREN)? ALL? #adminSetFrontendConfig
| ADMIN CHECK tabletList properties=propertyClause? #adminCheckTablets
| ADMIN REBALANCE DISK (ON LEFT_PAREN backends+=STRING_LITERAL
(COMMA backends+=STRING_LITERAL) RIGHT_PAREN)? #adminRebalanceDisk
| ADMIN CANCEL REBALANCE DISK (ON LEFT_PAREN backends+=STRING_LITERAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.doris.mtmv.MTMVRefreshTriggerInfo;
import org.apache.doris.nereids.DorisParser;
import org.apache.doris.nereids.DorisParser.AddConstraintContext;
import org.apache.doris.nereids.DorisParser.AdminCheckTabletsContext;
import org.apache.doris.nereids.DorisParser.AdminShowReplicaDistributionContext;
import org.apache.doris.nereids.DorisParser.AggClauseContext;
import org.apache.doris.nereids.DorisParser.AggStateDataTypeContext;
Expand Down Expand Up @@ -450,6 +451,7 @@
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
import org.apache.doris.nereids.trees.plans.algebra.SetOperation.Qualifier;
import org.apache.doris.nereids.trees.plans.commands.AddConstraintCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCheckTabletsCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterStorageVaultCommand;
Expand Down Expand Up @@ -4688,4 +4690,19 @@ public LogicalPlan visitShowTabletsBelong(ShowTabletsBelongContext ctx) {
});
return new ShowTabletsBelongCommand(tabletIdLists);
}

@Override
public LogicalPlan visitAdminCheckTablets(AdminCheckTabletsContext ctx) {
List<Long> tabletIdLists = new ArrayList<>();
if (ctx.tabletList() != null) {
ctx.tabletList().tabletIdList.stream().forEach(tabletToken -> {
tabletIdLists.add(Long.parseLong(tabletToken.getText()));
});
}
Map<String, String> properties = ctx.properties != null
? Maps.newHashMap(visitPropertyClause(ctx.properties))
: Maps.newHashMap();
return new AdminCheckTabletsCommand(tabletIdLists, properties);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public enum PlanType {
PHYSICAL_WINDOW,

// commands
ADMIN_CHECK_TABLETS_COMMAND,
CREATE_POLICY_COMMAND,
CREATE_TABLE_COMMAND,
DELETE_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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.nereids.trees.plans.commands;

import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.StmtExecutor;

import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* drop user command
*/
public class AdminCheckTabletsCommand extends Command {
private final List<Long> tabletIds;
private final Map<String, String> properties;

/**
* Check Type in Properties.
* At present only CONSISTENCY is supported
*/
public enum CheckType {
CONSISTENCY; // check the consistency of replicas of tablet
public static CheckType getTypeFromString(String str) throws AnalysisException {
try {
return CheckType.valueOf(str.toUpperCase());
} catch (Exception e) {
throw new AnalysisException("Unknown check type: " + str);
}
}
}

/**
* constructor
*/
// ADMIN CHECK TABLET (id1, id2, ...) PROPERTIES ("type" = "check_consistency");
public AdminCheckTabletsCommand(List<Long> tabletIds, Map<String, String> properties) {
super(PlanType.ADMIN_CHECK_TABLETS_COMMAND);
this.tabletIds = tabletIds;
this.properties = properties;
}

public List<Long> getTabletIds() {
return tabletIds;
}

@Override
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
// check auth
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}

if (CollectionUtils.isEmpty(tabletIds)) {
throw new AnalysisException("Tablet id list is empty");
}

String typeStr = PropertyAnalyzer.analyzeType(properties);
if (typeStr == null) {
throw new AnalysisException("Should specify 'type' property");
}
CheckType checkType = CheckType.getTypeFromString(typeStr);

if (properties != null && !properties.isEmpty()) {
throw new AnalysisException("Unknown properties: " + properties.keySet());
}

if (Objects.requireNonNull(checkType) == CheckType.CONSISTENCY) {
Env.getCurrentEnv().getConsistencyChecker().addTabletsToCheck(getTabletIds());
}
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitAdminCheckTabletsCommand(this, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.plans.visitor;

import org.apache.doris.nereids.trees.plans.commands.AddConstraintCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCheckTabletsCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterJobStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
Expand Down Expand Up @@ -489,4 +490,8 @@ default R visitShowTabletsBelongCommand(ShowTabletsBelongCommand showTabletBelon
default R visitCreateRoutineLoadCommand(CreateRoutineLoadCommand createRoutineLoadCommand, C context) {
return visitCommand(createRoutineLoadCommand, context);
}

default R visitAdminCheckTabletsCommand(AdminCheckTabletsCommand adminCheckTabletsCommand, C context) {
return visitCommand(adminCheckTabletsCommand, context);
}
}

0 comments on commit cd33a9b

Please sign in to comment.