[CARBONDATA-2854] Release the lock of tablestatus file in 'clean files' command before deleting physical files

Release table status file lock before delete physical files, otherwise table status file will be locked during deleting physical files, it may take a long time, other operations will fail to get table status file lock.

This closes #2634
diff --git a/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java b/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
index daf54a0..fdce76b 100755
--- a/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
+++ b/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
@@ -934,6 +934,8 @@
     CarbonLockUtil.deleteExpiredSegmentLockFiles(carbonTable);
     if (isLoadDeletionRequired(carbonTable.getMetadataPath())) {
       AbsoluteTableIdentifier identifier = carbonTable.getAbsoluteTableIdentifier();
+      boolean updationCompletionStatus = false;
+      LoadMetadataDetails[] newAddedLoadHistoryList = null;
       ReturnTuple tuple = isUpdationRequired(isForceDeletion, carbonTable, identifier);
       if (tuple.isUpdateRequired) {
         ICarbonLock carbonTableStatusLock =
@@ -958,7 +960,6 @@
             int maxSegmentId = SegmentStatusManager.getMaxSegmentId(tuple2.details);
             int invisibleSegmentCnt = SegmentStatusManager.countInvisibleSegments(
                 tuple2.details, maxSegmentId);
-            LoadMetadataDetails[] newAddedLoadHistoryList = null;
             // if execute command 'clean files' or the number of invisible segment info
             // exceeds the value of 'carbon.invisible.segments.preserve.count',
             // it need to append the invisible segment list to 'tablestatus.history' file.
@@ -983,9 +984,7 @@
                   updateLoadMetadataFromOldToNew(tuple2.details, latestMetadata);
               writeLoadMetadata(identifier, latestStatus);
             }
-            DeleteLoadFolders.physicalFactAndMeasureMetadataDeletion(
-                identifier, carbonTable.getMetadataPath(),
-                newAddedLoadHistoryList, isForceDeletion, partitionSpecs);
+            updationCompletionStatus = true;
           } else {
             String dbName = identifier.getCarbonTableIdentifier().getDatabaseName();
             String tableName = identifier.getCarbonTableIdentifier().getTableName();
@@ -1001,6 +1000,11 @@
           if (locked) {
             CarbonLockUtil.fileUnlock(carbonTableStatusLock, LockUsage.TABLE_STATUS_LOCK);
           }
+          if (updationCompletionStatus) {
+            DeleteLoadFolders.physicalFactAndMeasureMetadataDeletion(
+                identifier, carbonTable.getMetadataPath(),
+                newAddedLoadHistoryList, isForceDeletion, partitionSpecs);
+          }
         }
       }
     }