Search in sources :

Example 6 with AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl in project carbondata by apache.

the class StoreCreator method writeLoadMetadata.

public static void writeLoadMetadata(CarbonDataLoadSchema schema, String databaseName, String tableName, List<LoadMetadataDetails> listOfLoadFolderDetails) throws IOException {
    LoadMetadataDetails loadMetadataDetails = new LoadMetadataDetails();
    loadMetadataDetails.setLoadEndTime(System.currentTimeMillis());
    loadMetadataDetails.setLoadStatus("SUCCESS");
    loadMetadataDetails.setLoadName(String.valueOf(0));
    loadMetadataDetails.setLoadStartTime(loadMetadataDetails.getTimeStamp(readCurrentTime()));
    listOfLoadFolderDetails.add(loadMetadataDetails);
    String dataLoadLocation = schema.getCarbonTable().getMetaDataFilepath() + File.separator + CarbonCommonConstants.LOADMETADATA_FILENAME;
    DataOutputStream dataOutputStream;
    Gson gsonObjectToWrite = new Gson();
    BufferedWriter brWriter = null;
    AtomicFileOperations writeOperation = new AtomicFileOperationsImpl(dataLoadLocation, FileFactory.getFileType(dataLoadLocation));
    try {
        dataOutputStream = writeOperation.openForWrite(FileWriteOperation.OVERWRITE);
        brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
        String metadataInstance = gsonObjectToWrite.toJson(listOfLoadFolderDetails.toArray());
        brWriter.write(metadataInstance);
    } catch (Exception ex) {
        throw ex;
    } finally {
        try {
            if (null != brWriter) {
                brWriter.flush();
            }
        } catch (Exception e) {
            throw e;
        }
        CarbonUtil.closeStreams(brWriter);
    }
    writeOperation.close();
}
Also used : LoadMetadataDetails(org.apache.carbondata.core.statusmanager.LoadMetadataDetails) DataOutputStream(java.io.DataOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 7 with AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl in project carbondata by apache.

the class CarbonLoaderUtil method writeLoadMetadata.

public static void writeLoadMetadata(String storeLocation, String dbName, String tableName, List<LoadMetadataDetails> listOfLoadFolderDetails) throws IOException {
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(storeLocation, dbName, tableName);
    String dataLoadLocation = carbonTablePath.getTableStatusFilePath();
    DataOutputStream dataOutputStream;
    Gson gsonObjectToWrite = new Gson();
    BufferedWriter brWriter = null;
    AtomicFileOperations writeOperation = new AtomicFileOperationsImpl(dataLoadLocation, FileFactory.getFileType(dataLoadLocation));
    try {
        dataOutputStream = writeOperation.openForWrite(FileWriteOperation.OVERWRITE);
        brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
        String metadataInstance = gsonObjectToWrite.toJson(listOfLoadFolderDetails.toArray());
        brWriter.write(metadataInstance);
    } finally {
        try {
            if (null != brWriter) {
                brWriter.flush();
            }
        } catch (Exception e) {
            LOGGER.error("error in  flushing ");
        }
        CarbonUtil.closeStreams(brWriter);
        writeOperation.close();
    }
}
Also used : CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) DataOutputStream(java.io.DataOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BufferedWriter(java.io.BufferedWriter)

Example 8 with AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl in project carbondata by apache.

the class SegmentStatusManager method getValidAndInvalidSegments.

/**
   * get valid segment for given table
   *
   * @return
   * @throws IOException
   */
public ValidAndInvalidSegmentsInfo getValidAndInvalidSegments() throws IOException {
    // @TODO: move reading LoadStatus file to separate class
    List<String> listOfValidSegments = new ArrayList<String>(10);
    List<String> listOfValidUpdatedSegments = new ArrayList<String>(10);
    List<String> listOfInvalidSegments = new ArrayList<String>(10);
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
    String dataPath = carbonTablePath.getTableStatusFilePath();
    DataInputStream dataInputStream = null;
    Gson gsonObjectToRead = new Gson();
    AtomicFileOperations fileOperation = new AtomicFileOperationsImpl(dataPath, FileFactory.getFileType(dataPath));
    LoadMetadataDetails[] loadFolderDetailsArray;
    try {
        if (FileFactory.isFileExist(dataPath, FileFactory.getFileType(dataPath))) {
            dataInputStream = fileOperation.openForRead();
            BufferedReader buffReader = new BufferedReader(new InputStreamReader(dataInputStream, "UTF-8"));
            loadFolderDetailsArray = gsonObjectToRead.fromJson(buffReader, LoadMetadataDetails[].class);
            //just directly iterate Array
            for (LoadMetadataDetails loadMetadataDetails : loadFolderDetailsArray) {
                if (CarbonCommonConstants.STORE_LOADSTATUS_SUCCESS.equalsIgnoreCase(loadMetadataDetails.getLoadStatus()) || CarbonCommonConstants.MARKED_FOR_UPDATE.equalsIgnoreCase(loadMetadataDetails.getLoadStatus()) || CarbonCommonConstants.STORE_LOADSTATUS_PARTIAL_SUCCESS.equalsIgnoreCase(loadMetadataDetails.getLoadStatus())) {
                    // check for merged loads.
                    if (null != loadMetadataDetails.getMergedLoadName()) {
                        if (!listOfValidSegments.contains(loadMetadataDetails.getMergedLoadName())) {
                            listOfValidSegments.add(loadMetadataDetails.getMergedLoadName());
                        }
                        // if merged load is updated then put it in updated list
                        if (CarbonCommonConstants.MARKED_FOR_UPDATE.equalsIgnoreCase(loadMetadataDetails.getLoadStatus())) {
                            listOfValidUpdatedSegments.add(loadMetadataDetails.getMergedLoadName());
                        }
                        continue;
                    }
                    if (CarbonCommonConstants.MARKED_FOR_UPDATE.equalsIgnoreCase(loadMetadataDetails.getLoadStatus())) {
                        listOfValidUpdatedSegments.add(loadMetadataDetails.getLoadName());
                    }
                    listOfValidSegments.add(loadMetadataDetails.getLoadName());
                } else if ((CarbonCommonConstants.STORE_LOADSTATUS_FAILURE.equalsIgnoreCase(loadMetadataDetails.getLoadStatus()) || CarbonCommonConstants.COMPACTED.equalsIgnoreCase(loadMetadataDetails.getLoadStatus()) || CarbonCommonConstants.MARKED_FOR_DELETE.equalsIgnoreCase(loadMetadataDetails.getLoadStatus()))) {
                    listOfInvalidSegments.add(loadMetadataDetails.getLoadName());
                }
            }
        }
    } catch (IOException e) {
        LOG.error(e);
        throw e;
    } finally {
        try {
            if (null != dataInputStream) {
                dataInputStream.close();
            }
        } catch (Exception e) {
            LOG.error(e);
            throw e;
        }
    }
    return new ValidAndInvalidSegmentsInfo(listOfValidSegments, listOfValidUpdatedSegments, listOfInvalidSegments);
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) BufferedReader(java.io.BufferedReader) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)

Example 9 with AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl in project carbondata by apache.

the class SegmentStatusManager method readLoadMetadata.

/**
   * This method reads the load metadata file
   *
   * @param tableFolderPath
   * @return
   */
public static LoadMetadataDetails[] readLoadMetadata(String tableFolderPath) {
    Gson gsonObjectToRead = new Gson();
    DataInputStream dataInputStream = null;
    BufferedReader buffReader = null;
    InputStreamReader inStream = null;
    String metadataFileName = tableFolderPath + CarbonCommonConstants.FILE_SEPARATOR + CarbonCommonConstants.LOADMETADATA_FILENAME;
    LoadMetadataDetails[] listOfLoadFolderDetailsArray;
    AtomicFileOperations fileOperation = new AtomicFileOperationsImpl(metadataFileName, FileFactory.getFileType(metadataFileName));
    try {
        if (!FileFactory.isFileExist(metadataFileName, FileFactory.getFileType(metadataFileName))) {
            return new LoadMetadataDetails[0];
        }
        dataInputStream = fileOperation.openForRead();
        inStream = new InputStreamReader(dataInputStream, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
        buffReader = new BufferedReader(inStream);
        listOfLoadFolderDetailsArray = gsonObjectToRead.fromJson(buffReader, LoadMetadataDetails[].class);
    } catch (IOException e) {
        return new LoadMetadataDetails[0];
    } finally {
        closeStreams(buffReader, inStream, dataInputStream);
    }
    return listOfLoadFolderDetailsArray;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)

Example 10 with AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl in project carbondata by apache.

the class StoreCreator method writeLoadMetadata.

public static void writeLoadMetadata(CarbonDataLoadSchema schema, String databaseName, String tableName, List<LoadMetadataDetails> listOfLoadFolderDetails) throws IOException {
    LoadMetadataDetails loadMetadataDetails = new LoadMetadataDetails();
    loadMetadataDetails.setLoadEndTime(System.currentTimeMillis());
    loadMetadataDetails.setLoadStatus("SUCCESS");
    loadMetadataDetails.setLoadName(String.valueOf(0));
    loadMetadataDetails.setLoadStartTime(loadMetadataDetails.getTimeStamp(readCurrentTime()));
    listOfLoadFolderDetails.add(loadMetadataDetails);
    String dataLoadLocation = schema.getCarbonTable().getMetaDataFilepath() + File.separator + CarbonCommonConstants.LOADMETADATA_FILENAME;
    DataOutputStream dataOutputStream;
    Gson gsonObjectToWrite = new Gson();
    BufferedWriter brWriter = null;
    AtomicFileOperations writeOperation = new AtomicFileOperationsImpl(dataLoadLocation, FileFactory.getFileType(dataLoadLocation));
    try {
        dataOutputStream = writeOperation.openForWrite(FileWriteOperation.OVERWRITE);
        brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
        String metadataInstance = gsonObjectToWrite.toJson(listOfLoadFolderDetails.toArray());
        brWriter.write(metadataInstance);
    } finally {
        try {
            if (null != brWriter) {
                brWriter.flush();
            }
        } catch (Exception e) {
            throw e;
        }
        CarbonUtil.closeStreams(brWriter);
    }
    writeOperation.close();
}
Also used : LoadMetadataDetails(org.apache.carbondata.core.statusmanager.LoadMetadataDetails) DataOutputStream(java.io.DataOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

AtomicFileOperationsImpl (org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)10 Gson (com.google.gson.Gson)9 IOException (java.io.IOException)9 AtomicFileOperations (org.apache.carbondata.core.fileoperations.AtomicFileOperations)9 BufferedWriter (java.io.BufferedWriter)5 DataOutputStream (java.io.DataOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 BufferedReader (java.io.BufferedReader)4 DataInputStream (java.io.DataInputStream)4 InputStreamReader (java.io.InputStreamReader)4 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)4 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)1 DeleteDeltaBlockDetails (org.apache.carbondata.core.mutate.DeleteDeltaBlockDetails)1 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)1