Skip to content

Commit

Permalink
Refactor: flushIfLiveRefurbishIsNotSupported method
Browse files Browse the repository at this point in the history
  • Loading branch information
prdoyle committed Feb 7, 2024
1 parent c8f3c23 commit a39c4c9
Showing 1 changed file with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.vena.bosk.drivers.mongo.MongoDriverSettings.ManifestMode;
import io.vena.bosk.drivers.state.TestEntity;
import io.vena.bosk.junit.ParametersByName;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -123,27 +124,7 @@ void pairwise_writeCompatible() throws Exception {
LOGGER.debug("Refurbish toBosk ({})", toBosk.name());
((MongoDriver<?>)toBosk.driver()).refurbish();

if (fromHelper.driverSettings.preferredDatabaseFormat() == SEQUOIA
&& toHelper.driverSettings.preferredDatabaseFormat() != SEQUOIA) {
// When switching format classes, the old format's state documents
// disappear.
// Sequoia, being a fundamentally single-document format that does not
// use transactions, is not able to handle the time window between
// when that document disappears and when the corresponding change
// event arrives. We could add complexity to Sequoia to cope with
// this situation, but the point of Sequoia is its simplicity.
//
// Instead, we have a documented limitation that refurbishing from
// Sequoia to another format has a risk that updates occurring during
// a certain window could be ignored, and recommend that refurbish
// operation occur during a period of quiescence.
//
// Performing a flush causes Sequoia to "notice" its document is gone
// and correctly reinitialize itself.

LOGGER.debug("Flush so fromBosk notices the refurbish ({})", fromBosk.name());
fromBosk.driver().flush();
}
flushIfLiveRefurbishIsNotSupported(fromBosk, fromHelper, toHelper);

LOGGER.debug("Set distinctive string using fromBosk ({})", fromBosk.name());
fromBosk.driver().submitReplacement(fromRefs.string(), "Distinctive String");
Expand All @@ -163,6 +144,40 @@ void pairwise_writeCompatible() throws Exception {
// System.out.println("Status: " + ((MongoDriver<?>)toBosk.driver()).readStatus());
}

/**
* @param boskForUpdate {@link Bosk} that is about to submit an update
* @param helperForUpdate {@link Helper} for the bosk that is about to submit an update
* @param helperForRefurbish {@link Helper} for the bosk that performed the {@link MongoDriver#flush()} operation
*/
private static void flushIfLiveRefurbishIsNotSupported(
Bosk<TestEntity> boskForUpdate,
Helper helperForUpdate,
Helper helperForRefurbish
) throws IOException, InterruptedException {
if (helperForUpdate.driverSettings.preferredDatabaseFormat() == SEQUOIA
&& helperForRefurbish.driverSettings.preferredDatabaseFormat() != SEQUOIA) {
// When switching format classes, the old format's state documents
// disappear.
//
// Sequoia, being a fundamentally single-document format that does not
// use transactions, is not able to handle the time window between
// when that document disappears and when the corresponding change
// event arrives. We could add complexity to Sequoia to cope with
// this situation, but the point of Sequoia is its simplicity.
//
// Instead, we have a documented limitation that refurbishing from
// Sequoia to another format has a risk that updates occurring during
// a certain window could be ignored, and recommend that refurbish
// operation occur during a period of quiescence.
//
// Performing a flush causes Sequoia to "notice" its document is gone
// and correctly reinitialize itself.

LOGGER.debug("Flush so boskForUpdate notices the refurbish ({})", boskForUpdate.name());
boskForUpdate.driver().flush();
}
}

private static Bosk<TestEntity> newBosk(Helper helper) {
return new Bosk<TestEntity>("bosk" + boskCounter.incrementAndGet(), TestEntity.class, helper::initialRoot, helper.driverFactory);
}
Expand Down

0 comments on commit a39c4c9

Please sign in to comment.