cockroachdb / cockroachdb/cockroach
Retriable Serializable error while inserting at REPEATABLE-READ is difficult to parse
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Given the following schema:
```
-- Parent table - REGIONAL BY ROW automatically adds crdb_region column
CREATE TABLE parent (
id INT PRIMARY KEY,
data TEXT
) LOCALITY REGIONAL BY ROW;
-- Child table with region inference via foreign key constraint
CREATE TABLE child (
id INT PRIMARY KEY,
parent_id INT,
data TEXT,
CONSTRAINT fk_parent FOREIGN KEY (crdb_region, parent_id) REFERENCES parent (crdb_region, id)
) WITH (infer_rbr_region_col_using_constraint = 'fk_parent') LOCALITY REGIONAL BY ROW;
```
And the following test plan:
```
-- Setup parent with initial region
INSERT INTO parent (id, data, crdb_region) VALUES (1, 'snapshot_test', 'us-east1');
-- Session 1: Start transaction with repeatable read isolation
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
-- Explicitly read the parent first to establish snapshot
SELECT id, crdb_region FROM parent WHERE id = 1; -- Should show 'us-east1'
-- Session 2: Change parent region (this should succeed immediately)
UPDATE parent SET crdb_region = 'us-west1' WHERE id = 1;
-- Session 1: Now insert child with region inference
-- Under REPEATABLE READ: Should see 'us-east1' due to snapshot isolation
-- and should NOT get retry errors like SERIALIZABLE would
INSERT INTO child (id, parent_id, data) VALUES (1, 1, 'snapshot_child');
COMMIT;
```
The last COMMIT produces:
```
ERROR: restart transaction: TransactionRetryWithProtoRefreshError: TransactionRetryError: retry txn (RETRY_SERIALIZABLE - failed preemptive refresh due to encountered recently written committed value /Table/114/1/"\xc0"/1/0 @1753476906.523588000,2): "sql txn" meta={id=3d077576 key=/Table/115/4/"\x80"/1/0 iso=Serializable pri=0.03546574 epo=0 ts=1753476920.547805000,2 min=1753476897.086543000,0 seq=1} lock=true stat=PENDING rts=1753476897.086543000,0 gul=1753476897.586543000,0 obs={n1@1753476901.479743000,0 n3@1753476923.605954000,0 n4@1753476897.086543000,0 n5@1753476923.503066000,0 n6@1753476923.502744000,0, ...}
SQLSTATE: 40001
HINT: See: https://www.cockroachlabs.com/docs/v25.3/transaction-retry-error-reference.html#retry_serializable
```
This could be worse, but it feels like this message is excessively verbose and that verbosity masks the useful information (this is a transient error, please retry).
Jira issue: CRDB-52907
Contributor guide
Assessment
This issue has not been assessed yet.