yugabyte/yugabyte-db

[YSQL] "Keyspace 'system_postgres' already exists" error when creating sequences concurrently

Open

#4.890 geöffnet am 26. Juni 2020

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C (1.003 Forks)batch import
area/ysqlgood first issuekind/bugpriority/medium

Repository-Metriken

Stars
 (8.229 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 17T 21h) (92 gemergte PRs in 30 T)

Beschreibung

Jira Link: DB-4818 We currently store some sequence data (last val, is_called, etc) in a dedicated DocDB system table, that exists in the system_postgres namespace. That namespace is not pre-created, so "create sequence" calls will create it if needed by calling CreateNamespaceIfNotExists.

However, CreateNamespaceIfNotExists does not correctly handle the "If Not Exists" aspect for YSQL. Specifically, it checks if the namespace exists before, but if it gets an IsAlreadyPresent status that still gets reported as an error. See the code in: https://github.com/yugabyte/yugabyte-db/blob/master/src/yb/client/client.cc#L654 -- there the IsAlreadyPresent check at the end only handles YQL_DATABASE_CQL namespaces. That means that if many sequences are created concurrently at least some (possibly all-but-one) will fail.

Contributor Guide