@@ -30,6 +30,7 @@ TInitializer::TInitializer(TPartition* partition)
3030 Steps.push_back (MakeHolder<TInitInfoRangeStep>(this ));
3131 Steps.push_back (MakeHolder<TInitDataRangeStep>(this ));
3232 Steps.push_back (MakeHolder<TInitDataStep>(this ));
33+ Steps.push_back (MakeHolder<TInitEndWriteTimestampStep>(this ));
3334
3435 CurrentStep = Steps.begin ();
3536}
@@ -316,6 +317,8 @@ void TInitMetaStep::LoadMeta(const NKikimrClient::TResponse& kvResponse, const T
316317 }
317318 */
318319 Partition ()->SubDomainOutOfSpace = meta.GetSubDomainOutOfSpace ();
320+ Partition ()->EndWriteTimestamp = TInstant::MilliSeconds (meta.GetEndWriteTimestamp ());
321+ Partition ()->PendingWriteTimestamp = Partition ()->EndWriteTimestamp ;
319322 if (Partition ()->IsSupportive ()) {
320323 const auto & counterData = meta.GetCounterData ();
321324 Partition ()->BytesWrittenGrpc .SetSavedValue (counterData.GetBytesWrittenGrpc ());
@@ -495,7 +498,7 @@ void TInitDataRangeStep::FillBlobsMetaData(const NKikimrClient::TKeyValueRespons
495498 if (k.GetPartNo () > 0 ) ++startOffset;
496499 head.PartNo = 0 ;
497500 } else {
498- Y_ABORT_UNLESS (endOffset <= k.GetOffset (), " %s " , pair.GetKey ().c_str ());
501+ Y_ABORT_UNLESS (endOffset <= k.GetOffset (), " %d <= %d %s " , endOffset, k. GetOffset () , pair.GetKey ().c_str ());
499502 if (endOffset < k.GetOffset ()) {
500503 gapOffsets.push_back (std::make_pair (endOffset, k.GetOffset ()));
501504 gapSize += k.GetOffset () - endOffset;
@@ -619,7 +622,7 @@ void TInitDataStep::Handle(TEvKeyValue::TEvResponse::TPtr &ev, const TActorConte
619622
620623 Y_ABORT_UNLESS (offset + 1 >= Partition ()->StartOffset );
621624 Y_ABORT_UNLESS (offset < Partition ()->EndOffset );
622- Y_ABORT_UNLESS (size == read.GetValue ().size ());
625+ Y_ABORT_UNLESS (size == read.GetValue ().size (), " size=%d == read.GetValue().size() = %d " , size, read. GetValue (). size () );
623626
624627 for (TBlobIterator it (key, read.GetValue ()); it.IsValid (); it.Next ()) {
625628 head.AddBatch (it.GetBatch ());
@@ -653,6 +656,117 @@ void TInitDataStep::Handle(TEvKeyValue::TEvResponse::TPtr &ev, const TActorConte
653656}
654657
655658
659+ //
660+ // TInitEndWriteTimestampStep
661+ //
662+
663+ TInitEndWriteTimestampStep::TInitEndWriteTimestampStep (TInitializer* initializer)
664+ : TBaseKVStep(initializer, " TInitEndWriteTimestampStep" , true ) {
665+ }
666+
667+ void TInitEndWriteTimestampStep::Execute (const TActorContext &ctx) {
668+ if (Partition ()->EndWriteTimestamp != TInstant::Zero () || (Partition ()->Head .GetBatches ().empty () && Partition ()->DataKeysBody .empty ())) {
669+ PQ_LOG_D (" Initializing EndWriteTimestamp of the topic '" << Partition ()->TopicName ()
670+ << " ' partition " << Partition ()->Partition
671+ << " skiped because already initialized." );
672+ return Done (ctx);
673+ }
674+
675+ PQ_LOG_D (" Initializing EndWriteTimestamp of the topic '" << Partition ()->TopicName ()
676+ << " ' partition " << Partition ()->Partition
677+ << " ." );
678+
679+ auto & head = Partition ()->Head ;
680+ if (!head.GetBatches ().empty ()) {
681+ auto & batch = head.GetLastBatch ();
682+ Y_VERIFY (batch.Packed );
683+
684+ TVector<TClientBlob> result;
685+ batch.UnpackTo (&result);
686+ Y_VERIFY (!result.empty ());
687+
688+ Partition ()->EndWriteTimestamp = result.back ().WriteTimestamp ;
689+ Partition ()->PendingWriteTimestamp = Partition ()->EndWriteTimestamp ;
690+
691+ PQ_LOG_I (" Initializing EndWriteTimestamp of the topic '" << Partition ()->TopicName ()
692+ << " ' partition " << Partition ()->Partition
693+ << " from head completed. Value " << Partition ()->EndWriteTimestamp );
694+
695+ return Done (ctx);
696+ }
697+
698+ if (Partition ()->DataKeysBody .empty ()) {
699+ PQ_LOG_I (" Initializing EndWriteTimestamp of the topic '" << Partition ()->TopicName ()
700+ << " ' partition " << Partition ()->Partition
701+ << " skiped because DataKeys is empty." );
702+
703+ return Done (ctx);
704+ }
705+
706+ auto & p = Partition ()->DataKeysBody .back ();
707+
708+ THolder<TEvKeyValue::TEvRequest> request (new TEvKeyValue::TEvRequest);
709+ auto read = request->Record .AddCmdRead ();
710+ read->SetKey ({p.Key .Data (), p.Key .Size ()});
711+
712+ ctx.Send (Partition ()->Tablet , request.Release ());
713+ }
714+
715+ void TInitEndWriteTimestampStep::Handle (TEvKeyValue::TEvResponse::TPtr &ev, const TActorContext &ctx) {
716+ if (!ValidateResponse (*this , ev, ctx)) {
717+ PoisonPill (ctx);
718+ return ;
719+ }
720+
721+ auto & response = ev->Get ()->Record ;
722+ Y_ABORT_UNLESS (1 == response.ReadResultSize ());
723+
724+ auto & read = response.GetReadResult (0 );
725+ Y_ABORT_UNLESS (read.HasStatus ());
726+ switch (read.GetStatus ()) {
727+ case NKikimrProto::OK: {
728+ auto & key = Partition ()->DataKeysBody .back ().Key ;
729+
730+ for (TBlobIterator it (key, read.GetValue ()); it.IsValid (); it.Next ()) {
731+ auto b = it.GetBatch ();
732+ b.Unpack ();
733+ if (!b.Empty ()) {
734+ Partition ()->EndWriteTimestamp = b.GetEndWriteTimestamp ();
735+ }
736+ }
737+
738+ PQ_LOG_I (" Initializing EndWriteTimestamp of the topic '" << Partition ()->TopicName ()
739+ << " ' partition " << Partition ()->Partition
740+ << " from last blob completed. Value " << Partition ()->EndWriteTimestamp );
741+
742+ Partition ()->PendingWriteTimestamp = Partition ()->EndWriteTimestamp ;
743+
744+ break ;
745+ }
746+ case NKikimrProto::OVERRUN:
747+ Y_ABORT (" implement overrun in readresult!!" );
748+ return ;
749+ case NKikimrProto::NODATA:
750+ Y_ABORT (" NODATA can't be here" );
751+ return ;
752+ case NKikimrProto::ERROR:
753+ PQ_LOG_ERROR (" tablet " << Partition ()->TabletID << " HandleOnInit topic '" << TopicName ()
754+ << " ' partition " << PartitionId ()
755+ << " status NKikimrProto::ERROR result message: \" " << read.GetMessage ()
756+ << " \" errorReason: \" " << response.GetErrorReason () << " \" "
757+ );
758+ PoisonPill (ctx);
759+ return ;
760+ default :
761+ Cerr << " ERROR " << read.GetStatus () << " message: \" " << read.GetMessage () << " \"\n " ;
762+ Y_ABORT (" bad status" );
763+
764+ };
765+
766+ Done (ctx);
767+ }
768+
769+
656770//
657771// TPartition
658772//
0 commit comments