Search in sources :

Example 6 with ITreeIndexMetadataFrame

use of org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame in project asterixdb by apache.

the class LinkedMetaDataPageManager method init.

@Override
public void init(ITreeIndexFrameFactory interiorFrameFactory, ITreeIndexFrameFactory leafFrameFactory) throws HyracksDataException {
    // initialize meta data page
    ITreeIndexMetadataFrame metaFrame = createMetadataFrame();
    int metaPage = getMetadataPageId();
    if (metaPage == IBufferCache.INVALID_PAGEID) {
        throw new HyracksDataException("No valid metadata found in this file.");
    }
    ICachedPage metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getMetadataPageId()), true);
    metaNode.acquireWriteLatch();
    try {
        metaFrame.setPage(metaNode);
        metaFrame.init();
        metaFrame.setRootPageId(1);
        metaFrame.setMaxPage(1);
    } finally {
        metaNode.releaseWriteLatch(true);
        bufferCache.flushDirtyPage(metaNode);
        bufferCache.unpin(metaNode);
    }
    int rootPage = getRootPageId();
    ICachedPage rootNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rootPage), true);
    rootNode.acquireWriteLatch();
    try {
        ITreeIndexFrame leafFrame = leafFrameFactory.createFrame();
        leafFrame.setPage(rootNode);
        leafFrame.initBuffer((byte) 0);
    } finally {
        rootNode.releaseWriteLatch(true);
        bufferCache.flushDirtyPage(rootNode);
        bufferCache.unpin(rootNode);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) ITreeIndexFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexFrame) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 7 with ITreeIndexMetadataFrame

use of org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame in project asterixdb by apache.

the class LinkedMetaDataPageManager method setRootPageId.

@Override
public void setRootPageId(int rootPage) throws HyracksDataException {
    ICachedPage metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getMetadataPageId()), false);
    ITreeIndexMetadataFrame metaFrame = frameFactory.createFrame();
    metaNode.acquireWriteLatch();
    try {
        metaFrame.setPage(metaNode);
        metaFrame.setRootPageId(rootPage);
    } finally {
        metaNode.releaseWriteLatch(true);
        bufferCache.unpin(metaNode);
        ready = true;
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame)

Example 8 with ITreeIndexMetadataFrame

use of org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame in project asterixdb by apache.

the class AppendOnlyLinkedMetadataPageManager method setRootPageId.

@Override
public void setRootPageId(int rootPage) throws HyracksDataException {
    ITreeIndexMetadataFrame metaFrame = frameFactory.createFrame();
    confiscatedPage.acquireWriteLatch();
    try {
        metaFrame.setPage(confiscatedPage);
        metaFrame.setRootPageId(rootPage);
    } finally {
        confiscatedPage.releaseWriteLatch(false);
    }
    ready = true;
}
Also used : ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame)

Example 9 with ITreeIndexMetadataFrame

use of org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame in project asterixdb by apache.

the class AppendOnlyLinkedMetadataPageManager method getRootPageId.

@Override
public int getRootPageId() throws HyracksDataException {
    ICachedPage metaNode;
    if (confiscatedPage == null) {
        metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getMetadataPageId()), false);
    } else {
        metaNode = confiscatedPage;
    }
    ITreeIndexMetadataFrame metaFrame = frameFactory.createFrame();
    metaNode.acquireReadLatch();
    try {
        metaFrame.setPage(metaNode);
        return metaFrame.getRootPageId();
    } finally {
        metaNode.releaseReadLatch();
        if (confiscatedPage == null) {
            bufferCache.unpin(metaNode);
        }
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame)

Example 10 with ITreeIndexMetadataFrame

use of org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame in project asterixdb by apache.

the class BTreeStatsTest method test01.

@Test
public void test01() throws Exception {
    TestStorageManagerComponentHolder.init(PAGE_SIZE, NUM_PAGES, MAX_OPEN_FILES);
    IBufferCache bufferCache = harness.getBufferCache();
    IFileMapProvider fmp = harness.getFileMapProvider();
    // declare fields
    int fieldCount = 2;
    ITypeTraits[] typeTraits = new ITypeTraits[fieldCount];
    typeTraits[0] = IntegerPointable.TYPE_TRAITS;
    typeTraits[1] = IntegerPointable.TYPE_TRAITS;
    // declare keys
    int keyFieldCount = 1;
    IBinaryComparatorFactory[] cmpFactories = new IBinaryComparatorFactory[keyFieldCount];
    cmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
    TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
    ITreeIndexFrameFactory leafFrameFactory = new BTreeNSMLeafFrameFactory(tupleWriterFactory);
    ITreeIndexFrameFactory interiorFrameFactory = new BTreeNSMInteriorFrameFactory(tupleWriterFactory);
    ITreeIndexMetadataFrameFactory metaFrameFactory = new LIFOMetaDataFrameFactory();
    IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) leafFrameFactory.createFrame();
    IBTreeInteriorFrame interiorFrame = (IBTreeInteriorFrame) interiorFrameFactory.createFrame();
    ITreeIndexMetadataFrame metaFrame = metaFrameFactory.createFrame();
    IMetadataPageManager freePageManager = new LinkedMetaDataPageManager(bufferCache, metaFrameFactory);
    BTree btree = new BTree(bufferCache, fmp, freePageManager, interiorFrameFactory, leafFrameFactory, cmpFactories, fieldCount, harness.getFileReference());
    btree.create();
    btree.activate();
    Random rnd = new Random();
    rnd.setSeed(50);
    long start = System.currentTimeMillis();
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("INSERTING INTO TREE");
    }
    IFrame frame = new VSizeFrame(ctx);
    FrameTupleAppender appender = new FrameTupleAppender();
    ArrayTupleBuilder tb = new ArrayTupleBuilder(fieldCount);
    DataOutput dos = tb.getDataOutput();
    ISerializerDeserializer[] recDescSers = { IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE };
    RecordDescriptor recDesc = new RecordDescriptor(recDescSers);
    IFrameTupleAccessor accessor = new FrameTupleAccessor(recDesc);
    accessor.reset(frame.getBuffer());
    FrameTupleReference tuple = new FrameTupleReference();
    ITreeIndexAccessor indexAccessor = btree.createAccessor(TestOperationCallback.INSTANCE, TestOperationCallback.INSTANCE);
    // 10000
    for (int i = 0; i < 100000; i++) {
        int f0 = rnd.nextInt() % 100000;
        int f1 = 5;
        tb.reset();
        IntegerSerializerDeserializer.INSTANCE.serialize(f0, dos);
        tb.addFieldEndOffset();
        IntegerSerializerDeserializer.INSTANCE.serialize(f1, dos);
        tb.addFieldEndOffset();
        appender.reset(frame, true);
        appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize());
        tuple.reset(accessor, 0);
        if (LOGGER.isLoggable(Level.INFO)) {
            if (i % 10000 == 0) {
                long end = System.currentTimeMillis();
                LOGGER.info("INSERTING " + i + " : " + f0 + " " + f1 + " " + (end - start));
            }
        }
        try {
            indexAccessor.insert(tuple);
        } catch (HyracksDataException e) {
            if (e.getErrorCode() != ErrorCode.DUPLICATE_KEY) {
                e.printStackTrace();
                throw e;
            }
        }
    }
    int fileId = fmp.lookupFileId(harness.getFileReference());
    TreeIndexStatsGatherer statsGatherer = new TreeIndexStatsGatherer(bufferCache, freePageManager, fileId, btree.getRootPageId());
    TreeIndexStats stats = statsGatherer.gatherStats(leafFrame, interiorFrame, metaFrame);
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("\n" + stats.toString());
    }
    TreeIndexBufferCacheWarmup bufferCacheWarmup = new TreeIndexBufferCacheWarmup(bufferCache, freePageManager, fileId);
    bufferCacheWarmup.warmup(leafFrame, metaFrame, new int[] { 1, 2 }, new int[] { 2, 5 });
    btree.deactivate();
    btree.destroy();
    bufferCache.close();
}
Also used : DataOutput(java.io.DataOutput) IBTreeInteriorFrame(org.apache.hyracks.storage.am.btree.api.IBTreeInteriorFrame) IFrame(org.apache.hyracks.api.comm.IFrame) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) TreeIndexStatsGatherer(org.apache.hyracks.storage.am.common.util.TreeIndexStatsGatherer) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame) BTreeNSMInteriorFrameFactory(org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrameFactory) ITreeIndexFrameFactory(org.apache.hyracks.storage.am.common.api.ITreeIndexFrameFactory) BTreeNSMLeafFrameFactory(org.apache.hyracks.storage.am.btree.frames.BTreeNSMLeafFrameFactory) ITreeIndexMetadataFrameFactory(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrameFactory) LIFOMetaDataFrameFactory(org.apache.hyracks.storage.am.common.frames.LIFOMetaDataFrameFactory) Random(java.util.Random) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) TypeAwareTupleWriterFactory(org.apache.hyracks.storage.am.common.tuples.TypeAwareTupleWriterFactory) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) TreeIndexStats(org.apache.hyracks.storage.am.common.util.TreeIndexStats) IMetadataPageManager(org.apache.hyracks.storage.am.common.api.IMetadataPageManager) LinkedMetaDataPageManager(org.apache.hyracks.storage.am.common.freepage.LinkedMetaDataPageManager) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IFileMapProvider(org.apache.hyracks.storage.common.file.IFileMapProvider) TreeIndexBufferCacheWarmup(org.apache.hyracks.storage.am.common.util.TreeIndexBufferCacheWarmup) IBufferCache(org.apache.hyracks.storage.common.buffercache.IBufferCache) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) Test(org.junit.Test) AbstractBTreeTest(org.apache.hyracks.storage.am.btree.util.AbstractBTreeTest)

Aggregations

ITreeIndexMetadataFrame (org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame)10 ICachedPage (org.apache.hyracks.storage.common.buffercache.ICachedPage)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 IBufferCache (org.apache.hyracks.storage.common.buffercache.IBufferCache)2 DataOutput (java.io.DataOutput)1 Random (java.util.Random)1 IFrame (org.apache.hyracks.api.comm.IFrame)1 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)1 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)1 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)1 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)1 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)1 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)1 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)1 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)1 IBTreeInteriorFrame (org.apache.hyracks.storage.am.btree.api.IBTreeInteriorFrame)1 IBTreeLeafFrame (org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame)1 BTreeNSMInteriorFrameFactory (org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrameFactory)1