kfaraz commented on code in PR #13699:
URL: https://github.com/apache/druid/pull/13699#discussion_r1083237207


##########
server/src/main/java/org/apache/druid/server/coordinator/DataSourceCompactionConfigHistory.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator;
+
+import org.apache.druid.audit.AuditInfo;
+import org.joda.time.DateTime;
+
+import java.util.List;
+import java.util.Stack;
+
+/**
+ * A utility class to build the config history for a datasource from audit 
entries for
+ * {@link CoordinatorCompactionConfig}. The {@link 
CoordinatorCompactionConfig} contains the entire config for the
+ * cluster, so this class creates adds audit entires to the history only when 
a setting for this datasource or a global
+ * setting has changed.
+ */
+public class DataSourceCompactionConfigHistory
+{
+  private final Stack<DatasourceCompactionConfigAuditEntry> auditEntries = new 
Stack<>();
+  private final String dataSource;
+
+  public DataSourceCompactionConfigHistory(String dataSource)
+  {
+    this.dataSource = dataSource;
+  }
+
+  public void add(CoordinatorCompactionConfig coordinatorCompactionConfig, 
AuditInfo auditInfo, DateTime auditTime)
+  {
+    DatasourceCompactionConfigAuditEntry current = auditEntries.isEmpty() ? 
null : auditEntries.peek();
+    DatasourceCompactionConfigAuditEntry newEntry = null;
+    boolean hasDataSourceCompactionConfig = false;
+    for (DataSourceCompactionConfig dataSourceCompactionConfig : 
coordinatorCompactionConfig.getCompactionConfigs()) {
+      if (dataSource.equals(dataSourceCompactionConfig.getDataSource())) {
+        hasDataSourceCompactionConfig = true;
+        if (
+            current == null ||
+            (
+                
!dataSourceCompactionConfig.equals(current.getCompactionConfig()) ||
+                
!current.getGlobalConfig().hasSameConfig(coordinatorCompactionConfig)
+            )
+        ) {
+          current = new DatasourceCompactionConfigAuditEntry(
+              new DatasourceCompactionConfigAuditEntry.GlobalCompactionConfig(
+                  coordinatorCompactionConfig.getCompactionTaskSlotRatio(),
+                  coordinatorCompactionConfig.getMaxCompactionTaskSlots(),
+                  coordinatorCompactionConfig.isUseAutoScaleSlots()
+              ),
+              dataSourceCompactionConfig,
+              auditInfo,
+              auditTime
+          );
+          newEntry = current;
+        }
+        break;
+      }
+    }
+    if (newEntry != null || (current != null && 
!hasDataSourceCompactionConfig)) {
+      if (newEntry == null) {
+        newEntry = new DatasourceCompactionConfigAuditEntry(
+            new DatasourceCompactionConfigAuditEntry.GlobalCompactionConfig(
+                coordinatorCompactionConfig.getCompactionTaskSlotRatio(),
+                coordinatorCompactionConfig.getMaxCompactionTaskSlots(),
+                coordinatorCompactionConfig.isUseAutoScaleSlots()
+            ),
+            null,
+            auditInfo,
+            auditTime
+        );
+      }
+      auditEntries.push(newEntry);
+    }

Review Comment:
   Nit: maybe simplify this for readability:
   
   ```java
       if (newEntry != null) {
         auditEntries.push(newEntry);
       } else if (current != null && !hasDataSourceCompactionConfig) {
           newEntry = ...
           auditEntries.push(newEntry);
       }
   ```



##########
server/src/main/java/org/apache/druid/server/coordinator/DatasourceCompactionConfigAuditEntry.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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;
+
+/**
+ * A DTO containing audit information for compaction config for a datasource.
+ */
+public class DatasourceCompactionConfigAuditEntry

Review Comment:
   Nit: Rename to `DataSourceCompactionConfigAuditEntry` with a capitalized `S` 
in `DataSource`, similar to rest of the classes here.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to