This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 82e9361c6a6 Implemented max ttl under specific database getter for
table model (#14977)
82e9361c6a6 is described below
commit 82e9361c6a6664384330a93eda2d33bd39adf21c
Author: Caideyipi <[email protected]>
AuthorDate: Fri Feb 28 19:03:58 2025 +0800
Implemented max ttl under specific database getter for table model (#14977)
* complete
* rectify partition cleaner
---------
Co-authored-by: YongzaoDan <[email protected]>
---
.../manager/schema/ClusterSchemaManager.java | 12 +++++++++---
.../apache/iotdb/confignode/persistence/TTLInfo.java | 2 +-
.../persistence/schema/ClusterSchemaInfo.java | 20 ++++++++++++++++++++
.../procedure/PartitionTableAutoCleaner.java | 14 ++++++++------
.../apache/iotdb/commons/schema/table/TsTable.java | 2 +-
5 files changed, 39 insertions(+), 11 deletions(-)
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
index fda88974fcd..ab4b88fb78c 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
@@ -105,6 +105,7 @@ import org.apache.iotdb.mpp.rpc.thrift.TUpdateTemplateReq;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.tsfile.annotations.TableModel;
import org.apache.tsfile.file.metadata.IDeviceID;
import org.apache.tsfile.utils.Pair;
import org.slf4j.Logger;
@@ -142,9 +143,9 @@ public class ClusterSchemaManager {
"Failed in the write API executing the consensus layer due to: ";
public ClusterSchemaManager(
- IManager configManager,
- ClusterSchemaInfo clusterSchemaInfo,
- ClusterSchemaQuotaStatistics schemaQuotaStatistics) {
+ final IManager configManager,
+ final ClusterSchemaInfo clusterSchemaInfo,
+ final ClusterSchemaQuotaStatistics schemaQuotaStatistics) {
this.configManager = configManager;
this.clusterSchemaInfo = clusterSchemaInfo;
this.schemaQuotaStatistics = schemaQuotaStatistics;
@@ -1384,6 +1385,11 @@ public class ClusterSchemaManager {
return new Pair<>(RpcUtils.SUCCESS_STATUS, updatedTable);
}
+ @TableModel
+ public long getDatabaseMaxTTL(final String database) {
+ return clusterSchemaInfo.getDatabaseMaxTTL(database);
+ }
+
public void clearSchemaQuotaCache() {
schemaQuotaStatistics.clear();
}
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TTLInfo.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TTLInfo.java
index d4760439d20..edc00411d18 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TTLInfo.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TTLInfo.java
@@ -165,7 +165,7 @@ public class TTLInfo implements SnapshotProcessor {
* @return the maximum ttl of the subtree of the corresponding database.
return NULL_TTL if the
* TTL is not set or the database does not exist.
*/
- public long getDatabaseMaxTTL(String database) {
+ public long getDatabaseMaxTTL(final String database) {
lock.readLock().lock();
try {
return ttlCache.getDatabaseMaxTTL(database);
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
index d0019f33989..e313c6d93a0 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java
@@ -91,6 +91,7 @@ import
org.apache.iotdb.db.schemaengine.template.alter.TemplateExtendInfo;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.tsfile.annotations.TableModel;
import org.apache.tsfile.utils.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -620,6 +621,25 @@ public class ClusterSchemaInfo implements
SnapshotProcessor {
return schemaMap;
}
+ @TableModel
+ public long getDatabaseMaxTTL(final String database) {
+ databaseReadWriteLock.readLock().lock();
+ try {
+ return tableModelMTree
+
.getAllTablesUnderSpecificDatabase(PartialPath.getQualifiedDatabasePartialPath(database))
+ .stream()
+ .map(pair -> pair.getLeft().getTableTTL())
+ .reduce(Long::max)
+ .orElse(Long.MAX_VALUE);
+ } catch (final MetadataException e) {
+ LOGGER.warn(
+ ERROR_NAME + " when trying to get max ttl under one database, use
Long.MAX_VALUE.", e);
+ } finally {
+ databaseReadWriteLock.readLock().unlock();
+ }
+ return Long.MAX_VALUE;
+ }
+
/**
* Only leader use this interface. Get the maxRegionGroupNum of specified
Database.
*
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/PartitionTableAutoCleaner.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/PartitionTableAutoCleaner.java
index 8466c06b1a7..5daa95a34c8 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/PartitionTableAutoCleaner.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/PartitionTableAutoCleaner.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.confignode.procedure;
import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.TimePartitionUtils;
import
org.apache.iotdb.confignode.consensus.request.write.partition.AutoCleanPartitionTablePlan;
import org.apache.iotdb.confignode.manager.ConfigManager;
@@ -32,6 +33,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import static
org.apache.iotdb.confignode.manager.partition.PartitionManager.CONSENSUS_WRITE_ERROR;
@@ -54,13 +56,13 @@ public class PartitionTableAutoCleaner<Env> extends
InternalProcedure<Env> {
@Override
protected void periodicExecute(Env env) {
List<String> databases =
configManager.getClusterSchemaManager().getDatabaseNames(null);
- Map<String, Long> databaseTTLMap =
- configManager.getClusterSchemaManager().getTTLInfoForUpgrading();
+ Map<String, Long> databaseTTLMap = new TreeMap<>();
for (String database : databases) {
- long subTreeMaxTTL =
configManager.getTTLManager().getDatabaseMaxTTL(database);
- databaseTTLMap.put(
- database, Math.max(subTreeMaxTTL,
databaseTTLMap.getOrDefault(database, -1L)));
- long databaseTTL = databaseTTLMap.get(database);
+ long databaseTTL =
+ PathUtils.isTableModelDatabase(database)
+ ?
configManager.getClusterSchemaManager().getDatabaseMaxTTL(database)
+ : configManager.getTTLManager().getDatabaseMaxTTL(database);
+ databaseTTLMap.put(database, databaseTTL);
if (!configManager.getPartitionManager().isDatabaseExist(database)
|| databaseTTL < 0
|| databaseTTL == Long.MAX_VALUE) {
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
index 2d45794dcdd..e2e8f288a6a 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
@@ -221,7 +221,7 @@ public class TsTable {
return ttlValue;
}
- public long getTableTTLInMS() {
+ private long getTableTTLInMS() {
final Optional<String> ttl = getPropValue(TTL_PROPERTY);
return ttl.isPresent() && !ttl.get().equalsIgnoreCase(TTL_INFINITE)
? Long.parseLong(ttl.get())