HTHou commented on a change in pull request #983:
URL: https://github.com/apache/incubator-iotdb/pull/983#discussion_r422661202



##########
File path: 
server/src/main/java/org/apache/iotdb/db/engine/upgrade/UpgradeTask.java
##########
@@ -40,30 +47,69 @@ public UpgradeTask(TsFileResource upgradeResource) {
   @Override
   public void runMayThrow() {
     try {
-      upgradeResource.getWriteQueryLock().readLock().lock();
-      String tsfilePathBefore = upgradeResource.getFile().getAbsolutePath();
-      String tsfilePathAfter = 
UpgradeUtils.getUpgradeFileName(upgradeResource.getFile());
-
-      UpgradeLog.writeUpgradeLogFile(
-          tsfilePathBefore + COMMA_SEPERATOR + 
UpgradeCheckStatus.BEGIN_UPGRADE_FILE);
+      List<TsFileResource> upgradedResources = generateUpgradedFiles();
       upgradeResource.getWriteQueryLock().writeLock().lock();
+      String oldTsfilePath = upgradeResource.getFile().getAbsolutePath();
       try {
-        FSFactoryProducer.getFSFactory().getFile(tsfilePathBefore).delete();
-        FSFactoryProducer.getFSFactory()
-            
.moveFile(FSFactoryProducer.getFSFactory().getFile(tsfilePathAfter),
-                FSFactoryProducer.getFSFactory().getFile(tsfilePathBefore));
+        // delete old TsFile
+        upgradeResource.remove();
+        // move upgraded TsFiles to their own partition directories
+        for (TsFileResource upgradedResource : upgradedResources) {
+          File upgradedFile = upgradedResource.getFile();
+          long partition = upgradedResource.getTimePartitionWithCheck();
+          String storageGroupPath = 
upgradedFile.getParentFile().getParentFile().getParent();
+          File partitionDir = 
FSFactoryProducer.getFSFactory().getFile(storageGroupPath, partition + "");
+          if (!partitionDir.exists()) {
+            partitionDir.mkdir();
+          }
+          FSFactoryProducer.getFSFactory().moveFile(upgradedFile,
+              FSFactoryProducer.getFSFactory().getFile(partitionDir, 
upgradedFile.getName()));
+          upgradedResource.setFile(
+              FSFactoryProducer.getFSFactory().getFile(partitionDir, 
upgradedFile.getName()));
+          upgradedResource.serialize();
+          // delete tmp partition folder when it is empty
+          if (upgradedFile.getParentFile().isDirectory() 
+              && upgradedFile.getParentFile().listFiles().length == 0) {

Review comment:
       Isn't checking `isDirectory()` enough? 
   The javadoc of listFiles said 
   `If this abstract pathname does not denote a directory, then this
   method returns null .  Otherwise an array of File objects
   is returned, one for each file or directory in the directory.`




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to