{
Stopwatch splitTimer = Stopwatch.createStarted();
checkNotNull(partitions, "partitions is null");
if (partitions.isEmpty()) {
return new FixedSplitSource(connectorId, ImmutableList.<ConnectorSplit>of());
}
Map<String, Node> nodesById = uniqueIndex(nodeManager.getActiveNodes(), getIdentifierFunction());
List<ConnectorSplit> splits = new ArrayList<>();
Multimap<Long, Entry<UUID, String>> partitionShardNodes = shardManager.getShardNodesByPartition(tableHandle);
for (ConnectorPartition partition : partitions) {
RaptorPartition raptorPartition = checkType(partition, RaptorPartition.class, "partition");
ImmutableMultimap.Builder<UUID, String> shardNodes = ImmutableMultimap.builder();
for (Entry<UUID, String> shardNode : partitionShardNodes.get(raptorPartition.getRaptorPartitionId())) {
shardNodes.put(shardNode.getKey(), shardNode.getValue());
}
for (Map.Entry<UUID, Collection<String>> entry : shardNodes.build().asMap().entrySet()) {
List<HostAddress> addresses = getAddressesForNodes(nodesById, entry.getValue());
checkState(!addresses.isEmpty(), "no host for shard %s found: %s", entry.getKey(), entry.getValue());
ConnectorSplit split = new RaptorSplit(entry.getKey(), addresses);
splits.add(split);
}
}
log.debug("Split retrieval for %d partitions (%d splits): %dms", partitions.size(), splits.size(), splitTimer.elapsed(TimeUnit.MILLISECONDS));
// The query engine assumes that splits are returned in a somewhat random fashion. The Raptor split manager,
// because it loads the data from a database table, will return the splits somewhat ordered by node ID,
// so only a subset of nodes are fired up. Shuffle the splits to ensure random distribution.
Collections.shuffle(splits);
return new FixedSplitSource(connectorId, splits);
}