This is an automated email from the ASF dual-hosted git repository.
palashc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 55de06c410 PHOENIX-7732 : Drop CDC should not throw TNFE when IF
EXISTS is used (#2318)
55de06c410 is described below
commit 55de06c41065c7c59c336daccdf082793cdcfb0d
Author: Palash Chauhan <[email protected]>
AuthorDate: Fri Nov 21 11:04:51 2025 -0800
PHOENIX-7732 : Drop CDC should not throw TNFE when IF EXISTS is used (#2318)
Co-authored-by: Palash Chauhan
<[email protected]>
---
.../org/apache/phoenix/schema/MetaDataClient.java | 45 +++++++++++++---------
.../apache/phoenix/end2end/CDCDefinitionIT.java | 16 ++++++++
2 files changed, 43 insertions(+), 18 deletions(-)
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 99ffe14156..edb38da970 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -4060,26 +4060,35 @@ public class MetaDataClient {
String schemaName = statement.getTableName().getSchemaName();
String cdcTableName = statement.getCdcObjName().getName();
String parentTableName = statement.getTableName().getTableName();
- String indexName =
CDCUtil.getCDCIndexName(statement.getCdcObjName().getName());
- // Mark CDC Stream as Disabled
- long cdcIndexTimestamp =
- connection.getTable(SchemaUtil.getTableName(schemaName,
indexName)).getTimeStamp();
- String fullParentTableName = SchemaUtil.getTableName(schemaName,
parentTableName);
- String streamName = String.format(CDC_STREAM_NAME_FORMAT,
fullParentTableName, cdcTableName,
- cdcIndexTimestamp, CDCUtil.getCDCCreationUTCDateTime(cdcIndexTimestamp));
- markCDCStreamStatus(fullParentTableName, streamName,
CDCUtil.CdcStreamStatus.DISABLED);
- // Dropping the virtual CDC Table
- dropTable(schemaName, cdcTableName, parentTableName, PTableType.CDC,
statement.ifExists(),
- false, false);
- // Dropping the uncovered index associated with the CDC Table
+ boolean ifExists = statement.ifExists();
+ MutationState mutationState = new MutationState(0, 0, connection);
try {
- return dropTable(schemaName, indexName, parentTableName,
PTableType.INDEX,
- statement.ifExists(), false, false);
- } catch (SQLException e) {
- throw new
SQLExceptionInfo.Builder(SQLExceptionCode.fromErrorCode(e.getErrorCode()))
-
.setTableName(statement.getCdcObjName().getName()).setRootCause(e.getCause()).build()
- .buildException();
+ String indexName =
CDCUtil.getCDCIndexName(statement.getCdcObjName().getName());
+ // Mark CDC Stream as Disabled
+ long cdcIndexTimestamp =
+ connection.getTable(SchemaUtil.getTableName(schemaName,
indexName)).getTimeStamp();
+ String fullParentTableName = SchemaUtil.getTableName(schemaName,
parentTableName);
+ String streamName = String.format(CDC_STREAM_NAME_FORMAT,
fullParentTableName, cdcTableName,
+ cdcIndexTimestamp,
CDCUtil.getCDCCreationUTCDateTime(cdcIndexTimestamp));
+ markCDCStreamStatus(fullParentTableName, streamName,
CDCUtil.CdcStreamStatus.DISABLED);
+ // Dropping the virtual CDC Table
+ dropTable(schemaName, cdcTableName, parentTableName, PTableType.CDC,
statement.ifExists(),
+ false, false);
+ // Dropping the uncovered index associated with the CDC Table
+ try {
+ mutationState = dropTable(schemaName, indexName, parentTableName,
PTableType.INDEX,
+ statement.ifExists(), false, false);
+ } catch (SQLException e) {
+ throw new
SQLExceptionInfo.Builder(SQLExceptionCode.fromErrorCode(e.getErrorCode()))
+
.setTableName(statement.getCdcObjName().getName()).setRootCause(e.getCause()).build()
+ .buildException();
+ }
+ } catch (MetaDataEntityNotFoundException e) {
+ if (!ifExists) {
+ throw e;
+ }
}
+ return mutationState;
}
private void markCDCStreamStatus(String tableName, String streamName,
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCDefinitionIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCDefinitionIT.java
index 0aee3c9ab1..8e314b3170 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCDefinitionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCDefinitionIT.java
@@ -295,6 +295,22 @@ public class CDCDefinitionIT extends CDCBaseIT {
}
}
+ @Test
+ public void testDropCDCIfExists() throws SQLException {
+ Properties props = new Properties();
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ String tableName = generateUniqueName();
+ String schemaName = null;
+ String viewName = forView ? generateUniqueName() : null;
+ String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+ if (forView) {
+ fullTableName = SchemaUtil.getTableName(schemaName, viewName);
+ }
+ String cdcName = generateUniqueName();
+ String drop_cdc_sql = "DROP CDC IF EXISTS " + cdcName + " ON " +
fullTableName;
+ conn.createStatement().execute(drop_cdc_sql);
+ }
+
@Test
public void testDropCDC() throws SQLException {
Properties props = new Properties();