From 57755b01916a93c1327d3d383460edffdd47ffa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E9=9D=92?= Date: Wed, 22 Feb 2017 15:44:07 +0800 Subject: [PATCH] support specify authentication database --- config.bash | 3 +++ run.simple.bash | 4 ++-- src/jmongosysbenchexecute.java | 8 +++++--- src/jmongosysbenchload.java | 8 +++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config.bash b/config.bash index c030e16..4d83077 100644 --- a/config.bash +++ b/config.bash @@ -11,6 +11,9 @@ export USERNAME=myuser # database password to use for USERNAME export PASSWORD=mypass +# --authenticationDatabase +export AUTHDB=admin + # name of the server to connect to export MONGO_SERVER=localhost diff --git a/run.simple.bash b/run.simple.bash index 1eb780c..cb7cce6 100755 --- a/run.simple.bash +++ b/run.simple.bash @@ -35,7 +35,7 @@ if [[ $DOLOAD = "yes" ]]; then rm -f $BENCHMARK_TSV T="$(date +%s)" - java -cp $CLASSPATH:$PWD/src jmongosysbenchload $NUM_COLLECTIONS $DB_NAME $NUM_LOADER_THREADS $NUM_DOCUMENTS_PER_COLLECTION $NUM_DOCUMENTS_PER_INSERT $NUM_INSERTS_PER_FEEDBACK $NUM_SECONDS_PER_FEEDBACK $BENCHMARK_TSV $MONGO_COMPRESSION $MONGO_BASEMENT $WRITE_CONCERN $MONGO_SERVER $MONGO_PORT "$USERNAME" "$PASSWORD" + java -cp $CLASSPATH:$PWD/src jmongosysbenchload $NUM_COLLECTIONS $DB_NAME $NUM_LOADER_THREADS $NUM_DOCUMENTS_PER_COLLECTION $NUM_DOCUMENTS_PER_INSERT $NUM_INSERTS_PER_FEEDBACK $NUM_SECONDS_PER_FEEDBACK $BENCHMARK_TSV $MONGO_COMPRESSION $MONGO_BASEMENT $WRITE_CONCERN $MONGO_SERVER $MONGO_PORT "$USERNAME" "$PASSWORD" "$AUTHDB" echo "" | tee -a $LOG_NAME T="$(($(date +%s)-T))" printf "`date` | sysbench loader duration = %02d:%02d:%02d:%02d\n" "$((T/86400))" "$((T/3600%24))" "$((T/60%60))" "$((T%60))" | tee -a $LOG_NAME @@ -53,7 +53,7 @@ if [[ $DOQUERY = "yes" ]]; then rm -f $BENCHMARK_TSV T="$(date +%s)" - java -cp $CLASSPATH:$PWD/src jmongosysbenchexecute $NUM_COLLECTIONS $DB_NAME $NUM_WRITER_THREADS $NUM_DOCUMENTS_PER_COLLECTION $NUM_SECONDS_PER_FEEDBACK $BENCHMARK_TSV $SYSBENCH_AUTO_COMMIT $RUN_TIME_SECONDS $SYSBENCH_RANGE_SIZE $SYSBENCH_POINT_SELECTS $SYSBENCH_SIMPLE_RANGES $SYSBENCH_SUM_RANGES $SYSBENCH_ORDER_RANGES $SYSBENCH_DISTINCT_RANGES $SYSBENCH_INDEX_UPDATES $SYSBENCH_NON_INDEX_UPDATES $SYSBENCH_INSERTS $WRITE_CONCERN $MAX_TPS $MONGO_SERVER $MONGO_PORT $SEED "$USERNAME" "$PASSWORD" | tee -a $LOG_NAME + java -cp $CLASSPATH:$PWD/src jmongosysbenchexecute $NUM_COLLECTIONS $DB_NAME $NUM_WRITER_THREADS $NUM_DOCUMENTS_PER_COLLECTION $NUM_SECONDS_PER_FEEDBACK $BENCHMARK_TSV $SYSBENCH_AUTO_COMMIT $RUN_TIME_SECONDS $SYSBENCH_RANGE_SIZE $SYSBENCH_POINT_SELECTS $SYSBENCH_SIMPLE_RANGES $SYSBENCH_SUM_RANGES $SYSBENCH_ORDER_RANGES $SYSBENCH_DISTINCT_RANGES $SYSBENCH_INDEX_UPDATES $SYSBENCH_NON_INDEX_UPDATES $SYSBENCH_INSERTS $WRITE_CONCERN $MAX_TPS $MONGO_SERVER $MONGO_PORT $SEED "$USERNAME" "$PASSWORD" "$AUTHDB" | tee -a $LOG_NAME echo "" | tee -a $LOG_NAME T="$(($(date +%s)-T))" printf "`date` | sysbench benchmark duration = %02d:%02d:%02d:%02d\n" "$((T/86400))" "$((T/3600%24))" "$((T/60%60))" "$((T%60))" | tee -a $LOG_NAME diff --git a/src/jmongosysbenchexecute.java b/src/jmongosysbenchexecute.java index 1327aaa..fab959e 100644 --- a/src/jmongosysbenchexecute.java +++ b/src/jmongosysbenchexecute.java @@ -50,6 +50,7 @@ public class jmongosysbenchexecute { public static int serverPort; public static String userName; public static String passWord; + public static String authdb; public static int oltpRangeSize; public static int oltpPointSelects; @@ -71,12 +72,12 @@ public jmongosysbenchexecute() { } public static void main (String[] args) throws Exception { - if (args.length != 24) { + if (args.length != 25) { logMe("*** ERROR : CONFIGURATION ISSUE ***"); logMe("jsysbenchexecute [number of collections] [database name] [number of writer threads] [documents per collection] [seconds feedback] "+ "[log file name] [auto commit Y/N] [runtime (seconds)] [range size] [point selects] "+ "[simple ranges] [sum ranges] [order ranges] [distinct ranges] [index updates] [non index updates] [inserts] [writeconcern] "+ - "[max tps] [server] [port] [seed] [username] [password]"); + "[max tps] [server] [port] [seed] [username] [password] [authdb]"); System.exit(1); } @@ -104,6 +105,7 @@ public static void main (String[] args) throws Exception { rngSeed = Long.valueOf(args[21]); userName = args[22]; passWord = args[23]; + authdb = args[24]; maxThreadTPS = (maxTPS / writerThreads) + 1; @@ -163,7 +165,7 @@ else if ((myWriteConcern.toLowerCase().equals("safe"))) { if (userName.isEmpty() || userName.equalsIgnoreCase("none")) { m = new MongoClient(srvrAdd, clientOptions); } else { - MongoCredential credential = MongoCredential.createCredential(userName, dbName, passWord.toCharArray()); + MongoCredential credential = MongoCredential.createCredential(userName, authdb, passWord.toCharArray()); m = new MongoClient(srvrAdd, Arrays.asList(credential), clientOptions); } diff --git a/src/jmongosysbenchload.java b/src/jmongosysbenchload.java index 9388c30..9481a0a 100644 --- a/src/jmongosysbenchload.java +++ b/src/jmongosysbenchload.java @@ -41,6 +41,7 @@ public class jmongosysbenchload { public static int serverPort; public static String userName; public static String passWord; + public static String authdb; public static int allDone = 0; @@ -48,9 +49,9 @@ public jmongosysbenchload() { } public static void main (String[] args) throws Exception { - if (args.length != 15) { + if (args.length != 16) { logMe("*** ERROR : CONFIGURATION ISSUE ***"); - logMe("jsysbenchload [number of collections] [database name] [number of writer threads] [documents per collection] [documents per insert] [inserts feedback] [seconds feedback] [log file name] [compression type] [basement node size (bytes)] [writeconcern] [server] [port] [username] [password]"); + logMe("jsysbenchload [number of collections] [database name] [number of writer threads] [documents per collection] [documents per insert] [inserts feedback] [seconds feedback] [log file name] [compression type] [basement node size (bytes)] [writeconcern] [server] [port] [username] [password] [authdb]"); System.exit(1); } @@ -69,6 +70,7 @@ public static void main (String[] args) throws Exception { serverPort = Integer.valueOf(args[12]); userName = args[13]; passWord = args[14]; + authdb = args[15]; WriteConcern myWC = new WriteConcern(); if (myWriteConcern.toLowerCase().equals("fsync_safe")) { @@ -114,7 +116,7 @@ else if ((myWriteConcern.toLowerCase().equals("safe"))) { if (userName.isEmpty() || userName.equalsIgnoreCase("none")) { m = new MongoClient(srvrAdd, clientOptions); } else { - MongoCredential credential = MongoCredential.createCredential(userName, dbName, passWord.toCharArray()); + MongoCredential credential = MongoCredential.createCredential(userName, authdb, passWord.toCharArray()); m = new MongoClient(srvrAdd, Arrays.asList(credential), clientOptions); }