Commit 9ba8604
committed
[#26633] DocDB: Drop invalid index DDL halts the replication in xCluster
Summary:
### Problem
Dropping an INVALID index halts xCluster DDL replication. When CREATE UNIQUE INDEX fails due to a duplicate key violation, the index is left in an INVALID state (`indisvalid=false`) on the source but is never created on the target. Dropping this index causes replication to fail with:
- `index "<invalid_index_name>" does not exist` on the target
- `DDL replication is paused due to repeated failures`
### Root Cause
There is a state mismatch between the source and target catalogs. The CREATE INDEX that failed was never replicated to the target (since ddl_command_end doesn't execute for failed DDLs). However, the subsequent DROP INDEX was replicated, which causes the target to try dropping an index that doesn't exist. This causes the state mismatch between the source and target catalogs: the source has an invalid object and the target has no object. The replication stream sends DDLs assuming the object exists on the target, violating the "exactly one" semantics required for the target.
### Solution
On the target side, when `yb_xcluster_automatic_mode_target_ddl` is set (running in xCluster automatic mode), we implement a "silent skip" for DROP INDEX, RENAME INDEX and attribute/tablespace changes like SET STATISTICS, SET TABLESPACE. By treating these "phantom" objects (failed creation on the source and never existed on the target) as no-ops, the DDL applier can progress through the replication stream without halting. Valid objects are still dropped normally.
Test Plan:
### Automated Tests
```
./yb_build.sh release --cxx-test xcluster_ddl_replication-test --gtest_filter='XClusterDDLReplicationTest.DropInvalidIndexDoesNotHaltReplication'
./yb_build.sh release --cxx-test xcluster_ddl_replication-test --gtest_filter='XClusterDDLReplicationTest.DropPartitionedIndexOnOnlyReplicates'
./yb_build.sh release --cxx-test xcluster_ddl_replication-test --gtest_filter='XClusterDDLReplicationTest.AlterPhantomIndexLifecycleDoesNotHaltReplication'
```
Test 1: DropInvalidIndexDoesNotHaltReplication
- CREATE UNIQUE INDEX fails due to duplicate key, meaning the index is INVALID and not replicated
- DROP INDEX is replicated to target, which fails with "does not exist", and we validate that the error is ignored
- Then verify that replication continues normally
Test 2: DropPartitionedIndexOnOnlyReplicates
- CREATE INDEX ON ONLY creates an INVALID index that IS replicated, meaning the CREATE succeeded
- DROP INDEX is replicated to target, which succeeds since the index exists
- Then verify that we don't incorrectly skip DROP for valid cases
Test 3: AlterPhantomIndexLifecycleDoesNotHaltReplication
- CREATE UNIQUE INDEX (on an expression) fails on source and is not created on target
- ALTER INDEX ... SET STATISTICS and SET TABLESPACE are replicated for the phantom index
- ALTER INDEX ... RENAME TO is replicated, changing the phantom's name on the source
- ALTER TABLE ... SET SCHEMA is replicated, triggering an implicit schema move for the phantom index
- DROP INDEX using the new name is replicated
- Then verify that the target handles the entire lifecycle of attribute, name, and namespace changes on the missing index gracefully, and replication continues
(Note: SET TABLESPACE here goes through the same code path as SET STATISTICS: `T_AlterTableStmt`)
The fixed code passes all four tests. The old code fails Test 1 (because the "does not exist" error halts replication) and Test, but passes Test 2 (because the index was successfully created and replicated, so the DROP succeeds normally).
This is because Test 2 validates the fix doesn't break successful CREATEs of INVALID indexes (meaning the index was replicated).
Did not test DROP on multiple indices since this isn't supported yet in YB. See [issue #880](#880).
Reviewers: jhe, xCluster, hsunder
Reviewed By: jhe
Subscribers: ybase, yql
Differential Revision: https://phorge.dev.yugabyte.com/D501841 parent 1152182 commit 9ba8604
File tree
4 files changed
+204
-0
lines changed- src
- postgres/yb-extensions/yb_xcluster_ddl_replication
- yb/integration-tests/xcluster
4 files changed
+204
-0
lines changedLines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
483 | 522 | | |
484 | 523 | | |
485 | 524 | | |
486 | 525 | | |
487 | 526 | | |
| 527 | + | |
| 528 | + | |
488 | 529 | | |
489 | 530 | | |
490 | 531 | | |
| |||
Lines changed: 155 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
926 | 926 | | |
927 | 927 | | |
928 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
929 | 1084 | | |
930 | 1085 | | |
931 | 1086 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
510 | 516 | | |
511 | 517 | | |
512 | 518 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| |||
0 commit comments