You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "VGalaxies (via GitHub)" <gi...@apache.org> on 2024/08/31 03:50:24 UTC

[PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

VGalaxies opened a new pull request, #13360:
URL: https://github.com/apache/iotdb/pull/13360

   WIP...


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797644321


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {
+    Reference<? extends EnrichedEvent> reference;
+    try {
+      while ((reference = REFERENCE_QUEUE.remove(500)) != null) {
+        finalizeResource((PipeEventPhantomReference) reference);
+      }
+    } catch (final InterruptedException e) {
+      // Finalize remaining references.
+      while ((reference = REFERENCE_QUEUE.poll()) != null) {
+        finalizeResource((PipeEventPhantomReference) reference);
+      }
+    } catch (final Exception e) {
+      // Nowhere to really log this.
+    }
+  }
+
+  private void finalizeResource(final PipeEventPhantomReference reference) {
+    try {
+      reference.finalizeResources();
+      reference.clear();
+    } finally {
+      PIPE_EVENT_PHANTOM_REFERENCES.remove(reference);
+    }
+  }
+
+  private static class PipeEventPhantomReference extends PhantomReference<EnrichedEvent> {
+
+    private final String coreReportMessageSnapshot;
+    private PipeEventResource resource;
+
+    private PipeEventPhantomReference(
+        final EnrichedEvent event,
+        final PipeEventResource resource,
+        final ReferenceQueue<? super EnrichedEvent> queue) {
+      super(event, queue);
+      this.coreReportMessageSnapshot = event.coreReportMessage();
+      this.resource = resource;
+    }
+
+    private void finalizeResources() {
+      if (this.resource != null) {
+        try {
+          this.resource.clearReferenceCount(coreReportMessageSnapshot);
+        } finally {
+          this.resource = null;
+        }
+      }
+    }
+  }
+
+  ///////////////////// APIs provided for EnrichedEvent /////////////////////
+
+  public void trackPipeEventResource(final EnrichedEvent event, final PipeEventResource resource) {
+    final PipeEventPhantomReference reference =
+        new PipeEventPhantomReference(event, resource, REFERENCE_QUEUE);
+    PIPE_EVENT_PHANTOM_REFERENCES.add(reference);
+  }
+
+  public abstract static class PipeEventResource {
+
+    private final AtomicBoolean isReleased;
+    private final AtomicInteger referenceCount;
+
+    protected PipeEventResource(
+        final AtomicBoolean isReleased, final AtomicInteger referenceCount) {
+      this.isReleased = isReleased;
+      this.referenceCount = referenceCount;
+    }
+
+    private void clearReferenceCount(final String holderMessage) {
+      if (isReleased.get()) {
+        return;
+      }
+
+      if (referenceCount.get() >= 1) {
+        LOGGER.info("finalize resource for event with holder message {}", holderMessage);

Review Comment:
   ```suggestion
           LOGGER.error("finalize resource for event with holder message {}", holderMessage);
   ```
   "RESOURCE LEAK DETECTED: {}....", class name...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu merged PR #13360:
URL: https://github.com/apache/iotdb/pull/13360


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797692193


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java:
##########
@@ -604,6 +604,17 @@ private void loadPipeProps(Properties properties) {
             properties.getProperty(
                 "two_stage_aggregate_sender_end_points_cache_in_ms",
                 String.valueOf(config.getTwoStageAggregateSenderEndPointsCacheInMs()))));
+
+    config.setPipeEventReferenceTrackingEnabled(
+        Boolean.parseBoolean(
+            properties.getProperty(
+                "pipe_event_reference_tracking_enabled",
+                String.valueOf(config.getPipeEventReferenceTrackingEnabled()))));
+    config.setPipeEventReferenceEliminateIntervalSeconds(
+        Long.parseLong(
+            properties.getProperty(
+                "pipe_event_reference_eliminate_interval_seconds",

Review Comment:
   Can be shorter by default?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797642611


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {

Review Comment:
   We have to consider using a multi-threaded pool to run this method if necessary (maybe we can add a conf parma for this?)



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797694199


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {

Review Comment:
   consider optimizing in the next PR...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797642076


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {

Review Comment:
   For one thread, what is the max number of events per second can be checked?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797694118


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java:
##########
@@ -604,6 +604,17 @@ private void loadPipeProps(Properties properties) {
             properties.getProperty(
                 "two_stage_aggregate_sender_end_points_cache_in_ms",
                 String.valueOf(config.getTwoStageAggregateSenderEndPointsCacheInMs()))));
+
+    config.setPipeEventReferenceTrackingEnabled(
+        Boolean.parseBoolean(
+            properties.getProperty(
+                "pipe_event_reference_tracking_enabled",
+                String.valueOf(config.getPipeEventReferenceTrackingEnabled()))));
+    config.setPipeEventReferenceEliminateIntervalSeconds(
+        Long.parseLong(
+            properties.getProperty(
+                "pipe_event_reference_eliminate_interval_seconds",

Review Comment:
   no other ideas for now...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797691982


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {

Review Comment:
   add a check here: if this run is enabled by conf 



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797642117


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {
+    Reference<? extends EnrichedEvent> reference;
+    try {
+      while ((reference = REFERENCE_QUEUE.remove(500)) != null) {
+        finalizeResource((PipeEventPhantomReference) reference);
+      }
+    } catch (final InterruptedException e) {
+      // Finalize remaining references.
+      while ((reference = REFERENCE_QUEUE.poll()) != null) {
+        finalizeResource((PipeEventPhantomReference) reference);
+      }
+    } catch (final Exception e) {
+      // Nowhere to really log this.
+    }
+  }
+
+  private void finalizeResource(final PipeEventPhantomReference reference) {
+    try {
+      reference.finalizeResources();
+      reference.clear();
+    } finally {
+      PIPE_EVENT_PHANTOM_REFERENCES.remove(reference);
+    }
+  }
+
+  private static class PipeEventPhantomReference extends PhantomReference<EnrichedEvent> {
+
+    private final String coreReportMessageSnapshot;
+    private PipeEventResource resource;
+
+    private PipeEventPhantomReference(
+        final EnrichedEvent event,
+        final PipeEventResource resource,
+        final ReferenceQueue<? super EnrichedEvent> queue) {
+      super(event, queue);
+      this.coreReportMessageSnapshot = event.coreReportMessage();

Review Comment:
   Calling coreReportMessage is time consuming ...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Pipe: release resources of pipe event that have been GCed but the reference count is not zero by PhantomReference [iotdb]

Posted by "SteveYurongSu (via GitHub)" <gi...@apache.org>.
SteveYurongSu commented on code in PR #13360:
URL: https://github.com/apache/iotdb/pull/13360#discussion_r1797641954


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/ref/PipePhantomReferenceManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.pipe.resource.ref;
+
+import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class PipePhantomReferenceManager {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PipePhantomReferenceManager.class);
+
+  private static final Set<PipeEventPhantomReference> PIPE_EVENT_PHANTOM_REFERENCES =
+      ConcurrentHashMap.newKeySet();
+
+  private static final ReferenceQueue<EnrichedEvent> REFERENCE_QUEUE = new ReferenceQueue<>();
+
+  public PipePhantomReferenceManager() {
+    // Do nothing now.
+  }
+
+  public int getPhantomReferenceCount() {
+    return PIPE_EVENT_PHANTOM_REFERENCES.size();
+  }
+
+  protected void gcHook() {

Review Comment:
   Use a seperated thread pool (extends PipePeriodicalJobExecutor?) to run this method periodically?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org