Jason918 commented on a change in pull request #3357:
URL: https://github.com/apache/rocketmq/pull/3357#discussion_r713856997
##########
File path: store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
##########
@@ -144,35 +145,39 @@ void deleteExpiredFile(List<MappedFile> files) {
}
}
+
public boolean load() {
File dir = new File(this.storePath);
- File[] files = dir.listFiles();
- if (files != null) {
- // ascending order
- Arrays.sort(files);
- for (File file : files) {
-
- if (file.length() != this.mappedFileSize) {
- log.warn(file + "\t" + file.length()
- + " length not matched message store config value,
please check it manually");
- return false;
- }
+ File[] ls = dir.listFiles();
+ if (ls != null) {
+ return doLoad(Arrays.asList(ls));
+ }
+ return true;
+ }
- try {
- MappedFile mappedFile = new MappedFile(file.getPath(),
mappedFileSize);
-
- mappedFile.setWrotePosition(this.mappedFileSize);
- mappedFile.setFlushedPosition(this.mappedFileSize);
- mappedFile.setCommittedPosition(this.mappedFileSize);
- this.mappedFiles.add(mappedFile);
- log.info("load " + file.getPath() + " OK");
- } catch (IOException e) {
- log.error("load file " + file + " error", e);
- return false;
- }
+ public boolean doLoad(List<File> files) {
+ // ascending order
+ Collections.sort(files);
Review comment:
Great point.
Changed `Collections.sort(files)` to
`files.sort(Comparator.comparing(File::getName))`, sort the file using simple
filenames, aka, the last part of the path.
And added test in
org.apache.rocketmq.store.MultiPathMappedFileQueueTest#testLoadReadOnlyMappedFiles,
PTAL.
--
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]