Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Creating table with duplicate name results in multiple YB tables #4013

Closed
ndeodhar opened this issue Mar 19, 2020 · 2 comments
Closed
Assignees
Labels
area/ysql Yugabyte SQL (YSQL)
Milestone

Comments

@ndeodhar
Copy link
Contributor

ndeodhar commented Mar 19, 2020

If we create a duplicate table, then YSQL returns an error saying that table already exists, but yb master creates the table. For example:

yugabyte=# create table test(a int primary key);
CREATE TABLE
yugabyte=# create table test(a int primary key);
ERROR:  relation "test" already exists

Now, if you go to master UI, you'll see two tables with the name test.

This issue will get fixed once we have background job in master to delete such inconsistencies (rather the window during which the extra tables will exist will reduce). However, we should check if we can reorder the table creation process in YSQL such that table is created on master after constraint and sanity checks are done in postgres.

@ndeodhar ndeodhar added the area/ysql Yugabyte SQL (YSQL) label Mar 19, 2020
@m-iancu m-iancu added this to the v2.2 milestone Mar 19, 2020
ndeodhar added a commit that referenced this issue Apr 1, 2020
…table creation on yb-master

Summary:
This diff addresses 2 issues:
1. #3503 Speed up table creation by buffering writes to postgres system tables.
This **reduces write RPCs from 54 to 13.** We can't reduce this further for now because the writes are interleaved with reads.
Note that we still have 53 read RPCs generated to master due to postgres cache invalidation during DDL execution.
In yb-ctl RF=1 on mac, this change **reduced table creation time from ~115 ms to ~70 ms.**

2. #4013 Reorder table creation on yb-master
We now create table on master after we've created the table in pg_class system table. This ensures that simple condition checks like table name already exists etc. are done **before** the table is created on yb-master, thereby preventing duplicate tables on yb-master.

Test Plan:
Manual testing
Jenkins

Reviewers: alex, mihnea

Reviewed By: mihnea

Subscribers: hector, kannan, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D8196
@ndeodhar ndeodhar closed this as completed Apr 1, 2020
@marcus-sa
Copy link

marcus-sa commented Sep 23, 2020

Weird, I'm still getting this error using the latest version.
Here's the error that Keycloak outputs:

13:22:22,492 FATAL [org.keycloak.services] (ServerService Thread Pool -- 62) Error during startup: org.keycloak.connections.jpa.updater.liquibase.lock.LockRetryException: liquibase.exception.DatabaseException: ERROR: relation "databasechangeloglock" already exists [Failed SQL: CREATE TABLE public.databasechangeloglock (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP WITHOUT TIME ZONE, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]

@marcus-sa
Copy link

So, why is this still occurring?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL)
Projects
None yet
Development

No branches or pull requests

3 participants