maytasm opened a new pull request #11144:
URL: https://github.com/apache/druid/pull/11144
Make sure updating coordinator config is protected against race condition
### Description
Many coordinator config bundle multiple configurations into the same key.
For example, the auto compaction config (`coordinator.compaction.config`)
contains all the compaction configs for multiple datasources within the same
payload. In many places, when we do updates on coordinator config, we first do
a read to get the current value and apply the change. The read and write does
not have any lock to prevent concurrent update.
For example, let’s say we currently have current value for compaction
config: {datasource x} and we have concurrent deleteCompactionConfig and
addOrUpdateCompactionConfig calls happening at the same time in the following
order:
deleteCompactionConfig call to delete x -> deleteCompactionConfig read
current which is {x} from JacksonConfigManager-> addOrUpdateCompactionConfig
calls to add y -> addOrUpdateCompactionConfig got current which is {x} from
JacksonConfigManager-> deleteCompactionConfig write {} to database ->
addOrUpdateCompactionConfig write {x, y} to database. Final result is
compaction config for x and y in the database. This is incorrect as both calls
(call to deleteCompactionConfig and addOrUpdateCompactionConfig) would have
returned success and user would expect x to be deleted.
This PR changes the update to `coordinator.compaction.config`,
`coordinator.config` and `lookupsConfig` to pass the current config value
(which is used to build the new config value) to the MetadataStorageConnector
and to use MetadataStorageConnector.compareAndSwap method instead. The API to
update these configs may now fail if between the time we retrieve the current
config value to the time the database update happened, the config value changed.
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
(Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked
related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code
wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths,
ensuring the threshold for [code
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]