@@ -864,19 +864,36 @@ void TDataShard::PersistChangeRecord(NIceDb::TNiceDb& db, const TChangeRecord& r
864864 TSchemaSnapshotKey (res.first ->second .TableId , res.first ->second .SchemaVersion ));
865865 }
866866
867- db.GetDatabase ().OnRollback ([this , order = record.GetOrder ()] {
868- auto it = ChangesQueue.find (order);
869- Y_VERIFY_S (it != ChangesQueue.end (), " Cannot find change record: " << order);
867+ const auto key = TCommittingChangeRecordsKey::FromRecord (record);
868+ if (!CommittingChangeRecords.contains (key)) {
869+ db.GetDatabase ().OnCommit ([this , key] {
870+ auto it = CommittingChangeRecords.find (key);
871+ Y_ABORT_UNLESS (it != CommittingChangeRecords.end ());
872+ CommittingChangeRecords.erase (it);
873+ });
874+ db.GetDatabase ().OnRollback ([this , key] {
875+ auto it = CommittingChangeRecords.find (key);
876+ Y_ABORT_UNLESS (it != CommittingChangeRecords.end ());
877+
878+ for (const auto order : it->second ) {
879+ auto cIt = ChangesQueue.find (order);
880+ Y_VERIFY_S (cIt != ChangesQueue.end (), " Cannot find change record: " << order);
881+
882+ if (cIt->second .SchemaSnapshotAcquired ) {
883+ const auto snapshotKey = TSchemaSnapshotKey (cIt->second .TableId , cIt->second .SchemaVersion );
884+ if (const auto last = SchemaSnapshotManager.ReleaseReference (snapshotKey)) {
885+ ScheduleRemoveSchemaSnapshot (snapshotKey);
886+ }
887+ }
870888
871- if (it->second .SchemaSnapshotAcquired ) {
872- const auto snapshotKey = TSchemaSnapshotKey (it->second .TableId , it->second .SchemaVersion );
873- if (const auto last = SchemaSnapshotManager.ReleaseReference (snapshotKey)) {
874- ScheduleRemoveSchemaSnapshot (snapshotKey);
889+ ChangesQueue.erase (cIt);
875890 }
876- }
877891
878- ChangesQueue.erase (it);
879- });
892+ CommittingChangeRecords.erase (it);
893+ });
894+ }
895+
896+ CommittingChangeRecords[key].push_back (record.GetOrder ());
880897 } else {
881898 auto & state = LockChangeRecords[lockId];
882899 Y_ABORT_UNLESS (state.Changes .empty () || state.Changes .back ().LockOffset < record.GetLockOffset (),
0 commit comments