CRZbulabula commented on code in PR #17735:
URL: https://github.com/apache/iotdb/pull/17735#discussion_r3279235956


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/TTLInfo.java:
##########
@@ -92,6 +93,20 @@ public TSStatus setTTL(SetTTLPlan plan) {
     return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
   }
 
+  private int calculateNewTTLRuleCount(SetTTLPlan plan) {
+    int newTTLRuleCount = getNewTTLRuleCount(plan.getPathPattern());
+    if (plan.isDataBase()) {
+      String[] pathNodes = Arrays.copyOf(plan.getPathPattern(), 
plan.getPathPattern().length + 1);
+      pathNodes[pathNodes.length - 1] = 
IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;
+      newTTLRuleCount += getNewTTLRuleCount(pathNodes);
+    }
+    return newTTLRuleCount;
+  }
+
+  private int getNewTTLRuleCount(String[] pathNodes) {
+    return ttlCache.getLastNodeTTL(pathNodes) == TTLCache.NULL_TTL ? 1 : 0;

Review Comment:
   `getNewTTLRuleCount` 命名稍微有歧义——它实际返回的是「这个路径是否会新增一个 rule」(0/1),不是「新增 rule 
的数量」。建议改名为 `isNewTTLRule`(返回 boolean)或 `countNewRule`,在 
`calculateNewTTLRuleCount` 里直接累加 `boolean ? 1 : 0`,语义更清晰。



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/SetTTLProcedure.java:
##########
@@ -47,14 +49,19 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
 
 public class SetTTLProcedure extends 
StateMachineProcedure<ConfigNodeProcedureEnv, SetTTLState> {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(SetTTLProcedure.class);
+  private static final long TTL_NOT_EXIST = Long.MIN_VALUE;
 
   private SetTTLPlan plan;
+  private long previousTTL = TTL_NOT_EXIST;

Review Comment:
   建议加一行注释,说明为什么 sentinel 选 `Long.MIN_VALUE` 而不是 
`TTLCache.NULL_TTL`(`-1`)——这两个值在回滚路径里语义不同:`TTL_NOT_EXIST` 表示「写之前根本没设过 TTL」,而 
`NULL_TTL` 是「明确 unset」的 marker。混淆这两者会导致回滚行为错乱,值得留个 hint 给后来读代码的人。



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to