kfaraz commented on code in PR #13197: URL: https://github.com/apache/druid/pull/13197#discussion_r997808118
########## server/src/main/java/org/apache/druid/server/coordinator/SegmentStateManager.java: ########## @@ -0,0 +1,261 @@ +/* + * 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.google.inject.Inject; +import org.apache.druid.client.ServerInventoryView; +import org.apache.druid.java.util.emitter.EmittingLogger; +import org.apache.druid.metadata.SegmentsMetadataManager; +import org.apache.druid.timeline.DataSegment; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Manages state of segments being loaded. + */ +public class SegmentStateManager +{ + private static final EmittingLogger log = new EmittingLogger(SegmentStateManager.class); + + private final LoadQueueTaskMaster taskMaster; + private final ServerInventoryView serverInventoryView; + private final SegmentsMetadataManager segmentsMetadataManager; + + private final ConcurrentHashMap<String, TierLoadingState> currentlyMovingSegments = + new ConcurrentHashMap<>(); + private final ConcurrentHashMap<String, TierLoadingState> currentlyReplicatingSegments + = new ConcurrentHashMap<>(); + + @Inject + public SegmentStateManager( + ServerInventoryView serverInventoryView, + SegmentsMetadataManager segmentsMetadataManager, + LoadQueueTaskMaster taskMaster + ) + { + this.serverInventoryView = serverInventoryView; + this.segmentsMetadataManager = segmentsMetadataManager; + this.taskMaster = taskMaster; + } + + /** + * Queues load of a replica of the segment on the given server. + */ + public boolean loadSegment( + DataSegment segment, + ServerHolder server, + boolean isPrimary, + ReplicationThrottler throttler + ) + { + final String tier = server.getServer().getTier(); + final LoadPeonCallback callback; + if (isPrimary) { + // Primary replicas are not subject to throttling + callback = null; + } else if (canLoadReplica(tier, throttler)) { + throttler.incrementAssignedReplicas(tier); + + final TierLoadingState replicatingInTier = currentlyReplicatingSegments + .computeIfAbsent(tier, t -> new TierLoadingState(throttler.getMaxLifetime())); + replicatingInTier.addSegment(segment.getId(), server.getServer().getHost()); + callback = success -> replicatingInTier.removeSegment(segment.getId()); + } else { + throttler.incrementThrottledReplicas(tier); + return false; + } + + try { + if (!server.startOperation(segment, SegmentState.LOADING)) { + return false; + } + + server.getPeon().loadSegment( + segment, + isPrimary ? SegmentAction.LOAD_AS_PRIMARY : SegmentAction.LOAD_AS_REPLICA, Review Comment: Okay, I will include those changes in this PR itself. I am going with the term LOAD vs PRIORITY_LOAD. -- 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]
