1996fanrui commented on code in PR #865: URL: https://github.com/apache/flink-kubernetes-operator/pull/865#discussion_r1716301360
########## flink-autoscaler-plugin-jdbc/src/main/java/org/apache/flink/autoscaler/jdbc/event/JdbcEventInteractor.java: ########## @@ -152,4 +154,49 @@ protected List<AutoScalerEvent> queryEvents(String jobKey, String reason) throws void setClock(@Nonnull Clock clock) { this.clock = Preconditions.checkNotNull(clock); } + + @Nullable + ExpiredEventsResult queryExpiredEventsAndMaxId(Duration eventHandlerTtl) throws Exception { Review Comment: It's better to test the clean logic in AbstractJdbcAutoscalerEventHandlerITCase. ########## flink-autoscaler-plugin-jdbc/src/main/java/org/apache/flink/autoscaler/jdbc/event/JdbcEventInteractor.java: ########## @@ -152,4 +154,49 @@ protected List<AutoScalerEvent> queryEvents(String jobKey, String reason) throws void setClock(@Nonnull Clock clock) { this.clock = Preconditions.checkNotNull(clock); } + + @Nullable + ExpiredEventsResult queryExpiredEventsAndMaxId(Duration eventHandlerTtl) throws Exception { + var query = + "SELECT COUNT(1) records_num, max(id) max_target_id " + + "FROM t_flink_autoscaler_event_handler " + + "WHERE create_time < ? AND id < (" + + " SELECT id FROM t_flink_autoscaler_event_handler " + + " WHERE create_time >= ? ORDER BY id ASC LIMIT 1)"; + var date = Timestamp.from(clock.instant().minusMillis(eventHandlerTtl.toMillis())); + try (var pstmt = conn.prepareStatement(query)) { + pstmt.setObject(1, date); + pstmt.setObject(2, date); + ResultSet resultSet = pstmt.executeQuery(); + if (!resultSet.next()) { + return null; + } + var result = new ExpiredEventsResult(resultSet.getInt(1), resultSet.getLong(2)); + resultSet.close(); + return result; + } + } + + public void deleteExpiredEventsByMaxIdAndBatch(long maxTargetId, int batch) throws Exception { + var query = "delete from t_flink_autoscaler_event_handler where id < ? limit ?"; Review Comment: ```suggestion var query = "delete from t_flink_autoscaler_event_handler where id <= ? limit ?"; ``` It should be `<=` ? -- 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...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org