Skip to content

query transaction mode and asan tests fixed - merge stable-24-2 #8197

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
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion ydb/core/testlib/actors/test_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
namespace NActors {

void TTestActorRuntime::TNodeData::Stop() {
TNodeDataBase::Stop();
if (Mon) {
Mon->Stop();
GetAppData<NKikimr::TAppData>()->Mon = nullptr;
}
TNodeDataBase::Stop();
}

TTestActorRuntime::TNodeData::~TNodeData() {
Expand Down
4 changes: 4 additions & 0 deletions ydb/core/viewer/json_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_DML);
request.SetKeepSession(false);
SetTransactionMode(request);
if (!request.txcontrol().has_begin_tx()) {
request.mutable_txcontrol()->mutable_begin_tx()->mutable_serializable_read_write();
request.mutable_txcontrol()->set_commit_tx(true);
}
} 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
89 changes: 87 additions & 2 deletions ydb/core/viewer/viewer_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,91 @@ Y_UNIT_TEST_SUITE(Viewer) {
size_t AuthorizeTicketFails = 0;
};

TString PostQuery(TKeepAliveHttpClient& httpClient, TString query, TString action = "", TString transactionMode = "", HttpCodes expectedCode = HTTP_OK) {
TStringStream requestBody;
requestBody
<< "{ \"query\": \"" << query << "\","
<< " \"database\": \"/Root\","
<< " \"action\": \"" << action << "\","
<< " \"syntax\": \"yql_v1\","
<< " \"transaction_mode\": \"" << transactionMode << "\","
<< " \"stats\": \"none\" }";
TStringStream responseStream;
TKeepAliveHttpClient::THeaders headers;
headers["Content-Type"] = "application/json";
headers["Authorization"] = "test_ydb_token";
const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/json/query?timeout=600000&base64=false&schema=modern", requestBody.Str(), &responseStream, headers);
const TString response = responseStream.ReadAll();
UNIT_ASSERT_EQUAL_C(statusCode, expectedCode, statusCode << ": " << response);
return response;
}

Y_UNIT_TEST(ExecuteQueryDoesntExecuteSchemeOperationsInsideTransation) {
TPortManager tp;
ui16 port = tp.GetPort(2134);
ui16 grpcPort = tp.GetPort(2135);
ui16 monPort = tp.GetPort(8765);
auto settings = TServerSettings(port);
settings.InitKikimrRunConfig()
.SetNodeCount(1)
.SetUseRealThreads(true)
.SetDomainName("Root")
.SetMonitoringPortOffset(monPort, true);

TServer server(settings);
server.EnableGRpc(grpcPort);
TClient client(settings);
client.InitRootScheme();

TTestActorRuntime& runtime = *server.GetRuntime();
runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE);

TKeepAliveHttpClient httpClient("localhost", monPort);

//Scheme operations cannot be executed inside transaction
TString response = PostQuery(httpClient, "CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));", "execute-query", "serializable-read-write", HTTP_BAD_REQUEST);
{
NJson::TJsonReaderConfig jsonCfg;
NJson::TJsonValue json;
NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true);
UNIT_ASSERT_EQUAL_C(json["error"].GetMap().at("message").GetString(), "Scheme operations cannot be executed inside transaction", response);
}
}

Y_UNIT_TEST(UseTransactionWhenExecuteDataActionQuery) {
TPortManager tp;
ui16 port = tp.GetPort(2134);
ui16 grpcPort = tp.GetPort(2135);
ui16 monPort = tp.GetPort(8765);
auto settings = TServerSettings(port);
settings.InitKikimrRunConfig()
.SetNodeCount(1)
.SetUseRealThreads(true)
.SetDomainName("Root")
.SetMonitoringPortOffset(monPort, true);

TServer server(settings);
server.EnableGRpc(grpcPort);
TClient client(settings);
client.InitRootScheme();

TTestActorRuntime& runtime = *server.GetRuntime();
runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE);

TKeepAliveHttpClient httpClient("localhost", monPort);

PostQuery(httpClient, "CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));", "execute-query");
PostQuery(httpClient, "INSERT INTO `/Root/Test` (Key, Value) VALUES (1, 'testvalue');", "execute-query");
TString response = PostQuery(httpClient, "SELECT * FROM `/Root/Test`;", "execute-data");
{
NJson::TJsonReaderConfig jsonCfg;
NJson::TJsonValue json;
NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true);
auto resultSets = json["result"].GetArray();
UNIT_ASSERT_EQUAL_C(1, resultSets.size(), response);
}
}

Y_UNIT_TEST(FloatPointJsonQuery) {
TPortManager tp;
ui16 port = tp.GetPort(2134);
Expand Down Expand Up @@ -1145,7 +1230,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
"database": "/Root",
"action": "execute-script",
"syntax": "yql_v1",
"stats": "profile"
"stats": "none"
})json";
const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/json/query?timeout=600000&base64=false&schema=modern", requestBody, &responseStream, headers);
const TString response = responseStream.ReadAll();
Expand Down Expand Up @@ -1210,7 +1295,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
"database": "/Root",
"action": "execute-script",
"syntax": "yql_v1",
"stats": "profile"
"stats": "none"
})json";
const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/json/query?timeout=600000&base64=false&schema=modern", requestBody, &responseStream, headers);
const TString response = responseStream.ReadAll();
Expand Down
Loading