/** * Prepare the component to be scheduled for an IO operation * * @param ioOperationType * @throws HyracksDataException */ @Override public void schedule(LSMIOOperationType ioOperationType) throws HyracksDataException { activeate(); if (ioOperationType == LSMIOOperationType.FLUSH) { if (state == ComponentState.READABLE_WRITABLE || state == ComponentState.READABLE_UNWRITABLE) { if (writerCount != 0) { throw new IllegalStateException("Trying to schedule a flush when writerCount != 0"); } state = ComponentState.READABLE_UNWRITABLE_FLUSHING; } else if (state == ComponentState.READABLE_UNWRITABLE_FLUSHING || state == ComponentState.UNREADABLE_UNWRITABLE) { // There is an ongoing flush. Increase pending flush count pendingFlushes++; } else { throw new IllegalStateException("Trying to schedule a flush when the component state = " + state); } } else { throw new UnsupportedOperationException("Unsupported operation " + ioOperationType); } }
@Override public final void allocate() throws HyracksDataException { boolean allocated = false; ((IVirtualBufferCache) getIndex().getBufferCache()).open(); try { doAllocate(); allocated = true; } finally { if (!allocated) { getIndex().getBufferCache().close(); } } }
@Override public final void deallocate() throws HyracksDataException { try { state = ComponentState.INACTIVE; doDeallocate(); } finally { getIndex().getBufferCache().close(); } }
if (state == ComponentState.READABLE_WRITABLE && !failedOperation && isFull()) { state = ComponentState.READABLE_UNWRITABLE; readerCount--; if (state == ComponentState.UNREADABLE_UNWRITABLE && readerCount == 0) { reset(); readerCount--; if (state == ComponentState.UNREADABLE_UNWRITABLE && readerCount == 0) { reset(); reset(); } else { state = ComponentState.UNREADABLE_UNWRITABLE;
@Override public void updateMeta(ILSMIndexOperationContext ctx, IValueReference key, IValueReference value) throws HyracksDataException { if (!lsmIndex.isMemoryComponentsAllocated()) { lsmIndex.allocateMemoryComponents(); } getAndEnterComponents(ctx, LSMOperationType.MODIFICATION, false); try { AbstractLSMMemoryComponent c = (AbstractLSMMemoryComponent) ctx.getComponentHolder().get(0); c.getMetadata().put(key, value); c.setModified(); } finally { exitAndComplete(ctx, LSMOperationType.MODIFICATION); } }
@Override public final void reset() throws HyracksDataException { state = ComponentState.INACTIVE; isModified.set(false); metadata.reset(); if (filter != null) { filter.reset(); } doReset(); lsmIndex.memoryComponentsReset(); // a flush can be pending on a component that just completed its flush... here is when this can happen: // primary index has 2 components, secondary index has 2 components. // 2 flushes are scheduled on each p1, p2, s1, and s2. // p1 and p2 both finish. primary component 1 gets full and secondary doesn't have any entries (optional field). // then flush is scheduled on p1, s1 will have a pending flush in that case. if (pendingFlushes > 0) { schedule(LSMIOOperationType.FLUSH); pendingFlushes--; } }
public boolean isEmptyIndex() { boolean isModified = false; for (ILSMComponent c : memoryComponents) { AbstractLSMMemoryComponent mutableComponent = (AbstractLSMMemoryComponent) c; if (mutableComponent.isModified()) { isModified = true; break; } } return diskComponents.isEmpty() && !isModified; }
@Override public void doDeallocate() throws HyracksDataException { super.doDeallocate(); getBuddyIndex().deactivate(); getBuddyIndex().destroy(); }
@Override public void doAllocate() throws HyracksDataException { super.doAllocate(); getBuddyIndex().create(); getBuddyIndex().activate(); }
@Override public void doReset() throws HyracksDataException { super.doReset(); getBuddyIndex().deactivate(); getBuddyIndex().destroy(); getBuddyIndex().create(); getBuddyIndex().activate(); }
private void redoMemoryComponentSearchIfNeeded() throws HyracksDataException { if (!includeMutableComponent) { return; } // if the last n records, none were from memory and there are writers inside the component, // we need to re-do the search so the cursor doesn't block modifications due to latches over page if (tupleFromMemoryComponentCount == 0 && ((AbstractLSMMemoryComponent) operationalComponents.get(0)).getWriterCount() > 0) { // When we reach here, we know that the mutable component element is not the outputElement // since if it was the output element, the tupleFromMemoryComponentCount would be at least 1 PriorityQueueElement mutableElement = remove(outputPriorityQueue, 0); if (mutableElement != null) { // if the element is null, then there is nothing to do since no latches are held if (tupleBuilder == null) { tupleBuilder = new ArrayTupleBuilder(cmp.getKeyFieldCount()); } TupleUtils.copyTuple(tupleBuilder, mutableElement.getTuple(), cmp.getKeyFieldCount()); copyTuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray()); // Unlatches/unpins the leaf page of the index. rangeCursors[0].close(); // Re-traverses the index. reusablePred.setLowKey(copyTuple, true); btreeAccessors[0].search(rangeCursors[0], reusablePred); pushIntoQueueFromCursorAndReplaceThisElement(mutableElement); } } tupleFromMemoryComponentCount = 0; }
@Override public void forceUpdateMeta(ILSMIndexOperationContext ctx, IValueReference key, IValueReference value) throws HyracksDataException { if (!lsmIndex.isMemoryComponentsAllocated()) { lsmIndex.allocateMemoryComponents(); } getAndEnterComponents(ctx, LSMOperationType.FORCE_MODIFICATION, false); try { AbstractLSMMemoryComponent c = (AbstractLSMMemoryComponent) ctx.getComponentHolder().get(0); c.getMetadata().put(key, value); c.setModified(); } finally { exitAndComplete(ctx, LSMOperationType.FORCE_MODIFICATION); } }
@Override public void validate() throws HyracksDataException { getIndex().validate(); }
@Override public boolean threadEnter(LSMOperationType opType, boolean isMutableComponent) throws HyracksDataException { activeate(); switch (opType) { case FORCE_MODIFICATION:
@Override public long getSize() { IBufferCache virtualBufferCache = getIndex().getBufferCache(); return virtualBufferCache.getPageBudget() * (long) virtualBufferCache.getPageSize(); }