}
shardList.put(shard, shardObj);
}
result.put("shards", shardList);
FormDialog dia = (FormDialog) getBoundUnit(Item.regenRSList);
dia.setStringFieldValue(Item.regenRSListArea, txt);
if (!dia.show()) {
return;
}
DB config = cmongo.getDB("config");
// add database record
BasicDBObject doc = new BasicDBObject("_id", db);
doc.put("partitioned", true);
doc.put("primary", primaryShard);
config.getCollection("databases").save(doc);
// add collection record
doc = new BasicDBObject("_id", ns);
doc.put("lastmod", new Date());
doc.put("dropped", false);
doc.put("key", shardKey);
doc.put("unique", unique);
config.getCollection("collections").save(doc);
final DBCollection chunks = config.getCollection("chunks");
long count = chunks.count(new BasicDBObject("ns", ns));
if (count > 0) {
dia = (FormDialog) getBoundUnit(Item.regenDeleteChunks);
if (dia.show()) {
chunks.remove(new BasicDBObject("ns", ns));
} else {
return;
}
}
// add temp collection to sort chunks with shard key
final DBCollection tmpchunks = config.getCollection("_tmpchunks_" + col);
tmpchunks.drop();
// should be safe environment, and dup keys should be ignored
tmpchunks.setWriteConcern(WriteConcern.NORMAL);
// can use shardKey as unique _id
// tmpchunks.ensureIndex(shardKey, "shardKey", true);
// create filter for shard fields
final DBObject shardKeyFilter = new BasicDBObject();
// final DBObject shardKeyDescend = new BasicDBObject();
boolean hasId = false;
for (String key : shardKey.keySet()) {
shardKeyFilter.put(key, 1);
if (key.equals("_id")) {
hasId = true;
}
}
if (!hasId) {
shardKeyFilter.put("_id", 0);
}
dia = (FormDialog) getBoundUnit(Item.regenConfirm);
if (!dia.show()) {
return;
}
// now fetch all records from each shard
final AtomicInteger todo = new AtomicInteger(mongoToShard.size());