Skip to content
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

json query transaction mode (#5574) - merge stable-24-2 #6131

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
26 changes: 22 additions & 4 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 Syntax;
TString UserToken;
bool IsBase64Encode;
TString TransactionMode;

enum ESchemaType {
Classic,
Expand Down Expand Up @@ -83,6 +84,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
TString schemaStr = params.Get("schema");
Schema = StringToSchemaType(schemaStr);
Syntax = params.Get("syntax");
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> {
Stats = Stats.empty() ? requestData["stats"].GetStringSafe({}) : Stats;
Action = Action.empty() ? requestData["action"].GetStringSafe({}) : Action;
Syntax = Syntax.empty() ? requestData["syntax"].GetStringSafe({}) : Syntax;
TransactionMode = TransactionMode.empty() ? requestData["transaction_mode"].GetStringSafe({}) : TransactionMode;
}
}

Expand Down Expand Up @@ -161,6 +164,22 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
}
}

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 SendKpqProxyRequest() {
if (MadeKqpProxyRequest) {
return;
Expand All @@ -176,9 +195,8 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
} else if (Action == "execute-query") {
request.SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE);
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
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-query") {
request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN);
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
Expand All @@ -190,9 +208,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 @@ -634,6 +651,7 @@ struct TJsonRequestParameters<TJsonQuery> {
{"name":"schema","in":"query","description":"result format schema (classic, modern, ydb, multi)","required":false,"type":"string"},
{"name":"stats","in":"query","description":"return stats (profile, full)","required":false,"type":"string"},
{"name":"action","in":"query","description":"execute method (execute-scan, execute-script, execute-query, execute-data,explain-ast, explain-scan, explain-script, explain-query, explain-data)","required":false,"type":"string"},
{"name":"transaction_mode","in":"query","description":"transaction mode (serializable-read-write, online-read-only, stale-read-only, snapshot-read-only)","required":false,"type":"string"},
{"name":"base64","in":"query","description":"return strings using base64 encoding","required":false,"type":"string"},
{"name":"timeout","in":"query","description":"timeout in ms","required":false,"type":"integer"}])___";
}
Expand Down
Loading