@@ -4896,6 +4896,83 @@ Y_UNIT_TEST_SUITE(DataShardSnapshots) {
48964896 " { items { int32_value: 2 } items { int32_value: 20 } }" );
48974897 }
48984898
4899+ Y_UNIT_TEST (UncommittedChangesRenameTable) {
4900+ TPortManager pm;
4901+ TServerSettings serverSettings (pm.GetPort (2134 ));
4902+ serverSettings.SetDomainName (" Root" )
4903+ .SetUseRealThreads (false )
4904+ .SetDomainPlanResolution (100 )
4905+ .SetEnableDataShardVolatileTransactions (true );
4906+
4907+ Tests::TServer::TPtr server = new TServer (serverSettings);
4908+ auto &runtime = *server->GetRuntime ();
4909+ auto sender = runtime.AllocateEdgeActor ();
4910+
4911+ runtime.SetLogPriority (NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
4912+
4913+ InitRoot (server, sender);
4914+
4915+ TDisableDataShardLogBatching disableDataShardLogBatching;
4916+
4917+ UNIT_ASSERT_VALUES_EQUAL (
4918+ KqpSchemeExec (runtime, R"(
4919+ CREATE TABLE `/Root/table1` (key int, value int, PRIMARY KEY (key));
4920+ )" ),
4921+ " SUCCESS" );
4922+
4923+ ExecSQL (server, sender, " UPSERT INTO `/Root/table1` (key, value) VALUES (2, 22);" );
4924+
4925+ TString sessionId = CreateSessionRPC (runtime);
4926+ TString txId;
4927+ UNIT_ASSERT_VALUES_EQUAL (
4928+ KqpSimpleBegin (runtime, sessionId, txId, R"(
4929+ UPSERT INTO `/Root/table1` (key, value) VALUES (1, 11), (3, 33);
4930+ SELECT key, value FROM `/Root/table1` ORDER BY key;
4931+ )" ),
4932+ " { items { int32_value: 1 } items { int32_value: 11 } }, "
4933+ " { items { int32_value: 2 } items { int32_value: 22 } }, "
4934+ " { items { int32_value: 3 } items { int32_value: 33 } }" );
4935+
4936+ auto shards = GetTableShards (server, sender, " /Root/table1" );
4937+ auto tableId1 = ResolveTableId (server, sender, " /Root/table1" );
4938+
4939+ // Check shard has open transactions
4940+ {
4941+ runtime.SendToPipe (shards.at (0 ), sender, new TEvDataShard::TEvGetOpenTxs (tableId1.PathId ));
4942+ auto ev = runtime.GrabEdgeEventRethrow <TEvDataShard::TEvGetOpenTxsResult>(sender);
4943+ UNIT_ASSERT_C (!ev->Get ()->OpenTxs .empty (), " at shard " << shards.at (0 ));
4944+ }
4945+
4946+ WaitTxNotification (server, sender, AsyncMoveTable (server, " /Root/table1" , " /Root/table1moved" ));
4947+ auto tableId2 = ResolveTableId (server, sender, " /Root/table1moved" );
4948+
4949+ runtime.SimulateSleep (TDuration::Seconds (1 ));
4950+
4951+ // Check shard doesn't have open transactions
4952+ {
4953+ runtime.SendToPipe (shards.at (0 ), sender, new TEvDataShard::TEvGetOpenTxs (tableId2.PathId ));
4954+ auto ev = runtime.GrabEdgeEventRethrow <TEvDataShard::TEvGetOpenTxsResult>(sender);
4955+ UNIT_ASSERT_C (ev->Get ()->OpenTxs .empty (), " at shard " << shards.at (0 ));
4956+ }
4957+
4958+ RebootTablet (runtime, shards.at (0 ), sender);
4959+
4960+ // The original table was removed
4961+ // We must not be able to commit the transaction
4962+ UNIT_ASSERT_VALUES_EQUAL (
4963+ KqpSimpleCommit (runtime, sessionId, txId, " SELECT 1" ),
4964+ " ERROR: ABORTED" );
4965+
4966+ runtime.SimulateSleep (TDuration::Seconds (1 ));
4967+
4968+ // Check shard doesn't have open transactions
4969+ {
4970+ runtime.SendToPipe (shards.at (0 ), sender, new TEvDataShard::TEvGetOpenTxs (tableId2.PathId ));
4971+ auto ev = runtime.GrabEdgeEventRethrow <TEvDataShard::TEvGetOpenTxsResult>(sender);
4972+ UNIT_ASSERT_C (ev->Get ()->OpenTxs .empty (), " at shard " << shards.at (0 ));
4973+ }
4974+ }
4975+
48994976}
49004977
49014978} // namespace NKikimr
0 commit comments