luoluoyuyu commented on code in PR #17732:
URL: https://github.com/apache/iotdb/pull/17732#discussion_r3309317271
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/UDFInfo.java:
##########
@@ -272,6 +278,32 @@ public void deserializeExistedJarToMD5(InputStream
inputStream) throws IOExcepti
public void clear() {
existedJarToMD5.clear();
+ existedJarToReferenceCount.clear();
udfTable.clear();
}
+
+ private void addJarReference(String jarName, String jarMD5) {
+ existedJarToMD5.putIfAbsent(jarName, jarMD5);
Review Comment:
`putIfAbsent` 只会在 jar 名已存在时保留**第一次**写入的 MD5,但仍会执行 `merge` 增加引用计数。
当前 `validate()` 在 `addUDFInTable` 之前会拦截「同名 jar、不同
MD5」,因此正常路径是安全的。但若未来有代码路径绕过 `validate` 直接调用 `addJarReference`,会出现 refCount 与
MD5 不一致。
**建议**:在 `addJarReference` 内增加防御性检查,例如:
```java
final String existing = existedJarToMD5.get(jarName);
if (existing != null && !existing.equals(jarMD5)) {
throw new IoTDBRuntimeException(...);
}
existedJarToMD5.putIfAbsent(jarName, jarMD5);
```
这样与 `validate()` 形成双保险。
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/UDFInfo.java:
##########
@@ -248,6 +253,7 @@ public void processLoadSnapshot(File snapshotDir) throws
IOException {
deserializeExistedJarToMD5(fileInputStream);
udfTable.deserializeUDFTable(fileInputStream);
+ rebuildJarMetadataFromUDFTable();
Review Comment:
`processLoadSnapshot` 先 `deserializeExistedJarToMD5` 再
`rebuildJarMetadataFromUDFTable()`,后者会 clear 并完全从 `udfTable` 重建 jar 元数据,使得反序列化的
`existedJarToMD5` 内容被丢弃。
若这是有意为之(以 udfTable 为唯一真相源),建议在方法上加一行注释说明,避免后续维护者误以为需要同时保留 snapshot 里的 jar
map。
另:旧版本 snapshot 若 `existedJarToMD5` 与 udfTable 不一致,`rebuild` 能自动修复,这是加分项。
--
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]