Skip to content

Commit 7c1b95c

Browse files
authored
Use EvRead-based table reading in datashard_ut_write test (#7121)
1 parent 3c55951 commit 7c1b95c

File tree

4 files changed

+346
-138
lines changed

4 files changed

+346
-138
lines changed

ydb/core/tx/datashard/datashard_ut_read_iterator.cpp

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -280,42 +280,6 @@ void CheckContinuationToken(
280280
CheckRow(lastKey.GetCells(), goldRow, types);
281281
}
282282

283-
template <typename TKeyType>
284-
TVector<TCell> ToCells(const std::vector<TKeyType>& keys) {
285-
TVector<TCell> cells;
286-
for (auto& key: keys) {
287-
cells.emplace_back(TCell::Make(key));
288-
}
289-
return cells;
290-
}
291-
292-
void AddKeyQuery(
293-
TEvDataShard::TEvRead& request,
294-
const std::vector<ui32>& keys)
295-
{
296-
// convertion is ugly, but for tests is OK
297-
auto cells = ToCells(keys);
298-
request.Keys.emplace_back(cells);
299-
}
300-
301-
template <typename TCellType>
302-
void AddRangeQuery(
303-
TEvDataShard::TEvRead& request,
304-
std::vector<TCellType> from,
305-
bool fromInclusive,
306-
std::vector<TCellType> to,
307-
bool toInclusive)
308-
{
309-
auto fromCells = ToCells(from);
310-
auto toCells = ToCells(to);
311-
312-
// convertion is ugly, but for tests is OK
313-
auto fromBuf = TSerializedCellVec::Serialize(fromCells);
314-
auto toBuf = TSerializedCellVec::Serialize(toCells);
315-
316-
request.Ranges.emplace_back(fromBuf, toBuf, fromInclusive, toInclusive);
317-
}
318-
319283
struct TTableInfo {
320284
TString Name;
321285

@@ -502,20 +466,6 @@ struct TTestHelper {
502466
{
503467
const auto& table = Tables[tableName];
504468

505-
std::unique_ptr<TEvDataShard::TEvRead> request(new TEvDataShard::TEvRead());
506-
auto& record = request->Record;
507-
508-
record.SetReadId(readId);
509-
record.MutableTableId()->SetOwnerId(table.TableId.PathId.OwnerId);
510-
record.MutableTableId()->SetTableId(table.UserTable.GetPathId());
511-
512-
const auto& description = table.UserTable.GetDescription();
513-
for (const auto& column: description.GetColumns()) {
514-
record.AddColumns(column.GetId());
515-
}
516-
517-
record.MutableTableId()->SetSchemaVersion(description.GetTableSchemaVersion());
518-
519469
TRowVersion readVersion;
520470
if (!snapshot) {
521471
readVersion = CreateVolatileSnapshot(
@@ -526,12 +476,13 @@ struct TTestHelper {
526476
readVersion = snapshot;
527477
}
528478

529-
record.MutableSnapshot()->SetStep(readVersion.Step);
530-
record.MutableSnapshot()->SetTxId(readVersion.TxId);
531-
532-
record.SetResultFormat(format);
533-
534-
return request;
479+
return ::NKikimr::GetBaseReadRequest(
480+
table.TableId,
481+
table.UserTable.GetDescription(),
482+
readId,
483+
format,
484+
readVersion
485+
);
535486
}
536487

537488
std::unique_ptr<TEvDataShard::TEvRead> GetUserTablesRequest(
@@ -558,14 +509,7 @@ struct TTestHelper {
558509
}
559510

560511
std::unique_ptr<TEvDataShard::TEvReadResult> WaitReadResult(TDuration timeout = TDuration::Max()) {
561-
auto &runtime = *Server->GetRuntime();
562-
TAutoPtr<IEventHandle> handle;
563-
runtime.GrabEdgeEventRethrow<TEvDataShard::TEvReadResult>(handle, timeout);
564-
if (!handle) {
565-
return nullptr;
566-
}
567-
std::unique_ptr<TEvDataShard::TEvReadResult> event(handle->Release<TEvDataShard::TEvReadResult>().Release());
568-
return event;
512+
return ::NKikimr::WaitReadResult(Server, timeout);
569513
}
570514

571515
void SendReadAsync(
@@ -579,14 +523,15 @@ struct TTestHelper {
579523
}
580524

581525
const auto& table = Tables[tableName];
582-
auto &runtime = *Server->GetRuntime();
583-
runtime.SendToPipe(
526+
::NKikimr::SendReadAsync(
527+
Server,
584528
table.TabletId,
585-
sender,
586529
request,
530+
sender,
587531
node,
588532
GetTestPipeConfig(),
589-
table.ClientId);
533+
table.ClientId
534+
);
590535
}
591536

592537
std::unique_ptr<TEvDataShard::TEvReadResult> SendRead(
@@ -596,9 +541,21 @@ struct TTestHelper {
596541
TActorId sender = {},
597542
TDuration timeout = TDuration::Max())
598543
{
599-
SendReadAsync(tableName, request, node, sender);
544+
if (!sender) {
545+
sender = Sender;
546+
}
600547

601-
return WaitReadResult(timeout);
548+
const auto& table = Tables[tableName];
549+
return ::NKikimr::SendRead(
550+
Server,
551+
table.TabletId,
552+
request,
553+
sender,
554+
node,
555+
GetTestPipeConfig(),
556+
table.ClientId,
557+
timeout
558+
);
602559
}
603560

604561
void SendReadAck(

0 commit comments

Comments
 (0)