mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-30 18:10:44 +08:00
* bugfix: CopyOnWriteArray#listIterator do not support remove action when iterating * add testcase --------- Co-authored-by: mipengcheng3 <mipengcheng3@jd.com>
This commit is contained in:
@@ -406,6 +406,7 @@ public class MappedFileQueue implements Swappable {
|
||||
}
|
||||
|
||||
ListIterator<MappedFile> iterator = this.mappedFiles.listIterator(mappedFiles.size());
|
||||
List<MappedFile> toRemoves = new ArrayList<>();
|
||||
|
||||
while (iterator.hasPrevious()) {
|
||||
mappedFileLast = iterator.previous();
|
||||
@@ -416,9 +417,14 @@ public class MappedFileQueue implements Swappable {
|
||||
mappedFileLast.setCommittedPosition(where);
|
||||
break;
|
||||
} else {
|
||||
iterator.remove();
|
||||
toRemoves.add(mappedFileLast);
|
||||
}
|
||||
}
|
||||
|
||||
if (!toRemoves.isEmpty()) {
|
||||
this.mappedFiles.removeAll(toRemoves);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -477,6 +477,21 @@ public class MappedFileQueueTest {
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset() {
|
||||
final String fixedMsg = "0123456789abcdef";
|
||||
MappedFileQueue mappedFileQueue =
|
||||
new MappedFileQueue(storePath + File.separator + "a/", 64, null);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0);
|
||||
assertThat(mappedFile).isNotNull();
|
||||
assertThat(mappedFile.appendMessage(fixedMsg.getBytes())).isTrue();
|
||||
}
|
||||
assertThat(mappedFileQueue.getMappedFiles().size()).isEqualTo(2);
|
||||
assertThat(mappedFileQueue.resetOffset(0)).isTrue();
|
||||
assertThat(mappedFileQueue.getMappedFiles().size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
File file = new File(storePath);
|
||||
|
||||
Reference in New Issue
Block a user