You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "kfaraz (via GitHub)" <gi...@apache.org> on 2024/07/28 07:08:54 UTC
[PR] Refactor: Clean up compaction config classes (druid)
kfaraz opened a new pull request, #16810:
URL: https://github.com/apache/druid/pull/16810
### Changes
- Rename `CoordinatorCompactionConfig` to `DruidCompactionConfig`
- Rename `CompactionConfigUpdateRequest` to `ClusterCompactionConfig`
- Refactor methods in `DruidCompactionConfig`
- Clean up tests
<hr>
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.
- [ ] a release note entry in the PR description.
- [ ] 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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1694312722
##########
integration-tests/src/test/java/org/apache/druid/tests/coordinator/duty/ITAutoCompactionLockContentionTest.java:
##########
@@ -304,26 +303,26 @@
*/
private void submitAndVerifyCompactionConfig() throws Exception
{
- final DataSourceCompactionConfig compactionConfig = CompactionUtil
- .createCompactionConfig(fullDatasourceName, Specs.MAX_ROWS_PER_SEGMENT, Period.ZERO);
+ final DataSourceCompactionConfig dataSourceCompactionConfig = DataSourceCompactionConfig
+ .builder()
+ .forDataSource(fullDatasourceName)
+ .withSkipOffsetFromLatest(Period.ZERO)
+ .withMaxRowsPerSegment(Specs.MAX_ROWS_PER_SEGMENT)
Review Comment:
## Deprecated method or constructor invocation
Invoking [Builder.withMaxRowsPerSegment](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/7623)
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #16810:
URL: https://github.com/apache/druid/pull/16810#issuecomment-2257593087
Thanks a lot for the prompt reviews, @AmatyaAvadhanula , @gargvishesh !!
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "gargvishesh (via GitHub)" <gi...@apache.org>.
gargvishesh commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1695666189
##########
server/src/main/java/org/apache/druid/server/coordinator/DruidCompactionConfig.java:
##########
@@ -126,7 +128,36 @@ public boolean isUseAutoScaleSlots()
@JsonProperty
public CompactionEngine getEngine()
{
- return compactionEngine;
+ return engine;
+ }
+
+
+ // Null-safe getters not used for serialization
+ public ClusterCompactionConfig clusterConfig()
+ {
+ return new ClusterCompactionConfig(
+ compactionTaskSlotRatio,
+ maxCompactionTaskSlots,
+ useAutoScaleSlots,
+ engine
+ );
+ }
+
+ public Map<String, DataSourceCompactionConfig> dataSourceToCompactionConfig()
Review Comment:
The name seems to suggest conversion when it actually returns a map.
```suggestion
public Map<String, DataSourceCompactionConfig> dataSourceToCompactionConfigMap()
```
##########
server/src/main/java/org/apache/druid/server/coordinator/DataSourceCompactionConfigAuditEntry.java:
##########
@@ -50,7 +51,7 @@ public DataSourceCompactionConfigAuditEntry(
}
@JsonProperty
- public GlobalCompactionConfig getGlobalConfig()
+ public ClusterCompactionConfig getGlobalConfig()
Review Comment:
```suggestion
public ClusterCompactionConfig getClusterCompactionConfig()
```
##########
server/src/main/java/org/apache/druid/server/coordinator/DataSourceCompactionConfigAuditEntry.java:
##########
@@ -20,24 +20,25 @@
package org.apache.druid.server.coordinator;
import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.audit.AuditInfo;
import org.joda.time.DateTime;
+import java.util.Objects;
+
/**
* A DTO containing audit information for compaction config for a datasource.
*/
public class DataSourceCompactionConfigAuditEntry
{
- private final GlobalCompactionConfig globalConfig;
+ private final ClusterCompactionConfig globalConfig;
private final DataSourceCompactionConfig compactionConfig;
private final AuditInfo auditInfo;
private final DateTime auditTime;
@JsonCreator
public DataSourceCompactionConfigAuditEntry(
- @JsonProperty("globalConfig") GlobalCompactionConfig globalConfig,
+ @JsonProperty("globalConfig") ClusterCompactionConfig globalConfig,
Review Comment:
```suggestion
@JsonProperty("globalConfig") ClusterCompactionConfig clusterCompactionConfig,
```
##########
server/src/main/java/org/apache/druid/server/coordinator/DataSourceCompactionConfigAuditEntry.java:
##########
@@ -20,24 +20,25 @@
package org.apache.druid.server.coordinator;
import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.audit.AuditInfo;
import org.joda.time.DateTime;
+import java.util.Objects;
+
/**
* A DTO containing audit information for compaction config for a datasource.
*/
public class DataSourceCompactionConfigAuditEntry
{
- private final GlobalCompactionConfig globalConfig;
+ private final ClusterCompactionConfig globalConfig;
Review Comment:
Consistent naming may be better. Can use older annotation for getter property name.
```suggestion
private final ClusterCompactionConfig clusterCompactionConfig;
```
##########
server/src/main/java/org/apache/druid/server/coordinator/DruidCompactionConfig.java:
##########
@@ -126,7 +128,36 @@ public boolean isUseAutoScaleSlots()
@JsonProperty
public CompactionEngine getEngine()
{
- return compactionEngine;
+ return engine;
+ }
+
+
+ // Null-safe getters not used for serialization
+ public ClusterCompactionConfig clusterConfig()
+ {
+ return new ClusterCompactionConfig(
+ compactionTaskSlotRatio,
+ maxCompactionTaskSlots,
+ useAutoScaleSlots,
+ engine
+ );
+ }
+
+ public Map<String, DataSourceCompactionConfig> dataSourceToCompactionConfig()
+ {
+ return getCompactionConfigs().stream().collect(
+ Collectors.toMap(DataSourceCompactionConfig::getDataSource, Function.identity())
+ );
+ }
+
+ public Optional<DataSourceCompactionConfig> findConfigForDatasource(String dataSource)
Review Comment:
Thanks for this handy function!
##########
integration-tests/src/test/java/org/apache/druid/tests/coordinator/duty/ITAutoCompactionUpgradeTest.java:
##########
@@ -58,67 +56,56 @@ public void testUpgradeAutoCompactionConfigurationWhenConfigurationFromOlderVers
{
// Verify that compaction config already exist. This config was inserted manually into the database using SQL script.
// This auto compaction configuration payload is from Druid 0.21.0
- CoordinatorCompactionConfig coordinatorCompactionConfig = compactionResource.getCoordinatorCompactionConfigs();
- DataSourceCompactionConfig foundDataSourceCompactionConfig = null;
- for (DataSourceCompactionConfig dataSourceCompactionConfig : coordinatorCompactionConfig.getCompactionConfigs()) {
- if (dataSourceCompactionConfig.getDataSource().equals(UPGRADE_DATASOURCE_NAME)) {
- foundDataSourceCompactionConfig = dataSourceCompactionConfig;
- }
- }
+ DruidCompactionConfig coordinatorCompactionConfig = compactionResource.getCompactionConfig();
+ DataSourceCompactionConfig foundDataSourceCompactionConfig
+ = coordinatorCompactionConfig.findConfigForDatasource(UPGRADE_DATASOURCE_NAME).orNull();
Assert.assertNotNull(foundDataSourceCompactionConfig);
// Now submit a new auto compaction configuration
PartitionsSpec newPartitionsSpec = new DynamicPartitionsSpec(4000, null);
Period newSkipOffset = Period.seconds(0);
- DataSourceCompactionConfig compactionConfig = new DataSourceCompactionConfig(
- UPGRADE_DATASOURCE_NAME,
- null,
- null,
- null,
- newSkipOffset,
- new UserCompactionTaskQueryTuningConfig(
- null,
- null,
- null,
- null,
- new MaxSizeSplitHintSpec(null, 1),
- newPartitionsSpec,
- null,
- null,
- null,
- null,
- null,
- 1,
- null,
- null,
- null,
- null,
- null,
- 1,
- null
- ),
- new UserCompactionTaskGranularityConfig(Granularities.YEAR, null, null),
- null,
- null,
- null,
- new UserCompactionTaskIOConfig(true),
- null,
- null
- );
+ DataSourceCompactionConfig compactionConfig = DataSourceCompactionConfig
+ .builder()
+ .forDataSource(UPGRADE_DATASOURCE_NAME)
+ .withSkipOffsetFromLatest(newSkipOffset)
+ .withTuningConfig(
+ new UserCompactionTaskQueryTuningConfig(
Review Comment:
A builder can be introduced for this one as well in future.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1696307664
##########
server/src/main/java/org/apache/druid/server/coordinator/ClusterCompactionConfig.java:
##########
@@ -17,38 +17,39 @@
* under the License.
*/
-package org.apache.druid.server.http;
+package org.apache.druid.server.coordinator;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.indexer.CompactionEngine;
import javax.annotation.Nullable;
+import java.util.Objects;
/**
- * Payload to update the cluster-level compaction config.
- * All fields of this class must be nullable. A non-value indicates that the
- * corresponding field is being updated.
+ * Cluster-level compaction configs.
+ * All fields of this class are nullable. A non-null value denotes that the
+ * corresponding field has been explicitly specified.
*/
-public class CompactionConfigUpdateRequest
+public class ClusterCompactionConfig
{
private final Double compactionTaskSlotRatio;
private final Integer maxCompactionTaskSlots;
private final Boolean useAutoScaleSlots;
- private final CompactionEngine compactionEngine;
+ private final CompactionEngine engine;
@JsonCreator
- public CompactionConfigUpdateRequest(
+ public ClusterCompactionConfig(
@JsonProperty("compactionTaskSlotRatio") @Nullable Double compactionTaskSlotRatio,
@JsonProperty("maxCompactionTaskSlots") @Nullable Integer maxCompactionTaskSlots,
@JsonProperty("useAutoScaleSlots") @Nullable Boolean useAutoScaleSlots,
- @JsonProperty("compactionEngine") @Nullable CompactionEngine compactionEngine
+ @JsonProperty("engine") @Nullable CompactionEngine engine
)
{
Review Comment:
I considered that. But that becomes problematic since this payload is used to update cluster configs.
If we assign non-null values in the constructor, it would seem that the values are being updated even if we don't want them to be updated.
The audit entry thing is not an issue as there we always use non-null values.
See `DruidCompactionConfig.clusterConfig()` method which always returns non-null values.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1696201261
##########
integration-tests/src/test/java/org/apache/druid/tests/coordinator/duty/ITAutoCompactionUpgradeTest.java:
##########
@@ -58,67 +56,56 @@ public void testUpgradeAutoCompactionConfigurationWhenConfigurationFromOlderVers
{
// Verify that compaction config already exist. This config was inserted manually into the database using SQL script.
// This auto compaction configuration payload is from Druid 0.21.0
- CoordinatorCompactionConfig coordinatorCompactionConfig = compactionResource.getCoordinatorCompactionConfigs();
- DataSourceCompactionConfig foundDataSourceCompactionConfig = null;
- for (DataSourceCompactionConfig dataSourceCompactionConfig : coordinatorCompactionConfig.getCompactionConfigs()) {
- if (dataSourceCompactionConfig.getDataSource().equals(UPGRADE_DATASOURCE_NAME)) {
- foundDataSourceCompactionConfig = dataSourceCompactionConfig;
- }
- }
+ DruidCompactionConfig coordinatorCompactionConfig = compactionResource.getCompactionConfig();
+ DataSourceCompactionConfig foundDataSourceCompactionConfig
+ = coordinatorCompactionConfig.findConfigForDatasource(UPGRADE_DATASOURCE_NAME).orNull();
Assert.assertNotNull(foundDataSourceCompactionConfig);
// Now submit a new auto compaction configuration
PartitionsSpec newPartitionsSpec = new DynamicPartitionsSpec(4000, null);
Period newSkipOffset = Period.seconds(0);
- DataSourceCompactionConfig compactionConfig = new DataSourceCompactionConfig(
- UPGRADE_DATASOURCE_NAME,
- null,
- null,
- null,
- newSkipOffset,
- new UserCompactionTaskQueryTuningConfig(
- null,
- null,
- null,
- null,
- new MaxSizeSplitHintSpec(null, 1),
- newPartitionsSpec,
- null,
- null,
- null,
- null,
- null,
- 1,
- null,
- null,
- null,
- null,
- null,
- 1,
- null
- ),
- new UserCompactionTaskGranularityConfig(Granularities.YEAR, null, null),
- null,
- null,
- null,
- new UserCompactionTaskIOConfig(true),
- null,
- null
- );
+ DataSourceCompactionConfig compactionConfig = DataSourceCompactionConfig
+ .builder()
+ .forDataSource(UPGRADE_DATASOURCE_NAME)
+ .withSkipOffsetFromLatest(newSkipOffset)
+ .withTuningConfig(
+ new UserCompactionTaskQueryTuningConfig(
Review Comment:
Yeah, it's already in the works. 😄
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1696204677
##########
server/src/main/java/org/apache/druid/server/coordinator/DataSourceCompactionConfigAuditEntry.java:
##########
@@ -50,7 +51,7 @@ public DataSourceCompactionConfigAuditEntry(
}
@JsonProperty
- public GlobalCompactionConfig getGlobalConfig()
+ public ClusterCompactionConfig getGlobalConfig()
Review Comment:
`globalConfig` is also a term used by the web-console.
Renaming this getter would require us to use `@JsonProperty("globalConfig")` on the getter for backwards compatibility. Leaving the names as is seemed cleaner.
Let me know if you feel strongly about this.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz merged PR #16810:
URL: https://github.com/apache/druid/pull/16810
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "AmatyaAvadhanula (via GitHub)" <gi...@apache.org>.
AmatyaAvadhanula commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1696305636
##########
server/src/main/java/org/apache/druid/server/coordinator/ClusterCompactionConfig.java:
##########
@@ -17,38 +17,39 @@
* under the License.
*/
-package org.apache.druid.server.http;
+package org.apache.druid.server.coordinator;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.indexer.CompactionEngine;
import javax.annotation.Nullable;
+import java.util.Objects;
/**
- * Payload to update the cluster-level compaction config.
- * All fields of this class must be nullable. A non-value indicates that the
- * corresponding field is being updated.
+ * Cluster-level compaction configs.
+ * All fields of this class are nullable. A non-null value denotes that the
+ * corresponding field has been explicitly specified.
*/
-public class CompactionConfigUpdateRequest
+public class ClusterCompactionConfig
{
private final Double compactionTaskSlotRatio;
private final Integer maxCompactionTaskSlots;
private final Boolean useAutoScaleSlots;
- private final CompactionEngine compactionEngine;
+ private final CompactionEngine engine;
@JsonCreator
- public CompactionConfigUpdateRequest(
+ public ClusterCompactionConfig(
@JsonProperty("compactionTaskSlotRatio") @Nullable Double compactionTaskSlotRatio,
@JsonProperty("maxCompactionTaskSlots") @Nullable Integer maxCompactionTaskSlots,
@JsonProperty("useAutoScaleSlots") @Nullable Boolean useAutoScaleSlots,
- @JsonProperty("compactionEngine") @Nullable CompactionEngine compactionEngine
+ @JsonProperty("engine") @Nullable CompactionEngine engine
)
{
Review Comment:
I think the constructor should take in null values but create a compaction config with the non-null default fields.
Otherwise the comparison in the Audit history can be incorrect when there are null values but the default values change
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Refactor: Clean up compaction config classes (druid)
Posted by "AmatyaAvadhanula (via GitHub)" <gi...@apache.org>.
AmatyaAvadhanula commented on code in PR #16810:
URL: https://github.com/apache/druid/pull/16810#discussion_r1696319584
##########
server/src/main/java/org/apache/druid/server/coordinator/ClusterCompactionConfig.java:
##########
@@ -17,38 +17,39 @@
* under the License.
*/
-package org.apache.druid.server.http;
+package org.apache.druid.server.coordinator;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.indexer.CompactionEngine;
import javax.annotation.Nullable;
+import java.util.Objects;
/**
- * Payload to update the cluster-level compaction config.
- * All fields of this class must be nullable. A non-value indicates that the
- * corresponding field is being updated.
+ * Cluster-level compaction configs.
+ * All fields of this class are nullable. A non-null value denotes that the
+ * corresponding field has been explicitly specified.
*/
-public class CompactionConfigUpdateRequest
+public class ClusterCompactionConfig
{
private final Double compactionTaskSlotRatio;
private final Integer maxCompactionTaskSlots;
private final Boolean useAutoScaleSlots;
- private final CompactionEngine compactionEngine;
+ private final CompactionEngine engine;
@JsonCreator
- public CompactionConfigUpdateRequest(
+ public ClusterCompactionConfig(
@JsonProperty("compactionTaskSlotRatio") @Nullable Double compactionTaskSlotRatio,
@JsonProperty("maxCompactionTaskSlots") @Nullable Integer maxCompactionTaskSlots,
@JsonProperty("useAutoScaleSlots") @Nullable Boolean useAutoScaleSlots,
- @JsonProperty("compactionEngine") @Nullable CompactionEngine compactionEngine
+ @JsonProperty("engine") @Nullable CompactionEngine engine
)
{
Review Comment:
Thanks for the clarification!
--
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.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org