clintropolis commented on a change in pull request #11144:
URL: https://github.com/apache/druid/pull/11144#discussion_r629660293
##########
File path:
server/src/main/java/org/apache/druid/server/http/CoordinatorCompactionConfigsResource.java
##########
@@ -162,27 +165,68 @@ public Response deleteCompactionConfig(
@Context HttpServletRequest req
)
{
- final CoordinatorCompactionConfig current =
CoordinatorCompactionConfig.current(manager);
- final Map<String, DataSourceCompactionConfig> configs = current
- .getCompactionConfigs()
- .stream()
- .collect(Collectors.toMap(DataSourceCompactionConfig::getDataSource,
Function.identity()));
+ Callable<SetResult> callable = () -> {
+ final CoordinatorCompactionConfig current =
CoordinatorCompactionConfig.current(manager);
+ final Map<String, DataSourceCompactionConfig> configs = current
+ .getCompactionConfigs()
+ .stream()
+ .collect(Collectors.toMap(DataSourceCompactionConfig::getDataSource,
Function.identity()));
+
+ final DataSourceCompactionConfig config = configs.remove(dataSource);
+ if (config == null) {
+ return SetResult.fail(new NoSuchElementException("datasource not
found"), false);
+ }
+
+ return manager.set(
+ CoordinatorCompactionConfig.CONFIG_KEY,
+ // Do database insert without swap if the current config is empty as
this means the config may be null in the database
+ CoordinatorCompactionConfig.empty().equals(current) ? null : current,
+ CoordinatorCompactionConfig.from(current,
ImmutableList.copyOf(configs.values())),
+ new AuditInfo(author, comment, req.getRemoteAddr())
+ );
+ };
+ return updateConfigHelper(callable);
+ }
- final DataSourceCompactionConfig config = configs.remove(dataSource);
- if (config == null) {
- return Response.status(Response.Status.NOT_FOUND).build();
+ @VisibleForTesting
+ Response updateConfigHelper(Callable<SetResult> updateMethod)
+ {
+ int attemps = 0;
+ SetResult setResult = null;
+ try {
+ while (attemps < UPDATE_NUM_RETRY) {
+ setResult = updateMethod.call();
+ if (setResult.isOk() || !setResult.isRetryable()) {
+ break;
+ }
+ attemps++;
+ updateRetryDelay();
+ }
+ }
Review comment:
Ah cool, I guess it isn't as configurable as what I thought. Do you
think it would be worth maybe making an issue to suggest making it more
configurable to not use hard-coded stuffs and link to these places as potential
areas that could benefit from such a refactor?
--
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]