use of com.linkedin.pinot.controller.helix.core.sharding.SegmentAssignmentStrategy in project pinot by linkedin.
the class PinotHelixResourceManager method addNewOfflineSegment.
/**
* Helper method to add the passed in offline segment to the helix cluster.
* - Gets the segment name and the table name from the passed in segment meta-data.
* - Identifies the instance set onto which the segment needs to be added, based on
* segment assignment strategy and replicas in the table config in the property-store.
* - Updates ideal state such that the new segment is assigned to required set of instances as per
* the segment assignment strategy and replicas.
*
* @param segmentMetadata Meta-data for the segment, used to access segmentName and tableName.
* @throws JsonParseException
* @throws JsonMappingException
* @throws JsonProcessingException
* @throws JSONException
* @throws IOException
*/
private void addNewOfflineSegment(final SegmentMetadata segmentMetadata) throws JsonParseException, JsonMappingException, JsonProcessingException, JSONException, IOException {
final AbstractTableConfig offlineTableConfig = ZKMetadataProvider.getOfflineTableConfig(_propertyStore, segmentMetadata.getTableName());
final String segmentName = segmentMetadata.getName();
final String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(segmentMetadata.getTableName());
if (!SEGMENT_ASSIGNMENT_STRATEGY_MAP.containsKey(offlineTableName)) {
SEGMENT_ASSIGNMENT_STRATEGY_MAP.put(offlineTableName, SegmentAssignmentStrategyFactory.getSegmentAssignmentStrategy(offlineTableConfig.getValidationConfig().getSegmentAssignmentStrategy()));
}
final SegmentAssignmentStrategy segmentAssignmentStrategy = SEGMENT_ASSIGNMENT_STRATEGY_MAP.get(offlineTableName);
// Passing a callable to this api to avoid helixHelper having which is in pinot-common having to
// depend upon pinot-controller.
Callable<List<String>> getInstancesForSegment = new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
final IdealState currentIdealState = _helixAdmin.getResourceIdealState(_helixClusterName, offlineTableName);
final Set<String> currentInstanceSet = currentIdealState.getInstanceSet(segmentName);
if (currentInstanceSet.isEmpty()) {
final String serverTenant = ControllerTenantNameBuilder.getOfflineTenantNameForTenant(offlineTableConfig.getTenantConfig().getServer());
final int replicas = Integer.parseInt(offlineTableConfig.getValidationConfig().getReplication());
return segmentAssignmentStrategy.getAssignedInstances(_helixAdmin, _helixClusterName, segmentMetadata, replicas, serverTenant);
} else {
return new ArrayList<String>(currentIdealState.getInstanceSet(segmentName));
}
}
};
HelixHelper.addSegmentToIdealState(_helixZkManager, offlineTableName, segmentName, getInstancesForSegment);
}
Aggregations