core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
/**
   * updates deletion status
   *
   * @param loadIds
   * @param tableFolderPath
   * @return
   */
updates deletion status
@param loadIds
@param tableFolderPath
@return
updates deletion status @param loadIds @param tableFolderPath @return
public static List<String> updateDeletionStatus(AbsoluteTableIdentifier identifier,
      List<String> loadIds, String tableFolderPath) throws Exception {
    CarbonTableIdentifier carbonTableIdentifier = identifier.getCarbonTableIdentifier();
    ICarbonLock carbonDeleteSegmentLock =
        CarbonLockFactory.getCarbonLockObj(identifier, LockUsage.DELETE_SEGMENT_LOCK);
    ICarbonLock carbonTableStatusLock =
        CarbonLockFactory.getCarbonLockObj(identifier, LockUsage.TABLE_STATUS_LOCK);
    String tableDetails =
        carbonTableIdentifier.getDatabaseName() + "." + carbonTableIdentifier.getTableName();
    List<String> invalidLoadIds = new ArrayList<String>(0);
    try {
      if (carbonDeleteSegmentLock.lockWithRetries()) {
        LOG.info("Delete segment lock has been successfully acquired");
        CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(
            identifier.getTablePath(), identifier.getCarbonTableIdentifier());
        String dataLoadLocation = carbonTablePath.getTableStatusFilePath();
        LoadMetadataDetails[] listOfLoadFolderDetailsArray = null;
        if (!FileFactory.isFileExist(dataLoadLocation, FileFactory.getFileType(dataLoadLocation))) {
          LOG.error("Load metadata file is not present.");
          return loadIds;
        }
        listOfLoadFolderDetailsArray = readLoadMetadata(tableFolderPath);
        if (listOfLoadFolderDetailsArray.length != 0) {
          updateDeletionStatus(identifier, loadIds, listOfLoadFolderDetailsArray, invalidLoadIds);
          if (invalidLoadIds.isEmpty()) {
            if (carbonTableStatusLock.lockWithRetries()) {
              LOG.info("Table status lock has been successfully acquired");
              LoadMetadataDetails[] latestLoadMetadataDetails = readLoadMetadata(tableFolderPath);
              updateLatestTableStatusDetails(listOfLoadFolderDetailsArray,
                  latestLoadMetadataDetails);
              writeLoadDetailsIntoFile(dataLoadLocation, listOfLoadFolderDetailsArray);
            }
            else {
              String errorMsg = "Delete segment by id is failed for " + tableDetails
                  + ". Not able to acquire the table status lock due to other operation running "
                  + "in the background.";
              LOG.audit(errorMsg);
              LOG.error(errorMsg);
              throw new Exception(errorMsg + " Please try after some time.");
            }
          } else {
            return invalidLoadIds;
          }
        } else {
          LOG.audit("Delete segment by Id is failed. No matching segment id found.");
          return loadIds;
        }
      } else {
        String errorMsg = "Delete segment by id is failed for " + tableDetails
            + ". Not able to acquire the delete segment lock due to another delete "
            + "operation is running in the background.";
        LOG.audit(errorMsg);
        LOG.error(errorMsg);
        throw new Exception(errorMsg + " Please try after some time.");
      }
    } catch (IOException e) {
      LOG.error("IOException" + e.getMessage());
      throw e;
    } finally {
      CarbonLockUtil.fileUnlock(carbonTableStatusLock, LockUsage.TABLE_STATUS_LOCK);
      CarbonLockUtil.fileUnlock(carbonDeleteSegmentLock, LockUsage.DELETE_SEGMENT_LOCK);
    }
    return invalidLoadIds;
  }
public static List < String > updateDeletionStatus ( AbsoluteTableIdentifier identifier , List < String > loadIds , String tableFolderPath ) throws Exception { CarbonTableIdentifier carbonTableIdentifier = identifier . getCarbonTableIdentifier ( ) ; ICarbonLock carbonDeleteSegmentLock = CarbonLockFactory . getCarbonLockObj ( identifier , LockUsage . DELETE_SEGMENT_LOCK ) ; ICarbonLock carbonTableStatusLock = CarbonLockFactory . getCarbonLockObj ( identifier , LockUsage . TABLE_STATUS_LOCK ) ; String tableDetails = carbonTableIdentifier . getDatabaseName ( ) + "." + carbonTableIdentifier . getTableName ( ) ; List < String > invalidLoadIds = new ArrayList < String > ( 0 ) ; try { if ( carbonDeleteSegmentLock . lockWithRetries ( ) ) { LOG . info ( "Delete segment lock has been successfully acquired" ) ; CarbonTablePath carbonTablePath = CarbonStorePath . getCarbonTablePath ( identifier . getTablePath ( ) , identifier . getCarbonTableIdentifier ( ) ) ; String dataLoadLocation = carbonTablePath . getTableStatusFilePath ( ) ; LoadMetadataDetails [ ] listOfLoadFolderDetailsArray = null ; if ( ! FileFactory . isFileExist ( dataLoadLocation , FileFactory . getFileType ( dataLoadLocation ) ) ) { LOG . error ( "Load metadata file is not present." ) ; return loadIds ; } listOfLoadFolderDetailsArray = readLoadMetadata ( tableFolderPath ) ; if ( listOfLoadFolderDetailsArray . length != 0 ) { updateDeletionStatus ( identifier , loadIds , listOfLoadFolderDetailsArray , invalidLoadIds ) ; if ( invalidLoadIds . isEmpty ( ) ) { if ( carbonTableStatusLock . lockWithRetries ( ) ) { LOG . info ( "Table status lock has been successfully acquired" ) ; LoadMetadataDetails [ ] latestLoadMetadataDetails = readLoadMetadata ( tableFolderPath ) ; updateLatestTableStatusDetails ( listOfLoadFolderDetailsArray , latestLoadMetadataDetails ) ; writeLoadDetailsIntoFile ( dataLoadLocation , listOfLoadFolderDetailsArray ) ; } else { String errorMsg = "Delete segment by id is failed for " + tableDetails + ". Not able to acquire the table status lock due to other operation running " + "in the background." ; LOG . audit ( errorMsg ) ; LOG . error ( errorMsg ) ; throw new Exception ( errorMsg + " Please try after some time." ) ; } } else { return invalidLoadIds ; } } else { LOG . audit ( "Delete segment by Id is failed. No matching segment id found." ) ; return loadIds ; } } else { String errorMsg = "Delete segment by id is failed for " + tableDetails + ". Not able to acquire the delete segment lock due to another delete " + "operation is running in the background." ; LOG . audit ( errorMsg ) ; LOG . error ( errorMsg ) ; throw new Exception ( errorMsg + " Please try after some time." ) ; } } catch ( IOException e ) { LOG . error ( "IOException" + e . getMessage ( ) ) ; throw e ; } finally { CarbonLockUtil . fileUnlock ( carbonTableStatusLock , LockUsage . TABLE_STATUS_LOCK ) ; CarbonLockUtil . fileUnlock ( carbonDeleteSegmentLock , LockUsage . DELETE_SEGMENT_LOCK ) ; } return invalidLoadIds ; }
updates deletion status
 @param loadIds
 @param tableFolderPath
 @return
updates deletion status @param loadIds @param tableFolderPath @return
// log error. // read existing metadata details in load metadata. // All or None , if anything fails then dont write // To handle concurrency scenarios, always take latest metadata before writing // into status file.