Caideyipi commented on code in PR #18029:
URL: https://github.com/apache/iotdb/pull/18029#discussion_r3472891169


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/tag/TagManager.java:
##########
@@ -166,34 +165,33 @@ public void addIndex(String tagKey, String tagValue, 
IMeasurementMNode<?> measur
       return;
     }
 
-    int tagIndexOldSize = tagIndex.size();
-    Map<String, Set<IMeasurementMNode<?>>> tagValueMap =
-        tagIndex.computeIfAbsent(tagKey, k -> new ConcurrentHashMap<>());
-    int tagIndexNewSize = tagIndex.size();
-
-    int tagValueMapOldSize = tagValueMap.size();
-    Set<IMeasurementMNode<?>> measurementsSet =
-        tagValueMap.computeIfAbsent(tagValue, v -> 
Collections.synchronizedSet(new HashSet<>()));
-    int tagValueMapNewSize = tagValueMap.size();
+    tagIndex.compute(
+        tagKey,
+        (key, tagValueMap) -> {
+          long memorySize = 0;
+          if (tagValueMap == null) {
+            tagValueMap = new ConcurrentHashMap<>();
+            // the last 4 is the memory occupied by the size of tagvaluemap
+            memorySize += RamUsageEstimator.sizeOf(tagKey) + 4;

Review Comment:
   Good point. I replaced the hard-coded 4 with COLLECTION_SIZE_FIELD_BYTES = 
Integer.BYTES for the estimated collection size field and removed the 
misleading comments in ee56b901e8c.



-- 
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