Skip to content

json query transaction mode #5574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
34 changes: 32 additions & 2 deletions ydb/core/viewer/json_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
TString Stats;
TString Syntax;
TString QueryId;
TString TransactionMode;
bool Direct = false;
bool IsBase64Encode = true;

Expand Down Expand Up @@ -82,6 +83,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
Schema = StringToSchemaType(schemaStr);
Syntax = params.Get("syntax");
QueryId = params.Get("query_id");
TransactionMode = params.Get("transaction_mode");
Direct = FromStringWithDefault<bool>(params.Get("direct"), Direct);
IsBase64Encode = FromStringWithDefault<bool>(params.Get("base64"), true);
}
Expand All @@ -97,6 +99,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
Action = Action.empty() ? requestData["action"].GetStringSafe({}) : Action;
Syntax = Syntax.empty() ? requestData["syntax"].GetStringSafe({}) : Syntax;
QueryId = QueryId.empty() ? requestData["query_id"].GetStringSafe({}) : QueryId;
TransactionMode = TransactionMode.empty() ? requestData["transaction_mode"].GetStringSafe({}) : TransactionMode;
}
return success;
}
Expand Down Expand Up @@ -198,6 +201,22 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
Send(NKqp::MakeKqpProxyID(SelfId().NodeId()), event.release());
}

void SetTransactionMode(NKikimrKqp::TQueryRequest& request) {
if (TransactionMode == "serializable-read-write") {
request.mutable_txcontrol()->mutable_begin_tx()->mutable_serializable_read_write();
request.mutable_txcontrol()->set_commit_tx(true);
} else if (TransactionMode == "online-read-only") {
request.mutable_txcontrol()->mutable_begin_tx()->mutable_online_read_only();
request.mutable_txcontrol()->set_commit_tx(true);
} else if (TransactionMode == "stale-read-only") {
request.mutable_txcontrol()->mutable_begin_tx()->mutable_stale_read_only();
request.mutable_txcontrol()->set_commit_tx(true);
} else if (TransactionMode == "snapshot-read-only") {
request.mutable_txcontrol()->mutable_begin_tx()->mutable_snapshot_read_only();
request.mutable_txcontrol()->set_commit_tx(true);
}
}

void HandleReply(NKqp::TEvKqp::TEvCreateSessionResponse::TPtr& ev) {
if (ev->Get()->Record.GetYdbStatus() != Ydb::StatusIds::SUCCESS) {
return ReplyAndPassAway(
Expand Down Expand Up @@ -232,6 +251,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
request.SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE);
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
request.SetKeepSession(false);
SetTransactionMode(request);
} else if (Action == "explain-query") {
request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN);
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
Expand All @@ -243,9 +263,8 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
} else if (Action == "execute-data") {
request.SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE);
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_DML);
request.mutable_txcontrol()->mutable_begin_tx()->mutable_serializable_read_write();
request.mutable_txcontrol()->set_commit_tx(true);
request.SetKeepSession(false);
SetTransactionMode(request);
} else if (Action == "explain" || Action == "explain-ast" || Action == "explain-data") {
request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN);
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_DML);
Expand Down Expand Up @@ -662,6 +681,17 @@ YAML::Node TJsonRequestSwagger<TJsonQuery>::GetSwagger() {
type: string
enum: [profile, full]
required: false
- name: transaction_mode
in: query
description: >
transaction mode:
* `serializable-read-write`
* `online-read-only`
* `stale-read-only`
* `snapshot-read-only`
type: string
enum: [serializable-read-write, online-read-only, stale-read-only, snapshot-read-only]
required: false
- name: direct
in: query
description: force processing query on current node
Expand Down
Loading