@@ -470,7 +470,7 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
470
470
return ;
471
471
}
472
472
473
- const bool checkQuota = Opts.CheckRequestUnits () && IsQuotaRequired ();
473
+ const bool needToRequestQuota = Opts.CheckRequestUnits () && IsQuotaRequired ();
474
474
475
475
size_t processed = 0 ;
476
476
PendingQuotaAmount = 0 ;
@@ -490,23 +490,23 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
490
490
cmd.SetSize (it->second .ByteSize ());
491
491
cmd.SetLastRequest (false );
492
492
493
- if (checkQuota ) {
493
+ if (needToRequestQuota ) {
494
494
++processed;
495
495
PendingQuotaAmount += CalcRuConsumption (it->second .ByteSize ());
496
496
PendingQuota.emplace_back (it->first );
497
497
}
498
498
499
499
NTabletPipe::SendData (SelfId (), PipeClient, ev.Release ());
500
500
501
- PendingReserve.emplace (it->first , RequestHolder{ std::move (it->second ), checkQuota });
501
+ PendingReserve.emplace (it->first , RequestHolder{ std::move (it->second ), needToRequestQuota });
502
502
Pending.erase (it);
503
503
504
- if (checkQuota && processed == MAX_QUOTA_INFLIGHT) {
504
+ if (needToRequestQuota && processed == MAX_QUOTA_INFLIGHT) {
505
505
break ;
506
506
}
507
507
}
508
508
509
- if (checkQuota ) {
509
+ if (needToRequestQuota ) {
510
510
RequestDataQuota (PendingQuotaAmount, ctx);
511
511
}
512
512
}
@@ -527,18 +527,18 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
527
527
528
528
ReceivedReserve.emplace (it->first , std::move (it->second ));
529
529
530
- ProcessQuota ();
530
+ ProcessQuotaAndWrite ();
531
531
}
532
532
533
- void ProcessQuota () {
533
+ void ProcessQuotaAndWrite () {
534
534
auto rit = ReceivedReserve.begin ();
535
535
auto qit = ReceivedQuota.begin ();
536
536
537
537
while (rit != ReceivedReserve.end () && qit != ReceivedQuota.end ()) {
538
538
auto & request = rit->second ;
539
539
const auto cookie = rit->first ;
540
- TRACE (" processing quota for request cookie=" << cookie << " , QuotaChecked =" << request.QuotaChecked << " , QuotaAccepted=" << request.QuotaAccepted );
541
- if (!request.QuotaChecked || request.QuotaAccepted ) {
540
+ TRACE (" processing quota for request cookie=" << cookie << " , QuotaCheckEnabled =" << request.QuotaCheckEnabled << " , QuotaAccepted=" << request.QuotaAccepted );
541
+ if (!request.QuotaCheckEnabled || request.QuotaAccepted ) {
542
542
// A situation when a quota was not requested or was received while waiting for a reserve
543
543
Write (cookie, std::move (request.Request ));
544
544
ReceivedReserve.erase (rit++);
@@ -559,8 +559,8 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
559
559
while (rit != ReceivedReserve.end ()) {
560
560
auto & request = rit->second ;
561
561
const auto cookie = rit->first ;
562
- TRACE (" processing quota for request cookie=" << cookie << " , QuotaChecked =" << request.QuotaChecked << " , QuotaAccepted=" << request.QuotaAccepted );
563
- if (request.QuotaChecked && !request.QuotaAccepted ) {
562
+ TRACE (" processing quota for request cookie=" << cookie << " , QuotaCheckEnabled =" << request.QuotaCheckEnabled << " , QuotaAccepted=" << request.QuotaAccepted );
563
+ if (request.QuotaCheckEnabled && !request.QuotaAccepted ) {
564
564
break ;
565
565
}
566
566
@@ -587,27 +587,6 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
587
587
ReceivedQuota.clear ();
588
588
}
589
589
590
- void Write (ui64 cookie) {
591
- if (PendingReserve.empty ()) {
592
- ERROR (" The state of the PartitionWriter is invalid. PendingReserve is empty. Marker #02" );
593
- Disconnected (EErrorCode::InternalError);
594
- return ;
595
- }
596
- auto it = PendingReserve.begin ();
597
-
598
- auto cookieReserveValid = (it->first == cookie);
599
- auto cookieWriteValid = (PendingWrite.empty () || PendingWrite.back () < cookie);
600
- if (!(cookieReserveValid && cookieWriteValid)) {
601
- ERROR (" The cookie of Write is invalid. Cookie=" << cookie);
602
- Disconnected (EErrorCode::InternalError);
603
- return ;
604
- }
605
-
606
- Write (cookie, std::move (it->second .Request ));
607
-
608
- PendingReserve.erase (it);
609
- }
610
-
611
590
void Write (ui64 cookie, NKikimrClient::TPersQueueRequest&& req) {
612
591
auto ev = MakeHolder<TEvPersQueue::TEvRequest>();
613
592
ev->Record = std::move (req);
@@ -651,24 +630,26 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
651
630
return WriteResult (EErrorCode::InternalError, error, std::move (record));
652
631
}
653
632
654
- WriteAccepted (cookie);
655
-
656
- if (PendingReserve.empty ()) {
657
- ERROR (" The state of the PartitionWriter is invalid. PendingReserve is empty. Marker #03" );
633
+ auto cookieWriteValid = (PendingWrite.empty () || PendingWrite.back () < cookie);
634
+ if (!cookieWriteValid) {
635
+ ERROR (" The cookie of Write is invalid. Cookie=" << cookie);
658
636
Disconnected (EErrorCode::InternalError);
659
637
return ;
660
638
}
639
+
640
+ WriteAccepted (cookie);
661
641
auto it = PendingReserve.begin ();
662
642
auto & holder = it->second ;
663
643
664
- if ((holder.QuotaChecked && !holder.QuotaAccepted )|| !ReceivedReserve.empty ()) {
644
+ if ((holder.QuotaCheckEnabled && !holder.QuotaAccepted ) || !ReceivedReserve.empty ()) {
665
645
// There may be two situations:
666
646
// - a quota has been requested, and the quota has not been received yet
667
647
// - the quota was not requested, for example, due to a change in the metering option, but the previous quota requests have not yet been processed
668
648
EnqueueReservedAndProcess (cookie);
669
649
} else {
670
- Write (cookie);
650
+ Write (cookie, std::move (it-> second . Request ) );
671
651
}
652
+ PendingReserve.erase (it);
672
653
} else {
673
654
if (PendingWrite.empty ()) {
674
655
return WriteResult (EErrorCode::InternalError, " Unexpected Write response" , std::move (record));
@@ -740,7 +721,7 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
740
721
ReceivedQuota.insert (ReceivedQuota.end (), PendingQuota.begin (), PendingQuota.end ());
741
722
PendingQuota.clear ();
742
723
743
- ProcessQuota ();
724
+ ProcessQuotaAndWrite ();
744
725
745
726
break ;
746
727
@@ -829,12 +810,12 @@ class TPartitionWriter: public TActorBootstrapped<TPartitionWriter>, private TRl
829
810
830
811
struct RequestHolder {
831
812
NKikimrClient::TPersQueueRequest Request;
832
- bool QuotaChecked ;
813
+ bool QuotaCheckEnabled ;
833
814
bool QuotaAccepted;
834
815
835
- RequestHolder (NKikimrClient::TPersQueueRequest&& request, bool quotaChecked )
816
+ RequestHolder (NKikimrClient::TPersQueueRequest&& request, bool quotaCheckEnabled )
836
817
: Request(std::move(request))
837
- , QuotaChecked(quotaChecked )
818
+ , QuotaCheckEnabled(quotaCheckEnabled )
838
819
, QuotaAccepted(false ) {
839
820
}
840
821
};
0 commit comments