cryptoe commented on code in PR #14985: URL: https://github.com/apache/druid/pull/14985#discussion_r1328533621
########## server/src/main/java/org/apache/druid/client/CoordinatorTimeline.java: ########## @@ -0,0 +1,42 @@ +/* + * 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.client; + +import org.apache.druid.query.DataSource; +import org.apache.druid.timeline.SegmentId; +import org.apache.druid.timeline.VersionedIntervalTimeline; + +import java.util.Map; + +/** + * Segment timeline maintained in the coordinator. Review Comment: Could you add more details in this java doc. What does this class do? How is this class used. ########## server/src/main/java/org/apache/druid/client/BrokerServerView.java: ########## @@ -85,9 +81,14 @@ public class BrokerServerView implements TimelineServerView private final ServiceEmitter emitter; private final BrokerSegmentWatcherConfig segmentWatcherConfig; private final Predicate<Pair<DruidServerMetadata, DataSegment>> segmentFilter; - private final CountDownLatch initialized = new CountDownLatch(1); + protected final Object lock = new Object(); + + protected final Map<SegmentId, ServerSelector> selectors = new HashMap<>(); Review Comment: Why are there 2 hashmap's here? Are they both used in one flow ? If not lets document that ########## server/src/main/java/org/apache/druid/client/QueryableCoordinatorServerView.java: ########## @@ -0,0 +1,140 @@ +/* + * 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.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import org.apache.druid.client.selector.ServerSelector; +import org.apache.druid.client.selector.TierSelectorStrategy; +import org.apache.druid.guice.ManageLifecycle; +import org.apache.druid.guice.annotations.EscalatedClient; +import org.apache.druid.guice.annotations.Smile; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.http.client.HttpClient; +import org.apache.druid.query.DataSource; +import org.apache.druid.query.QueryToolChestWarehouse; +import org.apache.druid.query.QueryWatcher; +import org.apache.druid.timeline.DataSegment; +import org.apache.druid.timeline.SegmentId; +import org.apache.druid.timeline.VersionedIntervalTimeline; +import org.apache.druid.utils.CollectionUtils; + +import java.util.Collection; +import java.util.Comparator; +import java.util.Map; + +/** + * ServerView of coordinator for the state of segments being loaded in the cluster. + * + * <p>This class extends {@link BrokerServerView} and implements {@link CoordinatorTimeline}. + * The main distinction between this class and {@link CoordinatorServerView} is the maintenance of a timeline + * of {@link ServerSelector} objects, while the other class stores {@link SegmentLoadInfo} object in its timeline.</p> + * + * <p>A new timeline class (implementing {@link TimelineServerView}) is required for + * {@link org.apache.druid.segment.metadata.CoordinatorSegmentMetadataCache}, which will run on the Coordinator.</p> + */ +@ManageLifecycle +public class QueryableCoordinatorServerView extends BrokerServerView implements CoordinatorTimeline +{ + private final FilteredServerInventoryView baseView; + + @Inject + public QueryableCoordinatorServerView( + final QueryToolChestWarehouse warehouse, + final QueryWatcher queryWatcher, + final @Smile ObjectMapper smileMapper, + final @EscalatedClient HttpClient httpClient, + FilteredServerInventoryView baseView, + TierSelectorStrategy tierSelectorStrategy, + ServiceEmitter emitter, + CoordinatorSegmentWatcherConfig segmentWatcherConfig + ) + { + super(warehouse, queryWatcher, smileMapper, httpClient, baseView, tierSelectorStrategy, emitter, new BrokerSegmentWatcherConfig() { + @Override + public boolean isAwaitInitializationOnStart() + { + return segmentWatcherConfig.isAwaitInitializationOnStart(); + } + }); + this.baseView = baseView; + } + + /** + * Since this class maintains a timeline of {@link ServerSelector} objects, + * this method converts and returns a new timeline of the object {@link SegmentLoadInfo}. + * + * @param dataSource dataSoruce + * @return timeline for the given dataSource + */ + @Override + public VersionedIntervalTimeline<String, SegmentLoadInfo> getTimeline(DataSource dataSource) + { + String table = Iterables.getOnlyElement(dataSource.getTableNames()); + VersionedIntervalTimeline<String, ServerSelector> timeline; Review Comment: nit: Lets call this baseTimeline ########## server/src/main/java/org/apache/druid/client/QueryableCoordinatorServerView.java: ########## @@ -0,0 +1,140 @@ +/* + * 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.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import org.apache.druid.client.selector.ServerSelector; +import org.apache.druid.client.selector.TierSelectorStrategy; +import org.apache.druid.guice.ManageLifecycle; +import org.apache.druid.guice.annotations.EscalatedClient; +import org.apache.druid.guice.annotations.Smile; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.http.client.HttpClient; +import org.apache.druid.query.DataSource; +import org.apache.druid.query.QueryToolChestWarehouse; +import org.apache.druid.query.QueryWatcher; +import org.apache.druid.timeline.DataSegment; +import org.apache.druid.timeline.SegmentId; +import org.apache.druid.timeline.VersionedIntervalTimeline; +import org.apache.druid.utils.CollectionUtils; + +import java.util.Collection; +import java.util.Comparator; +import java.util.Map; + +/** + * ServerView of coordinator for the state of segments being loaded in the cluster. + * + * <p>This class extends {@link BrokerServerView} and implements {@link CoordinatorTimeline}. + * The main distinction between this class and {@link CoordinatorServerView} is the maintenance of a timeline + * of {@link ServerSelector} objects, while the other class stores {@link SegmentLoadInfo} object in its timeline.</p> + * + * <p>A new timeline class (implementing {@link TimelineServerView}) is required for + * {@link org.apache.druid.segment.metadata.CoordinatorSegmentMetadataCache}, which will run on the Coordinator.</p> + */ +@ManageLifecycle +public class QueryableCoordinatorServerView extends BrokerServerView implements CoordinatorTimeline +{ + private final FilteredServerInventoryView baseView; + + @Inject + public QueryableCoordinatorServerView( + final QueryToolChestWarehouse warehouse, + final QueryWatcher queryWatcher, + final @Smile ObjectMapper smileMapper, + final @EscalatedClient HttpClient httpClient, + FilteredServerInventoryView baseView, + TierSelectorStrategy tierSelectorStrategy, + ServiceEmitter emitter, + CoordinatorSegmentWatcherConfig segmentWatcherConfig + ) + { + super(warehouse, queryWatcher, smileMapper, httpClient, baseView, tierSelectorStrategy, emitter, new BrokerSegmentWatcherConfig() { + @Override + public boolean isAwaitInitializationOnStart() + { + return segmentWatcherConfig.isAwaitInitializationOnStart(); + } + }); + this.baseView = baseView; + } + + /** + * Since this class maintains a timeline of {@link ServerSelector} objects, + * this method converts and returns a new timeline of the object {@link SegmentLoadInfo}. + * + * @param dataSource dataSoruce + * @return timeline for the given dataSource + */ + @Override + public VersionedIntervalTimeline<String, SegmentLoadInfo> getTimeline(DataSource dataSource) + { + String table = Iterables.getOnlyElement(dataSource.getTableNames()); Review Comment: NIt: Lets use `CollectionUtils.getOnlyElement()` so that a better error message is thrown to the user. ########## server/src/main/java/org/apache/druid/client/CoordinatorTimeline.java: ########## @@ -0,0 +1,42 @@ +/* + * 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.client; + +import org.apache.druid.query.DataSource; +import org.apache.druid.timeline.SegmentId; +import org.apache.druid.timeline.VersionedIntervalTimeline; + +import java.util.Map; + +/** + * Segment timeline maintained in the coordinator. + */ +public interface CoordinatorTimeline extends InventoryView +{ + /** + * Retrieve timeline for a dataSource. + */ + VersionedIntervalTimeline<String, SegmentLoadInfo> getTimeline(DataSource dataSource); + + /** + * Server information for all segments in the timeline. + */ + Map<SegmentId, SegmentLoadInfo> getSegmentLoadInfos(); Review Comment: When should user use one API over the other. Example usages might help here. Also lets rename this method to `getAllSegmentLoadInformation()` ########## sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java: ########## @@ -84,6 +86,7 @@ public class QueryFrameworkUtils { + Review Comment: Nit: space can be removed ########## server/src/main/java/org/apache/druid/segment/metadata/AbstractSegmentMetadataCache.java: ########## @@ -96,41 +89,37 @@ import java.util.stream.StreamSupport; /** - * Broker-side cache of segment metadata which combines segments to identify - * datasources which become "tables" in Calcite. This cache provides the "physical" - * metadata about a datasource which is blended with catalog "logical" metadata - * to provide the final user-view of each datasource. + * An abstract class that listens for segment change events and caches segment metadata and periodically refreshes Review Comment: ```suggestion * An abstract class that listens for segment change events and caches segment metadata. It also periodically refreshes the segments and datasources by xxxx ``` Something like that will help the reader understand the details of this class. ########## server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java: ########## @@ -107,6 +110,23 @@ public ListenableFuture<List<DataSegment>> fetchUsedSegments(String dataSource, ); } + @Override + public ListenableFuture<List<DataSourceInformation>> fetchDataSourceInformation(Set<String> dataSources) + { + final String path = "/druid/coordinator/v1/metadata/dataSourceInformation"; + if (null == dataSources) { + dataSources = new HashSet<>(); Review Comment: Why is this null check here? Should we throw an exception here instead of passing the empty payload to the client? ########## server/src/main/java/org/apache/druid/client/QueryableCoordinatorServerView.java: ########## @@ -0,0 +1,140 @@ +/* + * 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.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import org.apache.druid.client.selector.ServerSelector; +import org.apache.druid.client.selector.TierSelectorStrategy; +import org.apache.druid.guice.ManageLifecycle; +import org.apache.druid.guice.annotations.EscalatedClient; +import org.apache.druid.guice.annotations.Smile; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.http.client.HttpClient; +import org.apache.druid.query.DataSource; +import org.apache.druid.query.QueryToolChestWarehouse; +import org.apache.druid.query.QueryWatcher; +import org.apache.druid.timeline.DataSegment; +import org.apache.druid.timeline.SegmentId; +import org.apache.druid.timeline.VersionedIntervalTimeline; +import org.apache.druid.utils.CollectionUtils; + +import java.util.Collection; +import java.util.Comparator; +import java.util.Map; + +/** + * ServerView of coordinator for the state of segments being loaded in the cluster. + * + * <p>This class extends {@link BrokerServerView} and implements {@link CoordinatorTimeline}. + * The main distinction between this class and {@link CoordinatorServerView} is the maintenance of a timeline + * of {@link ServerSelector} objects, while the other class stores {@link SegmentLoadInfo} object in its timeline.</p> + * + * <p>A new timeline class (implementing {@link TimelineServerView}) is required for + * {@link org.apache.druid.segment.metadata.CoordinatorSegmentMetadataCache}, which will run on the Coordinator.</p> + */ +@ManageLifecycle +public class QueryableCoordinatorServerView extends BrokerServerView implements CoordinatorTimeline +{ + private final FilteredServerInventoryView baseView; + + @Inject + public QueryableCoordinatorServerView( + final QueryToolChestWarehouse warehouse, + final QueryWatcher queryWatcher, + final @Smile ObjectMapper smileMapper, + final @EscalatedClient HttpClient httpClient, + FilteredServerInventoryView baseView, + TierSelectorStrategy tierSelectorStrategy, + ServiceEmitter emitter, + CoordinatorSegmentWatcherConfig segmentWatcherConfig + ) + { + super(warehouse, queryWatcher, smileMapper, httpClient, baseView, tierSelectorStrategy, emitter, new BrokerSegmentWatcherConfig() { + @Override + public boolean isAwaitInitializationOnStart() + { + return segmentWatcherConfig.isAwaitInitializationOnStart(); + } + }); + this.baseView = baseView; + } + + /** + * Since this class maintains a timeline of {@link ServerSelector} objects, + * this method converts and returns a new timeline of the object {@link SegmentLoadInfo}. + * + * @param dataSource dataSoruce + * @return timeline for the given dataSource + */ + @Override + public VersionedIntervalTimeline<String, SegmentLoadInfo> getTimeline(DataSource dataSource) + { + String table = Iterables.getOnlyElement(dataSource.getTableNames()); + VersionedIntervalTimeline<String, ServerSelector> timeline; + + synchronized (lock) { + timeline = timelines.get(table); + } + + VersionedIntervalTimeline<String, SegmentLoadInfo> newTimeline = Review Comment: Nit: rename this to segmentLoadInfoTimeline ########## server/src/main/java/org/apache/druid/segment/metadata/AbstractSegmentMetadataCache.java: ########## @@ -385,55 +378,26 @@ private void startCacheExec() ); } + private void setInitialized(Stopwatch stopwatch) Review Comment: The method name is misleading here. One would assume that it would have something to do with stopWatch but it does entirely different things. Could it be renamed to something else? -- 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]
