[Fix](thrift) Add fe master check in some thrift calls (#23757)

Signed-off-by: Jack Drogon <jack.xsuperman@gmail.com>
This commit is contained in:
Jack Drogon
2023-09-02 14:05:31 +08:00
committed by GitHub
parent f1c354e0cf
commit de8fa2cff5
2 changed files with 47 additions and 0 deletions

View File

@ -232,6 +232,9 @@ import java.util.stream.Collectors;
// thrift protocol
public class FrontendServiceImpl implements FrontendService.Iface {
private static final Logger LOG = LogManager.getLogger(FrontendServiceImpl.class);
private static final String NOT_MASTER_ERR_MSG = "FE is not master";
private MasterImpl masterImpl;
private ExecuteEnv exeEnv;
// key is txn id,value is index of plan fragment instance, it's used by multi table request plan
@ -1185,6 +1188,14 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TBeginTxnResult result = new TBeginTxnResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
if (!Env.getCurrentEnv().isMaster()) {
status.setStatusCode(TStatusCode.NOT_MASTER);
status.addToErrorMsgs(NOT_MASTER_ERR_MSG);
LOG.error("failed to get binlog: {}", NOT_MASTER_ERR_MSG);
return result;
}
try {
TBeginTxnResult tmpRes = beginTxnImpl(request, clientAddr);
result.setTxnId(tmpRes.getTxnId()).setDbId(tmpRes.getDbId());
@ -1532,6 +1543,14 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TCommitTxnResult result = new TCommitTxnResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
if (!Env.getCurrentEnv().isMaster()) {
status.setStatusCode(TStatusCode.NOT_MASTER);
status.addToErrorMsgs(NOT_MASTER_ERR_MSG);
LOG.error("failed to get binlog: {}", NOT_MASTER_ERR_MSG);
return result;
}
try {
if (!commitTxnImpl(request)) {
// committed success but not visible
@ -1705,6 +1724,14 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TRollbackTxnResult result = new TRollbackTxnResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
if (!Env.getCurrentEnv().isMaster()) {
status.setStatusCode(TStatusCode.NOT_MASTER);
status.addToErrorMsgs(NOT_MASTER_ERR_MSG);
LOG.error("failed to get binlog: {}", NOT_MASTER_ERR_MSG);
return result;
}
try {
rollbackTxnImpl(request);
} catch (UserException e) {
@ -2680,6 +2707,14 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TGetSnapshotResult result = new TGetSnapshotResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
if (!Env.getCurrentEnv().isMaster()) {
status.setStatusCode(TStatusCode.NOT_MASTER);
status.addToErrorMsgs(NOT_MASTER_ERR_MSG);
LOG.error("failed to get binlog: {}", NOT_MASTER_ERR_MSG);
return result;
}
try {
result = getSnapshotImpl(request, clientAddr);
} catch (UserException e) {
@ -2758,6 +2793,14 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TRestoreSnapshotResult result = new TRestoreSnapshotResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
if (!Env.getCurrentEnv().isMaster()) {
status.setStatusCode(TStatusCode.NOT_MASTER);
status.addToErrorMsgs(NOT_MASTER_ERR_MSG);
LOG.error("failed to get binlog: {}", NOT_MASTER_ERR_MSG);
return result;
}
try {
result = restoreSnapshotImpl(request, clientAddr);
} catch (UserException e) {
@ -2858,6 +2901,7 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TGetMasterTokenResult result = new TGetMasterTokenResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
try {
checkPassword(request.getCluster(), request.getUser(), request.getPassword(), clientAddr);
result.setToken(Env.getCurrentEnv().getToken());
@ -2882,6 +2926,7 @@ public class FrontendServiceImpl implements FrontendService.Iface {
TGetBinlogLagResult result = new TGetBinlogLagResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
try {
result = getBinlogLagImpl(request, clientAddr);
} catch (UserException e) {

View File

@ -99,6 +99,8 @@ enum TStatusCode {
HTTP_ERROR = 71,
TABLET_MISSING = 72,
NOT_MASTER = 73,
}
struct TStatus {