cockroachdb / cockroachdb/cockroach

import: successive import failure with gen_random_uuid

Open
#96,885 0 comments 0 reactions 0 assignees View on GitHub
A-import C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Reproduction steps**

Generate single column import CSV with values 1 to 1M inclusive (seems to work with numbers as low as 500K, but can be reproduced more reliably with larger numbers):
```
seq -f "%.0f" 1 1000000 > cockroach-data/extern/import.csv
```

Create a table:
```
CREATE TABLE t (
i BIGINT NULL,
rowid UUID NOT VISIBLE NOT NULL DEFAULT gen_random_uuid(),
CONSTRAINT t_pkey PRIMARY KEY (rowid ASC)
);

```

Run import twice. If the second run is done fast enough (easier with larger imports), it will error out with a key collision:
```
root@localhost:26257/defaultdb> IMPORT INTO t CSV DATA ('nodelocal://self/import.csv');
job_id | status | fraction_completed | rows | index_entries | bytes
---------------------+-----------+--------------------+---------+---------------+-----------
838500862854856705 | succeeded | 1 | 1000000 | 0 | 32000751
(1 row)

Time: 5.746s total (execution 5.746s / network 0.000s)

root@localhost:26257/defaultdb> IMPORT INTO t CSV DATA ('nodelocal://self/import.csv');
ERROR: addsstable [/Table/109/1/"\x00\x00\b\x12\xa2\x1aL\x98\x80\x00\x04\tQ\r~L"/0,/Table/109/1/"\x86K\xb3\xd34O@\x00\x83%\xd9\xe9\x9a'\x96\xef"/0/NULL): checking for key collisions: ingested key collides with an existing one: /Table/109/1/"\x00\x00\b\x12\xa2\x1aL\x98\x80\x00\x04\tQ\r~L"/0
```

**RCA**

`gen_random_uuid` is overridden for imports:
https://github.com/cockroachdb/cockroach/blob/6d22e25358435e4aa9e065c7c8a31fdfdb91c6ee/pkg/sql/row/expr_walker.go#L633

The random seed for `gen_random_uuid` is based on the import start time plus the row number of the batch:
https://github.com/cockroachdb/cockroach/blob/6d22e25358435e4aa9e065c7c8a31fdfdb91c6ee/pkg/sql/importer/read_import_base.go#L730

If enough rows are inserted in the previous import and the imports are started close enough together then the random number seeds will overlap causing a collision.

Additional context https://cockroachlabs.slack.com/archives/C0168LW5THS/p1675966988684039?thread_ts=1675796933.385789&cid=C0168LW5THS

Jira issue: CRDB-24389

gz#15706

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.