BUAAserein commented on code in PR #12293:
URL: https://github.com/apache/iotdb/pull/12293#discussion_r1560503570
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java:
##########
@@ -457,55 +454,30 @@ private void sendRegisterRequestToConfigNode() throws
StartupException, IOExcept
}
}
- // TODO: Implement in IConsensus, not in DataNode
- private List<ConsensusGroupId> getConsensusGroupId() {
- List<ConsensusGroupId> consensusGroupIds = new ArrayList<>();
- String dataRegionConsensusDir = config.getDataRegionConsensusDir();
- if
(config.getDataRegionConsensusProtocolClass().equals(ConsensusFactory.RATIS_CONSENSUS))
{
- return consensusGroupIds;
- }
- try (DirectoryStream<Path> stream =
- Files.newDirectoryStream(new File(dataRegionConsensusDir).toPath())) {
- for (Path path : stream) {
- String[] items = path.getFileName().toString().split("_");
- ConsensusGroupId consensusGroupId =
- ConsensusGroupId.Factory.create(Integer.parseInt(items[0]),
Integer.parseInt(items[1]));
- consensusGroupIds.add(consensusGroupId);
- }
- } catch (IOException e) {
- logger.error("Cannot get consensus group id from {}",
dataRegionConsensusDir, e);
- }
- return consensusGroupIds;
- }
-
- // TODO: remove for current version, add todo for rename
- private void renameInvalidRegionDirs(List<ConsensusGroupId>
invalidConsensusGroupIds) {
- for (ConsensusGroupId consensusGroupId : invalidConsensusGroupIds) {
- File oldDir =
- new File(
- IoTConsensus.buildPeerDir(
- new File(config.getDataRegionConsensusDir()),
consensusGroupId));
- File newDir =
- new File(
- IoTConsensus.buildPeerDir(
- new File(config.getInvalidDataRegionConsensusDir()),
consensusGroupId));
- if (oldDir.exists() && !FileUtils.moveFileSafe(oldDir, newDir)) {
- logger.error("move {} to {} failed.", oldDir.getAbsolutePath(),
newDir.getAbsolutePath());
- try {
- FileUtils.recursivelyDeleteFolder(oldDir.getPath());
- } catch (IOException e) {
- logger.error("delete {} failed.", oldDir.getAbsolutePath());
- }
- }
- }
- }
-
private void removeInvalidRegions(List<ConsensusGroupId>
dataNodeConsensusGroupIds) {
List<ConsensusGroupId> invalidConsensusGroupIds =
- getConsensusGroupId().stream()
+
DataRegionConsensusImpl.getInstance().getAllConsensusGroupIdsFromDisk().stream()
.filter(consensusGroupId ->
!dataNodeConsensusGroupIds.contains(consensusGroupId))
.collect(Collectors.toList());
- renameInvalidRegionDirs(invalidConsensusGroupIds);
+ if (!invalidConsensusGroupIds.isEmpty()) {
+ logger.info("Remove invalid region directories... {}",
invalidConsensusGroupIds);
+ for (ConsensusGroupId consensusGroupId : invalidConsensusGroupIds) {
+ File oldDir =
+ new File(
Review Comment:
Yes, we add `getRegionDirFromConsensusGroupId()` to IConsensus
--
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]