Search in sources :

Example 6 with IOManager

use of org.apache.hyracks.control.nc.io.IOManager in project asterixdb by apache.

the class BufferCacheRegressionTest method flushBehaviorTest.

private void flushBehaviorTest(boolean deleteFile) throws IOException {
    TestStorageManagerComponentHolder.init(PAGE_SIZE, 10, 1);
    IBufferCache bufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx.getJobletContext().getServiceContext());
    IFileMapProvider fmp = TestStorageManagerComponentHolder.getFileMapProvider();
    IOManager ioManager = TestStorageManagerComponentHolder.getIOManager();
    FileReference firstFileRef = ioManager.resolve(fileName);
    bufferCache.createFile(firstFileRef);
    int firstFileId = fmp.lookupFileId(firstFileRef);
    bufferCache.openFile(firstFileId);
    // Fill the first page with known data and make it dirty by write
    // latching it.
    ICachedPage writePage = bufferCache.pin(BufferedFileHandle.getDiskPageId(firstFileId, 0), true);
    writePage.acquireWriteLatch();
    try {
        ByteBuffer buf = writePage.getBuffer();
        for (int i = 0; i < buf.capacity(); i++) {
            buf.put(Byte.MAX_VALUE);
        }
    } finally {
        writePage.releaseWriteLatch(true);
        bufferCache.unpin(writePage);
    }
    bufferCache.closeFile(firstFileId);
    if (deleteFile) {
        bufferCache.deleteFile(firstFileId, false);
    }
    // Create a file with the same name.
    FileReference secondFileRef = ioManager.resolve(fileName);
    bufferCache.createFile(secondFileRef);
    int secondFileId = fmp.lookupFileId(secondFileRef);
    // This open will replace the firstFileRef's slot in the BufferCache,
    // causing it's pages to be cleaned up. We want to make sure that those
    // dirty pages are not flushed to the disk, because the file was
    // declared as deleted, and
    // somebody might be already using the same filename again (having been
    // assigned a different fileId).
    bufferCache.openFile(secondFileId);
    // Manually open the file and inspect it's contents. We cannot simply
    // ask the BufferCache to pin the page, because it would return the same
    // physical memory again, and for performance reasons pages are never
    // reset with 0's.
    FileReference testFileRef = ioManager.resolve(fileName);
    IFileHandle testFileHandle = ioManager.open(testFileRef, FileReadWriteMode.READ_ONLY, FileSyncMode.METADATA_SYNC_DATA_SYNC);
    ByteBuffer testBuffer = ByteBuffer.allocate(PAGE_SIZE + BufferCache.RESERVED_HEADER_BYTES);
    ioManager.syncRead(testFileHandle, 0, testBuffer);
    for (int i = BufferCache.RESERVED_HEADER_BYTES; i < testBuffer.capacity(); i++) {
        if (deleteFile) {
            // We deleted the file. We expect to see a clean buffer.
            if (testBuffer.get(i) == Byte.MAX_VALUE) {
                fail("Page 0 of deleted file was fazily flushed in openFile(), " + "corrupting the data of a newly created file with the same name.");
            }
        } else {
            // Byte.MAX_VALUE.
            if (testBuffer.get(i) != Byte.MAX_VALUE) {
                fail("Page 0 of closed file was not flushed when properly, when reclaiming the file slot of fileId 0 in the BufferCache.");
            }
        }
    }
    ioManager.close(testFileHandle);
    bufferCache.closeFile(secondFileId);
    if (deleteFile) {
        bufferCache.deleteFile(secondFileId, false);
    }
    bufferCache.close();
}
Also used : IFileMapProvider(org.apache.hyracks.storage.common.file.IFileMapProvider) ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) IFileHandle(org.apache.hyracks.api.io.IFileHandle) IOManager(org.apache.hyracks.control.nc.io.IOManager) FileReference(org.apache.hyracks.api.io.FileReference) ByteBuffer(java.nio.ByteBuffer) IBufferCache(org.apache.hyracks.storage.common.buffercache.IBufferCache)

Example 7 with IOManager

use of org.apache.hyracks.control.nc.io.IOManager in project asterixdb by apache.

the class IOManagerPathTest method testDuplicates.

@Test(expected = HyracksDataException.class)
public void testDuplicates() throws HyracksDataException {
    IODeviceHandle first = new IODeviceHandle(new File("/tmp/tst/1"), "storage");
    IODeviceHandle second = new IODeviceHandle(new File("/tmp/tst/1"), "storage");
    IOManager ioManager = new IOManager(Arrays.asList(new IODeviceHandle[] { first, second }), new DefaultDeviceResolver());
}
Also used : IODeviceHandle(org.apache.hyracks.api.io.IODeviceHandle) DefaultDeviceResolver(org.apache.hyracks.control.nc.io.DefaultDeviceResolver) IOManager(org.apache.hyracks.control.nc.io.IOManager) File(java.io.File) Test(org.junit.Test)

Example 8 with IOManager

use of org.apache.hyracks.control.nc.io.IOManager in project asterixdb by apache.

the class LSMIndexFileManagerTest method singleIODeviceTest.

@Test
public void singleIODeviceTest() throws InterruptedException, IOException {
    IOManager singleDeviceIOManager = createIOManager(1);
    cleanInvalidFilesTest(singleDeviceIOManager);
    cleanDirs(singleDeviceIOManager);
}
Also used : IOManager(org.apache.hyracks.control.nc.io.IOManager) Test(org.junit.Test)

Example 9 with IOManager

use of org.apache.hyracks.control.nc.io.IOManager in project asterixdb by apache.

the class LSMIndexFileManagerTest method createIOManager.

private IOManager createIOManager(int numDevices) throws HyracksDataException {
    List<IODeviceHandle> devices = new ArrayList<>();
    for (int i = 0; i < numDevices; i++) {
        String iodevPath = System.getProperty("java.io.tmpdir") + sep + "test_iodev" + i;
        devices.add(new IODeviceHandle(new File(iodevPath), "wa"));
    }
    return new IOManager(devices, Executors.newCachedThreadPool(), new DefaultDeviceResolver());
}
Also used : IODeviceHandle(org.apache.hyracks.api.io.IODeviceHandle) DefaultDeviceResolver(org.apache.hyracks.control.nc.io.DefaultDeviceResolver) IOManager(org.apache.hyracks.control.nc.io.IOManager) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

IOManager (org.apache.hyracks.control.nc.io.IOManager)9 File (java.io.File)5 IODeviceHandle (org.apache.hyracks.api.io.IODeviceHandle)5 DefaultDeviceResolver (org.apache.hyracks.control.nc.io.DefaultDeviceResolver)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FileReference (org.apache.hyracks.api.io.FileReference)2 ByteBuffer (java.nio.ByteBuffer)1 INCServiceContext (org.apache.hyracks.api.application.INCServiceContext)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 ActivityId (org.apache.hyracks.api.dataflow.ActivityId)1 OperatorDescriptorId (org.apache.hyracks.api.dataflow.OperatorDescriptorId)1 TaskAttemptId (org.apache.hyracks.api.dataflow.TaskAttemptId)1 TaskId (org.apache.hyracks.api.dataflow.TaskId)1 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)1 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)1 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)1 IFileHandle (org.apache.hyracks.api.io.IFileHandle)1 JobId (org.apache.hyracks.api.job.JobId)1 VirtualFreePageManager (org.apache.hyracks.storage.am.lsm.common.freepage.VirtualFreePageManager)1