@Override public boolean isEmpty(ITreeIndexFrame frame, int rootPage) throws HyracksDataException { return bufferCache.getNumPagesOfFile(fileId) <= AbstractTreeIndex.MINIMAL_TREE_PAGE_COUNT; }
@Override public int getNumPagesOfFile(int fileId) throws HyracksDataException { return bufferCache.getNumPagesOfFile(fileId); }
/** * For storage on append-only media (such as HDFS), the meta data page has to be written last. * However, some implementations still write the meta data to the front. To deal with this as well * as to provide downward compatibility, this method tries to find the meta data page first in the * last and then in the first page of the file. * * @return The Id of the page holding the meta data * @throws HyracksDataException */ @Override public int getMetadataPageId() throws HyracksDataException { if (metadataPage != IBufferCache.INVALID_PAGEID) { return metadataPage; } int pages = bufferCache.getNumPagesOfFile(fileId); if (pages == 0) { //At least there are 2 pages to consider the index is not empty return IBufferCache.INVALID_PAGEID; } metadataPage = pages - 1; return metadataPage; }
private void changeToFunctionalState() throws HyracksDataException { if (bufferCache.getNumPagesOfFile(fileId) == 0) { state = State.WRITABLE; lafWriter = new LAFWriter(this, bufferCache); } else { state = State.READABLE; init(); } }
private void readBloomFilterMetaData() throws HyracksDataException { if (bufferCache.getNumPagesOfFile(fileId) == 0) { numPages = 0; numHashes = 0; numElements = 0; numBits = 0; version = DEFAULT_BLOOM_FILTER_VERSION; return; } ICachedPage metaPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, METADATA_PAGE_ID), false); metaPage.acquireReadLatch(); try { numPages = metaPage.getBuffer().getInt(NUM_PAGES_OFFSET); numHashes = metaPage.getBuffer().getInt(NUM_HASHES_USED_OFFSET); numElements = metaPage.getBuffer().getLong(NUM_ELEMENTS_OFFSET); numBits = metaPage.getBuffer().getLong(NUM_BITS_OFFSET); version = metaPage.getBuffer().getInt(VERSION_OFFSET); } finally { metaPage.releaseReadLatch(); bufferCache.unpin(metaPage); } }
private void init() throws HyracksDataException { final int numOfPages = bufferCache.getNumPagesOfFile(fileId); //Maximum number of entries in a page final int numOfEntriesPerPage = bufferCache.getPageSize() / ENTRY_LENGTH; //get the last page which may contain less entries than maxNumOfEntries final long dpid = getDiskPageId(numOfPages - 1); final ICachedPage page = bufferCache.pin(dpid, false); try { final ByteBuffer buf = page.getBuffer(); //Start at 1 since it is impossible to have EOF at the first entry of a page int i = 1; //Seek EOF and count number of entries while (i < numOfEntriesPerPage && buf.getLong(i * ENTRY_LENGTH) != EOF) { i++; } totalNumOfPages = (numOfPages - 1) * numOfEntriesPerPage + i; } finally { bufferCache.unpin(page); } }
@Override public void open(int fileId) throws HyracksDataException { this.fileId = fileId; // get the number of pages of the file int pages = bufferCache.getNumPagesOfFile(fileId); //if there are no pages in the file yet, we're just initializing if (pages == 0) { if (confiscatedPage != null) { throw new HyracksDataException("Metadata Page Manager is already initialized"); } ITreeIndexMetadataFrame metaFrame = createMetadataFrame(); ICachedPage metaNode = bufferCache.confiscatePage(BufferCache.INVALID_DPID); try { metaFrame.setPage(metaNode); metaFrame.init(); metaFrame.setMaxPage(-1); } finally { confiscatedPage = metaNode; } } }