jt2594838 commented on code in PR #18866:
URL: https://github.com/apache/iotdb/pull/18866#discussion_r4268586039


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:
##########
@@ -2696,11 +2761,161 @@ private void retainEventMemory(final SubscriptionEvent 
event, final long bytes)
     }
   }
 
+  private void onResponseDelivered(
+      final SubscriptionEvent event, final SubscriptionPollResponse response) {
+    acquireReadLock();
+    try {
+      synchronized (event) {
+        final DeliveryBatchRecord record = deliveryBatches.get(event);
+        if (isClosed
+            || closeRequested
+            || pendingSeekRequest != null
+            || Objects.isNull(record)
+            || event.isCommitted()
+            || event.getCurrentResponse() != response
+            || outstandingEventsByCommitContext.get(event.getCommitContext()) 
!= event) {
+          return;
+        }
+        record.delivered = true;
+        reclaimDeliveredPayload(event, record);
+      }
+    } finally {
+      releaseReadLock();
+    }
+    requestPrefetch();
+  }
+
+  private void reclaimDeliveredPayloads() {
+    // Only materialized events need a check. The number of these is bounded 
by the memory budget.
+    for (final SubscriptionEvent event : retainedBytesByEvent.keySet()) {
+      synchronized (event) {
+        final DeliveryBatchRecord record = deliveryBatches.get(event);
+        if (Objects.nonNull(record) && record.delivered && 
!event.isCommitted()) {
+          reclaimDeliveredPayload(event, record);
+        }
+      }
+    }
+  }
+
+  private void reclaimDeliveredPayload(
+      final SubscriptionEvent event, final DeliveryBatchRecord record) {
+    if (event.isPayloadDetached() || !record.delivered) {
+      return;
+    }
+    // Pending entries can precede durable WAL visibility. Verify every member 
and fragment before
+    // releasing the only payload copy. This read does not change replay or 
committed progress.
+    if (!record.replayable && Objects.isNull(readDeliveryBatch(event, record, 
false))) {
+      return;
+    }

Review Comment:
   Will `readDeliveryBatch(event, record, false)` be too costly here?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:
##########
@@ -195,6 +199,15 @@ public class ConsensusPrefetchingQueue {
   private final Map<SubscriptionCommitContext, SubscriptionEvent> 
outstandingEventsByCommitContext =
       new ConcurrentHashMap<>();
 
+  /**
+   * Compact batch boundaries and source positions; no Tablet or serialized 
response is retained.
+   */
+  private final Map<SubscriptionEvent, DeliveryBatchRecord> deliveryBatches =
+      new ConcurrentHashMap<>();
+
+  private final ConcurrentSkipListMap<Long, Integer> deliveryStartIndices =
+      new ConcurrentSkipListMap<>();

Review Comment:
   Explain the key and value in a comment.



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