yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.94k stars 1.06k forks source link

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

Open m-iancu opened 4 years ago

m-iancu commented 4 years ago

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.

AbdallahKhaled93 commented 4 years ago

Hello, Is anyone working on this ticket ? I would like to give it a shot

ndeodhar commented 4 years ago

Hi @AbdallahKhaled93 , absolutely, please give it a shot. Feel free to join our community slack and reach out to @hectorgcr / @m-iancu while working on this.

AbdallahKhaled93 commented 4 years ago

@ndeodhar Thank you