Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/en/administrator-guide/config/fe_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ This will limit the max recursion depth of hash distribution pruner.
So that distribution pruner will no work and just return all buckets.
Increase the depth can support distribution pruning for more elements, but may cost more CPU.

### max_backup_restore_job_num_per_db

Default: 10

This configuration is mainly used to control the number of backup/restore tasks recorded in each database.

### using_old_load_usage_pattern

Expand Down
6 changes: 6 additions & 0 deletions docs/zh-CN/administrator-guide/config/fe_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ SmallFileMgr 中存储的最大文件数

最大 Routine Load 作业数,包括 NEED_SCHEDULED, RUNNING, PAUSE

### max_backup_restore_job_num_per_db

默认值:10

此配置用于控制每个 DB 能够记录的 backup/restore 任务的数量

### max_running_txn_num_per_db

默认值:100
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -2509,9 +2509,9 @@ show_param ::=
{:
RESULT = new ShowUserPropertyStmt(user, parser.wild);
:}
| KW_BACKUP opt_db:db
| KW_BACKUP opt_db:db opt_wild_where
{:
RESULT = new ShowBackupStmt(db);
RESULT = new ShowBackupStmt(db, parser.where);
:}
| KW_RESTORE opt_db:db opt_wild_where
{:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.CaseSensibility;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.PatternMatcher;
import org.apache.doris.common.UserException;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
Expand All @@ -31,6 +34,8 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;

import java.util.function.Predicate;

public class ShowBackupStmt extends ShowStmt {
public static final ImmutableList<String> TITLE_NAMES = new ImmutableList.Builder<String>()
.add("JobId").add("SnapshotName").add("DbName").add("State").add("BackupObjs").add("CreateTime")
Expand All @@ -39,9 +44,13 @@ public class ShowBackupStmt extends ShowStmt {
.build();

private String dbName;
private final Expr where;
private boolean isAccurateMatch;
private String labelValue;

public ShowBackupStmt(String dbName) {
public ShowBackupStmt(String dbName, Expr where) {
this.dbName = dbName;
this.where = where;
}

public String getDbName() {
Expand All @@ -65,6 +74,56 @@ public void analyze(Analyzer analyzer) throws UserException {
ErrorReport.reportAnalysisException(ErrorCode.ERR_DB_ACCESS_DENIED,
ConnectContext.get().getQualifiedUser(), dbName);
}

if (where == null) {
return;
}
boolean valid = analyzeWhereClause();
if (!valid) {
throw new AnalysisException("Where clause should like: LABEL = \"your_label_name\", "
+ " or LABEL LIKE \"matcher\"");
}
}

private boolean analyzeWhereClause() {
if (!(where instanceof LikePredicate) && !(where instanceof BinaryPredicate)) {
return false;
}

if (where instanceof BinaryPredicate) {
BinaryPredicate binaryPredicate = (BinaryPredicate) where;
if (BinaryPredicate.Operator.EQ != binaryPredicate.getOp()) {
return false;
}
isAccurateMatch = true;
}

if (where instanceof LikePredicate) {
LikePredicate likePredicate = (LikePredicate) where;
if (LikePredicate.Operator.LIKE != likePredicate.getOp()) {
return false;
}
}

// left child
if (!(where.getChild(0) instanceof SlotRef)) {
return false;
}
String leftKey = ((SlotRef) where.getChild(0)).getColumnName();
if (!"label".equalsIgnoreCase(leftKey)) {
return false;
}

// right child
if (!(where.getChild(1) instanceof StringLiteral)) {
return false;
}
labelValue = ((StringLiteral) where.getChild(1)).getStringValue();
if (Strings.isNullOrEmpty(labelValue)) {
return false;
}

return true;
}

@Override
Expand All @@ -84,6 +143,10 @@ public String toSql() {
builder.append(" FROM `").append(dbName).append("` ");
}

if (where != null) {
builder.append(where.toSql());
}

return builder.toString();
}

Expand All @@ -96,4 +159,28 @@ public String toString() {
public RedirectStatus getRedirectStatus() {
return RedirectStatus.FORWARD_NO_SYNC;
}

public boolean isAccurateMatch() {
return isAccurateMatch;
}

public String getLabelValue() {
return labelValue;
}

public Expr getWhere() {
return where;
}

public Predicate<String> getLabelPredicate() throws AnalysisException {
if (null == where) {
return label -> true;
}
if (isAccurateMatch) {
return CaseSensibility.LABEL.getCaseSensibility() ? label -> label.equals(labelValue) : label -> label.equalsIgnoreCase(labelValue);
} else {
PatternMatcher patternMatcher = PatternMatcher.createMysqlPattern(labelValue, CaseSensibility.LABEL.getCaseSensibility());
return patternMatcher::match;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.CaseSensibility;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.PatternMatcher;
import org.apache.doris.common.UserException;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
Expand All @@ -31,6 +34,8 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;

import java.util.function.Predicate;

public class ShowRestoreStmt extends ShowStmt {
public static final ImmutableList<String> TITLE_NAMES = new ImmutableList.Builder<String>()
.add("JobId").add("Label").add("Timestamp").add("DbName").add("State")
Expand All @@ -42,7 +47,8 @@ public class ShowRestoreStmt extends ShowStmt {

private String dbName;
private Expr where;
private String label;
private String labelValue;
private boolean isAccurateMatch;

public ShowRestoreStmt(String dbName, Expr where) {
this.dbName = dbName;
Expand All @@ -53,8 +59,8 @@ public String getDbName() {
return dbName;
}

public String getLabel() {
return label;
public String getLabelValue() {
return labelValue;
}

@Override
Expand All @@ -74,6 +80,56 @@ public void analyze(Analyzer analyzer) throws UserException {
ErrorReport.reportAnalysisException(ErrorCode.ERR_DB_ACCESS_DENIED,
ConnectContext.get().getQualifiedUser(), dbName);
}

if (where == null) {
return;
}
boolean valid = analyzeWhereClause();
if (!valid) {
throw new AnalysisException("Where clause should like: LABEL = \"your_label_name\", "
+ " or LABEL LIKE \"matcher\"");
}
}

private boolean analyzeWhereClause() {
if (!(where instanceof LikePredicate) && !(where instanceof BinaryPredicate)) {
return false;
}

if (where instanceof BinaryPredicate) {
BinaryPredicate binaryPredicate = (BinaryPredicate) where;
if (BinaryPredicate.Operator.EQ != binaryPredicate.getOp()) {
return false;
}
isAccurateMatch = true;
}

if (where instanceof LikePredicate) {
LikePredicate likePredicate = (LikePredicate) where;
if (LikePredicate.Operator.LIKE != likePredicate.getOp()) {
return false;
}
}

// left child
if (!(where.getChild(0) instanceof SlotRef)) {
return false;
}
String leftKey = ((SlotRef) where.getChild(0)).getColumnName();
if (!"label".equalsIgnoreCase(leftKey)) {
return false;
}

// right child
if (!(where.getChild(1) instanceof StringLiteral)) {
return false;
}
labelValue = ((StringLiteral) where.getChild(1)).getStringValue();
if (Strings.isNullOrEmpty(labelValue)) {
return false;
}

return true;
}

@Override
Expand Down Expand Up @@ -106,5 +162,25 @@ public String toString() {
public RedirectStatus getRedirectStatus() {
return RedirectStatus.FORWARD_NO_SYNC;
}

public boolean isAccurateMatch() {
return isAccurateMatch;
}

public Expr getWhere() {
return where;
}

public Predicate<String> getLabelPredicate() throws AnalysisException {
if (null == where) {
return label -> true;
}
if (isAccurateMatch) {
return CaseSensibility.LABEL.getCaseSensibility() ? label -> label.equals(labelValue) : label -> label.equalsIgnoreCase(labelValue);
} else {
PatternMatcher patternMatcher = PatternMatcher.createMysqlPattern(labelValue, CaseSensibility.LABEL.getCaseSensibility());
return patternMatcher::match;
}
}
}

Loading