@@ -74,6 +74,7 @@ struct TEvPrivate {
7474 EvBegin = EventSpaceBegin (NActors::TEvents::ES_PRIVATE),
7575
7676 EvSourceDataReady = EvBegin,
77+ EvReconnectSession,
7778
7879 EvEnd
7980 };
@@ -83,6 +84,7 @@ struct TEvPrivate {
8384 // Events
8485
8586 struct TEvSourceDataReady : public TEventLocal <TEvSourceDataReady, EvSourceDataReady> {};
87+ struct TEvReconnectSession : public TEventLocal <TEvReconnectSession, EvReconnectSession> {};
8688};
8789
8890} // namespace
@@ -98,6 +100,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
98100 InFlyAsyncInputData = task->GetCounter (" InFlyAsyncInputData" );
99101 InFlySubscribe = task->GetCounter (" InFlySubscribe" );
100102 AsyncInputDataRate = task->GetCounter (" AsyncInputDataRate" , true );
103+ ReconnectRate = task->GetCounter (" ReconnectRate" , true );
101104 }
102105
103106 ~TMetrics () {
@@ -110,6 +113,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
110113 ::NMonitoring::TDynamicCounters::TCounterPtr InFlyAsyncInputData;
111114 ::NMonitoring::TDynamicCounters::TCounterPtr InFlySubscribe;
112115 ::NMonitoring::TDynamicCounters::TCounterPtr AsyncInputDataRate;
116+ ::NMonitoring::TDynamicCounters::TCounterPtr ReconnectRate;
113117 };
114118
115119public:
@@ -139,6 +143,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
139143 , CredentialsProviderFactory(std::move(credentialsProviderFactory))
140144 , PqGateway(pqGateway)
141145 {
146+ Y_UNUSED (TDuration::TryParse (SourceParams.GetReconnectPeriod (), ReconnectPeriod));
142147 MetadataFields.reserve (SourceParams.MetadataFieldsSize ());
143148 TPqMetaExtractor fieldsExtractor;
144149 for (const auto & fieldName : SourceParams.GetMetadataFields ()) {
@@ -209,6 +214,7 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
209214private:
210215 STRICT_STFUNC (StateFunc,
211216 hFunc (TEvPrivate::TEvSourceDataReady, Handle);
217+ hFunc (TEvPrivate::TEvReconnectSession, Handle);
212218 )
213219
214220 void Handle (TEvPrivate::TEvSourceDataReady::TPtr& ev) {
@@ -222,6 +228,18 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
222228 Send (ComputeActorId, new TEvNewAsyncInputDataArrived (InputIndex));
223229 }
224230
231+ void Handle (TEvPrivate::TEvReconnectSession::TPtr&) {
232+ SRC_LOG_D (" SessionId: " << GetSessionId () << " , Reconnect epoch: " << Metrics.ReconnectRate ->Val ());
233+ Metrics.ReconnectRate ->Inc ();
234+ if (ReadSession) {
235+ ReadSession->Close (TDuration::Zero ());
236+ ReadSession.reset ();
237+ ReadyBuffer = std::queue<TReadyBatch>{}; // clear read buffer
238+ }
239+
240+ Schedule (ReconnectPeriod, new TEvPrivate::TEvReconnectSession ());
241+ }
242+
225243 // IActor & IDqComputeActorAsyncInput
226244 void PassAway () override { // Is called from Compute Actor
227245 std::queue<TReadyBatch> empty;
@@ -259,6 +277,12 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
259277 const auto now = TInstant::Now ();
260278 MaybeScheduleNextIdleCheck (now);
261279
280+ if (!InflightReconnect && ReconnectPeriod != TDuration::Zero ()) {
281+ Metrics.ReconnectRate ->Inc ();
282+ Schedule (ReconnectPeriod, new TEvPrivate::TEvSourceDataReady ());
283+ InflightReconnect = true ;
284+ }
285+
262286 i64 usedSpace = 0 ;
263287 if (MaybeReturnReadyBatch (buffer, watermark, usedSpace)) {
264288 return usedSpace;
@@ -565,6 +589,8 @@ class TDqPqReadActor : public NActors::TActor<TDqPqReadActor>, public NYql::NDq:
565589 };
566590
567591private:
592+ bool InflightReconnect = false ;
593+ TDuration ReconnectPeriod;
568594 TMetrics Metrics;
569595 const i64 BufferSize;
570596 const THolderFactory& HolderFactory;
0 commit comments