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


##########
server/src/main/java/org/apache/druid/metadata/segment/SqlSegmentsMetadataManagerV2.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.metadata.segment;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Supplier;
+import org.apache.druid.client.DataSourcesSnapshot;
+import org.apache.druid.guice.ManageLifecycle;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.metadata.MetadataStorageTablesConfig;
+import org.apache.druid.metadata.SQLMetadataConnector;
+import org.apache.druid.metadata.SegmentsMetadataManager;
+import org.apache.druid.metadata.SegmentsMetadataManagerConfig;
+import org.apache.druid.metadata.SqlSegmentsMetadataManager;
+import org.apache.druid.metadata.segment.cache.SegmentMetadataCache;
+import org.apache.druid.segment.metadata.CentralizedDatasourceSchemaConfig;
+import org.apache.druid.segment.metadata.SegmentSchemaCache;
+import org.apache.druid.server.coordinator.DruidCompactionConfig;
+
+/**
+ * Implementation V2 of {@link SegmentsMetadataManager}, that can use the
+ * segments cached in {@link SegmentMetadataCache} to build a {@link 
DataSourcesSnapshot}.
+ * <p>
+ * This class acts as a wrapper over {@link SqlSegmentsMetadataManager} and the
+ * {@link SegmentMetadataCache}. If the cache is enabled, an additional poll is
+ * not done and the segments already present in the cache are used to build the
+ * snapshot. If the {@link SegmentMetadataCache} is disabled, the polling is
+ * delegated to the legacy implementation in {@link 
SqlSegmentsMetadataManager}.
+ * <p>
+ * The Coordinator always uses the snapshot to perform various segment 
management
+ * duties such as loading, balancing, etc.
+ * The Overlord uses the snapshot only when compaction supervisors are enabled.
+ * Thus, when running the Overlord as a standalone service (i.e. not combined
+ * with the Coordinator), {@link #startPollingDatabasePeriodically()} and
+ * {@link #stopPollingDatabasePeriodically()} are called based on the current
+ * state of {@link DruidCompactionConfig#isUseSupervisors()}.
+ */
+@ManageLifecycle
+public class SqlSegmentsMetadataManagerV2 implements SegmentsMetadataManager
+{
+  private static final Logger log = new 
Logger(SqlSegmentsMetadataManagerV2.class);
+
+  private final SegmentsMetadataManager delegate;
+  private final SegmentMetadataCache segmentMetadataCache;
+  private final SegmentsMetadataManagerConfig managerConfig;
+  private final CentralizedDatasourceSchemaConfig schemaConfig;
+
+  public SqlSegmentsMetadataManagerV2(
+      SegmentMetadataCache segmentMetadataCache,
+      SegmentSchemaCache segmentSchemaCache,
+      SQLMetadataConnector connector,
+      Supplier<SegmentsMetadataManagerConfig> managerConfig,
+      Supplier<MetadataStorageTablesConfig> tablesConfig,
+      CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig,
+      ServiceEmitter serviceEmitter,
+      ObjectMapper jsonMapper
+  )
+  {
+    this.delegate = new SqlSegmentsMetadataManager(
+        jsonMapper,
+        managerConfig, tablesConfig, connector, segmentSchemaCache,
+        centralizedDatasourceSchemaConfig, serviceEmitter
+    );
+    this.managerConfig = managerConfig.get();
+    this.segmentMetadataCache = segmentMetadataCache;
+    this.schemaConfig = centralizedDatasourceSchemaConfig;
+  }
+
+  /**
+   * @return true if segment metadata cache is enabled and segment schema cache
+   * is not enabled. Segment metadata cache currently does not handle segment
+   * schema updates.
+   */
+  private boolean useCacheToBuildTimeline()
+  {
+    return segmentMetadataCache.isEnabled() && !schemaConfig.isEnabled();

Review Comment:
   Thanks for the suggestion! It makes sense to error out if both features are 
enabled simultaneously, at least for the time being. 
   
   I wanted to address handling both features being enabled in this PR itself 
but since the patch became a little bloated, I decided to do it in a follow up.
   
   The long term solution would be to poll the schemas inside 
`HeapMemorySegmentMetadataCache` itself if schema caching is enabled.
   Eventually, we will get rid of `SqlSegmentsMetadataManager` completely.



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