@@ -969,6 +969,19 @@ void TPartition::Handle(TEvPersQueue::TEvProposeTransaction::TPtr& ev, const TAc
969
969
ProcessTxsAndUserActs (ctx);
970
970
}
971
971
972
+ template <class T >
973
+ void TPartition::ProcessPendingEvent (TAutoPtr<TEventHandle<T>>& ev, const TActorContext& ctx)
974
+ {
975
+ if (PendingEvents.empty ()) {
976
+ // Optimization: if the queue is empty, you can process the message immediately
977
+ ProcessPendingEvent (std::unique_ptr<T>(ev->Release ().Release ()), ctx);
978
+ } else {
979
+ // We need to keep the order in which the messages arrived
980
+ AddPendingEvent (ev);
981
+ ProcessPendingEvents (ctx);
982
+ }
983
+ }
984
+
972
985
template <>
973
986
void TPartition::ProcessPendingEvent (std::unique_ptr<TEvPQ::TEvProposePartitionConfig> ev, const TActorContext& ctx)
974
987
{
@@ -983,8 +996,7 @@ void TPartition::Handle(TEvPQ::TEvProposePartitionConfig::TPtr& ev, const TActor
983
996
" Step " << ev->Get ()->Step <<
984
997
" , TxId " << ev->Get ()->TxId );
985
998
986
- AddPendingEvent (ev);
987
- ProcessPendingEvents (ctx);
999
+ ProcessPendingEvent (ev, ctx);
988
1000
}
989
1001
990
1002
template <class T >
@@ -1075,8 +1087,7 @@ void TPartition::Handle(TEvPQ::TEvTxCalcPredicate::TPtr& ev, const TActorContext
1075
1087
" Step " << ev->Get ()->Step <<
1076
1088
" , TxId " << ev->Get ()->TxId );
1077
1089
1078
- AddPendingEvent (ev);
1079
- ProcessPendingEvents (ctx);
1090
+ ProcessPendingEvent (ev, ctx);
1080
1091
}
1081
1092
1082
1093
template <>
@@ -1122,8 +1133,7 @@ void TPartition::Handle(TEvPQ::TEvTxCommit::TPtr& ev, const TActorContext& ctx)
1122
1133
" Step " << ev->Get ()->Step <<
1123
1134
" , TxId " << ev->Get ()->TxId );
1124
1135
1125
- AddPendingEvent (ev);
1126
- ProcessPendingEvents (ctx);
1136
+ ProcessPendingEvent (ev, ctx);
1127
1137
}
1128
1138
1129
1139
template <>
@@ -1160,8 +1170,7 @@ void TPartition::ProcessPendingEvent(std::unique_ptr<TEvPQ::TEvTxRollback> ev, c
1160
1170
1161
1171
void TPartition::Handle (TEvPQ::TEvTxRollback::TPtr& ev, const TActorContext& ctx)
1162
1172
{
1163
- AddPendingEvent (ev);
1164
- ProcessPendingEvents (ctx);
1173
+ ProcessPendingEvent (ev, ctx);
1165
1174
}
1166
1175
1167
1176
template <>
@@ -1206,8 +1215,7 @@ void TPartition::Handle(TEvPQ::TEvGetWriteInfoRequest::TPtr& ev, const TActorCon
1206
1215
1207
1216
ev->Get ()->OriginalPartition = ev->Sender ;
1208
1217
1209
- AddPendingEvent (ev);
1210
- ProcessPendingEvents (ctx);
1218
+ ProcessPendingEvent (ev, ctx);
1211
1219
}
1212
1220
1213
1221
void TPartition::WriteInfoResponseHandler (
@@ -1310,8 +1318,7 @@ void TPartition::Handle(TEvPQ::TEvGetWriteInfoResponse::TPtr& ev, const TActorCo
1310
1318
1311
1319
ev->Get ()->SupportivePartition = ev->Sender ;
1312
1320
1313
- AddPendingEvent (ev);
1314
- ProcessPendingEvents (ctx);
1321
+ ProcessPendingEvent (ev, ctx);
1315
1322
}
1316
1323
1317
1324
template <>
@@ -1328,8 +1335,7 @@ void TPartition::Handle(TEvPQ::TEvGetWriteInfoError::TPtr& ev, const TActorConte
1328
1335
1329
1336
ev->Get ()->SupportivePartition = ev->Sender ;
1330
1337
1331
- AddPendingEvent (ev);
1332
- ProcessPendingEvents (ctx);
1338
+ ProcessPendingEvent (ev, ctx);
1333
1339
}
1334
1340
1335
1341
void TPartition::ReplyToProposeOrPredicate (TSimpleSharedPtr<TTransaction>& tx, bool isPredicate) {
@@ -3643,8 +3649,7 @@ void TPartition::Handle(TEvPQ::TEvDeletePartition::TPtr& ev, const TActorContext
3643
3649
{
3644
3650
PQ_LOG_D (" Handle TEvPQ::TEvDeletePartition" );
3645
3651
3646
- AddPendingEvent (ev);
3647
- ProcessPendingEvents (ctx);
3652
+ ProcessPendingEvent (ev, ctx);
3648
3653
}
3649
3654
3650
3655
void TPartition::ScheduleNegativeReplies ()
0 commit comments