palashc commented on code in PR #2033:
URL: https://github.com/apache/phoenix/pull/2033#discussion_r1873042035


##########
phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java:
##########
@@ -2039,9 +2041,57 @@ public MutationState createCDC(CreateCDCStatement 
statement) throws SQLException
         createTableInternal(tableStatement, null, dataTable, null, null, null, 
null,
                 null, null, false, null,
                 null, statement.getIncludeScopes(), tableProps, 
commonFamilyProps);
+        // for now, only track stream partition metadata for tables, TODO: 
updatable views
+        if (PTableType.TABLE.equals(dataTable.getType())) {
+            updateStreamPartitionMetadata(dataTableFullName);
+        }
         return new MutationState(0, 0, connection);
     }
 
+    /**
+     * Trigger CDC Stream Partition metadata bootstrap for the given table in 
the background.
+     * Mark status as ENABLING in SYSTEM.CDC_STREAM_STATUS and add {@link 
CdcStreamPartitionMetadataTask}
+     * to SYSTEM.TASK which updates partition metadata based on table regions.
+     */
+    private void updateStreamPartitionMetadata(String tableName) throws 
SQLException {
+        long cdcIndexTimestamp = 
CDCUtil.getCDCCreationTimestamp(connection.getTable(tableName));
+        String streamStatusSQL = "UPSERT INTO " + 
SYSTEM_CDC_STREAM_STATUS_NAME + " VALUES (?, ?, ?)";
+        PreparedStatement ps = connection.prepareStatement(streamStatusSQL);
+        String streamName = String.format(CDC_STREAM_NAME_FORMAT, tableName, 
cdcIndexTimestamp);
+        ps.setString(1, tableName);
+        ps.setString(2, streamName);
+        ps.setString(3, CDCUtil.CdcStreamStatus.ENABLING.getSerializedValue());
+        ps.executeUpdate();
+        connection.commit();

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to