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


##########
server/src/main/java/org/apache/druid/segment/metadata/CoordinatorSegmentMetadataCache.java:
##########
@@ -419,6 +521,128 @@ private Set<SegmentId> 
filterSegmentWithCachedSchema(Set<SegmentId> segmentIds)
     return cachedSegments;
   }
 
+  @Nullable
+  private Integer getReplicationFactor(SegmentId segmentId)
+  {
+    if (segmentReplicationStatus == null) {
+      return null;
+    }
+    SegmentReplicaCount replicaCountsInCluster = 
segmentReplicationStatus.getReplicaCountsInCluster(segmentId);
+    return replicaCountsInCluster == null ? null : 
replicaCountsInCluster.required();
+  }
+
+  @VisibleForTesting
+  protected void coldDatasourceSchemaExec()
+  {
+    Stopwatch stopwatch = Stopwatch.createStarted();
+    Collection<ImmutableDruidDataSource> immutableDataSources =
+        
sqlSegmentsMetadataManager.getImmutableDataSourcesWithAllUsedSegments();
+
+    Set<String> dataSources = new HashSet<>();
+
+    int datasources = 0;
+    int segments = 0;
+    int datasourceWithColdSegments = 0;
+
+    for (ImmutableDruidDataSource dataSource : immutableDataSources) {
+      String dataSourceName = dataSource.getName();
+      dataSources.add(dataSourceName);
+      datasources++;
+
+      Collection<DataSegment> dataSegments = dataSource.getSegments();
+
+      final Map<String, ColumnType> columnTypes = new LinkedHashMap<>();
+
+      for (DataSegment segment : dataSegments) {
+        Integer replicationFactor = getReplicationFactor(segment.getId());
+        if (replicationFactor != null && replicationFactor != 0) {
+          continue;
+        }
+        Optional<SchemaPayloadPlus> optionalSchema = 
segmentSchemaCache.getSchemaForSegment(segment.getId());
+        if (optionalSchema.isPresent()) {
+          RowSignature rowSignature = 
optionalSchema.get().getSchemaPayload().getRowSignature();
+          mergeRowSignature(columnTypes, rowSignature);
+        }
+        segments++;
+      }
+
+      final RowSignature.Builder builder = RowSignature.builder();
+      columnTypes.forEach(builder::add);
+
+      RowSignature coldSignature = builder.build();
+
+      if (coldSignature.getColumnNames().isEmpty()) {
+        // the given datasource doesn't have any cold segments
+        continue;
+      }
+
+      log.debug("[%s] signature from cold segments is [%s]", dataSourceName, 
coldSignature);
+
+      datasourceWithColdSegments++;
+      coldSchemaTable.put(dataSourceName, new 
DataSourceInformation(dataSourceName, coldSignature));
+
+      // update tables map with merged schema, if signature doesn't exist we 
do not add entry in this table
+      // schema for entirely cold datasource is maintained separately
+      tables.computeIfPresent(
+          dataSourceName,
+          (ds, info) -> {
+            RowSignature mergedSignature = 
mergeHotAndColdSchema(info.getRowSignature(), coldSignature);
+
+            if (!info.getRowSignature().equals(mergedSignature)) {
+              log.info(
+                  "[%s] has new merged signature: %s. hot signature [%s], cold 
signature [%s].",
+                  ds, mergedSignature, info.getRowSignature(), coldSignature
+              );
+            } else {
+              log.debug("[%s] merged signature is unchanged.", ds);
+            }
+
+            return new DataSourceInformation(ds, mergedSignature);
+          }
+      );
+    }
+
+    // remove any stale datasource from the map
+    coldSchemaTable.keySet().retainAll(dataSources);
+
+    if (stopwatch.millisElapsed() > COLD_SCHEMA_SLOWNESS_THRESHOLD_MILLIS) {
+      log.info("Cold schema processing was slow, taking [%d] millis. "

Review Comment:
   Else for this should be debug. 



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