Skip to content

Commit

Permalink
Merge pull request #126 from jgi-kbase/dev-add_retryWrites
Browse files Browse the repository at this point in the history
Add retryWrites
  • Loading branch information
Xiangs18 authored Sep 5, 2024
2 parents 6c58bc4 + 1eb5fc1 commit 6dfadab
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Assembly Homology Service release notes

## 0.1.5

* The MongoDB clients have been updated to the most recent version.
* Added the ``mongo-retrywrites`` configuration setting in ``deploy.cfg``, defaulting to
``false``.

## 0.1.4

* Switched the build system from Ant to Gradle. As such, all build artifacts, including the
Expand Down
4 changes: 4 additions & 0 deletions deploy.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ mongo-db=
mongo-user=
mongo-pwd=

# Whether to enable ('true') the MongoDB retryWrites parameter or not (anything other than 'true').
# See https://www.mongodb.com/docs/manual/core/retryable-writes/
mongo-retrywrites=false

# A directory to use for temporary files:
temp-dir=./assemblyhomology_temp

Expand Down
1 change: 1 addition & 0 deletions deployment/conf/.templates/deployment.cfg.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mongo-host={{ default .Env.mongo_host "ci-mongo" }}
mongo-db={{ default .Env.mongo_db "assemblyhomology" }}
mongo-user={{ default .Env.mongo_user "" }}
mongo-pwd={{ default .Env.mongo_pwd "" }}
mongo-retrywrites={{ default .Env.mongo_retrywrites "false" }}
temp-dir={{ default .Env.temp_dir "./tmp_ah" }}
minhash-timeout={{ default .Env.minhash_timeout "60" }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public AssemblyHomologyBuilder(

private MongoClient buildMongo(final AssemblyHomologyConfig c) throws StorageInitException {
//TODO ZLATER MONGO handle shards & replica sets
final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder().applyToClusterSettings(
builder -> builder.hosts(Arrays.asList(new ServerAddress(c.getMongoHost()))));
final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder()
.retryWrites(c.getMongoRetryWrites())
.applyToClusterSettings(builder -> builder.hosts(
Arrays.asList(new ServerAddress(c.getMongoHost()))));
try {
if (c.getMongoUser().isPresent()) {
final MongoCredential creds = MongoCredential.createCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class AssemblyHomologyConfig {
private static final String KEY_MONGO_DB = "mongo-db";
private static final String KEY_MONGO_USER = "mongo-user";
private static final String KEY_MONGO_PWD = "mongo-pwd";
private static final String KEY_MONGO_RETRY_WRITES = "mongo-retrywrites";
private static final String KEY_TEMP_DIR = "temp-dir";
private static final String KEY_MINHASH_TIMEOUT = "minhash-timeout";
private static final String KEY_IGNORE_IP_HEADERS = "dont-trust-x-ip-headers";
Expand All @@ -78,6 +79,7 @@ public class AssemblyHomologyConfig {
private final String mongoDB;
private final Optional<String> mongoUser;
private final Optional<char[]> mongoPwd;
private final boolean mongoRetryWrites;
private final Path tempDir;
private final int minhashTimeoutSec;
private final SLF4JAutoLogger logger;
Expand Down Expand Up @@ -137,6 +139,7 @@ private AssemblyHomologyConfig(
tempDir = Paths.get(getString(KEY_TEMP_DIR, cfg, true));
mongoHost = getString(KEY_MONGO_HOST, cfg, true);
mongoDB = getString(KEY_MONGO_DB, cfg, true);
mongoRetryWrites = TRUE.equals(getString(KEY_MONGO_RETRY_WRITES, cfg));
mongoUser = Optional.fromNullable(getString(KEY_MONGO_USER, cfg));
Optional<String> mongop = Optional.fromNullable(getString(KEY_MONGO_PWD, cfg));
if (mongoUser.isPresent() ^ mongop.isPresent()) {
Expand Down Expand Up @@ -328,13 +331,20 @@ public String getMongoHost() {
return mongoHost;
}

/** Ge the MongoDB database to use.
/** Get the MongoDB database to use.
* @return the database.
*/
public String getMongoDatabase() {
return mongoDB;
}

/** Get whether the MongoDB retryWrites parameter should be set.
* @return True to set the retryWrites parameter when connecting to MongoDB, false otherwise.
*/
public boolean getMongoRetryWrites() {
return mongoRetryWrites;
}

/** Get the MongoDB user name, if any. If provided a password will also be provided.
* @return the user name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Root {
//TODO ZLATER ROOT add configurable contact email or link
//TODO ZLATER swagger

private static final String VERSION = "0.1.4";
private static final String VERSION = "0.1.5";
private static final String SERVER_NAME = "Assembly Homology service";

/** Return the root information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void sysPropAssemHomolNoUserNoIgnoreIPNoTimeout() throws Throwable {
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.absent()));
assertThat("incorrect mongo pwd", cfg.getMongoPwd(), is(Optional.absent()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect minhash timeout", cfg.getMinhashTimeoutSec(), is(30));
assertThat("incorrect temp dir", cfg.getPathToTemporaryFileDirectory(),
is(Paths.get("/foo/bar/baz")));
Expand All @@ -106,6 +107,7 @@ public void sysPropKBNoUserNoIgnoreIPNoTimout() throws Throwable {
"mongo-db=database\n" +
"mongo-user=\n" +
"mongo-pwd=\n" +
"mongo-retrywrites=\n" +
"minhash-timeout=\n" +
"dont-trust-x-ip-headers=true1\n" +
"temp-dir=/foo/bar/baz\n" +
Expand All @@ -121,6 +123,7 @@ public void sysPropKBNoUserNoIgnoreIPNoTimout() throws Throwable {
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.absent()));
assertThat("incorrect mongo pwd", cfg.getMongoPwd(), is(Optional.absent()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect minhash timeout", cfg.getMinhashTimeoutSec(), is(30));
assertThat("incorrect temp dir", cfg.getPathToTemporaryFileDirectory(),
is(Paths.get("/foo/bar/baz")));
Expand All @@ -143,6 +146,7 @@ public void envVarAssemHomolWithUserWithIgnoreIPWithTimeoutWithFilters() throws
"mongo-db=database\n" +
"mongo-user=userfoo\n" +
"mongo-pwd=somepwd\n" +
"mongo-retrywrites= false \n" +
"minhash-timeout=600\n" +
"dont-trust-x-ip-headers=true\n" +
"temp-dir=/foo/bar/baz\n" +
Expand All @@ -164,6 +168,7 @@ public void envVarAssemHomolWithUserWithIgnoreIPWithTimeoutWithFilters() throws
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.of("userfoo")));
assertThat("incorrect mongo pwd", cfg.getMongoPwd().get(),
equalTo("somepwd".toCharArray()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect minhash timeout", cfg.getMinhashTimeoutSec(), is(600));
assertThat("incorrect temp dir", cfg.getPathToTemporaryFileDirectory(),
is(Paths.get("/foo/bar/baz")));
Expand All @@ -187,6 +192,7 @@ public void envVarKBWithUserWithIgnoreIPWithTimeout() throws Throwable {
"mongo-db=database\n" +
"mongo-user=userfoo\n" +
"mongo-pwd=somepwd\n" +
"mongo-retrywrites=true\n" +
"minhash-timeout=15\n" +
"dont-trust-x-ip-headers=true\n" +
"temp-dir=/foo/bar/baz")
Expand All @@ -201,6 +207,7 @@ public void envVarKBWithUserWithIgnoreIPWithTimeout() throws Throwable {
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.of("userfoo")));
assertThat("incorrect mongo pwd", cfg.getMongoPwd().get(),
equalTo("somepwd".toCharArray()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(true));
assertThat("incorrect minhash timeout", cfg.getMinhashTimeoutSec(), is(15));
assertThat("incorrect temp dir", cfg.getPathToTemporaryFileDirectory(),
is(Paths.get("/foo/bar/baz")));
Expand All @@ -224,6 +231,7 @@ public void pathNoUserNoIgnoreIPStdLogger() throws Throwable {
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.absent()));
assertThat("incorrect mongo pwd", cfg.getMongoPwd(), is(Optional.absent()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect minhash timeout", cfg.getMinhashTimeoutSec(), is(30));
assertThat("incorrect temp dir", cfg.getPathToTemporaryFileDirectory(),
is(Paths.get("/foo/bar/baz")));
Expand All @@ -241,6 +249,7 @@ public void pathWithUserWithIgnoreIPNullLoggerWithFilters() throws Throwable {
"mongo-db=database\n" +
"mongo-user=userfoo\n" +
"mongo-pwd=somepwd\n" +
"mongo-retrywrites=true \n" +
"dont-trust-x-ip-headers=true\n" +
"temp-dir=/foo/bar/baz\n" +
"filters=foo, \t , bar \n" +
Expand All @@ -256,6 +265,7 @@ public void pathWithUserWithIgnoreIPNullLoggerWithFilters() throws Throwable {
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.of("userfoo")));
assertThat("incorrect mongo pwd", cfg.getMongoPwd().get(),
equalTo("somepwd".toCharArray()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(true));
assertThat("incorrect minhash timeout", cfg.getMinhashTimeoutSec(), is(30));
assertThat("incorrect temp dir", cfg.getPathToTemporaryFileDirectory(),
is(Paths.get("/foo/bar/baz")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class RootTest {

public static final String SERVER_VER = "0.1.4";
public static final String SERVER_VER = "0.1.5";
private static final String GIT_ERR =
"Missing git commit file gitcommit, should be in us.kbase.assemblyhomology";

Expand Down

0 comments on commit 6dfadab

Please sign in to comment.