From 71f87bfbbf27645f42da203b77f5870d3e8ec364 Mon Sep 17 00:00:00 2001 From: StekPerepolnen Date: Fri, 14 Jun 2024 15:02:00 +0000 Subject: [PATCH] json_query transaction mode --- ydb/core/viewer/json_query.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ydb/core/viewer/json_query.h b/ydb/core/viewer/json_query.h index 0bae8ee76beb..8d538a65d4f7 100644 --- a/ydb/core/viewer/json_query.h +++ b/ydb/core/viewer/json_query.h @@ -39,6 +39,7 @@ class TJsonQuery : public TViewerPipeClient { TString Stats; TString Syntax; TString QueryId; + TString TransactionMode; bool Direct = false; bool IsBase64Encode = true; @@ -82,6 +83,7 @@ class TJsonQuery : public TViewerPipeClient { Schema = StringToSchemaType(schemaStr); Syntax = params.Get("syntax"); QueryId = params.Get("query_id"); + TransactionMode = params.Get("transaction_mode"); Direct = FromStringWithDefault(params.Get("direct"), Direct); IsBase64Encode = FromStringWithDefault(params.Get("base64"), true); } @@ -97,6 +99,7 @@ class TJsonQuery : public TViewerPipeClient { 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; } @@ -231,8 +234,6 @@ class TJsonQuery : public TViewerPipeClient { } 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); } else if (Action == "explain-query") { request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN); @@ -245,8 +246,6 @@ class TJsonQuery : public TViewerPipeClient { } 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); } else if (Action == "explain" || Action == "explain-ast" || Action == "explain-data") { request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN); @@ -270,6 +269,16 @@ class TJsonQuery : public TViewerPipeClient { } else if (Syntax == "pg") { request.SetSyntax(Ydb::Query::Syntax::SYNTAX_PG); } + if (TransactionMode == "online-read-only") { + request.mutable_txcontrol()->mutable_begin_tx()->mutable_online_read_only(); + } else if (TransactionMode == "stale-read-only") { + request.mutable_txcontrol()->mutable_begin_tx()->mutable_stale_read_only(); + } else if (TransactionMode == "snapshot-read-only") { + request.mutable_txcontrol()->mutable_begin_tx()->mutable_snapshot_read_only(); + } else if (TransactionMode == "serializable-read-write" || Action == "execute-query" || Action == "execute-data") { + request.mutable_txcontrol()->mutable_begin_tx()->mutable_serializable_read_write(); + request.mutable_txcontrol()->set_commit_tx(true); + } ActorIdToProto(SelfId(), event->Record.MutableRequestActorId()); Send(NKqp::MakeKqpProxyID(SelfId().NodeId()), event.Release()); BLOG_TRACE("Query sent"); @@ -664,6 +673,17 @@ YAML::Node TJsonRequestSwagger::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