|
65 | 65 | import java.util.concurrent.TimeUnit; |
66 | 66 | import java.util.concurrent.atomic.AtomicBoolean; |
67 | 67 | import java.util.concurrent.atomic.AtomicLong; |
68 | | -import java.util.regex.Matcher; |
69 | | -import java.util.regex.Pattern; |
70 | 68 |
|
71 | 69 | /** {@link IStateMachine} for ConfigRegion. */ |
72 | 70 | public class ConfigRegionStateMachine implements IStateMachine, IStateMachine.EventApi { |
@@ -94,14 +92,14 @@ public class ConfigRegionStateMachine implements IStateMachine, IStateMachine.Ev |
94 | 92 |
|
95 | 93 | private static final String CURRENT_FILE_DIR = |
96 | 94 | ConsensusManager.getConfigRegionDir() + File.separator + "current"; |
| 95 | + private static final String LOG_INPROGRESS_FILE_PREFIX = "log_inprogress_"; |
| 96 | + private static final String LOG_FILE_PREFIX = "log_"; |
97 | 97 | private static final String PROGRESS_FILE_PATH = |
98 | | - CURRENT_FILE_DIR + File.separator + "log_inprogress_"; |
99 | | - private static final String FILE_PATH = CURRENT_FILE_DIR + File.separator + "log_"; |
| 98 | + CURRENT_FILE_DIR + File.separator + LOG_INPROGRESS_FILE_PREFIX; |
| 99 | + private static final String FILE_PATH = CURRENT_FILE_DIR + File.separator + LOG_FILE_PREFIX; |
100 | 100 | private static final long LOG_FILE_MAX_SIZE = |
101 | 101 | CONF.getConfigNodeSimpleConsensusLogSegmentSizeMax(); |
102 | 102 | private final TEndPoint currentNodeTEndPoint; |
103 | | - private static final Pattern LOG_INPROGRESS_PATTERN = Pattern.compile("\\d+"); |
104 | | - private static final Pattern LOG_PATTERN = Pattern.compile("(?<=_)(\\d+)$"); |
105 | 103 |
|
106 | 104 | public ConfigRegionStateMachine(ConfigManager configManager, ConfigPlanExecutor executor) { |
107 | 105 | this.executor = executor; |
@@ -626,17 +624,27 @@ private void createLogFile(int startIndex) { |
626 | 624 | } |
627 | 625 |
|
628 | 626 | private static long parseEndIndex(String filename) { |
629 | | - if (filename.startsWith("log_inprogress_")) { |
630 | | - Matcher matcher = LOG_INPROGRESS_PATTERN.matcher(filename); |
631 | | - if (matcher.find()) { |
632 | | - return Long.parseLong(matcher.group()); |
| 627 | + final String endIndexString; |
| 628 | + if (filename.startsWith(LOG_INPROGRESS_FILE_PREFIX)) { |
| 629 | + endIndexString = filename.substring(LOG_INPROGRESS_FILE_PREFIX.length()); |
| 630 | + } else if (filename.startsWith(LOG_FILE_PREFIX)) { |
| 631 | + final int lastSeparatorIndex = filename.lastIndexOf('_'); |
| 632 | + if (lastSeparatorIndex < LOG_FILE_PREFIX.length()) { |
| 633 | + return 0; |
633 | 634 | } |
| 635 | + endIndexString = filename.substring(lastSeparatorIndex + 1); |
634 | 636 | } else { |
635 | | - Matcher matcher = LOG_PATTERN.matcher(filename); |
636 | | - if (matcher.find()) { |
637 | | - return Long.parseLong(matcher.group()); |
| 637 | + return 0; |
| 638 | + } |
| 639 | + |
| 640 | + if (endIndexString.isEmpty()) { |
| 641 | + return 0; |
| 642 | + } |
| 643 | + for (int i = 0; i < endIndexString.length(); i++) { |
| 644 | + if (!Character.isDigit(endIndexString.charAt(i))) { |
| 645 | + return 0; |
638 | 646 | } |
639 | 647 | } |
640 | | - return 0; |
| 648 | + return Long.parseLong(endIndexString); |
641 | 649 | } |
642 | 650 | } |
0 commit comments