core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java
/**
   * This method will calculate the data size and index size for carbon table
   */
This method will calculate the data size and index size for carbon table
This method will calculate the data size and index size for carbon table
public static Map<String, Long> calculateDataIndexSize(CarbonTable carbonTable)
      throws IOException {
    Map<String, Long> dataIndexSizeMap = new HashMap<String, Long>();
    long dataSize = 0L;
    long indexSize = 0L;
    long lastUpdateTime = 0L;
    boolean needUpdate = false;
    AbsoluteTableIdentifier absoluteTableIdentifier = carbonTable.getAbsoluteTableIdentifier();
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier);
    String isCalculated = CarbonProperties.getInstance()
        .getProperty(CarbonCommonConstants.ENABLE_CALCULATE_SIZE,
            CarbonCommonConstants.DEFAULT_ENABLE_CALCULATE_SIZE);
    if (isCalculated.equalsIgnoreCase("true")) {
      SegmentStatusManager segmentStatusManager = new SegmentStatusManager(absoluteTableIdentifier);
      ICarbonLock carbonLock = segmentStatusManager.getTableStatusLock();
      try {
        if (carbonLock.lockWithRetries()) {
          LOGGER.info("Acquired lock for table for table status updation");
          String metadataPath = carbonTable.getMetaDataFilepath();
          LoadMetadataDetails[] loadMetadataDetails =
              SegmentStatusManager.readLoadMetadata(metadataPath);
          for (LoadMetadataDetails loadMetadataDetail : loadMetadataDetails) {
            SegmentStatus loadStatus = loadMetadataDetail.getSegmentStatus();
            if (loadStatus == SegmentStatus.SUCCESS || loadStatus ==
                      SegmentStatus.LOAD_PARTIAL_SUCCESS) {
              String dsize = loadMetadataDetail.getDataSize();
              String isize = loadMetadataDetail.getIndexSize();
              if (null == dsize || null == isize) {
                needUpdate = true;
                LOGGER.info("It is an old segment, need calculate data size and index size again");
                HashMap<String, Long> map = CarbonUtil
                    .getDataSizeAndIndexSize(carbonTablePath, loadMetadataDetail.getLoadName());
                dsize = String.valueOf(map.get(CarbonCommonConstants.CARBON_TOTAL_DATA_SIZE));
                isize = String.valueOf(map.get(CarbonCommonConstants.CARBON_TOTAL_INDEX_SIZE));
                loadMetadataDetail.setDataSize(dsize);
                loadMetadataDetail.setIndexSize(isize);
              }
              dataSize += Long.parseLong(dsize);
              indexSize += Long.parseLong(isize);
            }
          }
          if (needUpdate) {
            SegmentStatusManager.writeLoadDetailsIntoFile(carbonTablePath.getTableStatusFilePath(),
                loadMetadataDetails);
          }
          String tableStatusPath = carbonTablePath.getTableStatusFilePath();
          if (FileFactory.isFileExist(tableStatusPath, FileFactory.getFileType(tableStatusPath))) {
            lastUpdateTime =
                FileFactory.getCarbonFile(tableStatusPath, FileFactory.getFileType(tableStatusPath))
                    .getLastModifiedTime();
          }
          dataIndexSizeMap
              .put(String.valueOf(CarbonCommonConstants.CARBON_TOTAL_DATA_SIZE), dataSize);
          dataIndexSizeMap
              .put(String.valueOf(CarbonCommonConstants.CARBON_TOTAL_INDEX_SIZE), indexSize);
          dataIndexSizeMap
              .put(String.valueOf(CarbonCommonConstants.LAST_UPDATE_TIME), lastUpdateTime);
        } else {
          LOGGER.error("Not able to acquire the lock for Table status updation for table");
        }
      } finally {
        if (carbonLock.unlock()) {
          LOGGER.info("Table unlocked successfully after table status updation");
        } else {
          LOGGER.error("Unable to unlock Table lock for table during table status updation");
        }
      }
    }
    return dataIndexSizeMap;
  }
public static Map < String , Long > calculateDataIndexSize ( CarbonTable carbonTable ) throws IOException { Map < String , Long > dataIndexSizeMap = new HashMap < String , Long > ( ) ; long dataSize = 0L ; long indexSize = 0L ; long lastUpdateTime = 0L ; boolean needUpdate = false ; AbsoluteTableIdentifier absoluteTableIdentifier = carbonTable . getAbsoluteTableIdentifier ( ) ; CarbonTablePath carbonTablePath = CarbonStorePath . getCarbonTablePath ( absoluteTableIdentifier ) ; String isCalculated = CarbonProperties . getInstance ( ) . getProperty ( CarbonCommonConstants . ENABLE_CALCULATE_SIZE , CarbonCommonConstants . DEFAULT_ENABLE_CALCULATE_SIZE ) ; if ( isCalculated . equalsIgnoreCase ( "true" ) ) { SegmentStatusManager segmentStatusManager = new SegmentStatusManager ( absoluteTableIdentifier ) ; ICarbonLock carbonLock = segmentStatusManager . getTableStatusLock ( ) ; try { if ( carbonLock . lockWithRetries ( ) ) { LOGGER . info ( "Acquired lock for table for table status updation" ) ; String metadataPath = carbonTable . getMetaDataFilepath ( ) ; LoadMetadataDetails [ ] loadMetadataDetails = SegmentStatusManager . readLoadMetadata ( metadataPath ) ; for ( LoadMetadataDetails loadMetadataDetail : loadMetadataDetails ) { SegmentStatus loadStatus = loadMetadataDetail . getSegmentStatus ( ) ; if ( loadStatus == SegmentStatus . SUCCESS || loadStatus == SegmentStatus . LOAD_PARTIAL_SUCCESS ) { String dsize = loadMetadataDetail . getDataSize ( ) ; String isize = loadMetadataDetail . getIndexSize ( ) ; if ( null == dsize || null == isize ) { needUpdate = true ; LOGGER . info ( "It is an old segment, need calculate data size and index size again" ) ; HashMap < String , Long > map = CarbonUtil . getDataSizeAndIndexSize ( carbonTablePath , loadMetadataDetail . getLoadName ( ) ) ; dsize = String . valueOf ( map . get ( CarbonCommonConstants . CARBON_TOTAL_DATA_SIZE ) ) ; isize = String . valueOf ( map . get ( CarbonCommonConstants . CARBON_TOTAL_INDEX_SIZE ) ) ; loadMetadataDetail . setDataSize ( dsize ) ; loadMetadataDetail . setIndexSize ( isize ) ; } dataSize += Long . parseLong ( dsize ) ; indexSize += Long . parseLong ( isize ) ; } } if ( needUpdate ) { SegmentStatusManager . writeLoadDetailsIntoFile ( carbonTablePath . getTableStatusFilePath ( ) , loadMetadataDetails ) ; } String tableStatusPath = carbonTablePath . getTableStatusFilePath ( ) ; if ( FileFactory . isFileExist ( tableStatusPath , FileFactory . getFileType ( tableStatusPath ) ) ) { lastUpdateTime = FileFactory . getCarbonFile ( tableStatusPath , FileFactory . getFileType ( tableStatusPath ) ) . getLastModifiedTime ( ) ; } dataIndexSizeMap . put ( String . valueOf ( CarbonCommonConstants . CARBON_TOTAL_DATA_SIZE ) , dataSize ) ; dataIndexSizeMap . put ( String . valueOf ( CarbonCommonConstants . CARBON_TOTAL_INDEX_SIZE ) , indexSize ) ; dataIndexSizeMap . put ( String . valueOf ( CarbonCommonConstants . LAST_UPDATE_TIME ) , lastUpdateTime ) ; } else { LOGGER . error ( "Not able to acquire the lock for Table status updation for table" ) ; } } finally { if ( carbonLock . unlock ( ) ) { LOGGER . info ( "Table unlocked successfully after table status updation" ) ; } else { LOGGER . error ( "Unable to unlock Table lock for table during table status updation" ) ; } } } return dataIndexSizeMap ; }
This method will calculate the data size and index size for carbon table
This method will calculate the data size and index size for carbon table
// If it is old segment, need to calculate data size and index size again // If it contains old segment, write new load details