1515
1616#include < util/string/join.h>
1717
18+ #define PQ_ENSURE (condition ) AFL_ENSURE(condition)(" tablet_id" , TabletId)(" partition_id" , Partition)
19+
1820using namespace NPersQueue ;
1921
2022namespace NKikimr {
@@ -27,6 +29,7 @@ constexpr NKikimrServices::TActivity::EType TMirrorer::ActorActivityType() {
2729}
2830
2931TMirrorer::TMirrorer (
32+ ui64 tabletId,
3033 TActorId tabletActor,
3134 TActorId partitionActor,
3235 const NPersQueue::TTopicConverterPtr& topicConverter,
@@ -36,7 +39,8 @@ TMirrorer::TMirrorer(
3639 const NKikimrPQ::TMirrorPartitionConfig& config,
3740 const TTabletCountersBase& counters
3841)
39- : TabletActor(tabletActor)
42+ : TabletId(tabletId)
43+ , TabletActor(tabletActor)
4044 , PartitionActor(partitionActor)
4145 , TopicConverter(topicConverter)
4246 , Partition(partition)
@@ -160,8 +164,8 @@ void TMirrorer::ProcessError(const TActorContext& ctx, const TString& msg, const
160164}
161165
162166void TMirrorer::AfterSuccesWrite (const TActorContext& ctx) {
163- Y_ABORT_UNLESS (WriteInFlight.empty ());
164- Y_ABORT_UNLESS (WriteRequestInFlight);
167+ PQ_ENSURE (WriteInFlight.empty ());
168+ PQ_ENSURE (WriteRequestInFlight);
165169 LOG_INFO_S (ctx, NKikimrServices::PQ_MIRRORER, MirrorerDescription ()
166170 << " written " << WriteRequestInFlight.value ().CmdWriteSize ()
167171 << " messages with first offset=" << WriteRequestInFlight.value ().GetCmdWriteOffset ()
@@ -203,7 +207,7 @@ void TMirrorer::ProcessWriteResponse(
203207 MirrorerTimeLags->IncFor (lag.MilliSeconds (), 1 );
204208 }
205209 ui64 offset = writtenMessageInfo.GetOffset ();
206- Y_ABORT_UNLESS ((ui64)result.GetOffset () == offset);
210+ PQ_ENSURE ((ui64)result.GetOffset () == offset);
207211 Y_VERIFY_S (EndOffset <= offset, MirrorerDescription ()
208212 << " end offset more the written " << EndOffset << " >" << offset);
209213 EndOffset = offset + 1 ;
@@ -417,7 +421,7 @@ void TMirrorer::HandleInitCredentials(TEvPQ::TEvInitCredentials::TPtr& /*ev*/, c
417421 CredentialsProvider = nullptr ;
418422
419423 auto factory = AppData (ctx)->PersQueueMirrorReaderFactory ;
420- Y_ABORT_UNLESS (factory);
424+ PQ_ENSURE (factory);
421425 auto future = factory->GetCredentialsProvider (Config.GetCredentials ());
422426 future.Subscribe (
423427 [
@@ -457,7 +461,7 @@ void TMirrorer::HandleCredentialsCreated(TEvPQ::TEvCredentialsCreated::TPtr& ev,
457461}
458462
459463void TMirrorer::RetryWrite (const TActorContext& ctx) {
460- Y_ABORT_UNLESS (WriteRequestInFlight);
464+ PQ_ENSURE (WriteRequestInFlight);
461465
462466 THolder<TEvPersQueue::TEvRequest> request = MakeHolder<TEvPersQueue::TEvRequest>();
463467 auto req = request->Record .MutablePartitionRequest ();
@@ -485,7 +489,7 @@ void TMirrorer::CreateConsumer(TEvPQ::TEvCreateConsumer::TPtr&, const TActorCont
485489 OffsetToRead = Queue.front ().GetOffset ();
486490 while (!Queue.empty ()) {
487491 ui64 dataSize = Queue.back ().GetData ().size ();
488- Y_ABORT_UNLESS (BytesInFlight >= dataSize);
492+ PQ_ENSURE (BytesInFlight >= dataSize);
489493 BytesInFlight -= dataSize;
490494 Queue.pop_back ();
491495 }
@@ -497,7 +501,7 @@ void TMirrorer::CreateConsumer(TEvPQ::TEvCreateConsumer::TPtr&, const TActorCont
497501 PartitionStream.Reset ();
498502
499503 auto factory = AppData (ctx)->PersQueueMirrorReaderFactory ;
500- Y_ABORT_UNLESS (factory);
504+ PQ_ENSURE (factory);
501505
502506 TLog log (MakeHolder<TDeferredActorLogBackend>(
503507 factory->GetSharedActorSystem (),
@@ -554,7 +558,7 @@ void TMirrorer::TryUpdateWriteTimetsamp(const TActorContext &ctx) {
554558void TMirrorer::AddMessagesToQueue (std::vector<TPersQueueReadEvent::TDataReceivedEvent::TCompressedMessage>&& messages) {
555559 for (auto & msg : messages) {
556560 ui64 offset = msg.GetOffset ();
557- Y_ABORT_UNLESS (OffsetToRead <= offset);
561+ PQ_ENSURE (OffsetToRead <= offset);
558562 ui64 messageSize = msg.GetData ().size ();
559563
560564 Counters.Cumulative ()[COUNTER_PQ_TABLET_NETWORK_BYTES_USAGE].Increment (messageSize);
@@ -730,15 +734,26 @@ void TMirrorer::DoProcessNextReaderEvent(const TActorContext& ctx, bool wakeup)
730734 ConsumerInitInterval = CONSUMER_INIT_INTERVAL_START;
731735}
732736
733- NActors::IActor* CreateMirrorer (const NActors::TActorId& tabletActor,
737+ bool TMirrorer::OnUnhandledException (const std::exception& exc) {
738+ LOG_CRIT_S (*TlsActivationContext, NKikimrServices::PQ_MIRRORER,
739+ MirrorerDescription () << " unhandled exception " << TypeName (exc) << " : " << exc.what () << Endl
740+ << TBackTrace::FromCurrentException ().PrintToString ());
741+
742+ Send (TabletActor, new TEvents::TEvPoison ());
743+ PassAway ();
744+ return true ;
745+ }
746+
747+ NActors::IActor* CreateMirrorer (const ui64 tabletId,
748+ const NActors::TActorId& tabletActor,
734749 const NActors::TActorId& partitionActor,
735750 const NPersQueue::TTopicConverterPtr& topicConverter,
736751 const ui32 partition,
737752 const bool localDC,
738753 const ui64 endOffset,
739754 const NKikimrPQ::TMirrorPartitionConfig& config,
740755 const TTabletCountersBase& counters) {
741- return new TMirrorer (tabletActor, partitionActor, topicConverter, partition, localDC, endOffset, config, counters);
756+ return new TMirrorer (tabletId, tabletActor, partitionActor, topicConverter, partition, localDC, endOffset, config, counters);
742757}
743758
744759}// NPQ
0 commit comments