Skip to content

Commit e1103b2

Browse files
committed
MongoDriverSettings.timescaleMS.
Combine recoveryPollingMS and flushTimeoutMS into a single "timescale" setting. Tuning a multitude of individual timeouts is not a reasonable thing to ask users to do. Just ask them about how responsive they want the system to be, and then we can take the responsibility of balancing the actual individual timeout settings in a way that makes sense given how all the parts of this rather complex driver work together. This is something I already did in the SQL driver. I'll likely also copy the patienceFactor idea too.
1 parent 6b73a67 commit e1103b2

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

bosk-mongo/src/main/java/works/bosk/drivers/mongo/ChangeReceiver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ChangeReceiver implements Closeable {
5959
ex.scheduleWithFixedDelay(
6060
this::connectionLoop,
6161
0,
62-
settings.recoveryPollingMS(),
62+
settings.timescaleMS(),
6363
MILLISECONDS
6464
);
6565
}
@@ -73,7 +73,7 @@ public void close() {
7373

7474
/**
7575
* This method has a loop to do immediate reconnections and skip the
76-
* {@link MongoDriverSettings#recoveryPollingMS() recoveryPollingMS} delay,
76+
* {@link MongoDriverSettings#timescaleMS() recoveryPollingMS} delay,
7777
* but besides that, exiting this method has the same effect as continuing
7878
* around the loop.
7979
*/
@@ -200,7 +200,7 @@ private void addContextToException(Throwable x) {
200200
private MongoChangeStreamCursor<ChangeStreamDocument<BsonDocument>> openCursor() {
201201
MongoChangeStreamCursor<ChangeStreamDocument<BsonDocument>> result = collection
202202
.watch()
203-
.maxAwaitTime(settings.recoveryPollingMS(), MILLISECONDS)
203+
.maxAwaitTime(settings.timescaleMS(), MILLISECONDS)
204204
.cursor();
205205
LOGGER.debug("Cursor is open");
206206
return result;

bosk-mongo/src/main/java/works/bosk/drivers/mongo/FlushLock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void awaitRevision(BsonInt64 revision) throws InterruptedException, FlushFailure
9292
}
9393
if (revisionValue > past) {
9494
LOGGER.debug("Awaiting revision {} > {} [{}]", revisionValue, past, identityHashCode(this));
95-
if (!semaphore.tryAcquire(settings.flushTimeoutMS(), MILLISECONDS)) {
95+
if (!semaphore.tryAcquire(settings.timescaleMS(), MILLISECONDS)) {
9696
throw new FlushFailureException("Timed out waiting for revision " + revisionValue + " > " + alreadySeen);
9797
}
9898
if (isClosed) {

bosk-mongo/src/main/java/works/bosk/drivers/mongo/MainDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public void onConnectionSucceeded() throws
421421
private void runInitialRootAction(FutureTask<R> initialRootAction) throws InterruptedException, TimeoutException, InitialRootActionException {
422422
initialRootAction.run();
423423
try {
424-
initialRootAction.get(5 * driverSettings.recoveryPollingMS(), MILLISECONDS);
424+
initialRootAction.get(5 * driverSettings.timescaleMS(), MILLISECONDS);
425425
LOGGER.debug("initialRoot action completed successfully");
426426
} catch (ExecutionException e) {
427427
LOGGER.debug("initialRoot action failed", e);
@@ -621,7 +621,7 @@ private <X extends Exception, Y extends Exception> void doRetryableDriverOperati
621621
private <X extends Exception, Y extends Exception> void waitAndRetry(RetryableOperation<X, Y> operation, String description, Object... args) throws X, Y {
622622
try {
623623
formatDriverLock.lock();
624-
long waitTimeMS = 5 * driverSettings.recoveryPollingMS();
624+
long waitTimeMS = 5 * driverSettings.timescaleMS();
625625
LOGGER.debug("Waiting for new FormatDriver for {} ms", waitTimeMS);
626626
boolean success = formatDriverChanged.await(waitTimeMS, MILLISECONDS);
627627
if (!success) {

bosk-mongo/src/main/java/works/bosk/drivers/mongo/MongoDriverSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
public class MongoDriverSettings {
1414
String database;
1515

16-
@Default long flushTimeoutMS = 30_000;
17-
@Default long recoveryPollingMS = 30_000;
16+
@Default long timescaleMS = 30_000;
17+
1818
/**
1919
* @see DatabaseFormat#SEQUOIA
2020
* @see PandoFormat

bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverRecoveryTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ static Stream<TestParameters.ParameterSet> parameters() {
5858
),
5959
Stream.of(TestParameters.EventTiming.NORMAL)
6060
).map(b -> b.applyDriverSettings(s -> s
61-
.recoveryPollingMS(1500) // Note that some tests can take as long as 10x this
62-
.flushTimeoutMS(2000) // A little more than recoveryPollingMS
61+
.timescaleMS(1500) // Note that some tests can take as long as 10x this
6362
));
6463
}
6564

@@ -127,7 +126,7 @@ private void waitFor(BoskDriver driver) throws IOException, InterruptedException
127126
driver.flush();
128127
break;
129128
case WAIT:
130-
Thread.sleep(2 * driverSettings.recoveryPollingMS());
129+
Thread.sleep(2 * driverSettings.timescaleMS());
131130
break;
132131
}
133132
}

bosk-mongo/src/test/java/works/bosk/drivers/mongo/TestParameters.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public static ParameterSet from(MongoDriverSettings.DatabaseFormat format, Event
2525
timing + "," + format,
2626
MongoDriverSettings.builder()
2727
.preferredDatabaseFormat(format)
28-
.recoveryPollingMS(3000) // Note that some tests can take as long as 10x this
29-
.flushTimeoutMS(4000) // A little more than recoveryPollingMS
28+
.timescaleMS(3000) // Note that some tests can take as long as 10x this
3029
.testing(MongoDriverSettings.Testing.builder()
3130
.eventDelayMS(timing.eventDelayMS)
3231
.build())

0 commit comments

Comments
 (0)