@@ -125,10 +125,12 @@ struct TTxCoordinator::TTxRestoreTransactions : public TTransactionBase<TTxCoord
125125 return true ;
126126 }
127127
128- void RestoreVolatileSteps () {
128+ TStepId RestoreVolatileSteps () {
129+ TStepId maxStep = 0 ;
129130 for (auto &pr : Self->VolatileTransactions ) {
130131 auto txId = pr.first ;
131132 auto &tx = pr.second ;
133+ maxStep = Max (maxStep, tx.PlanOnStep );
132134 for (auto &prmed : tx.UnconfirmedAffectedSet ) {
133135 auto medId = prmed.first ;
134136 auto &medTx = GetMediatorTx (medId, tx.PlanOnStep , txId);
@@ -137,6 +139,7 @@ struct TTxCoordinator::TTxRestoreTransactions : public TTransactionBase<TTxCoord
137139 }
138140 }
139141 }
142+ return maxStep;
140143 }
141144
142145 TTxType GetTxType () const override { return TXTYPE_INIT; }
@@ -146,15 +149,24 @@ struct TTxCoordinator::TTxRestoreTransactions : public TTransactionBase<TTxCoord
146149 bool result = Restore (transactions, txc, ctx);
147150 if (!result)
148151 return false ;
149- RestoreVolatileSteps ();
152+ TStepId maxVolatileStep = RestoreVolatileSteps ();
150153 i64 txCounter = transactions.size () + Self->VolatileTransactions .size ();
151154 Self->Transactions .swap (transactions);
152155 *Self->MonCounters .TxInFly += txCounter;
153156 Self->MonCounters .CurrentTxInFly = txCounter;
154157
155- if (Self->PrevStateActorId ) {
156- NIceDb::TNiceDb db (txc.DB );
158+ NIceDb::TNiceDb db (txc.DB );
157159
160+ // Previous coordinator might have had transactions that were after
161+ // its persistent blocked range, but before LastPlanned was updated.
162+ // Since we pick them up as planned and send to mediators we also need
163+ // to make sure LastPlanned reflects that.
164+ if (Self->VolatileState .LastPlanned < maxVolatileStep) {
165+ Self->VolatileState .LastPlanned = maxVolatileStep;
166+ Schema::SaveState (db, Schema::State::KeyLastPlanned, maxVolatileStep);
167+ }
168+
169+ if (Self->PrevStateActorId ) {
158170 ui64 volatileLeaseMs = Self->VolatilePlanLeaseMs ;
159171 if (volatileLeaseMs > 0 ) {
160172 // Make sure we start and persist new state actor before allowing clients to acquire new read steps
0 commit comments