Search in sources :

Example 11 with IIOManager

use of org.apache.hyracks.api.io.IIOManager in project asterixdb by apache.

the class LSMBTreeLocalResource method createInstance.

@Override
public ILSMIndex createInstance(INCServiceContext serviceCtx) throws HyracksDataException {
    IIOManager ioManager = serviceCtx.getIoManager();
    FileReference file = ioManager.resolve(path);
    List<IVirtualBufferCache> vbcs = vbcProvider.getVirtualBufferCaches(serviceCtx, file);
    return LSMBTreeUtil.createLSMTree(ioManager, vbcs, file, storageManager.getBufferCache(serviceCtx), storageManager.getFileMapProvider(serviceCtx), typeTraits, cmpFactories, bloomFilterKeyFields, bloomFilterFalsePositiveRate, mergePolicyFactory.createMergePolicy(mergePolicyProperties, serviceCtx), opTrackerProvider.getOperationTracker(serviceCtx), ioSchedulerProvider.getIoScheduler(serviceCtx), ioOpCallbackFactory.createIoOpCallback(), isPrimary, filterTypeTraits, filterCmpFactories, btreeFields, filterFields, durable, metadataPageManagerFactory);
}
Also used : IVirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache) FileReference(org.apache.hyracks.api.io.FileReference) IIOManager(org.apache.hyracks.api.io.IIOManager)

Example 12 with IIOManager

use of org.apache.hyracks.api.io.IIOManager in project asterixdb by apache.

the class BufferCacheTest method simpleOpenPinCloseTest.

@Test
public void simpleOpenPinCloseTest() throws HyracksException {
    TestStorageManagerComponentHolder.init(PAGE_SIZE, NUM_PAGES, MAX_OPEN_FILES);
    IBufferCache bufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx.getJobletContext().getServiceContext());
    IFileMapProvider fmp = TestStorageManagerComponentHolder.getFileMapProvider();
    IIOManager ioManager = TestStorageManagerComponentHolder.getIOManager();
    String fileName = getFileName();
    FileReference file = ioManager.resolve(fileName);
    bufferCache.createFile(file);
    int fileId = fmp.lookupFileId(file);
    int num = 10;
    int testPageId = 0;
    bufferCache.openFile(fileId);
    ICachedPage page = null;
    // tryPin should fail
    page = bufferCache.tryPin(BufferedFileHandle.getDiskPageId(fileId, testPageId));
    Assert.assertNull(page);
    // pin page should succeed
    page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, testPageId), true);
    page.acquireWriteLatch();
    try {
        for (int i = 0; i < num; i++) {
            page.getBuffer().putInt(i * 4, i);
        }
        // try pin should succeed
        ICachedPage page2 = bufferCache.tryPin(BufferedFileHandle.getDiskPageId(fileId, testPageId));
        Assert.assertNotNull(page2);
        bufferCache.unpin(page2);
    } finally {
        page.releaseWriteLatch(true);
        bufferCache.unpin(page);
    }
    bufferCache.closeFile(fileId);
    // This code is commented because the method pinSanityCheck in the BufferCache is commented.
    /*boolean exceptionThrown = false;

        // tryPin should fail since file is not open
        try {
            page = bufferCache.tryPin(BufferedFileHandle.getDiskPageId(fileId, testPageId));
        } catch (HyracksDataException e) {
            exceptionThrown = true;
        }
        Assert.assertTrue(exceptionThrown);

        // pin should fail since file is not open
        exceptionThrown = false;
        try {
            page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, testPageId), false);
        } catch (HyracksDataException e) {
            exceptionThrown = true;
        }
        Assert.assertTrue(exceptionThrown);*/
    // open file again
    bufferCache.openFile(fileId);
    // tryPin should succeed because page should still be cached
    page = bufferCache.tryPin(BufferedFileHandle.getDiskPageId(fileId, testPageId));
    Assert.assertNotNull(page);
    page.acquireReadLatch();
    try {
        // verify contents of page
        for (int i = 0; i < num; i++) {
            Assert.assertEquals(page.getBuffer().getInt(i * 4), i);
        }
    } finally {
        page.releaseReadLatch();
        bufferCache.unpin(page);
    }
    bufferCache.closeFile(fileId);
    bufferCache.close();
}
Also used : IFileMapProvider(org.apache.hyracks.storage.common.file.IFileMapProvider) ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) FileReference(org.apache.hyracks.api.io.FileReference) IIOManager(org.apache.hyracks.api.io.IIOManager) IBufferCache(org.apache.hyracks.storage.common.buffercache.IBufferCache) Test(org.junit.Test)

Example 13 with IIOManager

use of org.apache.hyracks.api.io.IIOManager in project asterixdb by apache.

the class RTreeTestHarness method setUp.

public void setUp() throws HyracksDataException {
    TestStorageManagerComponentHolder.init(pageSize, numPages, maxOpenFiles);
    IIOManager ioManager = TestStorageManagerComponentHolder.getIOManager();
    fileName = simpleDateFormat.format(new Date());
    file = ioManager.resolve(fileName);
    ctx = TestUtils.create(getHyracksFrameSize());
    bufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx.getJobletContext().getServiceContext());
    fileMapProvider = TestStorageManagerComponentHolder.getFileMapProvider();
    rnd.setSeed(RANDOM_SEED);
}
Also used : IIOManager(org.apache.hyracks.api.io.IIOManager) Date(java.util.Date)

Example 14 with IIOManager

use of org.apache.hyracks.api.io.IIOManager in project asterixdb by apache.

the class BTreeResource method createInstance.

@Override
public IIndex createInstance(INCServiceContext ctx) throws HyracksDataException {
    IBufferCache bufferCache = storageManager.getBufferCache(ctx);
    IIOManager ioManager = ctx.getIoManager();
    FileReference resourceRef = ioManager.resolve(path);
    return BTreeUtils.createBTree(bufferCache, storageManager.getFileMapProvider(ctx), typeTraits, comparatorFactories, BTreeLeafFrameType.REGULAR_NSM, resourceRef, pageManagerFactory.createPageManager(bufferCache));
}
Also used : FileReference(org.apache.hyracks.api.io.FileReference) IIOManager(org.apache.hyracks.api.io.IIOManager) IBufferCache(org.apache.hyracks.storage.common.buffercache.IBufferCache)

Example 15 with IIOManager

use of org.apache.hyracks.api.io.IIOManager in project asterixdb by apache.

the class PlainFileWriterOperatorDescriptor method createPushRuntime.

/*
     * (non-Javadoc)
     *
     * @see
     * org.apache.hyracks.api.dataflow.IActivityNode#createPushRuntime(edu.
     * uci.ics.hyracks.api.context.IHyracksContext,
     * org.apache.hyracks.api.job.IOperatorEnvironment,
     * org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider, int,
     * int)
     */
@Override
public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, final int partition, int nPartitions) throws HyracksDataException {
    // Output files
    final FileSplit[] splits = fileSplitProvider.getFileSplits();
    IIOManager ioManager = ctx.getIoManager();
    // Frame accessor
    final FrameTupleAccessor frameTupleAccessor = new FrameTupleAccessor(recordDescProvider.getInputRecordDescriptor(getActivityId(), 0));
    // Record descriptor
    final RecordDescriptor recordDescriptor = recordDescProvider.getInputRecordDescriptor(getActivityId(), 0);
    return new AbstractUnaryInputSinkOperatorNodePushable() {

        private BufferedWriter out;

        private ByteBufferInputStream bbis;

        private DataInputStream di;

        @Override
        public void open() throws HyracksDataException {
            try {
                out = new BufferedWriter(new FileWriter(splits[partition].getFile(ioManager)));
                bbis = new ByteBufferInputStream();
                di = new DataInputStream(bbis);
            } catch (Exception e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            try {
                frameTupleAccessor.reset(buffer);
                for (int tIndex = 0; tIndex < frameTupleAccessor.getTupleCount(); tIndex++) {
                    int start = frameTupleAccessor.getTupleStartOffset(tIndex) + frameTupleAccessor.getFieldSlotsLength();
                    bbis.setByteBuffer(buffer, start);
                    Object[] record = new Object[recordDescriptor.getFieldCount()];
                    for (int i = 0; i < record.length; ++i) {
                        Object instance = recordDescriptor.getFields()[i].deserialize(di);
                        if (i == 0) {
                            out.write(String.valueOf(instance));
                        } else {
                            out.write(delim + String.valueOf(instance));
                        }
                    }
                    out.write("\n");
                }
            } catch (IOException ex) {
                throw new HyracksDataException(ex);
            }
        }

        @Override
        public void fail() throws HyracksDataException {
        }

        @Override
        public void close() throws HyracksDataException {
            try {
                out.close();
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) FileWriter(java.io.FileWriter) ByteBufferInputStream(org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream) IOException(java.io.IOException) FileSplit(org.apache.hyracks.api.io.FileSplit) DataInputStream(java.io.DataInputStream) IIOManager(org.apache.hyracks.api.io.IIOManager) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) BufferedWriter(java.io.BufferedWriter) AbstractUnaryInputSinkOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputSinkOperatorNodePushable) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Aggregations

IIOManager (org.apache.hyracks.api.io.IIOManager)22 FileReference (org.apache.hyracks.api.io.FileReference)16 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 IBufferCache (org.apache.hyracks.storage.common.buffercache.IBufferCache)6 IFileMapProvider (org.apache.hyracks.storage.common.file.IFileMapProvider)5 FileSplit (org.apache.hyracks.api.io.FileSplit)4 IVirtualBufferCache (org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)2 AbstractUnaryInputSinkOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractUnaryInputSinkOperatorNodePushable)2 AbortRecoverLSMIndexFileManager (org.apache.hyracks.storage.am.lsm.common.impls.AbortRecoverLSMIndexFileManager)2 ICachedPage (org.apache.hyracks.storage.common.buffercache.ICachedPage)2 BufferedWriter (java.io.BufferedWriter)1 DataInputStream (java.io.DataInputStream)1 DataOutput (java.io.DataOutput)1