Search in sources :

Example 1 with ILSMMemoryComponent

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

the class PrimaryIndexLogMarkerCallback method lsnFromImmutableMemoryComponents.

private long lsnFromImmutableMemoryComponents() {
    List<ILSMMemoryComponent> memComponents = index.getMemoryComponents();
    int numOtherMemComponents = memComponents.size() - 1;
    int next = index.getCurrentMemoryComponentIndex();
    long lsn = ComponentMetadataUtil.NOT_FOUND;
    for (int i = 0; i < numOtherMemComponents; i++) {
        next = next - 1;
        if (next < 0) {
            next = memComponents.size() - 1;
        }
        ILSMMemoryComponent c = index.getMemoryComponents().get(next);
        if (c.isReadable()) {
            try {
                lsn = ComponentMetadataUtil.getLong(c.getMetadata(), ComponentMetadataUtil.MARKER_LSN_KEY, ComponentMetadataUtil.NOT_FOUND);
            } catch (HyracksDataException e) {
                // Should never happen since this is a memory component
                throw new IllegalStateException(e);
            }
            if (lsn != ComponentMetadataUtil.NOT_FOUND) {
                return lsn;
            }
        }
    }
    return lsn;
}
Also used : ILSMMemoryComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with ILSMMemoryComponent

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

the class ComponentMetadataUtil method fromImmutableMemoryComponents.

private static void fromImmutableMemoryComponents(ILSMIndex index, IValueReference key, IPointable pointable) {
    List<ILSMMemoryComponent> memComponents = index.getMemoryComponents();
    int numOtherMemComponents = memComponents.size() - 1;
    int next = index.getCurrentMemoryComponentIndex();
    for (int i = 0; i < numOtherMemComponents; i++) {
        next = next - 1;
        if (next < 0) {
            next = memComponents.size() - 1;
        }
        ILSMMemoryComponent c = index.getMemoryComponents().get(next);
        if (c.isReadable()) {
            c.getMetadata().get(key, pointable);
            if (pointable.getLength() != 0) {
                // Found
                return;
            }
        }
    }
}
Also used : ILSMMemoryComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent)

Example 3 with ILSMMemoryComponent

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

the class AbstractLSMIndex method addOperationalMutableComponents.

private void addOperationalMutableComponents(List<ILSMComponent> operationalComponents) {
    int cmc = currentMutableComponentId.get();
    int numMutableComponents = memoryComponents.size();
    for (int i = 0; i < numMutableComponents - 1; i++) {
        ILSMMemoryComponent c = memoryComponents.get((cmc + i + 1) % numMutableComponents);
        if (c.isReadable()) {
            // Make sure newest components are added first
            operationalComponents.add(0, c);
        }
    }
    // The current mutable component is always added
    operationalComponents.add(0, memoryComponents.get(cmc));
}
Also used : ILSMMemoryComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent)

Example 4 with ILSMMemoryComponent

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

the class PrimaryIndexOperationTracker method flushIfRequested.

public void flushIfRequested() throws HyracksDataException {
    // If we need a flush, and this is the last completing operation, then schedule the flush,
    // or if there is a flush scheduled by the checkpoint (flushOnExit), then schedule it
    boolean needsFlush = false;
    Set<ILSMIndex> indexes = dsInfo.getDatasetIndexes();
    if (!flushOnExit) {
        for (ILSMIndex lsmIndex : indexes) {
            if (lsmIndex.hasFlushRequestForCurrentMutableComponent()) {
                needsFlush = true;
                break;
            }
        }
    }
    if (needsFlush || flushOnExit) {
        //Make the current mutable components READABLE_UNWRITABLE to stop coming modify operations from entering them until the current flush is scheduled.
        for (ILSMIndex lsmIndex : indexes) {
            ILSMOperationTracker opTracker = lsmIndex.getOperationTracker();
            synchronized (opTracker) {
                ILSMMemoryComponent memComponent = lsmIndex.getCurrentMemoryComponent();
                if (memComponent.getState() == ComponentState.READABLE_WRITABLE && memComponent.isModified()) {
                    memComponent.setState(ComponentState.READABLE_UNWRITABLE);
                }
            }
        }
        LogRecord logRecord = new LogRecord();
        flushOnExit = false;
        if (dsInfo.isDurable()) {
            /**
                 * Generate a FLUSH log.
                 * Flush will be triggered when the log is written to disk by LogFlusher.
                 */
            TransactionUtil.formFlushLogRecord(logRecord, datasetID, this, logManager.getNodeId(), dsInfo.getDatasetIndexes().size());
            try {
                logManager.log(logRecord);
            } catch (ACIDException e) {
                throw new HyracksDataException("could not write flush log", e);
            }
            flushLogCreated = true;
        } else {
            //trigger flush for temporary indexes without generating a FLUSH log.
            triggerScheduleFlush(logRecord);
        }
    }
}
Also used : LogRecord(org.apache.asterix.common.transactions.LogRecord) ILSMMemoryComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ILSMOperationTracker(org.apache.hyracks.storage.am.lsm.common.api.ILSMOperationTracker) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 5 with ILSMMemoryComponent

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

the class AbstractLSMIndex method scheduleFlush.

@Override
public void scheduleFlush(ILSMIndexOperationContext ctx, ILSMIOOperationCallback callback) throws HyracksDataException {
    ILSMMemoryComponent flushingComponent = (ILSMMemoryComponent) ctx.getComponentHolder().get(0);
    LSMComponentFileReferences componentFileRefs = fileManager.getRelFlushFileReference();
    AbstractLSMIndexOperationContext opCtx = createOpContext(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    opCtx.setOperation(IndexOperation.FLUSH);
    opCtx.getComponentHolder().add(flushingComponent);
    ILSMIOOperation flushOp = createFlushOperation(opCtx, flushingComponent, componentFileRefs, callback);
    ioScheduler.scheduleOperation(flushOp);
}
Also used : ILSMIOOperation(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperation) ILSMMemoryComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent)

Aggregations

ILSMMemoryComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent)5 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 LogRecord (org.apache.asterix.common.transactions.LogRecord)1 ILSMIOOperation (org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperation)1 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)1 ILSMOperationTracker (org.apache.hyracks.storage.am.lsm.common.api.ILSMOperationTracker)1