[ 
https://issues.apache.org/jira/browse/ROCKETMQ-270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16288951#comment-16288951
 ] 

ASF GitHub Bot commented on ROCKETMQ-270:
-----------------------------------------

vongosling closed pull request #189: [ROCKETMQ-270] Move flush position forward 
to first MappedFile whose start offset is non-zero
URL: https://github.com/apache/rocketmq/pull/189
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java 
b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
index edf4c918..0ee1b9f9 100644
--- a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
+++ b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
@@ -421,7 +421,7 @@ public int deleteExpiredFileByOffset(long offset, int 
unitSize) {
 
     public boolean flush(final int flushLeastPages) {
         boolean result = true;
-        MappedFile mappedFile = this.findMappedFileByOffset(this.flushedWhere, 
false);
+        MappedFile mappedFile = this.findMappedFileByOffset(this.flushedWhere, 
this.flushedWhere == 0);
         if (mappedFile != null) {
             long tmpTimeStamp = mappedFile.getStoreTimestamp();
             int offset = mappedFile.flush(flushLeastPages);
@@ -438,7 +438,7 @@ public boolean flush(final int flushLeastPages) {
 
     public boolean commit(final int commitLeastPages) {
         boolean result = true;
-        MappedFile mappedFile = 
this.findMappedFileByOffset(this.committedWhere, false);
+        MappedFile mappedFile = 
this.findMappedFileByOffset(this.committedWhere, this.committedWhere == 0);
         if (mappedFile != null) {
             int offset = mappedFile.commit(commitLeastPages);
             long where = mappedFile.getFileFromOffset() + offset;
diff --git 
a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java 
b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
index 203dfcd5..dd7b229d 100644
--- a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
+++ b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java
@@ -20,9 +20,7 @@
 import java.io.File;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
-
 import org.apache.rocketmq.common.UtilAll;
-import org.apache.rocketmq.store.config.MessageStoreConfig;
 import org.junit.After;
 import org.junit.Test;
 
@@ -47,7 +45,7 @@ public void testGetLastMappedFile() {
     }
 
     @Test
-    public void test_findMappedFileByOffset() {
+    public void testFindMappedFileByOffset() {
         // four-byte string.
         final String fixedMsg = "abcd";
 
@@ -97,6 +95,28 @@ public void test_findMappedFileByOffset() {
         mappedFileQueue.destroy();
     }
 
+    @Test
+    public void testFindMappedFileByOffset_StartOffsetIsNonZero() {
+        MappedFileQueue mappedFileQueue =
+            new MappedFileQueue("target/unit_test_store/b/", 1024, null);
+
+        //Start from a non-zero offset
+        MappedFile mappedFile = mappedFileQueue.getLastMappedFile(1024);
+        assertThat(mappedFile).isNotNull();
+
+        
assertThat(mappedFileQueue.findMappedFileByOffset(1025)).isEqualTo(mappedFile);
+
+        assertThat(mappedFileQueue.findMappedFileByOffset(0)).isNull();
+        assertThat(mappedFileQueue.findMappedFileByOffset(123, 
false)).isNull();
+        assertThat(mappedFileQueue.findMappedFileByOffset(123, 
true)).isEqualTo(mappedFile);
+
+        assertThat(mappedFileQueue.findMappedFileByOffset(0, false)).isNull();
+        assertThat(mappedFileQueue.findMappedFileByOffset(0, 
true)).isEqualTo(mappedFile);
+
+        mappedFileQueue.shutdown(1000);
+        mappedFileQueue.destroy();
+    }
+
     @Test
     public void testAppendMessage() {
         final String fixedMsg = "0123456789abcdef";


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Slave Broker can't start normally if master broker has been cleaned commit log
> ------------------------------------------------------------------------------
>
>                 Key: ROCKETMQ-270
>                 URL: https://issues.apache.org/jira/browse/ROCKETMQ-270
>             Project: Apache RocketMQ
>          Issue Type: Bug
>          Components: rocketmq-broker
>    Affects Versions: 4.0.0-incubating, 4.1.0-incubating
>            Reporter: yukon
>            Assignee: yukon
>             Fix For: 4.2.0
>
>
> How to reproduce this bug?
> 1. Start master broker, and write lots of messages until broker starts 
> cleaning commit log.
> 2. When the first commit log file isn't 00000000000000, start slave broker.
> In current state, slave broker will pull messages from master broker, but the 
> first message's offset isn't zero, and isn't equal to commit offset, so slave 
> broker could't do right flush.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to