You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2022/09/01 11:48:13 UTC

[rocketmq] branch develop updated: [ISSUE#4959] Fix the logic when deal with a write event with empty events

This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new de7cd0df1 [ISSUE#4959] Fix the logic when deal with a write event with empty events
de7cd0df1 is described below

commit de7cd0df10161b83819df8d97aa786c41c8f4f34
Author: TheR1sing3un <87...@users.noreply.github.com>
AuthorDate: Thu Sep 1 19:48:05 2022 +0800

    [ISSUE#4959] Fix the logic when deal with a write event with empty events
    
    * fix(controller): fix the logic when deal with a write event with empty events
    
    1. fix the logic when deal with a write event with empty events
    
    * style(controller): remove unused import
    
    1. remove unused import
---
 .../controller/impl/DLedgerController.java         | 23 +++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java b/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java
index 54fc753f1..601514594 100644
--- a/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java
+++ b/controller/src/main/java/org/apache/rocketmq/controller/impl/DLedgerController.java
@@ -343,7 +343,18 @@ public class DLedgerController implements Controller {
             final ControllerResult<T> result = this.supplier.get();
             log.info("Event queue run event {}, get the result {}", this.name, result);
             boolean appendSuccess = true;
-            if (this.isWriteEvent) {
+
+            if (!this.isWriteEvent || result.getEvents() == null || result.getEvents().isEmpty()) {
+                // read event, or write event with empty events in response which also equals to read event
+                if (DLedgerController.this.controllerConfig.isProcessReadEvent()) {
+                    // Now the dledger don't have the function of Read-Index or Lease-Read,
+                    // So we still need to propose an empty request to dledger.
+                    final AppendEntryRequest request = new AppendEntryRequest();
+                    request.setBody(new byte[0]);
+                    appendSuccess = appendToDLedgerAndWait(request);
+                }
+            } else {
+                // write event
                 final List<EventMessage> events = result.getEvents();
                 final List<byte[]> eventBytes = new ArrayList<>(events.size());
                 for (final EventMessage event : events) {
@@ -356,19 +367,13 @@ public class DLedgerController implements Controller {
                 }
                 // Append events to dledger
                 if (!eventBytes.isEmpty()) {
+                    // batch append events
                     final BatchAppendEntryRequest request = new BatchAppendEntryRequest();
                     request.setBatchMsgs(eventBytes);
                     appendSuccess = appendToDLedgerAndWait(request);
                 }
-            } else {
-                if (DLedgerController.this.controllerConfig.isProcessReadEvent()) {
-                    // Now the dledger don't have the function of Read-Index or Lease-Read,
-                    // So we still need to propose an empty request to dledger.
-                    final AppendEntryRequest request = new AppendEntryRequest();
-                    request.setBody(new byte[0]);
-                    appendSuccess = appendToDLedgerAndWait(request);
-                }
             }
+
             if (appendSuccess) {
                 final RemotingCommand response = RemotingCommand.createResponseCommandWithHeader(result.getResponseCode(), (CommandCustomHeader) result.getResponse());
                 if (result.getBody() != null) {