This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push: new de047de87c Retain +1 day tables when deleting history (#10597) de047de87c is described below commit de047de87cb7c769ceacdfc1ccc4235b4005c873 Author: kezhenxu94 <kezhenx...@apache.org> AuthorDate: Mon Mar 27 21:24:08 2023 +0800 Retain +1 day tables when deleting history (#10597) --- .../storage/plugin/jdbc/common/TableHelper.java | 32 +++++++++++----------- .../jdbc/common/dao/JDBCHistoryDeleteDAO.java | 6 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/TableHelper.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/TableHelper.java index cac5de380e..08f6160a16 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/TableHelper.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/TableHelper.java @@ -85,15 +85,6 @@ public class TableHelper { return tableName + Const.UNDERSCORE + dayTimeBucket; } - /** - * @param rawTableName the table name without time bucket suffix. - * @return the table name with time bucket. - */ - public static String getLatestTableForWrite(String rawTableName) { - final var dayTimeBucket = TimeBucket.getTimeBucket(System.currentTimeMillis(), DownSampling.Day); - return rawTableName + Const.UNDERSCORE + dayTimeBucket; - } - public static String getTable(Model model, long timeBucket) { final var tableName = getTableName(model); if (timeBucket == 0) { @@ -116,6 +107,22 @@ public class TableHelper { } public List<String> getTablesForRead(String modelName, long timeBucketStart, long timeBucketEnd) { + return getTablesInTimeBucketRange(modelName, timeBucketStart, timeBucketEnd) + .stream() + .filter(table -> { + try { + return tableExistence.get(table); + } catch (Exception e) { + throw new RuntimeException(e); + } + }) + .collect(toList()); + } + + /** + * Similar to {@link #getTablesForRead(String, long, long)}, but don't check the table existence. + */ + public List<String> getTablesInTimeBucketRange(String modelName, long timeBucketStart, long timeBucketEnd) { final var model = TableMetaInfo.get(modelName); final var tableName = getTableName(model); @@ -133,13 +140,6 @@ public class TableHelper { .distinct() .filter(ttlTimeBucketRange::contains) .mapToObj(it -> tableName + "_" + it) - .filter(table -> { - try { - return tableExistence.get(table); - } catch (Exception e) { - throw new RuntimeException(e); - } - }) .collect(toList()); } diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java index 8d716e7af3..43354807bd 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHistoryDeleteDAO.java @@ -50,8 +50,8 @@ public class JDBCHistoryDeleteDAO implements IHistoryDeleteDAO { @Override @SneakyThrows public void deleteHistory(Model model, String timeBucketColumnName, int ttl) { - final var endTimeBucket = TimeBucket.getTimeBucket(clock.millis(), DownSampling.Day); - final var startTimeBucket = endTimeBucket - ttl; + final var endTimeBucket = TimeBucket.getTimeBucket(clock.millis() + TimeUnit.DAYS.toMillis(1), DownSampling.Day); + final var startTimeBucket = endTimeBucket - ttl - 1; log.info( "Deleting history data, ttl: {}, now: {}. Keep [{}, {}]", ttl, @@ -73,7 +73,7 @@ public class JDBCHistoryDeleteDAO implements IHistoryDeleteDAO { return; } - final var ttlTables = tableHelper.getTablesForRead(model.getName(), startTimeBucket, endTimeBucket); + final var ttlTables = tableHelper.getTablesInTimeBucketRange(model.getName(), startTimeBucket, endTimeBucket); final var tablesToDrop = new HashSet<String>(); final var tableName = TableHelper.getTableName(model);