[ISSUE #14981] Fix concurrent publishConfig race condition for PostgreSQL#15278
[ISSUE #14981] Fix concurrent publishConfig race condition for PostgreSQL#15278wushiyuanmaimob wants to merge 1 commit into
Conversation
|
Thanks for your this PR. 🙏 感谢您提交的PR。 🙏 |
|
| Commit | Author | |
|---|---|---|
77b7a20 |
sywu14 | sywu14@iflytek.com |
How to fix:
- Add your commit email to your GitHub account: https://github.com/settings/emails
- Or update your local git config to use an email already linked to GitHub:
git config user.name "Your GitHub Username" git config user.email "your-github-email@example.com" - Amend your commits and force-push:
git rebase -i HEAD~1 # mark commits as "edit" and amend author git push --force-with-lease
This check will re-run automatically after you push.
|
|
…libaba#14981) Under high concurrency, multiple threads calling publishConfig for the same dataId/group/tenant can both pass the check-then-act check in insertOrUpdate(), resulting in one thread getting a UniqueIndexConflict error from PostgreSQL. Fix: Catch DataIntegrityViolationException on INSERT and fall back to UPDATE, making the operation idempotent across all database backends (MySQL, PostgreSQL, Oracle, etc.). Affected methods: - ExternalConfigInfoPersistServiceImpl.insertOrUpdate() - ExternalConfigInfoPersistServiceImpl.insertOrUpdateCas() Fixes alibaba#14981 Signed-off-by: sywu14 <sywu14@iflytek.com>
77b7a20 to
44e947e
Compare
Fixes
Description
In a Nacos cluster using PostgreSQL as the database backend, concurrent calls to the
publishConfigAPI for the samedataId,group, andtenantoccasionally result in a 500 Internal Server Error due toUniqueIndexConflict.Root Cause
ExternalConfigInfoPersistServiceImpl.insertOrUpdate()uses a check-then-act pattern:SELECTto check if the config existsINSERTUPDATEUnder high concurrency, two threads can both find "not exists" and both attempt
INSERT. The second one hits the unique constraint (uk_configinfo_datagrouptenant) and throwsDataIntegrityViolationException.For MySQL, this is typically handled by
ON DUPLICATE KEY UPDATEor automatic retry in some deployments. PostgreSQL has no such fallback.Fix
Catch
DataIntegrityViolationExceptionon INSERT and fall back to UPDATE, making the operation idempotent across all database backends (MySQL, PostgreSQL, Oracle, etc.).Before:
After:
Changes
ExternalConfigInfoPersistServiceImpl.javaTesting
This fix makes
insertOrUpdateandinsertOrUpdateCasidempotent under concurrent access without requiring application-level retries.