Skip to content

Commit

Permalink
A commit to enhance SnapshotUtil, IncrementalBackupUtil and Replicati…
Browse files Browse the repository at this point in the history
…onUtil by adding an option to accept multiple seed source IPs
  • Loading branch information
dmpark04 committed Apr 6, 2015
1 parent 08b4dba commit 14db020
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void run(){

// create the thread and give it a connection + the util
OplogTailThread thd = new OplogTailThread(util, MongoDBConnectionManager.getOplog("oplog", DATABASE_HOST, DATABASE_USER_NAME, DATABASE_PASSWORD).get());
thd.setExitOnStopThread(true);
thd.setExitOnStopThread(true);
List<String> inclusions = new ArrayList<String>();
List<String> exclusions = new ArrayList<String>();
selectCollections(COLLECTIONS_STRING, inclusions, exclusions);
Expand Down Expand Up @@ -110,7 +110,7 @@ public static boolean parseArgs(String...args){
public static void usage(){
System.out.println("usage: IncrementalBackupUtil");
System.out.println(" -c : CSV of collections to process, scoped to the db (database.collection), ! will exclude");
System.out.println(" -h : source database host[:port]");
System.out.println(" -h : CSV of source database host[:port] (ex)x.x.x.x,y.y.y.y)");
System.out.println(" -o : output directory");
System.out.println(" [-u : source database username]");
System.out.println(" [-p : source database password]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static boolean parseArgs(String...args){
public static void usage(){
System.out.println("usage: ReplicationUtil");
System.out.println(" -c : CSV collection string (prefix with ! to exclude)");
System.out.println(" -h : source database host[:port]");
System.out.println(" -h : CSV of source database host[:port] (ex)x.x.x.x,y.y.y.y)");
System.out.println(" [-u : source database username]");
System.out.println(" [-p : source database password]");
System.out.println(" -H : target database host[:port]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ public static void usage(){
System.out.println(" -d : database name");
System.out.println(" -o : output directory");
System.out.println(" [-c : CSV collection string (prefix with ! to exclude)]");
System.out.println(" [-h : database host[:port]]");
System.out.println(" -h : CSV of source database host[:port] (ex)x.x.x.x,y.y.y.y)");
System.out.println(" [-t : threads to run (default 3)]");
System.out.println(" [-u : database username]");
System.out.println(" [-p : database password]");
System.out.println(" [-s : max file size in MB]");
System.out.println(" [-J : output in JSON (default is BSON)]");
System.out.println(" [-Z : compress files]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import java.util.logging.Logger
import scala.collection.JavaConversions._
import scala.collection.mutable._

import scala.util.control._

object SchemaType {
val READ_ONLY = 1
val READ_WRITE = 2
Expand Down Expand Up @@ -90,6 +92,32 @@ object MongoDBConnectionManager {

@throws(classOf[PersistenceException])
def getConnection(schemaName: String, h: String, schema: String, u: String, pw: String, schemaType: Int): DB = {
if (h.indexOf(",") > 0) {
val hosts = h.split(",")
var ret: DB = null
val loop = new Breaks
loop.breakable {
for(oh <- hosts)
{
try {
ret = getConnectionPrivate(schemaName, oh, schema, u, pw, schemaType)
loop.break
} catch {
case e: PersistenceException => {
}
}
}
}
if (ret == null) throw PersistenceException("no replica set member can be connected")
else ret
}
else {
getConnectionPrivate(schemaName, h, schema, u, pw, schemaType)
}
}

@throws(classOf[PersistenceException])
private def getConnectionPrivate(schemaName: String, h: String, schema: String, u: String, pw: String, schemaType: Int): DB = {
if (h.indexOf(":") > 0) getConnection(schemaName, h.split(":")(0), h.split(":")(1).toInt, schema, u, pw, schemaType)
else getConnection(schemaName, h, 27017, schema, u, pw, schemaType)
}
Expand Down Expand Up @@ -128,6 +156,7 @@ object MongoDBConnectionManager {
var mongo = new Mongo(sa)

var db = mongo.getDB(schema)
db.getStats() // Command as a connection check to make a connection to the server for availability check of the server
val replicationType = detectReplicationType(db, username, password)

if (replicationType == Member.RS) {
Expand Down

0 comments on commit 14db020

Please sign in to comment.