Skip to content

Commit 59c9b9d

Browse files
committed
ttlgras
1 parent 629f319 commit 59c9b9d

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TTLInfo.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ public TSStatus setTTL(SetTTLPlan plan) {
7171
// check ttl rule capacity
7272
final int tTlRuleCapacity = CommonDescriptor.getInstance().getConfig().getTTlRuleCapacity();
7373
final int newTTLRuleCount = calculateNewTTLRuleCount(plan);
74-
if (newTTLRuleCount > 0 && ttlCache.getTtlCount() + newTTLRuleCount > tTlRuleCapacity) {
74+
final int requestedTTLRuleCount = ttlCache.getTtlCount() + newTTLRuleCount;
75+
if (newTTLRuleCount > 0 && requestedTTLRuleCount > tTlRuleCapacity) {
7576
TSStatus errorStatus = new TSStatus(TSStatusCode.OVERSIZE_TTL.getStatusCode());
7677
errorStatus.setMessage(
7778
String.format(
78-
"The number of TTL rules has reached the limit (%d). Please delete "
79-
+ "some existing rules first.",
80-
tTlRuleCapacity));
79+
"The number of TTL rules has reached the limit "
80+
+ "(capacity: %d, requested total: %d). Please delete some existing rules first.",
81+
tTlRuleCapacity, requestedTTLRuleCount));
8182
return errorStatus;
8283
}
8384
ttlCache.setTTL(plan.getPathPattern(), plan.getTTL());
@@ -94,17 +95,17 @@ public TSStatus setTTL(SetTTLPlan plan) {
9495
}
9596

9697
private int calculateNewTTLRuleCount(SetTTLPlan plan) {
97-
int newTTLRuleCount = getNewTTLRuleCount(plan.getPathPattern());
98+
int newTTLRuleCount = isNewTTLRule(plan.getPathPattern()) ? 1 : 0;
9899
if (plan.isDataBase()) {
99100
String[] pathNodes = Arrays.copyOf(plan.getPathPattern(), plan.getPathPattern().length + 1);
100101
pathNodes[pathNodes.length - 1] = IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;
101-
newTTLRuleCount += getNewTTLRuleCount(pathNodes);
102+
newTTLRuleCount += isNewTTLRule(pathNodes) ? 1 : 0;
102103
}
103104
return newTTLRuleCount;
104105
}
105106

106-
private int getNewTTLRuleCount(String[] pathNodes) {
107-
return ttlCache.getLastNodeTTL(pathNodes) == TTLCache.NULL_TTL ? 1 : 0;
107+
private boolean isNewTTLRule(String[] pathNodes) {
108+
return ttlCache.getLastNodeTTL(pathNodes) == TTLCache.NULL_TTL;
108109
}
109110

110111
/** Only used for upgrading from database level ttl to device level ttl. */

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/SetTTLProcedure.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
public class SetTTLProcedure extends StateMachineProcedure<ConfigNodeProcedureEnv, SetTTLState> {
5858
private static final Logger LOGGER = LoggerFactory.getLogger(SetTTLProcedure.class);
59+
// Distinguishes no previous TTL from TTLCache.NULL_TTL, the explicit unset marker for rollback.
5960
private static final long TTL_NOT_EXIST = Long.MIN_VALUE;
6061

6162
private SetTTLPlan plan;

iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/TTLInfoTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ public void testTooManyTTL() {
244244
final TSStatus status = ttlInfo.setTTL(setTTLPlan);
245245
assertEquals(TSStatusCode.OVERSIZE_TTL.getStatusCode(), status.code);
246246
assertEquals(
247-
"The number of TTL rules has reached the limit (1000). Please delete some existing rules first.",
247+
"The number of TTL rules has reached the limit "
248+
+ "(capacity: 1000, requested total: 1001). Please delete some existing rules first.",
248249
status.message);
249250
}
250251

0 commit comments

Comments
 (0)