Search in sources :

Example 6 with BufferedFileHandle

use of org.apache.hyracks.storage.common.file.BufferedFileHandle in project asterixdb by apache.

the class BufferCache method deleteFile.

@Override
public synchronized void deleteFile(int fileId, boolean flushDirtyPages) throws HyracksDataException {
    if (LOGGER.isLoggable(fileOpsLevel)) {
        LOGGER.log(fileOpsLevel, "Deleting file: " + fileId + " in cache: " + this);
    }
    synchronized (fileInfoMap) {
        sweepAndFlush(fileId, flushDirtyPages);
        BufferedFileHandle fInfo = null;
        try {
            fInfo = fileInfoMap.get(fileId);
            if (fInfo != null && fInfo.getReferenceCount() > 0) {
                throw new HyracksDataException("Deleting open file");
            }
        } finally {
            fileMapManager.unregisterFile(fileId);
            if (fInfo != null) {
                // the pages are not flushed to disk but only invalidated.
                synchronized (fInfo) {
                    if (!fInfo.fileHasBeenDeleted()) {
                        ioManager.close(fInfo.getFileHandle());
                        fInfo.markAsDeleted();
                    }
                }
            }
        }
    }
}
Also used : BufferedFileHandle(org.apache.hyracks.storage.common.file.BufferedFileHandle) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 7 with BufferedFileHandle

use of org.apache.hyracks.storage.common.file.BufferedFileHandle in project asterixdb by apache.

the class BufferCache method purgeHandle.

@Override
public /**
     * _ONLY_ call this if you absolutely, positively know this file has no dirty pages in the cache!
     * Bypasses the normal lifecycle of a file handle and evicts all references to it immediately.
     */
void purgeHandle(int fileId) throws HyracksDataException {
    synchronized (fileInfoMap) {
        BufferedFileHandle fh = fileInfoMap.get(fileId);
        if (fh != null) {
            ioManager.close(fh.getFileHandle());
            fileInfoMap.remove(fileId);
            fileMapManager.unregisterFile(fileId);
        }
    }
}
Also used : BufferedFileHandle(org.apache.hyracks.storage.common.file.BufferedFileHandle)

Aggregations

BufferedFileHandle (org.apache.hyracks.storage.common.file.BufferedFileHandle)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)5 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FileReference (org.apache.hyracks.api.io.FileReference)1 IFileHandle (org.apache.hyracks.api.io.IFileHandle)1