diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCBaseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCBaseIT.java index 167f059be73..819e795ae2d 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCBaseIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCBaseIT.java @@ -396,15 +396,25 @@ protected void applyMutations(CommitAdapter committer, String schemaName, String String datatableName, String tid, List> batches, String cdcName) throws Exception { EnvironmentEdgeManager.injectEdge(injectEdge); + long latestChangeTS = injectEdge.currentTime(); try (Connection conn = committer.getConnection(tid)) { for (Set 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); @@ -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(); } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java index 9a86354778d..63b99d96114 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java @@ -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; @@ -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(