@@ -24,6 +24,7 @@ namespace {
2424
2525static constexpr TDuration SCHEME_CACHE_REQUEST_TIMEOUT = TDuration::Seconds(10 );
2626NActors::TActorId MainPipeCacheId = NKikimr::MakePipePerNodeCacheID(false );
27+ NActors::TActorId FollowersPipeCacheId = NKikimr::MakePipePerNodeCacheID(true );
2728
2829class TKqpStreamLookupActor : public NActors ::TActorBootstrapped<TKqpStreamLookupActor>, public NYql::NDq::IDqComputeActorAsyncInput {
2930public:
@@ -37,6 +38,8 @@ class TKqpStreamLookupActor : public NActors::TActorBootstrapped<TKqpStreamLooku
3738 , Alloc(args.Alloc)
3839 , Snapshot(settings.GetSnapshot().GetStep(), settings.GetSnapshot().GetTxId())
3940 , AllowInconsistentReads(settings.GetAllowInconsistentReads())
41+ , UseFollowers(settings.GetAllowUseFollowers())
42+ , PipeCacheId(UseFollowers ? FollowersPipeCacheId : MainPipeCacheId)
4043 , LockTxId(settings.HasLockTxId() ? settings.GetLockTxId() : TMaybe<ui64>())
4144 , NodeLockId(settings.HasLockNodeId() ? settings.GetLockNodeId() : TMaybe<ui32>())
4245 , LockMode(settings.HasLockMode() ? settings.GetLockMode() : TMaybe<NKikimrDataEvents::ELockMode>())
@@ -207,11 +210,11 @@ class TKqpStreamLookupActor : public NActors::TActorBootstrapped<TKqpStreamLooku
207210 Counters->SentIteratorCancels ->Inc ();
208211 auto cancel = MakeHolder<TEvDataShard::TEvReadCancel>();
209212 cancel->Record .SetReadId (id);
210- Send (MainPipeCacheId , new TEvPipeCache::TEvForward (cancel.Release (), state.ShardId , false ));
213+ Send (PipeCacheId , new TEvPipeCache::TEvForward (cancel.Release (), state.ShardId , false ));
211214 }
212215 }
213216
214- Send (MainPipeCacheId , new TEvPipeCache::TEvUnlink (0 ));
217+ Send (PipeCacheId , new TEvPipeCache::TEvUnlink (0 ));
215218 TActorBootstrapped<TKqpStreamLookupActor>::PassAway ();
216219
217220 LookupActorSpan.End ();
@@ -344,6 +347,14 @@ class TKqpStreamLookupActor : public NActors::TActorBootstrapped<TKqpStreamLooku
344347 Locks.push_back (lock);
345348 }
346349
350+ if (UseFollowers) {
351+ YQL_ENSURE (Locks.empty ());
352+ if (!record.GetFinished ()) {
353+ RuntimeError (" read from follower returned partial data." , NYql::NDqProto::StatusIds::INTERNAL_ERROR);
354+ return ;
355+ }
356+ }
357+
347358 if (!Snapshot.IsValid ()) {
348359 Snapshot = IKqpGateway::TKqpSnapshot (record.GetSnapshot ().GetStep (), record.GetSnapshot ().GetTxId ());
349360 }
@@ -429,7 +440,7 @@ class TKqpStreamLookupActor : public NActors::TActorBootstrapped<TKqpStreamLooku
429440 request->Record .SetMaxRows (defaultSettings.GetMaxRows ());
430441 request->Record .SetMaxBytes (defaultSettings.GetMaxBytes ());
431442
432- Send (MainPipeCacheId , new TEvPipeCache::TEvForward (request.Release (), read.ShardId , true ),
443+ Send (PipeCacheId , new TEvPipeCache::TEvForward (request.Release (), read.ShardId , true ),
433444 IEventHandle::FlagTrackDelivery);
434445
435446 CA_LOG_D (" TEvReadAck was sent to shard: " << read.ShardId );
@@ -562,7 +573,7 @@ class TKqpStreamLookupActor : public NActors::TActorBootstrapped<TKqpStreamLooku
562573 << " , lockTxId=" << record.GetLockTxId ()
563574 << " , lockNodeId=" << record.GetLockNodeId ());
564575
565- Send (MainPipeCacheId , new TEvPipeCache::TEvForward (request.Release (), shardId, true ),
576+ Send (PipeCacheId , new TEvPipeCache::TEvForward (request.Release (), shardId, true ),
566577 IEventHandle::FlagTrackDelivery, 0 , LookupActorSpan.GetTraceId ());
567578
568579 read.State = EReadState::Running;
@@ -699,6 +710,8 @@ class TKqpStreamLookupActor : public NActors::TActorBootstrapped<TKqpStreamLooku
699710 std::shared_ptr<NKikimr::NMiniKQL::TScopedAlloc> Alloc;
700711 IKqpGateway::TKqpSnapshot Snapshot;
701712 const bool AllowInconsistentReads;
713+ const bool UseFollowers;
714+ const TActorId PipeCacheId;
702715 const TMaybe<ui64> LockTxId;
703716 const TMaybe<ui32> NodeLockId;
704717 const TMaybe<NKikimrDataEvents::ELockMode> LockMode;
0 commit comments