Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,25 @@ protected void applyMutations(CommitAdapter committer, String schemaName, String
String datatableName, String tid, List<Set<ChangeRow>> batches, String cdcName)
throws Exception {
EnvironmentEdgeManager.injectEdge(injectEdge);
long latestChangeTS = injectEdge.currentTime();
try (Connection conn = committer.getConnection(tid)) {
for (Set<ChangeRow> batch : batches) {
for (ChangeRow changeRow : batch) {
addChange(conn, tableName, changeRow);
if (changeRow.changeTS > latestChangeTS) {
latestChangeTS = changeRow.changeTS;
}
}
committer.commit(conn);
}
}
committer.reset();
// Keep the manual edge installed for the remainder of the test so
// EnvironmentEdgeManager.currentTimeMillis() does not silently revert
// to the wall clock and trip QueryCompiler.verifySCN against the
// configured max-lookback age. Pin to the latest changeTS so SCN-bounded
// reads of the just-applied mutations remain in-window. Per-test
// cleanup is the responsibility of the suite's @After hook.
injectEdge.setValue(latestChangeTS);

// For debug: uncomment to see the exact HBase cells.
dumpCells(schemaName, tableName, datatableName, cdcName);
Expand Down Expand Up @@ -950,6 +960,13 @@ void init() {
EnvironmentEdgeManager.injectEdge(injectEdge);
}

/**
* Uninstall the manual time edge. Callers should NOT invoke this from inside test bodies that
* still need to issue SCN-bounded reads of the just-applied mutations: doing so reverts
* {@link EnvironmentEdgeManager#currentTimeMillis()} to the wall clock and may push the SCN
* outside the configured max-lookback window. Per-test cleanup belongs in an {@code @After}
* hook instead (see {@code CDCQueryIT#afterTest}).
*/
public void reset() {
EnvironmentEdgeManager.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -145,6 +146,14 @@ public void beforeTest() {
injectEdge.setValue(EnvironmentEdgeManager.currentTimeMillis());
}

@After
public void afterTest() {
// CDCBaseIT.applyMutations intentionally leaves the manual edge installed so
// SCN-bounded reads in the test body remain inside the max-lookback window.
// Restore the real clock here so per-test isolation is preserved.
EnvironmentEdgeManager.reset();
}

private void cdcIndexShouldNotBeUsedForDataTableQueries(Connection conn, String dataTableName,
String cdcName) throws Exception {
ResultSet rs = conn.createStatement().executeQuery(
Expand Down