cryptoe commented on code in PR #15817:
URL: https://github.com/apache/druid/pull/15817#discussion_r1555238951


##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java:
##########
@@ -216,6 +245,12 @@ public void refresh(final Set<SegmentId> 
segmentsToRefresh, final Set<String> da
     }
   }
 
+  @Override
+  protected void removeSegmentAction(SegmentId segmentId)
+  {

Review Comment:
   Could you mention why this is noOp ?
   



##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java:
##########
@@ -148,6 +154,23 @@ public ServerView.CallbackAction 
segmentSchemasAnnounced(SegmentSchemas segmentS
     );
   }
 
+  @LifecycleStart
+  public void start() throws InterruptedException

Review Comment:
   This should go into the abstract Class.
   Child classes can ovveride the method.
   If you are facing guice issues, then have the lifecycle annotation on a non 
abstract method and then that method calls a abstract method which the child 
classes provide the impl for.  
   



##########
indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentInsertAction.java:
##########
@@ -38,12 +39,16 @@ public class SegmentInsertAction implements 
TaskAction<Set<DataSegment>>
 {
   private final Set<DataSegment> segments;
 
+  private final MinimalSegmentSchemas minimalSegmentSchemas;
+
   @JsonCreator
   public SegmentInsertAction(
-      @JsonProperty("segments") Set<DataSegment> segments
+      @JsonProperty("segments") Set<DataSegment> segments,
+      @JsonProperty("minimalSegmentSchemas") MinimalSegmentSchemas 
minimalSegmentSchemas

Review Comment:
   This should be nullable else rolling upgrade/downgrade will fail 
   



##########
indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SequenceMetadata.java:
##########
@@ -219,9 +220,9 @@ boolean canHandle(
       }
 
       if (runner.isEndOffsetExclusive()) {
-        ret &= recordOffset.compareTo(partitionEndOffset) < 0;
+        ret = ret && recordOffset.compareTo(partitionEndOffset) < 0;

Review Comment:
   These changes does not seem related to the PR. 



##########
processing/src/main/java/org/apache/druid/segment/column/SegmentAndSchemas.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.segment.column;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Encapsulates segment metadata and corresponding schema.
+ */
+public class SegmentAndSchemas

Review Comment:
   One would ideally expect List<SegmentAndSchema> in this class but the class 
serves a different purpose all together. 
   Can we rename this to 
   SegmentsWithSchemas?
   



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/processor/SegmentGeneratorFrameProcessorFactory.java:
##########
@@ -50,48 +50,50 @@
 import org.apache.druid.msq.kernel.StageDefinition;
 import org.apache.druid.msq.kernel.StagePartition;
 import org.apache.druid.segment.IndexSpec;
+import org.apache.druid.segment.column.SegmentAndSchemas;
 import org.apache.druid.segment.data.CompressionFactory;
 import org.apache.druid.segment.data.CompressionStrategy;
 import org.apache.druid.segment.incremental.AppendableIndexSpec;
 import org.apache.druid.segment.incremental.ParseExceptionHandler;
 import org.apache.druid.segment.incremental.RowIngestionMeters;
 import org.apache.druid.segment.indexing.DataSchema;
 import org.apache.druid.segment.indexing.TuningConfig;
+import org.apache.druid.segment.metadata.CentralizedDatasourceSchemaConfig;
 import org.apache.druid.segment.realtime.appenderator.Appenderator;
 import org.apache.druid.segment.realtime.appenderator.AppenderatorConfig;
 import org.apache.druid.segment.realtime.appenderator.Appenderators;
 import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
 import org.apache.druid.segment.writeout.SegmentWriteOutMediumFactory;
 import org.apache.druid.sql.calcite.planner.ColumnMappings;
-import org.apache.druid.timeline.DataSegment;
 import org.joda.time.Period;
 
 import javax.annotation.Nullable;
 import java.io.File;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
-import java.util.Set;
 import java.util.function.Consumer;
 
 @JsonTypeName("segmentGenerator")
 public class SegmentGeneratorFrameProcessorFactory
-    implements FrameProcessorFactory<DataSegment, Set<DataSegment>, 
List<SegmentIdWithShardSpec>>
+    implements FrameProcessorFactory<SegmentAndSchemas, SegmentAndSchemas, 
List<SegmentIdWithShardSpec>>
 {
   private final DataSchema dataSchema;
   private final ColumnMappings columnMappings;
   private final MSQTuningConfig tuningConfig;
+  private final Boolean publishSchema;
 
   @JsonCreator
   public SegmentGeneratorFrameProcessorFactory(
       @JsonProperty("dataSchema") final DataSchema dataSchema,
       @JsonProperty("columnMappings") final ColumnMappings columnMappings,
-      @JsonProperty("tuningConfig") final MSQTuningConfig tuningConfig
+      @JsonProperty("tuningConfig") final MSQTuningConfig tuningConfig,
+      @JsonProperty("publishSchema") final Boolean publishSchema
   )

Review Comment:
   This should be nullable for the cases where controller is on the newer 
version and the worker is on the older version 
   



##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java:
##########
@@ -199,7 +222,13 @@ public void refresh(final Set<SegmentId> 
segmentsToRefresh, final Set<String> da
 
       // Remove those datasource for which we received schema from the 
Coordinator.
       dataSourcesToRebuild.removeAll(polledDataSourceMetadata.keySet());
-      dataSourcesNeedingRebuild.clear();
+
+      if (centralizedDatasourceSchemaConfig.isEnabled()) {
+        dataSourcesNeedingRebuild.addAll(dataSourcesToQuery);
+      } else {
+        dataSourcesNeedingRebuild.clear();
+      }
+      log.debug("DatasourcesNeedingRebuild is [%s]", 
dataSourcesNeedingRebuild);

Review Comment:
   This should be "DatasourcesNeedingRebuild are [%s]."



##########
server/src/main/java/org/apache/druid/indexing/overlord/IndexerMetadataStorageCoordinator.java:
##########
@@ -303,12 +306,14 @@ SegmentIdWithShardSpec allocatePendingSegment(
   SegmentPublishResult commitSegmentsAndMetadata(
       Set<DataSegment> segments,
       @Nullable DataSourceMetadata startMetadata,
-      @Nullable DataSourceMetadata endMetadata
+      @Nullable DataSourceMetadata endMetadata,
+      MinimalSegmentSchemas minimalSegmentSchemas

Review Comment:
   This can be nullable rite ?



##########
processing/src/main/java/org/apache/druid/segment/column/MinimalSegmentSchemas.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.segment.column;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Compact representation of segment schema for multiple segments.
+ */
+public class MinimalSegmentSchemas
+{
+  // Mapping of segmentId to segment level information like schema fingerprint 
and numRows.

Review Comment:
   Nit: we can loose the map as well. 



##########
extensions-contrib/sqlserver-metadata-storage/src/test/java/org/apache/druid/metadata/storage/sqlserver/SQLServerConnectorTest.java:
##########
@@ -38,7 +39,8 @@ public void testIsTransientException()
         Suppliers.ofInstance(new MetadataStorageConnectorConfig()),
         Suppliers.ofInstance(
             MetadataStorageTablesConfig.fromBase(null)
-        )
+        ),
+        CentralizedDatasourceSchemaConfig.create()

Review Comment:
   There should be test case which test the schema is created only when the 
config is set.
   



##########
services/src/main/java/org/apache/druid/cli/CliOverlord.java:
##########
@@ -187,6 +199,30 @@ public void configure(Binder binder)
                     .to(DEFAULT_SERVICE_NAME);
               
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(8090);
               
binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(8290);
+
+              String serverViewType = (String) properties.getOrDefault(
+                  ServerViewModule.SERVERVIEW_TYPE_PROPERTY,
+                  ServerViewModule.DEFAULT_SERVERVIEW_TYPE
+              );
+
+              if 
(Boolean.parseBoolean(properties.getProperty(CliCoordinator.CENTRALIZED_DATASOURCE_SCHEMA_ENABLED))

Review Comment:
   This check should be in all services. 



##########
indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/AbstractParallelIndexSupervisorTaskTest.java:
##########
@@ -678,6 +680,8 @@ protected TaskToolbox createTaskToolbox(Task task, 
TaskActionClient actionClient
     TaskConfig config = new TaskConfigBuilder()
         
.setBatchProcessingMode(TaskConfig.BATCH_PROCESSING_MODE_DEFAULT.name())
         .build();
+    CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig = new 
CentralizedDatasourceSchemaConfig();

Review Comment:
   Use centralizedDataSourceSchema.create(true)



##########
services/src/main/java/org/apache/druid/cli/CliPeon.java:
##########
@@ -245,12 +245,12 @@ public void configure(Binder binder)
                       ));
             }
 
+            JsonConfigProvider.bind(binder, 
"druid.centralizedDatasourceSchema", CentralizedDatasourceSchemaConfig.class);

Review Comment:
   Please make a constant of this Prefix. You can put it in the 
CentralizedDataSourceSchemaConfig 
   



##########
processing/src/main/java/org/apache/druid/segment/column/SchemaPayload.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.segment.column;

Review Comment:
   This should be under segment no ?



##########
indexing-service/src/test/java/org/apache/druid/indexing/common/task/IndexTaskTest.java:
##########
@@ -563,6 +656,40 @@ public void testTransformSpec() throws Exception
     Assert.assertEquals(Intervals.of("2014/P1D"), 
segments.get(0).getInterval());
     Assert.assertEquals(NumberedShardSpec.class, 
segments.get(0).getShardSpec().getClass());
     Assert.assertEquals(0, segments.get(0).getShardSpec().getPartitionNum());
+
+    Assert.assertEquals(1, 
segmentAndSchema.getMinimalSegmentSchemas().getSegmentStatsMap().size());

Review Comment:
   This should through a utility. 



##########
processing/src/test/java/org/apache/druid/segment/column/MinimalSegmentSchemasTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.segment.column;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.query.aggregation.last.StringLastAggregatorFactory;
+import org.apache.druid.segment.TestHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Collections;
+
+public class MinimalSegmentSchemasTest
+{
+  static {
+    NullHandling.initializeForTests();

Review Comment:
   Why is nullHandling needed for all these tests ? We donot have any data in 
these tests 



##########
indexing-service/src/test/java/org/apache/druid/indexing/common/task/IngestionTestBase.java:
##########
@@ -400,6 +436,8 @@ public ListenableFuture<TaskStatus> run(Task task)
         final TaskConfig config = new TaskConfigBuilder()
             
.setBatchProcessingMode(TaskConfig.BATCH_PROCESSING_MODE_DEFAULT.name())
             .build();
+        CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig = 
new CentralizedDatasourceSchemaConfig();

Review Comment:
   Use the helper contructor. 



##########
processing/src/test/java/org/apache/druid/guice/MetadataStorageTablesConfigTest.java:
##########
@@ -81,5 +82,15 @@ public ObjectMapper jsonMapper()
     
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.dataSource"),
 config.getDataSourceTable());
     
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.supervisors"),
 config.getSupervisorTable());
     
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.upgradeSegments"),
 config.getUpgradeSegmentsTable());
+
+    MetadataStorageTablesConfig fromBase = 
MetadataStorageTablesConfig.fromBase("druid.metadata.storage.tables");

Review Comment:
   This can be a whole new test case. 



##########
processing/src/main/java/org/apache/druid/metadata/MetadataStorageTablesConfig.java:
##########
@@ -94,7 +97,8 @@ public MetadataStorageTablesConfig(
       @JsonProperty("taskLock") String taskLockTable,
       @JsonProperty("audit") String auditTable,
       @JsonProperty("supervisors") String supervisorTable,
-      @JsonProperty("upgradeSegments") String upgradeSegmentsTable
+      @JsonProperty("upgradeSegments") String upgradeSegmentsTable,
+      @JsonProperty("segmentSchema") String segmentSchemaTable

Review Comment:
   Shouldn't this be marked nullable ?



##########
processing/src/main/java/org/apache/druid/metadata/MetadataStorageConnector.java:
##########
@@ -90,4 +90,6 @@ default void exportTable(
   void createSupervisorsTable();
 
   void deleteAllRecords(String tableName);
+
+  void createSegmentSchemaTable();

Review Comment:
   Lets add some java docs here and when the table is creaded 



##########
processing/src/main/java/org/apache/druid/segment/column/SchemaPayload.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.segment.column;

Review Comment:
   All of these classes does not seem col specific. 



##########
processing/src/main/java/org/apache/druid/segment/column/MinimalSegmentSchemas.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.segment.column;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Compact representation of segment schema for multiple segments.
+ */
+public class MinimalSegmentSchemas
+{
+  // Mapping of segmentId to segment level information like schema fingerprint 
and numRows.

Review Comment:
   +1



##########
server/src/main/java/org/apache/druid/indexing/overlord/IndexerMetadataStorageCoordinator.java:
##########
@@ -303,12 +306,14 @@ SegmentIdWithShardSpec allocatePendingSegment(
   SegmentPublishResult commitSegmentsAndMetadata(
       Set<DataSegment> segments,
       @Nullable DataSourceMetadata startMetadata,
-      @Nullable DataSourceMetadata endMetadata
+      @Nullable DataSourceMetadata endMetadata,
+      MinimalSegmentSchemas minimalSegmentSchemas

Review Comment:
   In other methods as well. 



-- 
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