You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "kezhenxu94 (via GitHub)" <gi...@apache.org> on 2023/03/25 14:21:04 UTC

[GitHub] [skywalking] kezhenxu94 commented on a diff in pull request #10592: Fix jdbc storage, delete table by mistake

kezhenxu94 commented on code in PR #10592:
URL: https://github.com/apache/skywalking/pull/10592#discussion_r1148377762


##########
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java:
##########
@@ -75,16 +75,17 @@ public void deleteHistory(Model model, String timeBucketColumnName, int ttl) {
 
         final var ttlTables = tableHelper.getTablesForRead(model.getName(), startTimeBucket, endTimeBucket);
         final var tablesToDrop = new HashSet<String>();
+        final var tableName = TableHelper.getTableName(model);
 
         try (final var conn = jdbcClient.getConnection();
-             final var result = conn.getMetaData().getTables(null, null, TableHelper.getTableName(model) + "%", new String[]{"TABLE"})) {
+             final var result = conn.getMetaData().getTables(null, null, tableName + "%", new String[]{"TABLE"})) {
             while (result.next()) {
                 tablesToDrop.add(result.getString("TABLE_NAME"));
             }
         }
 
         ttlTables.forEach(tablesToDrop::remove);
-        tablesToDrop.removeIf(it -> !it.matches(".*_\\d{8}$"));
+        tablesToDrop.removeIf(it -> !it.matches(tableName + "_\\d{8}$"));

Review Comment:
   This fixes the issue when one model name is the prefix of another, the longer one will be deleted by mistake.
   
   Example: when model `meter_sumpermin` is deleting its outdated tables, the `meter_sumperminlabeled` will be deleted by mistake



-- 
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: notifications-unsubscribe@skywalking.apache.org

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