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

[PR] Pipe: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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

   ## Description
   Introduce counter to return TsFileInsertionEvent if event consumption goes over 'pendingQueueConsumeThreshold'
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this 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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -38,6 +39,12 @@ public class PipeRealtimePriorityBlockingQueue extends UnboundedBlockingPendingQ
   private final BlockingDeque<TsFileInsertionEvent> tsfileInsertEventDeque =
       new LinkedBlockingDeque<>();
 
+  private final AtomicInteger eventCount = new AtomicInteger(0);
+
+  private static final int pendingQueueConsumeThreshold = 1000;

Review Comment:
   Better add these into commonConfig & pipeConfig and add configure logic from iotdb-system.properties. However, these shall not appear in iotdb-system.properties by default. Then it can be a hidden config for the convenience of online operation.



-- 
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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,30 +78,53 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= realTimeEventConsumeThreshold) {

Review Comment:
   There're some slightly non-atomic issues.. Two subtasks may concurrently call the "pollFirst", breaking the strictness of the parameter. May use updateAndGet....



-- 
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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,9 +78,20 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= pendingQueueConsumeThreshold && !tsfileInsertEventDeque.isEmpty()) {
+      event = tsfileInsertEventDeque.pollLast();
+      resetEventCount();
+    }
+
+    if (Objects.isNull(event)) {
+      event = super.directPoll();
+      eventCount.incrementAndGet();
+    }
+
     if (Objects.isNull(event)) {
       event = tsfileInsertEventDeque.pollLast();
+      resetEventCount();

Review Comment:
   Only poll first shall be considered as an effective commit and shall reset the counter. Poll last oppositely shall increase the count...



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -89,19 +107,26 @@ public Event directPoll() {
   public Event waitedPoll() {
     Event event = null;
 
-    if (!super.isEmpty()) {
+    if (eventCount.get() >= pendingQueueConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollLast();
+      resetEventCount();
+    }
+    if (event == null && !super.isEmpty()) {
       // Sequentially poll the first offered non-TsFileInsertionEvent
       event = super.directPoll();
+      eventCount.incrementAndGet();
     } else if (!tsfileInsertEventDeque.isEmpty()) {

Review Comment:
   If the event is not null, the previous event will be discarded and will again be "Deque.pollLast()".....



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -140,4 +165,14 @@ public int size() {
   public int getTsFileInsertionEventCount() {
     return tsfileInsertEventDeque.size();
   }
+
+  private void resetEventCount() {
+    long v = 0;
+    while (eventCount.compareAndSet(eventCount.get(), 0)) {

Review Comment:
   Directly setting it is already atomic...



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,9 +78,20 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= pendingQueueConsumeThreshold && !tsfileInsertEventDeque.isEmpty()) {
+      event = tsfileInsertEventDeque.pollLast();
+      resetEventCount();
+    }
+
+    if (Objects.isNull(event)) {
+      event = super.directPoll();
+      eventCount.incrementAndGet();
+    }
+
     if (Objects.isNull(event)) {
       event = tsfileInsertEventDeque.pollLast();
+      resetEventCount();

Review Comment:
   Do not reset here...



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,9 +78,20 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= pendingQueueConsumeThreshold && !tsfileInsertEventDeque.isEmpty()) {
+      event = tsfileInsertEventDeque.pollLast();

Review Comment:
   Poll first...



-- 
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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/config/PipeConfig.java:
##########
@@ -58,6 +58,12 @@ public double getPipeDataStructureTabletMemoryBlockAllocationRejectThreshold() {
     return COMMON_CONFIG.getPipeDataStructureTabletMemoryBlockAllocationRejectThreshold();
   }
 
+  /////////////////////////////// Subtask Connector ///////////////////////////////
+
+  public int getPipeRealTimeFirstDequeHistoryThreshold() {

Review Comment:
   The name can be "pollHistoryThreshold"?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,30 +78,53 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= realTimeEventConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollFirst();
+      eventCount.set(0);
+    }
     if (Objects.isNull(event)) {
-      event = tsfileInsertEventDeque.pollLast();
+      event = super.directPoll();
+      if (Objects.isNull(event)) {
+        event = tsfileInsertEventDeque.pollLast();
+      }
+      if (event != null) {
+        eventCount.incrementAndGet();
+      }
     }
+
     return event;
   }
 
   /**
-   * Try to poll the freshest insertion event from the queue. First, try to poll the first offered
-   * non-TsFileInsertionEvent. If no such event is available, poll the last offered
-   * TsFileInsertionEvent. If no event is available, block until an event is available.
+   * When the number of polls exceeds the realtimeConsumeThreshold, the {@link TsFileInsertionEvent}
+   * of the earliest write to the queue is returned. if the realtimeConsumeThreshold is not reached
+   * then an attempt is made to poll the queue for the latest insertion {@link Event}. First, it
+   * tries to poll the first provided If there is no such {@link Event}, poll the last supplied
+   * {@link TsFileInsertionEvent}. If no {@link Event} is available, it blocks until a {@link Event}
+   * is available.
    *
-   * @return the freshest insertion event. can be null if no event is available.
+   * @return the freshest insertion {@link Event}. can be {@code null} if no event is available.

Review Comment:
   There is an "event" too. (doge)



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,30 +78,53 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= realTimeEventConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollFirst();
+      eventCount.set(0);
+    }
     if (Objects.isNull(event)) {
-      event = tsfileInsertEventDeque.pollLast();
+      event = super.directPoll();
+      if (Objects.isNull(event)) {
+        event = tsfileInsertEventDeque.pollLast();
+      }
+      if (event != null) {
+        eventCount.incrementAndGet();
+      }
     }
+
     return event;
   }
 
   /**
-   * Try to poll the freshest insertion event from the queue. First, try to poll the first offered
-   * non-TsFileInsertionEvent. If no such event is available, poll the last offered
-   * TsFileInsertionEvent. If no event is available, block until an event is available.
+   * When the number of polls exceeds the realtimeConsumeThreshold, the {@link TsFileInsertionEvent}
+   * of the earliest write to the queue is returned. if the realtimeConsumeThreshold is not reached
+   * then an attempt is made to poll the queue for the latest insertion {@link Event}. First, it
+   * tries to poll the first provided If there is no such {@link Event}, poll the last supplied
+   * {@link TsFileInsertionEvent}. If no {@link Event} is available, it blocks until a {@link Event}
+   * is available.
    *
-   * @return the freshest insertion event. can be null if no event is available.
+   * @return the freshest insertion {@link Event}. can be {@code null} if no event is available.
    */
   @Override
   public Event waitedPoll() {
     Event event = null;
-
-    if (!super.isEmpty()) {
+    if (eventCount.get() >= realTimeEventConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollFirst();
+      if (event != null) {
+        eventCount.set(0);
+      }
+    }
+    if (event == null && !super.isEmpty()) {

Review Comment:
   If super.isEmpty(), the tsFile in the deque will not polled here. It may be polled in the "block" code before waiting for a period of time if super.isEmpty() is always true(usually 5s). Adjust the code logic to achieve consistency with the previous logic.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -38,6 +40,11 @@ public class PipeRealtimePriorityBlockingQueue extends UnboundedBlockingPendingQ
   private final BlockingDeque<TsFileInsertionEvent> tsfileInsertEventDeque =
       new LinkedBlockingDeque<>();
 
+  private final AtomicInteger eventCount = new AtomicInteger(0);
+
+  private static final int realTimeEventConsumeThreshold =
+      PipeConfig.getInstance().getPipeRealTimeFirstDequeHistoryThreshold();

Review Comment:
   Better keep the same name with the config's



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -71,30 +78,53 @@ public boolean put(final Event event) {
 
   @Override
   public Event directPoll() {
-    Event event = super.directPoll();
+    Event event = null;
+    if (eventCount.get() >= realTimeEventConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollFirst();
+      eventCount.set(0);
+    }
     if (Objects.isNull(event)) {
-      event = tsfileInsertEventDeque.pollLast();
+      event = super.directPoll();
+      if (Objects.isNull(event)) {
+        event = tsfileInsertEventDeque.pollLast();
+      }
+      if (event != null) {
+        eventCount.incrementAndGet();
+      }
     }
+
     return event;
   }
 
   /**
-   * Try to poll the freshest insertion event from the queue. First, try to poll the first offered
-   * non-TsFileInsertionEvent. If no such event is available, poll the last offered
-   * TsFileInsertionEvent. If no event is available, block until an event is available.
+   * When the number of polls exceeds the realtimeConsumeThreshold, the {@link TsFileInsertionEvent}
+   * of the earliest write to the queue is returned. if the realtimeConsumeThreshold is not reached
+   * then an attempt is made to poll the queue for the latest insertion {@link Event}. First, it
+   * tries to poll the first provided If there is no such {@link Event}, poll the last supplied
+   * {@link TsFileInsertionEvent}. If no {@link Event} is available, it blocks until a {@link Event}
+   * is available.
    *
-   * @return the freshest insertion event. can be null if no event is available.
+   * @return the freshest insertion {@link Event}. can be {@code null} if no event is available.
    */
   @Override
   public Event waitedPoll() {
     Event event = null;
-
-    if (!super.isEmpty()) {
+    if (eventCount.get() >= realTimeEventConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollFirst();
+      if (event != null) {
+        eventCount.set(0);
+      }
+    }
+    if (event == null && !super.isEmpty()) {

Review Comment:
   May delete the "isEmpty" judgment directly...



-- 
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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


##########
integration-test/src/test/java/org/apache/iotdb/subscription/it/local/IoTDBSubscriptionBasicIT.java:
##########
@@ -188,9 +188,11 @@ public void onFailure(final Throwable e) {
     // Check row count
     try {
       // Keep retrying if there are execution failures
-      AWAIT.untilAsserted(() -> Assert.assertEquals(200, rowCount.get()));
-      Assert.assertTrue(commitSuccessCount.get() > lastCommitSuccessCount.get());
-      Assert.assertEquals(0, commitFailureCount.get());
+      AWAIT.untilAsserted(() -> {
+        Assert.assertEquals(200, rowCount.get());
+        Assert.assertTrue(commitSuccessCount.get() > lastCommitSuccessCount.get());
+        Assert.assertEquals(0, commitFailureCount.get());
+      });

Review Comment:
   By the way, fix the same issue here https://github.com/apache/iotdb/blob/master/integration-test/src/test/java/org/apache/iotdb/subscription/it/local/IoTDBSubscriptionBasicIT.java#L165...



-- 
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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/task/subtask/connector/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -89,19 +107,26 @@ public Event directPoll() {
   public Event waitedPoll() {
     Event event = null;
 
-    if (!super.isEmpty()) {
+    if (eventCount.get() >= pendingQueueConsumeThreshold) {
+      event = tsfileInsertEventDeque.pollLast();
+      resetEventCount();
+    }
+    if (event == null && !super.isEmpty()) {
       // Sequentially poll the first offered non-TsFileInsertionEvent
       event = super.directPoll();
+      eventCount.incrementAndGet();
     } else if (!tsfileInsertEventDeque.isEmpty()) {

Review Comment:
   If the event is not null, the previous event will be discarded and the "event"'s reference will again be "Deque.pollLast()".....



-- 
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: Introduce counter to reduce historical data buildup in PipeRealtimePriorityBlockingQueue [iotdb]

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


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