17
17
#include < ydb/library/yql/utils/log/log.h>
18
18
#include < ydb/library/yql/utils/yql_panic.h>
19
19
20
- #include < ydb/public/sdk/cpp/client/ydb_persqueue_core/persqueue .h>
20
+ #include < ydb/public/sdk/cpp/client/ydb_topic/topic .h>
21
21
#include < ydb/public/sdk/cpp/client/ydb_types/credentials/credentials.h>
22
22
23
23
#include < ydb/library/actors/core/actor.h>
24
24
#include < ydb/library/actors/core/event_local.h>
25
25
#include < ydb/library/actors/core/events.h>
26
26
#include < ydb/library/actors/core/hfunc.h>
27
27
#include < ydb/library/actors/core/log.h>
28
+ #include < ydb/library/actors/log_backend/actor_log_backend.h>
28
29
#include < library/cpp/lwtrace/mon/mon_lwtrace.h>
29
30
30
31
#include < util/generic/algorithm.h>
@@ -131,8 +132,8 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
131
132
IngressStats.Level = statsLevel;
132
133
}
133
134
134
- NYdb::NPersQueue::TPersQueueClientSettings GetPersQueueClientSettings () const {
135
- NYdb::NPersQueue::TPersQueueClientSettings opts;
135
+ NYdb::NTopic::TTopicClientSettings GetTopicClientSettings () const {
136
+ NYdb::NTopic::TTopicClientSettings opts;
136
137
opts.Database (SourceParams.GetDatabase ())
137
138
.DiscoveryEndpoint (SourceParams.GetEndpoint ())
138
139
.SslCredentials (NYdb::TSslCredentials (SourceParams.GetUseSsl ()))
@@ -173,7 +174,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
173
174
data->SetBlob (stateBlob);
174
175
175
176
DeferredCommits.emplace (checkpoint.GetId (), std::make_pair (std::move (CurrentDeferredCommit), CurrentDeferredCommitOffset));
176
- CurrentDeferredCommit = NYdb::NPersQueue ::TDeferredCommit ();
177
+ CurrentDeferredCommit = NYdb::NTopic ::TDeferredCommit ();
177
178
CurrentDeferredCommitOffset.Clear ();
178
179
}
179
180
@@ -238,16 +239,16 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
238
239
return IngressStats;
239
240
}
240
241
241
- NYdb::NPersQueue::TPersQueueClient& GetPersQueueClient () {
242
- if (!PersQueueClient ) {
243
- PersQueueClient = std::make_unique<NYdb::NPersQueue::TPersQueueClient >(Driver, GetPersQueueClientSettings ());
242
+ NYdb::NTopic::TTopicClient& GetTopicClient () {
243
+ if (!TopicClient ) {
244
+ TopicClient = std::make_unique<NYdb::NTopic::TTopicClient >(Driver, GetTopicClientSettings ());
244
245
}
245
- return *PersQueueClient ;
246
+ return *TopicClient ;
246
247
}
247
248
248
- NYdb::NPersQueue ::IReadSession& GetReadSession () {
249
+ NYdb::NTopic ::IReadSession& GetReadSession () {
249
250
if (!ReadSession) {
250
- ReadSession = GetPersQueueClient ().CreateReadSession (GetReadSessionSettings ());
251
+ ReadSession = GetTopicClient ().CreateReadSession (GetReadSessionSettings ());
251
252
}
252
253
return *ReadSession;
253
254
}
@@ -272,7 +273,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
272
273
ReadSession->Close (TDuration::Zero ());
273
274
ReadSession.reset ();
274
275
}
275
- PersQueueClient .reset ();
276
+ TopicClient .reset ();
276
277
TActor<TDqPqReadActor>::PassAway ();
277
278
}
278
279
@@ -312,13 +313,13 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
312
313
313
314
ui32 batchItemsEstimatedCount = 0 ;
314
315
for (auto & event : events) {
315
- if (const auto * val = std::get_if<NYdb::NPersQueue ::TReadSessionEvent::TDataReceivedEvent>(&event)) {
316
+ if (const auto * val = std::get_if<NYdb::NTopic ::TReadSessionEvent::TDataReceivedEvent>(&event)) {
316
317
batchItemsEstimatedCount += val->GetMessages ().size ();
317
318
}
318
319
}
319
320
320
321
for (auto & event : events) {
321
- std::visit (TPQEventProcessor {*this , batchItemsEstimatedCount, LogPrefix}, event);
322
+ std::visit (TTopicEventProcessor {*this , batchItemsEstimatedCount, LogPrefix}, event);
322
323
}
323
324
}
324
325
@@ -374,26 +375,30 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
374
375
TInstant::Now ());
375
376
}
376
377
377
- NYdb::NPersQueue ::TReadSessionSettings GetReadSessionSettings () const {
378
- NYdb::NPersQueue ::TTopicReadSettings topicReadSettings;
378
+ NYdb::NTopic ::TReadSessionSettings GetReadSessionSettings () const {
379
+ NYdb::NTopic ::TTopicReadSettings topicReadSettings;
379
380
topicReadSettings.Path (SourceParams.GetTopicPath ());
380
381
auto partitionsToRead = GetPartitionsToRead ();
381
382
SRC_LOG_D (" PartitionsToRead: " << JoinSeq (" , " , partitionsToRead));
382
383
for (const auto partitionId : partitionsToRead) {
383
- topicReadSettings.AppendPartitionGroupIds (partitionId);
384
+ topicReadSettings.AppendPartitionIds (partitionId);
384
385
}
385
386
386
- return NYdb::NPersQueue::TReadSessionSettings ()
387
- .DisableClusterDiscovery (SourceParams.GetClusterType () == NPq::NProto::DataStreams)
387
+ Y_UNUSED (RangesMode);
388
+ TLog log (MakeHolder<TActorLogBackend>(NActors::TActivationContext::ActorSystem (), NKikimrServices::KQP_COMPUTE));
389
+ return NYdb::NTopic::TReadSessionSettings ()
390
+ // .DisableClusterDiscovery(SourceParams.GetClusterType() == NPq::NProto::DataStreams)
388
391
.AppendTopics (topicReadSettings)
389
392
.ConsumerName (SourceParams.GetConsumerName ())
390
393
.MaxMemoryUsageBytes (BufferSize)
391
- .StartingMessageTimestamp (StartingMessageTimestamp)
392
- .RangesMode (RangesMode);
394
+ .ReadFromTimestamp (StartingMessageTimestamp)
395
+ .Log (log)
396
+ ;
397
+ // .RangesMode(RangesMode);
393
398
}
394
399
395
- static TPartitionKey MakePartitionKey (const NYdb::NPersQueue::TPartitionStream ::TPtr& partitionStreamPtr ) {
396
- return std::make_pair (partitionStreamPtr-> GetCluster (), partitionStreamPtr ->GetPartitionId ());
400
+ static TPartitionKey MakePartitionKey (const NYdb::NTopic::TPartitionSession ::TPtr& partitionSession ) {
401
+ return std::make_pair (partitionSession-> GetTopicPath (), partitionSession ->GetPartitionId ());
397
402
}
398
403
399
404
void SubscribeOnNextEvent () {
@@ -408,15 +413,15 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
408
413
409
414
struct TReadyBatch {
410
415
public:
411
- TReadyBatch (TMaybe<TInstant> watermark, ui32 dataCapacity) : Watermark(watermark){
416
+ TReadyBatch (TMaybe<TInstant> watermark, ui32 dataCapacity): Watermark(watermark){
412
417
Data.reserve (dataCapacity);
413
418
}
414
419
415
420
public:
416
421
TMaybe<TInstant> Watermark;
417
422
TUnboxedValueVector Data;
418
423
i64 UsedSpace = 0 ;
419
- THashMap<NYdb::NPersQueue::TPartitionStream ::TPtr, TList<std::pair<ui64, ui64>>> OffsetRanges; // [start, end)
424
+ THashMap<NYdb::NTopic::TPartitionSession ::TPtr, TList<std::pair<ui64, ui64>>> OffsetRanges; // [start, end)
420
425
};
421
426
422
427
bool MaybeReturnReadyBatch (NKikimr::NMiniKQL::TUnboxedValueBatch& buffer, TMaybe<TInstant>& watermark, i64 & usedSpace) {
@@ -431,17 +436,17 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
431
436
watermark = readyBatch.Watermark ;
432
437
usedSpace = readyBatch.UsedSpace ;
433
438
434
- for (const auto & [partitionStream , ranges] : readyBatch.OffsetRanges ) {
439
+ for (const auto & [PartitionSession , ranges] : readyBatch.OffsetRanges ) {
435
440
for (const auto & [start, end] : ranges) {
436
- CurrentDeferredCommit.Add (partitionStream , start, end);
441
+ CurrentDeferredCommit.Add (PartitionSession , start, end);
437
442
if (!CurrentDeferredCommitOffset) {
438
443
CurrentDeferredCommitOffset = std::make_pair (start, end);
439
444
} else {
440
445
CurrentDeferredCommitOffset->first = std::min (CurrentDeferredCommitOffset->first , start);
441
446
CurrentDeferredCommitOffset->second = std::max (CurrentDeferredCommitOffset->second , end);
442
447
}
443
448
}
444
- PartitionToOffset[MakePartitionKey (partitionStream )] = ranges.back ().second ;
449
+ PartitionToOffset[MakePartitionKey (PartitionSession )] = ranges.back ().second ;
445
450
}
446
451
447
452
ReadyBuffer.pop ();
@@ -470,9 +475,9 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
470
475
ReadyBuffer.back ().Watermark = watermark;
471
476
}
472
477
473
- struct TPQEventProcessor {
474
- void operator ()(NYdb::NPersQueue ::TReadSessionEvent::TDataReceivedEvent& event) {
475
- const auto partitionKey = MakePartitionKey (event.GetPartitionStream ());
478
+ struct TTopicEventProcessor {
479
+ void operator ()(NYdb::NTopic ::TReadSessionEvent::TDataReceivedEvent& event) {
480
+ const auto partitionKey = MakePartitionKey (event.GetPartitionSession ());
476
481
for (const auto & message : event.GetMessages ()) {
477
482
const TString& data = message.GetData ();
478
483
Self.IngressStats .Bytes += data.size ();
@@ -490,7 +495,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
490
495
curBatch.Data .emplace_back (std::move (item));
491
496
curBatch.UsedSpace += size;
492
497
493
- auto & offsets = curBatch.OffsetRanges [message.GetPartitionStream ()];
498
+ auto & offsets = curBatch.OffsetRanges [message.GetPartitionSession ()];
494
499
if (!offsets.empty () && offsets.back ().second == message.GetOffset ()) {
495
500
offsets.back ().second = message.GetOffset () + 1 ;
496
501
} else {
@@ -499,29 +504,29 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
499
504
}
500
505
}
501
506
502
- void operator ()(NYdb::NPersQueue ::TSessionClosedEvent& ev) {
507
+ void operator ()(NYdb::NTopic ::TSessionClosedEvent& ev) {
503
508
ythrow yexception () << " Read session to topic \" " << Self.SourceParams .GetTopicPath ()
504
509
<< " \" was closed: " << ev.DebugString ();
505
510
}
506
511
507
- void operator ()(NYdb::NPersQueue ::TReadSessionEvent::TCommitAcknowledgementEvent &) { }
512
+ void operator ()(NYdb::NTopic ::TReadSessionEvent::TCommitOffsetAcknowledgementEvent &) { }
508
513
509
- void operator ()(NYdb::NPersQueue ::TReadSessionEvent::TCreatePartitionStreamEvent & event) {
514
+ void operator ()(NYdb::NTopic ::TReadSessionEvent::TStartPartitionSessionEvent & event) {
510
515
TMaybe<ui64> readOffset;
511
- const auto offsetIt = Self.PartitionToOffset .find (MakePartitionKey (event.GetPartitionStream ()));
516
+ const auto offsetIt = Self.PartitionToOffset .find (MakePartitionKey (event.GetPartitionSession ()));
512
517
if (offsetIt != Self.PartitionToOffset .end ()) {
513
518
readOffset = offsetIt->second ;
514
519
}
515
520
event.Confirm (readOffset);
516
521
}
517
522
518
- void operator ()(NYdb::NPersQueue ::TReadSessionEvent::TDestroyPartitionStreamEvent & event) {
523
+ void operator ()(NYdb::NTopic ::TReadSessionEvent::TStopPartitionSessionEvent & event) {
519
524
event.Confirm ();
520
525
}
521
526
522
- void operator ()(NYdb::NPersQueue ::TReadSessionEvent::TPartitionStreamStatusEvent &) { }
527
+ void operator ()(NYdb::NTopic ::TReadSessionEvent::TPartitionSessionStatusEvent &) { }
523
528
524
- void operator ()(NYdb::NPersQueue ::TReadSessionEvent::TPartitionStreamClosedEvent &) { }
529
+ void operator ()(NYdb::NTopic ::TReadSessionEvent::TPartitionSessionClosedEvent &) { }
525
530
526
531
TReadyBatch& GetActiveBatch (const TPartitionKey& partitionKey, TInstant time) {
527
532
if (Y_UNLIKELY (Self.ReadyBuffer .empty () || Self.ReadyBuffer .back ().Watermark .Defined ())) {
@@ -548,7 +553,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
548
553
return Self.ReadyBuffer .emplace (Nothing (), BatchCapacity); // And open new batch
549
554
}
550
555
551
- std::pair<NUdf::TUnboxedValuePod, i64 > CreateItem (const NYdb::NPersQueue ::TReadSessionEvent::TDataReceivedEvent::TMessage& message) {
556
+ std::pair<NUdf::TUnboxedValuePod, i64 > CreateItem (const NYdb::NTopic ::TReadSessionEvent::TDataReceivedEvent::TMessage& message) {
552
557
const TString& data = message.GetData ();
553
558
554
559
i64 usedSpace = 0 ;
@@ -589,14 +594,14 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public IDqCompute
589
594
std::shared_ptr<NYdb::ICredentialsProviderFactory> CredentialsProviderFactory;
590
595
const NPq::NProto::TDqPqTopicSource SourceParams;
591
596
const NPq::NProto::TDqReadTaskParams ReadParams;
592
- std::unique_ptr<NYdb::NPersQueue::TPersQueueClient> PersQueueClient ;
593
- std::shared_ptr<NYdb::NPersQueue ::IReadSession> ReadSession;
597
+ std::unique_ptr<NYdb::NTopic::TTopicClient> TopicClient ;
598
+ std::shared_ptr<NYdb::NTopic ::IReadSession> ReadSession;
594
599
NThreading::TFuture<void > EventFuture;
595
600
THashMap<TPartitionKey, ui64> PartitionToOffset; // {cluster, partition} -> offset of next event.
596
601
TInstant StartingMessageTimestamp;
597
602
const NActors::TActorId ComputeActorId;
598
- std::queue<std::pair<ui64, std::pair<NYdb::NPersQueue ::TDeferredCommit, TDebugOffsets>>> DeferredCommits;
599
- NYdb::NPersQueue ::TDeferredCommit CurrentDeferredCommit;
603
+ std::queue<std::pair<ui64, std::pair<NYdb::NTopic ::TDeferredCommit, TDebugOffsets>>> DeferredCommits;
604
+ NYdb::NTopic ::TDeferredCommit CurrentDeferredCommit;
600
605
TDebugOffsets CurrentDeferredCommitOffset;
601
606
bool SubscribedOnEvent = false ;
602
607
std::vector<std::tuple<TString, TPqMetaExtractor::TPqMetaExtractorLambda>> MetadataFields;
0 commit comments