Skip to content

Commit d298e46

Browse files
committed
Fix schema version mismatch for index restore with AtTable operation
Problem: - After restoring index impl tables, schema version mismatch occurred - Index metadata expected version X but impl table had version X+1 - Tests failed with: "schema version mismatch during metadata loading" Root Cause: - Index impl table restore incremented the impl table's schema version - Parent index metadata schema version was not updated - This caused a mismatch when querying the restored table Solution: - Added AtTable operation at the index path after impl table restore - Mirrors CDC stream pattern (schemeshard__operation_backup_backup_collection.cpp:218) - AtTable operation syncs index metadata schema version with impl table - Ensures index object and impl table stay in sync The fix creates two operations per index restore: 1. Restore impl table (increments impl table schema version) 2. AtTable at index path (syncs index metadata schema version) This matches how CDC streams handle the same issue when creating streams on index impl tables during backup operations.
1 parent 0197f82 commit d298e46

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

ydb/core/tx/schemeshard/schemeshard_incremental_restore_scan.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,41 @@ void TSchemeShard::CreateSingleIndexRestoreOperation(
857857
// Send the request (parallel with table operations)
858858
LOG_I("Sending index restore operation for: " << dstIndexImplPath);
859859
Send(SelfId(), indexRequest.Release());
860+
861+
// Create AtTable operation to sync index schema version with impl table
862+
// (similar to CDC stream pattern - see schemeshard__operation_backup_backup_collection.cpp:218)
863+
// This ensures the index metadata schema version matches the restored impl table
864+
{
865+
auto indexPath = TPath::Init(indexPathId, this);
866+
867+
auto atTableRequest = MakeHolder<TEvSchemeShard::TEvModifySchemeTransaction>();
868+
auto& atTableRecord = atTableRequest->Record;
869+
870+
TTxId atTableTxId = GetCachedTxId(ctx);
871+
atTableRecord.SetTxId(ui64(atTableTxId));
872+
873+
auto& atTableTx = *atTableRecord.AddTransaction();
874+
atTableTx.SetOperationType(NKikimrSchemeOp::ESchemeOpRestoreIncrementalBackupAtTable);
875+
atTableTx.SetInternal(true);
876+
atTableTx.SetWorkingDir(indexPath.Parent().PathString());
877+
878+
auto& atTableRestore = *atTableTx.MutableRestoreMultipleIncrementalBackups();
879+
atTableRestore.AddSrcTablePaths(srcIndexBackupPath);
880+
atTableRestore.SetDstTablePath(indexPath.PathString());
881+
882+
// Track this AtTable operation
883+
TOperationId atTableOpId(atTableTxId, 0);
884+
IncrementalRestoreOperationToState[atTableOpId] = operationId;
885+
TxIdToIncrementalRestore[atTableTxId] = operationId;
886+
887+
if (stateIt != IncrementalRestoreStates.end()) {
888+
stateIt->second.InProgressOperations.insert(atTableOpId);
889+
LOG_I("Tracking index AtTable operation " << atTableOpId << " for schema version sync");
890+
}
891+
892+
LOG_I("Sending index AtTable operation for schema version sync at: " << indexPath.PathString());
893+
Send(SelfId(), atTableRequest.Release());
894+
}
860895
}
861896

862897
// Notification function for operation completion

0 commit comments

Comments
 (0)