-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] duplicate key value violation on identity key column #22935
Comments
It turns out to be a server side cache id conflict.
other session, connected to the same node, but other database creates brand new sequence, but it looks used:
The problem affects clusters with gflag |
Related to that, sequence cache may have stale entries from dropped sequences and dropped databases, and they may conflict with active sessions. |
Summary: Since the tserver's sequence cache was introduced, the entry key was the sequence's oid. However, it is not unique, each database has its own oid generator, and each new database starts its oids from 16384, hence high probability of collision in the sequence cache, which is one instance per node and shared between all the databases. Solution is to use both database oid and sequence oid as the entry key. Database oid is unique between all databases within the cluster, and the oids of the sequences are unique within the database. Initially the bug was discovered when a database was dropped and recreated, because the cache entries are not invalidated when sequence is dropped. We may want to add invalidation logic, however, the problem isn't critical with composite key: oids of dropped databases and other objects are not recycled. Jira: DB-11851 Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgSequences#testMultiDbIsolation ./yb_build.sh --java-test org.yb.pgsql.TestPgSequencesWithServerCache#testMultiDbIsolation Reviewers: jason Reviewed By: jason Subscribers: ybase, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D36182
…cache entry key Summary: Original commit: 214d44a / D36182 Since the tserver's sequence cache was introduced, the entry key was the sequence's oid. However, it is not unique, each database has its own oid generator, and each new database starts its oids from 16384, hence high probability of collision in the sequence cache, which is one instance per node and shared between all the databases. Solution is to use both database oid and sequence oid as the entry key. Database oid is unique between all databases within the cluster, and the oids of the sequences are unique within the database. Initially the bug was discovered when a database was dropped and recreated, because the cache entries are not invalidated when sequence is dropped. We may want to add invalidation logic, however, the problem isn't critical with composite key: oids of dropped databases and other objects are not recycled. Jira: DB-11851 Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgSequences#testMultiDbIsolation ./yb_build.sh --java-test org.yb.pgsql.TestPgSequencesWithServerCache#testMultiDbIsolation Reviewers: jason Reviewed By: jason Subscribers: yql, ybase Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D36214
Summary: 9c637e2 [PLAT-14429]: Modify Troubleshooting Platform registration workflow in YBA 0a1406d [PLAT-14098]: Updating yb.runtime_conf_ui.tag_filter with appropriate tags value does not display the flags accordingly 70a87f9 [PLAT-13605][PLAT-13609]: Edit Volume controls and storage type in FULL_MOVE but not in case of UPDATE 26fbfe0 [PLAT-14515][UI] Clicking preview doesn't show the correct info and clears up the data provided while setting up the ysql_ident or ysql_hba multiline flags.- [PLAT-14514] [PLAT-14513] a07946b [#18233] Initial commit for yugabyted unit test framework. b2e8ee7 [#22842] docdb: Improve usability of stack trace tracking endpoints 508f26e [docs] Added RN 2.20.2.3-b2 (#23042) 214d44a [#22935] YSQL: Use db oid in the tserver's sequence cache entry key c47b2d9 [#22802] YSQL: Avoid renaming DocDb tables during legacy rewrite Excluded: 7c8343d [#22874] YSQL: Fix cascaded drops on columns 58c8d4e [#23046] xCluster: Remove ns_replication from the code a70681d [#22816] YSQL: Bug fixes for replication connections in ysql connection manager b239e07 Doc upgrade versions (#22988) Excluded: ec76062 [#16408] YSQL: Split TestPgRegressIndex.testPgRegressIndex Test Plan: Jenkins: rebase: pg15-cherrypicks Reviewers: jason, tfoucher Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D36247
…che entry key Summary: Original commit: 214d44a / D36182 Since the tserver's sequence cache was introduced, the entry key was the sequence's oid. However, it is not unique, each database has its own oid generator, and each new database starts its oids from 16384, hence high probability of collision in the sequence cache, which is one instance per node and shared between all the databases. Solution is to use both database oid and sequence oid as the entry key. Database oid is unique between all databases within the cluster, and the oids of the sequences are unique within the database. Initially the bug was discovered when a database was dropped and recreated, because the cache entries are not invalidated when sequence is dropped. We may want to add invalidation logic, however, the problem isn't critical with composite key: oids of dropped databases and other objects are not recycled. Jira: DB-11851 Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgSequences#testMultiDbIsolation ./yb_build.sh --java-test org.yb.pgsql.TestPgSequencesWithServerCache#testMultiDbIsolation Reviewers: jason Reviewed By: jason Subscribers: ybase, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D36215
…che entry key Summary: Original commit: 214d44a / D36182 Since the tserver's sequence cache was introduced, the entry key was the sequence's oid. However, it is not unique, each database has its own oid generator, and each new database starts its oids from 16384, hence high probability of collision in the sequence cache, which is one instance per node and shared between all the databases. Solution is to use both database oid and sequence oid as the entry key. Database oid is unique between all databases within the cluster, and the oids of the sequences are unique within the database. Initially the bug was discovered when a database was dropped and recreated, because the cache entries are not invalidated when sequence is dropped. We may want to add invalidation logic, however, the problem isn't critical with composite key: oids of dropped databases and other objects are not recycled. Jira: DB-11851 Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgSequences#testMultiDbIsolation ./yb_build.sh --java-test org.yb.pgsql.TestPgSequencesWithServerCache#testMultiDbIsolation Reviewers: jason Reviewed By: jason Subscribers: yql, ybase Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D36216
…cache entry key Summary: Original commit: 214d44a / D36182 Since the tserver's sequence cache was introduced, the entry key was the sequence's oid. However, it is not unique, each database has its own oid generator, and each new database starts its oids from 16384, hence high probability of collision in the sequence cache, which is one instance per node and shared between all the databases. Solution is to use both database oid and sequence oid as the entry key. Database oid is unique between all databases within the cluster, and the oids of the sequences are unique within the database. Initially the bug was discovered when a database was dropped and recreated, because the cache entries are not invalidated when sequence is dropped. We may want to add invalidation logic, however, the problem isn't critical with composite key: oids of dropped databases and other objects are not recycled. Jira: DB-11851 Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgSequences#testMultiDbIsolation ./yb_build.sh --java-test org.yb.pgsql.TestPgSequencesWithServerCache#testMultiDbIsolation Reviewers: jason Reviewed By: jason Subscribers: yql, ybase Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D36227
Jira Link: DB-11851
Description
When dropping a database with a sequence in it with ysql_sequence_cache_method=server, it is possible that the sequence cache is not invalidated, when the database is re-created with the application object (with a sequence) it leads to a situation where subsequent inserts can error with duplicate key value violation, on the identity key column
this seems present in 2024.1 and also 20.4
I observed it with a more complex test case , to observe the duplicate key value violation
but a much simpler repro is possible to observe the behaviour when dropping the database
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information
The text was updated successfully, but these errors were encountered: