Description
When changing the shard for a chain using graphman chain change-shard, the existing chain is correctly renamed to <chain>-old and persists in the database.
However, if a subsequent attempt is made to revert the chain's shard back to the original shard (which would cause the currently active chain to be renamed to <chain>-old again), the operation fails due to a unique constraint violation on the chains table. The error indicates that the key value (<chain>-old) already exists, as it was created during the initial shard change.
Steps to Reproduce
- Start with chain A on shard S1 (e.g., matic on polygon_chain).
- Change the shard for chain A to S2 (e.g., primary):
graphman chain change-shard A S2
# Result: Successful. A is on S2. A-old (the original chain) is on S1.
- Attempt to change the shard for chain A back to the original shard S1:
graphman chain change-shard A S1
Expected Behavior
The shard change should complete successfully. The current chain A (on S2) should be renamed to A-old (or a more uniquely named backup), and the old chain A-old (on S1) should be re-promoted/renamed to A.
Actual Behavior
The command fails with a database constraint violation:
Error: database constraint violated: duplicate key value violates unique constraint "chains_name_key": Key (name)=(matic-old) already exists.
Additional
The current logic for change-shard unconditionally attempts to rename the current chain to <chain>-old. This approach is fragile because it doesn't account for the persistence of a previously archived <chain>-old entity. The failure occurs because the database enforces a unique constraint on the name column.
Relevant log output
root@b5c46359fc62:/# graphman chain change-shard matic primary
Changing block cache shard for matic to primary
Current shard: polygon_chain
Error: database constraint violated: duplicate key value violates unique constraint "chains_name_key": Key (name)=(matic-old) already exists.
IPFS hash
No response
Subgraph name or link to explorer
No response
Some information to help us out
OS information
Linux
Description
When changing the shard for a chain using
graphman chain change-shard, the existing chain is correctly renamed to<chain>-oldand persists in the database.However, if a subsequent attempt is made to revert the chain's shard back to the original shard (which would cause the currently active chain to be renamed to
<chain>-oldagain), the operation fails due to a unique constraint violation on thechainstable. The error indicates that the key value (<chain>-old) already exists, as it was created during the initial shard change.Steps to Reproduce
Expected Behavior
The shard change should complete successfully. The current chain A (on S2) should be renamed to A-old (or a more uniquely named backup), and the old chain A-old (on S1) should be re-promoted/renamed to A.
Actual Behavior
The command fails with a database constraint violation:
Additional
The current logic for
change-shardunconditionally attempts to rename the current chain to<chain>-old. This approach is fragile because it doesn't account for the persistence of a previously archived<chain>-oldentity. The failure occurs because the database enforces a unique constraint on thenamecolumn.Relevant log output
IPFS hash
No response
Subgraph name or link to explorer
No response
Some information to help us out
OS information
Linux