@@ -1875,6 +1875,103 @@ NKikimrDataEvents::TEvWriteResult Write(TTestActorRuntime& runtime, TActorId sen
1875
1875
return Write (runtime, sender, shardId, std::move (request), expectedStatus, std::move (traceId));
1876
1876
}
1877
1877
1878
+
1879
+
1880
+ TTestActorRuntimeBase::TEventObserverHolder ReplaceEvProposeTransactionWithEvWrite (TTestActorRuntime& runtime, TEvWriteRows& rows) {
1881
+ if (rows.empty ())
1882
+ return {};
1883
+
1884
+ return runtime.AddObserver ([&rows](TAutoPtr<IEventHandle>& event) {
1885
+ if (event->GetTypeRewrite () != TEvDataShard::EvProposeTransaction)
1886
+ return ;
1887
+
1888
+ const auto & record = event->Get <TEvDataShard::TEvProposeTransaction>()->Record ;
1889
+
1890
+ if (record.GetTxKind () != NKikimrTxDataShard::TX_KIND_DATA)
1891
+ return ;
1892
+
1893
+ // Parse original TEvProposeTransaction
1894
+ const TString& txBody = record.GetTxBody ();
1895
+ NKikimrTxDataShard::TDataTransaction tx;
1896
+ Y_VERIFY (tx.ParseFromArray (txBody.data (), txBody.size ()));
1897
+
1898
+ // Construct new EvWrite
1899
+ TVector<TCell> cells;
1900
+ ui64 tableId = 0 ;
1901
+ ui16 colCount = 0 ;
1902
+ for (const auto & task : tx.GetKqpTransaction ().GetTasks ()) {
1903
+ NKikimrTxDataShard::TKqpTransaction::TDataTaskMeta meta;
1904
+ Y_VERIFY (task.GetMeta ().UnpackTo (&meta));
1905
+ if (!meta.HasWrites ())
1906
+ continue ;
1907
+
1908
+ const auto & tableMeta = meta.GetTable ();
1909
+ Y_VERIFY_S (tableId == 0 || tableId == tableMeta.GetTableId ().GetTableId (), " Only writes to one table is supported now" );
1910
+ tableId = tableMeta.GetTableId ().GetTableId ();
1911
+ const auto & writes = meta.GetWrites ();
1912
+ Y_VERIFY_S (colCount == 0 || colCount == writes.GetColumns ().size (), " Only equal column count is supported now." );
1913
+ colCount = writes.GetColumns ().size ();
1914
+
1915
+ const auto & row = rows.ProcessNextRow ();
1916
+ Y_VERIFY (row.Cells .size () == colCount);
1917
+ std::copy (row.Cells .begin (), row.Cells .end (), std::back_inserter (cells));
1918
+ }
1919
+
1920
+ if (cells.empty ()) {
1921
+ Cerr << " TEvProposeTransaction TX_KIND_DATA has no writes.\n " ;
1922
+ return ;
1923
+ }
1924
+
1925
+ Cerr << " TEvProposeTransaction TX_KIND_DATA event is observed and will be replaced with EvWrite: " << record.ShortDebugString () << Endl;
1926
+
1927
+ TSerializedCellMatrix matrix (cells, cells.size () / colCount, colCount);
1928
+ TString blobData = matrix.ReleaseBuffer ();
1929
+
1930
+ UNIT_ASSERT (blobData.size () < 8_MB);
1931
+
1932
+ ui64 txId = record.GetTxId ();
1933
+ auto txMode = NKikimr::NDataShard::EvWrite::Convertor::GetTxMode (record.GetFlags ());
1934
+ std::vector<ui32> columnIds (colCount);
1935
+ std::iota (columnIds.begin (), columnIds.end (), 1 );
1936
+
1937
+ auto evWrite = std::make_unique<NKikimr::NEvents::TDataEvents::TEvWrite>(txId, txMode);
1938
+ ui64 payloadIndex = NKikimr::NEvWrite::TPayloadHelper<NKikimr::NEvents::TDataEvents::TEvWrite>(*evWrite).AddDataToPayload (std::move (blobData));
1939
+ evWrite->AddOperation (NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPSERT, tableId, 1 , columnIds, payloadIndex, NKikimrDataEvents::FORMAT_CELLVEC);
1940
+
1941
+ // Replace event
1942
+ auto handle = new IEventHandle (event->Recipient , event->Sender , evWrite.release (), 0 , event->Cookie );
1943
+ handle->Rewrite (handle->GetTypeRewrite (), event->GetRecipientRewrite ());
1944
+ event.Reset (handle);
1945
+ });
1946
+ }
1947
+
1948
+ TTestActorRuntimeBase::TEventObserverHolder ReplaceEvProposeTransactionResultWithEvWrite (TTestActorRuntime& runtime, TEvWriteRows& rows) {
1949
+ if (rows.empty ())
1950
+ return {};
1951
+
1952
+ return runtime.AddObserver ([&rows](TAutoPtr<IEventHandle>& event) {
1953
+ if (event->GetTypeRewrite () != NEvents::TDataEvents::EvWriteResult)
1954
+ return ;
1955
+
1956
+ rows.CompleteNextRow ();
1957
+
1958
+ const auto & record = event->Get <NEvents::TDataEvents::TEvWriteResult>()->Record ;
1959
+ Cerr << " EvWriteResult event is observed and will be replaced with EvProposeTransactionResult: " << record.ShortDebugString () << Endl;
1960
+
1961
+ // Construct new EvProposeTransactionResult
1962
+ ui64 txId = record.GetTxId ();
1963
+ ui64 origin = record.GetOrigin ();
1964
+ auto status = NKikimr::NDataShard::EvWrite::Convertor::GetStatus (record.GetStatus ());
1965
+
1966
+ auto evResult = std::make_unique<TEvDataShard::TEvProposeTransactionResult>(NKikimrTxDataShard::TX_KIND_DATA, origin, txId, status);
1967
+
1968
+ // Replace event
1969
+ auto handle = new IEventHandle (event->Recipient , event->Sender , evResult.release (), 0 , event->Cookie );
1970
+ handle->Rewrite (handle->GetTypeRewrite (), event->GetRecipientRewrite ());
1971
+ event.Reset (handle);
1972
+ });
1973
+ }
1974
+
1878
1975
void UploadRows (TTestActorRuntime& runtime, const TString& tablePath, const TVector<std::pair<TString, Ydb::Type_PrimitiveTypeId>>& types, const TVector<TCell>& keys, const TVector<TCell>& values)
1879
1976
{
1880
1977
auto txTypes = std::make_shared<NTxProxy::TUploadTypes>();
@@ -1903,9 +2000,10 @@ void WaitTabletBecomesOffline(TServer::TPtr server, ui64 tabletId)
1903
2000
struct IsShardStateChange
1904
2001
{
1905
2002
IsShardStateChange (ui64 tabletId)
1906
- : TabletId(tabletId)
1907
- {
1908
- }
2003
+ :
2004
+ TabletId (tabletId)
2005
+ {
2006
+ }
1909
2007
1910
2008
bool operator ()(IEventHandle& ev)
1911
2009
{
@@ -1959,7 +2057,8 @@ namespace {
1959
2057
, Snapshot(snapshot)
1960
2058
, Ordered(ordered)
1961
2059
, State(pause ? EState::PauseWait : EState::Normal)
1962
- { }
2060
+ {
2061
+ }
1963
2062
1964
2063
void Bootstrap (const TActorContext& ctx) {
1965
2064
auto request = MakeHolder<TEvTxUserProxy::TEvProposeTransaction>();
0 commit comments