} catch (UnknownHostException e) {
throw new IllegalStateException( " Unable to connect to MongoDB at '" + uri + "'", e);
}
DB db = mongo.getDB(uri.getDatabase());
DBCollection coll = db.getCollection(uri.getCollection());
final CommandResult stats = coll.getStats();
final boolean isSharded = stats.getBoolean( "sharded", false );
log.info("Collection Sharded? " + isSharded);
final DBObject splitKey = getInputSplitKey(splitKeyPattern);
final String ns = coll.getFullName();
final DBObject q = getDBObject(inputQuery);
log.info( "Calculating unsharded input splits on namespace '" + ns
+ "' with Split Key '" + splitKey.toString()
+ "' and a split size of '" + splitSize + "'mb per" );
/*
* examples:
* { splitVector : "blog.post" , keyPattern:{x:1} , min:{x:10} , max:{x:20}, maxChunkSize:200 }
* maxChunkSize unit in MBs
* May optionally specify 'maxSplitPoints' and 'maxChunkObjects' to avoid traversing the whole chunk
*
* { splitVector : "blog.post" , keyPattern:{x:1} , min:{x:10} , max:{x:20}, force: true }
* 'force' will produce one split point even if data is small; defaults to false
* NOTE: This command may take a while to run
*/
final DBObject cmd = BasicDBObjectBuilder.start("splitVector", ns).
add( "keyPattern", splitKey ).
add( "force", false ).
add( "maxChunkSize", splitSize ).get();
log.trace( "Issuing Command: " + cmd );
CommandResult data = coll.getDB().command(cmd);
if (data.containsField("$err")){
throw new IllegalArgumentException("Error calculating splits: " + data);
}else if ((Double) data.get("ok") != 1.0){
throw new IllegalArgumentException("Unable to calculate input splits: " + ((String) data.get( "errmsg" )));
}
BasicDBList splitData = (BasicDBList)data.get("splitKeys");
if (splitData.size() <= 1) {
// no splits really. Just do the whole thing data is likely small
splits.add(createParamSplit(this.param, q, null, null));
}else {
log.info( "Calculated " + splitData.size() + " splits." );