This is an automated email from the ASF dual-hosted git repository.
jiangtian 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 5434efefc92 Report an error when unsetting a non-exist ttl (#12862)
5434efefc92 is described below
commit 5434efefc9294c3bdb37df4bada0bcb88d6810aa
Author: Jiang Tian <[email protected]>
AuthorDate: Fri Jul 5 17:57:20 2024 +0800
Report an error when unsetting a non-exist ttl (#12862)
* report an error when unsetting a non-exist ttl
* fix test
---
.../consensus/request/write/database/SetTTLPlan.java | 6 ++++++
.../apache/iotdb/confignode/persistence/TTLInfo.java | 16 +++++++++-------
.../iotdb/confignode/persistence/TTLInfoTest.java | 19 +++++++++++++++++++
.../org/apache/iotdb/commons/schema/ttl/TTLCache.java | 19 ++++++++++++++-----
4 files changed, 48 insertions(+), 12 deletions(-)
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/SetTTLPlan.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/SetTTLPlan.java
index 4dd61e9a730..a06b6bb811a 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/SetTTLPlan.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/database/SetTTLPlan.java
@@ -42,6 +42,12 @@ public class SetTTLPlan extends ConfigPhysicalPlan {
super(ConfigPhysicalPlanType.SetTTL);
}
+ public SetTTLPlan(long TTL, String... pathPatterns) {
+ super(ConfigPhysicalPlanType.SetTTL);
+ this.pathPattern = pathPatterns;
+ this.TTL = TTL;
+ }
+
public SetTTLPlan(List<String> pathPattern, long TTL) {
this();
this.pathPattern = pathPattern.toArray(new String[0]);
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 a72445c3fbd..90eb7bacd80 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
@@ -108,20 +108,22 @@ public class TTLInfo implements SnapshotProcessor {
}
public TSStatus unsetTTL(SetTTLPlan plan) {
+ TSStatus status;
lock.writeLock().lock();
try {
- ttlCache.unsetTTL(plan.getPathPattern());
- if (plan.isDataBase()) {
+ status = ttlCache.unsetTTL(plan.getPathPattern());
+ if (status.code == TSStatusCode.SUCCESS_STATUS.getStatusCode() &&
plan.isDataBase()) {
// unset ttl to path.**
- ttlCache.unsetTTL(
- new PartialPath(plan.getPathPattern())
- .concatNode(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD)
- .getNodes());
+ status =
+ ttlCache.unsetTTL(
+ new PartialPath(plan.getPathPattern())
+ .concatNode(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD)
+ .getNodes());
}
} finally {
lock.writeLock().unlock();
}
- return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
+ return status;
}
public ShowTTLResp showTTL(ShowTTLPlan plan) {
diff --git
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/TTLInfoTest.java
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/TTLInfoTest.java
index acf5bac1800..d5deb1d2b2c 100644
---
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/TTLInfoTest.java
+++
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/TTLInfoTest.java
@@ -208,6 +208,25 @@ public class TTLInfoTest {
Assert.assertEquals(4, ttlInfo.getTTLCount());
}
+ @Test
+ public void testUnsetNonExistTTL() throws IllegalPathException {
+ assertEquals(
+ TSStatusCode.ILLEGAL_PATH.getStatusCode(),
+ ttlInfo.unsetTTL(new SetTTLPlan(-1, "root")).getCode());
+ assertEquals(
+ TSStatusCode.PATH_NOT_EXIST.getStatusCode(),
+ ttlInfo.unsetTTL(new SetTTLPlan(-1, "root", "sg100", "f10",
"d1")).getCode());
+
+ PartialPath path = new PartialPath("root.test.db1.group1.group2.d1");
+ ttlInfo.setTTL(new SetTTLPlan(Arrays.asList(path.getNodes()), 11111222L));
+ assertEquals(
+ TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+ ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()),
11111222L)).getCode());
+ assertEquals(
+ TSStatusCode.PATH_NOT_EXIST.getStatusCode(),
+ ttlInfo.unsetTTL(new SetTTLPlan(Arrays.asList(path.getNodes()),
11111222L)).getCode());
+ }
+
@Test
public void testTooManyTTL() {
final int tTlRuleCapacity =
CommonDescriptor.getInstance().getConfig().getTTlRuleCapacity();
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/ttl/TTLCache.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/ttl/TTLCache.java
index 1a3e65d3ac5..c06d2c9e0c3 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/ttl/TTLCache.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/ttl/TTLCache.java
@@ -18,9 +18,12 @@
*/
package org.apache.iotdb.commons.schema.ttl;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.utils.PathUtils;
+import org.apache.iotdb.commons.utils.StatusUtils;
+import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.tsfile.utils.ReadWriteIOUtils;
@@ -78,15 +81,16 @@ public class TTLCache {
*
* @param nodes path to be removed
*/
- public void unsetTTL(String[] nodes) {
+ public TSStatus unsetTTL(String[] nodes) {
if (nodes.length < 2) {
- return;
+ return new TSStatus(TSStatusCode.ILLEGAL_PATH.getStatusCode())
+ .setMessage(String.join(IoTDBConstant.PATH_SEPARATOR + "", nodes));
} else if (nodes.length == 2) {
// if path equals to root.**, then unset it to configured ttl
if (nodes[0].equals(IoTDBConstant.PATH_ROOT)
&& nodes[1].equals(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD)) {
ttlCacheTree.getChild(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD).ttl =
Long.MAX_VALUE;
- return;
+ return StatusUtils.OK;
}
}
CacheNode current = ttlCacheTree;
@@ -98,7 +102,11 @@ public class TTLCache {
CacheNode child = current.getChild(nodes[i]);
if (child == null) {
// there is no matching path on ttl cache tree
- return;
+ return new TSStatus(TSStatusCode.PATH_NOT_EXIST.getStatusCode())
+ .setMessage(
+ "Not TTL rule"
+ + " set for "
+ + String.join(IoTDBConstant.PATH_SEPARATOR + "", nodes));
}
if (hasNonDefaultTTL) {
parentOfSubPathToBeRemoved = current;
@@ -114,13 +122,14 @@ public class TTLCache {
if (!current.getChildren().isEmpty()) {
// node to be removed is internal node, then just reset its ttl
current.ttl = NULL_TTL;
- return;
+ return StatusUtils.OK;
}
// node to be removed is leaf node, then remove corresponding node of this
path from cache tree
if (parentOfSubPathToBeRemoved != null) {
parentOfSubPathToBeRemoved.removeChild(nodes[index]);
}
+ return StatusUtils.OK;
}
/**