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

GH-3282: Fix JdbcMetadataStore for DuplicateKeyEx #3285

Merged
merged 2 commits into from May 20, 2020

Conversation

artembilan
Copy link
Member

Fixes: #3282

The INSERT INTO ... SELECT ... FROM ... HAVING may fail with
DuplicateKeyException in between transactions.

  • Catch DuplicateKeyException from in the tryToPutIfAbsent()
    and return 0 as a fact of not inserted to let other logic to work
    as expected.

There is no test coverage for this since it is almost impossible to
reproduce such a race condition on DB

Cherry-pick to 5.3.x & 5.2.x

Fixes: spring-projects#3282

The `INSERT INTO ... SELECT ... FROM ... HAVING` may fail with
`DuplicateKeyException` in between transactions.
* Catch `DuplicateKeyException` from in the `tryToPutIfAbsent()`
and return `0` as a fact of not inserted to let other logic to work
as expected.

There is no test coverage for this since it is almost impossible to
reproduce such a race condition on DB

**Cherry-pick to 5.3.x & 5.2.x**
@@ -142,7 +147,7 @@ public String putIfAbsent(String key, String value) {
//try to insert if does not exists
int affectedRows = tryToPutIfAbsent(key, value);
if (affectedRows > 0) {
//it was not in the table, so we have just inserted it
//it was not in the table, so we have just inserted it or DuplicateKeyException has been thrown
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? This comment seems wrong; we return 0 on the DKE and go to the else block.

@garyrussell garyrussell merged commit 665f6bf into spring-projects:master May 20, 2020
garyrussell pushed a commit that referenced this pull request May 20, 2020
* GH-3282: Fix JdbcMetadataStore for DuplicateKeyEx

Fixes: #3282

The `INSERT INTO ... SELECT ... FROM ... HAVING` may fail with
`DuplicateKeyException` in between transactions.
* Catch `DuplicateKeyException` from in the `tryToPutIfAbsent()`
and return `0` as a fact of not inserted to let other logic to work
as expected.

There is no test coverage for this since it is almost impossible to
reproduce such a race condition on DB

**Cherry-pick to 5.3.x & 5.2.x**

* * Remove misleading message in the comment sentence
garyrussell pushed a commit that referenced this pull request May 20, 2020
* GH-3282: Fix JdbcMetadataStore for DuplicateKeyEx

Fixes: #3282

The `INSERT INTO ... SELECT ... FROM ... HAVING` may fail with
`DuplicateKeyException` in between transactions.
* Catch `DuplicateKeyException` from in the `tryToPutIfAbsent()`
and return `0` as a fact of not inserted to let other logic to work
as expected.

There is no test coverage for this since it is almost impossible to
reproduce such a race condition on DB

**Cherry-pick to 5.3.x & 5.2.x**

* * Remove misleading message in the comment sentence
@garyrussell
Copy link
Contributor

And cherry-picked to 5.3.x, 5.2.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DuplicateKeyException raised when using Spring JdbcMetadataStore (Oracle)
2 participants