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
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
{
"title": "ADMIN-SET-REPLICA-VERSION",
"language": "en"
}
---

<!--
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.
-->

## ADMIN-SET-REPLICA-VERSION

### Name

ADMIN SET REPLICA VERSION

### Description

This statement is used to set the version, maximum success version, and maximum failure version of the specified replica.

This command is currently only used to manually repair the replica version when the program is abnormal, so that the replica can recover from the abnormal state.

grammar:

```sql
ADMIN SET REPLICA VERSION
PROPERTIES ("key" = "value", ...);
```

The following properties are currently supported:

1. `tablet_id`: Required. Specify a Tablet Id.
2. `backend_id`: Required. Specify Backend Id.
3. `version`: Optional. Set the replica version.
4. `last_success_version`: Optional. Set the replica max success version.
5. `last_failed_version`: Optional. Set the replica max failed version.

If the specified replica does not exist, it will be ignored.

> Note:
>
> Modifying these values ​​may cause subsequent data reading and writing failures, resulting in data inconsistency. Please operate with caution!
>
> Record the original value before modifying it. After the modification is completed, verify the read and write of the table. If the read and write fail, please restore the original value! But recovery may fail!
>
> It is strictly prohibited to operate the tablet that is writing data!

### Example

1. Clear the replica failed version of tablet 10003 on BE 10001.

```sql
ADMIN SET REPLICA VERSION PROPERTIES("tablet_id" = "10003", "backend_id" = "10001", "last_failed_version" = "-1");
```

2. Set the replica status of tablet 10003 on BE 10001 to ok.

```sql
ADMIN SET REPLICA VERSION PROPERTIES("tablet_id" = "10003", "backend_id" = "10001", "version" = "1004");
```

### Keywords

ADMIN, SET, REPLICA, VERSION

### Best Practice

1 change: 1 addition & 0 deletions docs/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@
"sql-manual/sql-reference/Database-Administration-Statements/INSTALL-PLUGIN",
"sql-manual/sql-reference/Database-Administration-Statements/UNINSTALL-PLUGIN",
"sql-manual/sql-reference/Database-Administration-Statements/ADMIN-SET-REPLICA-STATUS",
"sql-manual/sql-reference/Database-Administration-Statements/ADMIN-SET-REPLICA-VERSION",
"sql-manual/sql-reference/Database-Administration-Statements/ADMIN-SET-PARTITION-VERSION",
"sql-manual/sql-reference/Database-Administration-Statements/ADMIN-SET-TABLE-STATUS",
"sql-manual/sql-reference/Database-Administration-Statements/ADMIN-SHOW-REPLICA-DISTRIBUTION",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
{
"title": "ADMIN-SET-REPLICA-VERSION",
"language": "zh-CN"
}
---

<!--
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.
-->

## ADMIN-SET-REPLICA-VERSION

### Name

ADMIN SET REPLICA VERSION

### Description

该语句用于设置指定副本的版本、最大成功版本、最大失败版本。

该命令目前仅用于在程序异常情况下,手动修复副本的版本,从而使得副本从异常状态恢复过来。

语法:

```sql
ADMIN SET REPLICA VERSION
PROPERTIES ("key" = "value", ...);
```

目前支持如下属性:

1. `tablet_id`:必需。指定一个 Tablet Id.
2. `backend_id`:必需。指定 Backend Id.
3. `version`:可选。设置副本的版本.
4. `last_success_version`:可选。设置副本的最大成功版本.
5. `last_failed_version`:可选。设置副本的最大失败版本。


如果指定的副本不存在,则会被忽略。

> 注意:
>
> 修改这几个数值,可能会导致后面数据读写失败,造成数据不一致,请谨慎操作!
>
> 修改之前先记录原来的值。修改完毕之后,对表进行读写验证,如果读写失败,请恢复原来的值!但可能会恢复失败!
>
> 严禁对正在写入数据的tablet进行操作 !


### Example

1. 清除 tablet 10003 在 BE 10001 上的副本状态失败标志。

```sql
ADMIN SET REPLICA VERSION PROPERTIES("tablet_id" = "10003", "backend_id" = "10001", "last_failed_version" = "-1");
```

2. 设置 tablet 10003 在 BE 10001 上的副本版本号为 1004。

```sql
ADMIN SET REPLICA VERSION PROPERTIES("tablet_id" = "10003", "backend_id" = "10001", "version" = "1004");
```

### Keywords

ADMIN, SET, REPLICA, VERSION

### Best Practice

4 changes: 4 additions & 0 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -7173,6 +7173,10 @@ admin_stmt ::=
{:
RESULT = new AdminSetReplicaStatusStmt(prop);
:}
| KW_ADMIN KW_SET KW_REPLICA KW_VERSION KW_PROPERTIES LPAREN key_value_map:prop RPAREN
{:
RESULT = new AdminSetReplicaVersionStmt(prop);
:}
| KW_ADMIN KW_REPAIR KW_TABLE base_table_ref:table_ref
{:
RESULT = new AdminRepairTableStmt(table_ref);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// 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.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;

import java.util.Map;

/*
* admin set replicas status properties ("key" = "val", ..);
* Required:
* "tablet_id" = "10010",
* "backend_id" = "10001",
* Optional:
* "version" = "100",
* "last_success_version" = "100",
* "last_failed_version" = "-1",
*/
public class AdminSetReplicaVersionStmt extends DdlStmt {

public static final String TABLET_ID = "tablet_id";
public static final String BACKEND_ID = "backend_id";
public static final String VERSION = "version";
public static final String LAST_SUCCESS_VERSION = "last_success_version";
public static final String LAST_FAILED_VERSION = "last_failed_version";

private Map<String, String> properties;
private long tabletId = -1;
private long backendId = -1;
private Long version = null;
private Long lastSuccessVersion = null;
private Long lastFailedVersion = null;

public AdminSetReplicaVersionStmt(Map<String, String> properties) {
this.properties = properties;
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
super.analyze(analyzer);

// check auth
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}

checkProperties();
}

private void checkProperties() throws AnalysisException {
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();
String val = entry.getValue();

if (key.equalsIgnoreCase(TABLET_ID)) {
try {
tabletId = Long.valueOf(val);
} catch (NumberFormatException e) {
throw new AnalysisException("Invalid tablet id format: " + val);
}
} else if (key.equalsIgnoreCase(BACKEND_ID)) {
try {
backendId = Long.valueOf(val);
} catch (NumberFormatException e) {
throw new AnalysisException("Invalid backend id format: " + val);
}
} else if (key.equalsIgnoreCase(VERSION)) {
try {
version = Long.valueOf(val);
} catch (NumberFormatException e) {
throw new AnalysisException("Invalid version format: " + val);
}
if (version <= 0) {
throw new AnalysisException("Required version > 0");
}
} else if (key.equalsIgnoreCase(LAST_SUCCESS_VERSION)) {
try {
lastSuccessVersion = Long.valueOf(val);
} catch (NumberFormatException e) {
throw new AnalysisException("Invalid last success version format: " + val);
}
if (lastSuccessVersion <= 0) {
throw new AnalysisException("Required last success version > 0");
}
} else if (key.equalsIgnoreCase(LAST_FAILED_VERSION)) {
try {
lastFailedVersion = Long.valueOf(val);
} catch (NumberFormatException e) {
throw new AnalysisException("Invalid last failed version format: " + val);
}
if (lastFailedVersion <= 0 && lastFailedVersion != -1) {
throw new AnalysisException("Required last failed version > 0 or == -1");
}
} else {
throw new AnalysisException("Unknown property: " + key);
}
}

if (tabletId == -1 || backendId == -1
|| (version == null && lastSuccessVersion == null && lastFailedVersion == null)) {
throw new AnalysisException("Should add following properties: TABLET_ID, BACKEND_ID, "
+ "VERSION, LAST_SUCCESS_VERSION, LAST_FAILED_VERSION");
}
}

public long getTabletId() {
return tabletId;
}

public long getBackendId() {
return backendId;
}

public Long getVersion() {
return version;
}

public Long getLastSuccessVersion() {
return lastSuccessVersion;
}

public Long getLastFailedVersion() {
return lastFailedVersion;
}

@Override
public RedirectStatus getRedirectStatus() {
return RedirectStatus.FORWARD_WITH_SYNC;
}
}
Loading