@@ -52,19 +52,19 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
52
52
ui32 Generation;
53
53
TTabletTypes::EType TabletType;
54
54
NKikimrLocal::EBootMode BootMode;
55
- ui32 FollowerId;
56
55
57
56
TTablet ()
58
57
: Tablet()
59
58
, Generation(0 )
60
59
, TabletType()
61
60
, BootMode(NKikimrLocal::EBootMode::BOOT_MODE_LEADER)
62
- , FollowerId(0 )
63
61
{}
64
62
};
65
63
66
64
struct TTabletEntry : TTablet {
67
65
TInstant From;
66
+ bool IsPromoting = false ;
67
+ ui32 PromotingFromFollower = 0 ;
68
68
69
69
TTabletEntry ()
70
70
: From(TInstant::MicroSeconds(0 ))
@@ -141,6 +141,10 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
141
141
::NMonitoring::TDynamicCounters::TCounterPtr CounterCancelDemotedByBS;
142
142
::NMonitoring::TDynamicCounters::TCounterPtr CounterCancelUnknownReason;
143
143
144
+ static TTabletId LeaderId (TTabletId tabletId) {
145
+ return {tabletId.first , 0 };
146
+ }
147
+
144
148
void Die (const TActorContext &ctx) override {
145
149
if (HivePipeClient) {
146
150
if (Connected) {
@@ -385,6 +389,24 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
385
389
ScheduleSendTabletMetrics (ctx);
386
390
}
387
391
392
+ void StartPromotion (TTabletId tabletId, TOnlineTabletEntry& followerEntry, ui32 suggestedGen, TInstant now) {
393
+ TTabletId leaderId = LeaderId (tabletId);
394
+ TTabletEntry& leaderEntry = InbootTablets[leaderId];
395
+ followerEntry.IsPromoting = true ;
396
+ leaderEntry = followerEntry;
397
+ leaderEntry.From = now;
398
+ leaderEntry.BootMode = NKikimrLocal::EBootMode::BOOT_MODE_LEADER;
399
+ leaderEntry.Generation = suggestedGen;
400
+ leaderEntry.PromotingFromFollower = tabletId.second ;
401
+ }
402
+
403
+ void FinishPromotion (TTabletId tabletId, TTabletEntry& entry) {
404
+ TTabletId promotedTablet{tabletId.first , entry.PromotingFromFollower };
405
+ OnlineTablets.erase (promotedTablet);
406
+ entry.IsPromoting = false ;
407
+ entry.PromotingFromFollower = 0 ;
408
+ }
409
+
388
410
void Handle (TEvLocal::TEvBootTablet::TPtr &ev, const TActorContext &ctx) {
389
411
NKikimrLocal::TEvBootTablet &record = ev->Get ()->Record ;
390
412
TIntrusivePtr<TTabletStorageInfo> info (TabletStorageInfoFromProto (record.GetInfo ()));
@@ -427,18 +449,9 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
427
449
if (it != OnlineTablets.end ()) {
428
450
if (it->second .BootMode == NKikimrLocal::EBootMode::BOOT_MODE_FOLLOWER
429
451
&& record.GetBootMode () == NKikimrLocal::EBootMode::BOOT_MODE_LEADER) {
430
- // promote to leader
431
- it->second .BootMode = NKikimrLocal::EBootMode::BOOT_MODE_LEADER;
432
- it->second .Generation = suggestedGen;
433
- tabletId.second = 0 ; // FollowerId = 0
434
- TTabletEntry &entry = InbootTablets[tabletId];
435
- entry = it->second ;
436
- entry.From = ctx.Now ();
437
- entry.BootMode = NKikimrLocal::EBootMode::BOOT_MODE_LEADER;
438
- entry.Generation = suggestedGen;
439
- ctx.Send (entry.Tablet , new TEvTablet::TEvPromoteToLeader (suggestedGen, info));
452
+ StartPromotion (tabletId, it->second , suggestedGen, ctx.Now ());
453
+ ctx.Send (it->second .Tablet , new TEvTablet::TEvPromoteToLeader (suggestedGen, info));
440
454
MarkDeadTablet (it->first , 0 , TEvLocal::TEvTabletStatus::StatusSupersededByLeader, TEvTablet::TEvTabletDead::ReasonError, ctx);
441
- OnlineTablets.erase (it);
442
455
LOG_DEBUG_S (ctx, NKikimrServices::LOCAL,
443
456
" TLocalNodeRegistrar::Handle TEvLocal::TEvBootTablet follower tablet " << tabletId << " promoted to leader" );
444
457
return ;
@@ -718,6 +731,9 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
718
731
<< " marked as running at generation "
719
732
<< generation);
720
733
NTabletPipe::SendData (ctx, HivePipeClient, new TEvLocal::TEvTabletStatus (TEvLocal::TEvTabletStatus::StatusOk, tabletId, generation));
734
+ if (inbootIt->second .IsPromoting ) {
735
+ FinishPromotion (tabletId, inbootIt->second );
736
+ }
721
737
OnlineTablets.emplace (tabletId, inbootIt->second );
722
738
InbootTablets.erase (inbootIt);
723
739
}
@@ -818,6 +834,14 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
818
834
});
819
835
if (onlineIt != OnlineTablets.end ()) { // from online list
820
836
MarkDeadTablet (onlineIt->first , generation, TEvLocal::TEvTabletStatus::StatusFailed, msg->Reason , ctx);
837
+ if (onlineIt->second .IsPromoting ) {
838
+ TTabletId leader = LeaderId (onlineIt->first );
839
+ auto inbootIt = InbootTablets.find (leader);
840
+ if (inbootIt != InbootTablets.end ()) {
841
+ MarkDeadTablet (leader, inbootIt->second .Generation , TEvLocal::TEvTabletStatus::StatusFailed, msg->Reason , ctx);
842
+ }
843
+ InbootTablets.erase (inbootIt);
844
+ }
821
845
OnlineTablets.erase (onlineIt);
822
846
UpdateEstimate ();
823
847
return ;
0 commit comments