Skip to content

Commit

Permalink
support specify authentication database
Browse files Browse the repository at this point in the history
  • Loading branch information
tfs-taobao committed Feb 22, 2017
1 parent 1ca941c commit 57755b0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions config.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions run.simple.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/jmongosysbenchexecute.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 5 additions & 3 deletions src/jmongosysbenchload.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ public class jmongosysbenchload {
public static int serverPort;
public static String userName;
public static String passWord;
public static String authdb;

public static int allDone = 0;

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);
}

Expand All @@ -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")) {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 57755b0

Please sign in to comment.