dharakk commented on a change in pull request #6286: URL: https://github.com/apache/incubator-pinot/pull/6286#discussion_r534650637
########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/assignment/segment/OfflineDimTableSegmentAssignment.java ########## @@ -0,0 +1,80 @@ +/** + * 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.pinot.controller.helix.core.assignment.segment; + +import com.google.common.base.Preconditions; +import org.apache.commons.configuration.Configuration; +import org.apache.helix.HelixManager; +import org.apache.pinot.common.assignment.InstancePartitions; +import org.apache.pinot.common.tier.Tier; +import org.apache.pinot.common.utils.CommonConstants; +import org.apache.pinot.common.utils.config.TagNameUtils; +import org.apache.pinot.common.utils.helix.HelixHelper; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TenantConfig; +import org.apache.pinot.spi.config.table.assignment.InstancePartitionsType; + +import javax.annotation.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +public class OfflineDimTableSegmentAssignment implements SegmentAssignment { + + private HelixManager _helixManager; + private String _offlineTableName; + private boolean _isDimTable; + private TenantConfig _tenantConfig; + + @Override + public void init(HelixManager helixManager, TableConfig tableConfig) { + _helixManager = helixManager; + _offlineTableName = tableConfig.getTableName(); + _tenantConfig = tableConfig.getTenantConfig(); + _isDimTable = Boolean.parseBoolean(tableConfig.getIsDimTable()); + Preconditions.checkState(_isDimTable, "Not a dimension table: %s" + _offlineTableName); + } + + @Override + public List<String> assignSegment(String segmentName, Map<String, Map<String, String>> currentAssignment, Map<InstancePartitionsType, InstancePartitions> instancePartitionsMap) { + String serverTag = TagNameUtils.extractOfflineServerTag(_tenantConfig); + + List<String> instances = HelixHelper.getInstancesWithTag(_helixManager, serverTag); + int numInstances = instances.size(); + Preconditions.checkState(numInstances > 0, "No instance found with tag: %s", serverTag); + + // Sort the instances and rotate the list based on the table name Review comment: I was taking my cue from other places where we were getting all the instances under a tag, but you are right there is no need here, removed it. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org