Skip to content

Commit

Permalink
Cleanup ConstructSnapshot, add multiple UpdateGraph awareness, and op…
Browse files Browse the repository at this point in the history
…timize static cases (#4228)
  • Loading branch information
rcaudy authored Jul 26, 2023
1 parent acc5474 commit a438c49
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ public Table setTotalsTable(String directive) {
public static void initializeWithSnapshot(
String logPrefix, SwapListener swapListener, ConstructSnapshot.SnapshotFunction snapshotFunction) {
if (swapListener == null) {
snapshotFunction.call(false, ExecutionContext.getContext().getUpdateGraph().clock().currentValue());
snapshotFunction.call(false, LogicalClock.NULL_CLOCK_VALUE);
return;
}
ConstructSnapshot.callDataSnapshotFunction(logPrefix, swapListener.makeSnapshotControl(), snapshotFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public SwapListener(final BaseTable<?> sourceTable) {
public ConstructSnapshot.SnapshotControl makeSnapshotControl() {
// noinspection AutoBoxing
return ConstructSnapshot.makeSnapshotControl(
sourceTable.getUpdateGraph(),
this::start,
(final long currentClockValue, final boolean usingPreviousValues) -> isInInitialNotificationWindow(),
(final long afterClockValue, final boolean usedPreviousValues) -> end(afterClockValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public SwapListenerEx(@NotNull final BaseTable<?> sourceTable, @NotNull final No
@Override
public ConstructSnapshot.SnapshotControl makeSnapshotControl() {
return ConstructSnapshot.makeSnapshotControl(
sourceTable.getUpdateGraph(),
this::startWithExtra,
(final long currentClockValue, final boolean usingPreviousValues) -> isInInitialNotificationWindow()
&& extra.getLastNotificationStep() == extraLastNotificationStep,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.deephaven.engine.testutil.ControlledUpdateGraph;
import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase;
import io.deephaven.engine.updategraph.LogicalClock;
import io.deephaven.engine.updategraph.UpdateGraph;
import io.deephaven.util.SafeCloseable;
import org.apache.commons.lang3.mutable.MutableLong;

Expand All @@ -16,6 +17,7 @@ public class TestConstructSnapshot extends RefreshingTableTestCase {
public void testClockChange() throws InterruptedException {
final MutableLong changed = new MutableLong(0);
final ConstructSnapshot.SnapshotControl control = new ConstructSnapshot.SnapshotControl() {

@Override
public Boolean usePreviousValues(long beforeClockValue) {
// noinspection AutoBoxing
Expand All @@ -26,6 +28,11 @@ public Boolean usePreviousValues(long beforeClockValue) {
public boolean snapshotConsistent(final long currentClockValue, final boolean usingPreviousValues) {
return true;
}

@Override
public UpdateGraph getUpdateGraph() {
return ExecutionContext.getContext().getUpdateGraph();
}
};
final ExecutionContext executionContext = ExecutionContext.getContext();
final Runnable snapshot_test = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
*/
public interface LogicalClock {

/**
* The "null" value, which encodes {step=-1, state=Idle}. Used as a marker when no clock value is appropriate, e.g.
* for snapshots of static data.
*/
long NULL_CLOCK_VALUE = -1L;

/**
* The state component of a logical timestamp.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ public class LogicalClockImpl implements LogicalClock {

private static final Logger log = LoggerFactory.getLogger(LogicalClockImpl.class);

// {2, Idle}, just in case any code has 0 or 1 as an initializer.
private final AtomicLong currentValue = new AtomicLong(5L);
/**
* Our initial clock value. Equivalent to {step=2, state=Idle}. Uses step 2 in case any code has 0 or 1 as an
* initializer.
*/
private static final long INITIAL_CLOCK_VALUE = 5L;

/**
* The current value, encoding both step and state as a single long value.
*/
private final AtomicLong currentValue = new AtomicLong(INITIAL_CLOCK_VALUE);

/**
* Get the current value of the clock.
Expand Down Expand Up @@ -106,6 +114,6 @@ public final void ensureUpdateCycleCompleted(final long updatingCycleValue) {
*/
@TestUseOnly
public final void resetForUnitTests() {
currentValue.set(5L);
currentValue.set(INITIAL_CLOCK_VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,11 @@ public boolean snapshotCompletedConsistently(final long afterClockValue, final b
}
return success;
}

@Override
public UpdateGraph getUpdateGraph() {
return parent.getUpdateGraph();
}
}

@VisibleForTesting
Expand Down

0 comments on commit a438c49

Please sign in to comment.