while (cur.hasNext()) {
final BasicDBObject row = (BasicDBObject) cur.next();
BasicDBObject chunkLowerBound = (BasicDBObject) row.get("min");
BasicDBObject chunkUpperBound = (BasicDBObject) row.get("max");
MongoInputSplit chunkSplit = createSplitFromBounds(chunkLowerBound, chunkUpperBound);
chunkSplit.setInputURI(inputURI);
String shard = (String) row.get("shard");
if (targetShards) {
//The job is configured to target shards, so replace the
//mongos hostname with the host of the shard's servers
String shardHosts = shardsMap.get(shard);
if (shardHosts == null) {
throw new SplitFailedException("Couldn't find shard ID: " + shard + " in config.shards.");
}
MongoClientURI newURI = rewriteURI(inputURI, shardHosts);
chunkSplit.setInputURI(newURI);
} else if (mongosHostNames.size() > 0) {
//Multiple mongos hosts are specified, so
//choose a host name in round-robin fashion
//and rewrite the URI using that hostname.
//This evenly distributes the load to avoid
//pegging a single mongos instance.
String roundRobinHost = mongosHostNames.get(numChunks % mongosHostNames.size());
MongoClientURI newURI = rewriteURI(inputURI, roundRobinHost);
chunkSplit.setInputURI(newURI);
}
LinkedList<InputSplit> shardList = shardToSplits.get(shard);
if (shardList == null) {
shardList = new LinkedList<InputSplit>();
shardToSplits.put(shard, shardList);