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 Dec 4, 2024
1 parent 08b187b commit ea9d777
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ unsupportedCancelStatement

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

supportedRecoverStatement
Expand All @@ -496,7 +497,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 @@ -452,6 +453,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 @@ -4743,4 +4745,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,105 @@
// 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.analysis.RedirectStatus;
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 implements Redirect {
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;
}

@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(tabletIds);
}
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitAdminCheckTabletsCommand(this, context);
}

@Override
public RedirectStatus toRedirectStatus() {
return RedirectStatus.FORWARD_NO_SYNC;
}
}
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 @@ -514,4 +515,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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.


suite("test_nereids_admin_check_tablet") {
def table = "test_nereids_admin_check_tablet"
// create table and insert data
sql """ drop table if exists ${table} force"""
sql """
create table ${table} (
`id` int(11),
`name` varchar(128),
`da` date
)
engine=olap
duplicate key(id)
partition by range(da)(
PARTITION p3 VALUES LESS THAN ('2023-01-01'),
PARTITION p4 VALUES LESS THAN ('2024-01-01'),
PARTITION p5 VALUES LESS THAN ('2025-01-01')
)
distributed by hash(id) buckets 2
properties(
"replication_num"="1",
"light_schema_change"="true"
);
"""

def res = sql_return_maparray "show tablets from ${table}"

checkNereidsExecute("ADMIN CHECK TABLET (${res[0][0]}, ${res[1][0]}) PROPERTIES('type' = 'consistency')");

}

0 comments on commit ea9d777

Please sign in to comment.