private List<Shard> getShards(boolean isMongos) { List<Shard> shards = new ArrayList<>(); if (isMongos) { try (DBCursor cursor = getConfigDb().getCollection("shards").find()) { while (cursor.hasNext()) { DBObject item = cursor.next(); List<ServerAddress> shardServers = getServerAddressForReplica(item); if (shardServers != null) { String shardName = item.get(MongoDBRiver.MONGODB_ID_FIELD).toString(); MongoClient shardClient = mongoClientService.getMongoShardClient(definition, shardServers); ensureIsReplicaSet(shardClient); Timestamp<?> latestOplogTimestamp = getCurrentOplogTimestamp(shardClient); shards.add(new Shard(shardName, shardServers, latestOplogTimestamp)); } } } return shards; } else { ensureIsReplicaSet(clusterClient); List<ServerAddress> servers = clusterClient.getServerAddressList(); Timestamp<?> latestOplogTimestamp = getCurrentOplogTimestamp(clusterClient); shards.add(new Shard("unsharded", servers, latestOplogTimestamp)); return shards; } }
} else { for (Shard shard : config.getShards()) { if (startTimestamp == null || shard.getLatestOplogTimestamp().compareTo(startTimestamp) < 1) { startTimestamp = shard.getLatestOplogTimestamp(); if (initialImportTimestamp == null || shard.getLatestOplogTimestamp().compareTo(initialImportTimestamp) < 1) { initialImportTimestamp = shard.getLatestOplogTimestamp(); Timestamp shardSlurperStartTimestamp = slurperStartTimestamp != null ? slurperStartTimestamp : shard.getLatestOplogTimestamp(); MongoClient mongoClient = mongoClientService.getMongoShardClient(definition, shard.getReplicas()); Thread tailerThread = EsExecutors.daemonThreadFactory( settings.globalSettings(), "mongodb_river_slurper_" + shard.getName() + ":" + definition.getIndexName() ).newThread(new OplogSlurper(MongoDBRiver.this, shardSlurperStartTimestamp, mongoClusterClient, mongoClient)); tailerThreads.add(tailerThread);