Search in sources :

Example 1 with BufferedRandomAccessFile

use of org.apache.hudi.common.util.BufferedRandomAccessFile in project hudi by apache.

the class BitCaskDiskMap method close.

@Override
public void close() {
    valueMetadataMap.clear();
    try {
        if (writeOnlyFileHandle != null) {
            writeOnlyFileHandle.flush();
            fileOutputStream.getChannel().force(false);
            writeOnlyFileHandle.close();
        }
        while (!openedAccessFiles.isEmpty()) {
            BufferedRandomAccessFile file = openedAccessFiles.poll();
            if (null != file) {
                try {
                    file.close();
                } catch (IOException ioe) {
                // skip exception
                }
            }
        }
        writeOnlyFile.delete();
        this.iterators.forEach(ClosableIterator::close);
    } catch (Exception e) {
        // delete the file for any sort of exception
        writeOnlyFile.delete();
    } finally {
        super.close();
    }
}
Also used : BufferedRandomAccessFile(org.apache.hudi.common.util.BufferedRandomAccessFile) ClosableIterator(org.apache.hudi.common.util.ClosableIterator) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieException(org.apache.hudi.exception.HoodieException) HoodieNotSupportedException(org.apache.hudi.exception.HoodieNotSupportedException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 2 with BufferedRandomAccessFile

use of org.apache.hudi.common.util.BufferedRandomAccessFile in project hudi by apache.

the class BitCaskDiskMap method getRandomAccessFile.

/**
 * RandomAcessFile is not thread-safe. This API opens a new file handle per thread and returns.
 *
 * @return
 */
private BufferedRandomAccessFile getRandomAccessFile() {
    try {
        BufferedRandomAccessFile readHandle = randomAccessFile.get();
        if (readHandle == null) {
            readHandle = new BufferedRandomAccessFile(filePath, "r", BUFFER_SIZE);
            readHandle.seek(0);
            randomAccessFile.set(readHandle);
            openedAccessFiles.offer(readHandle);
        }
        return readHandle;
    } catch (IOException ioe) {
        throw new HoodieException(ioe);
    }
}
Also used : BufferedRandomAccessFile(org.apache.hudi.common.util.BufferedRandomAccessFile) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Aggregations

IOException (java.io.IOException)2 BufferedRandomAccessFile (org.apache.hudi.common.util.BufferedRandomAccessFile)2 HoodieException (org.apache.hudi.exception.HoodieException)2 HoodieIOException (org.apache.hudi.exception.HoodieIOException)2 ClosableIterator (org.apache.hudi.common.util.ClosableIterator)1 HoodieNotSupportedException (org.apache.hudi.exception.HoodieNotSupportedException)1