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