[Enhancement] Make BE reject multi-statement transaction stream load (#63242)

Signed-off-by: meegoo <meegoo.sr@gmail.com>
This commit is contained in:
meegoo 2025-09-19 10:33:40 -07:00 committed by GitHub
parent 064cde829d
commit af7052ff34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 0 deletions

View File

@ -120,6 +120,14 @@ void TransactionManagerAction::handle(HttpRequest* req) {
return _send_error_reply(req, Status::InvalidArgument(fmt::format("empty label")));
}
// HTTP_TRANSACTION_TYPE header is used for multi-statement transactions and should only be sent to FE
// (Frontend) nodes. BE (Backend) nodes cannot process multi-statement transaction requests.
if (!req->header(HTTP_TRANSACTION_TYPE).empty()) {
return _send_error_reply(
req, Status::InvalidArgument(
"Multi-statement transaction requests can only be sent to FE nodes, not BE nodes"));
}
if (boost::iequals(txn_op, TXN_BEGIN)) {
st = _exec_env->transaction_mgr()->begin_transaction(req, &resp);
} else if (boost::iequals(txn_op, TXN_COMMIT) || boost::iequals(txn_op, TXN_PREPARE)) {

View File

@ -78,6 +78,7 @@ static const std::string HTTP_ENABLE_REPLICATED_STORAGE = "enable_replicated_sto
static const std::string HTTP_MERGE_CONDITION = "merge_condition";
static const std::string HTTP_LOG_REJECTED_RECORD_NUM = "log_rejected_record_num";
static const std::string HTTP_PARTIAL_UPDATE_MODE = "partial_update_mode";
static const std::string HTTP_TRANSACTION_TYPE = "transaction_type";
static const std::string HTTP_100_CONTINUE = "100-continue";
static const std::string HTTP_CHANNEL_ID = "channel_id";

View File

@ -0,0 +1,18 @@
-- name: test_be_reject_transaction_type_header
create database db_${uuid0};
-- result:
-- !result
use db_${uuid0};
-- result:
-- !result
create table dummy_table (id int) distributed by hash(id) buckets 1 properties("replication_num" = "1");
-- result:
-- !result
shell: curl --location-trusted -u root: -H "label:test_multi_${uuid0}" -H "db:db_${uuid0}" -H "table:dummy_table" -H "transaction_type:multi" -XPOST "http://$(${mysql_cmd} -e "show backends;" | tail -n +2 | head -n 1 | cut -f2):$(${mysql_cmd} -e "show backends;" | tail -n +2 | head -n 1 | cut -f5)/api/transaction/begin"
-- result:
0
{
"Status": "INVALID_ARGUMENT",
"Message": "Multi-statement transaction requests can only be sent to FE nodes, not BE nodes"
}
-- !result

View File

@ -0,0 +1,7 @@
-- name: test_be_reject_transaction_type_header
create database db_${uuid0};
use db_${uuid0};
create table dummy_table (id int) distributed by hash(id) buckets 1 properties("replication_num" = "1");
shell: curl --location-trusted -u root: -H "label:test_multi_${uuid0}" -H "db:db_${uuid0}" -H "table:dummy_table" -H "transaction_type:multi" -XPOST "http://$(${mysql_cmd} -e "show backends;" | tail -n +2 | head -n 1 | cut -f2):$(${mysql_cmd} -e "show backends;" | tail -n +2 | head -n 1 | cut -f5)/api/transaction/begin"