Search in sources :

Example 1 with TransactionContext

use of org.apache.asterix.transaction.management.service.transaction.TransactionContext in project asterixdb by apache.

the class MetadataNode method insertTupleIntoIndex.

private void insertTupleIntoIndex(JobId jobId, IMetadataIndex metadataIndex, ITupleReference tuple) throws ACIDException, HyracksDataException {
    long resourceID = metadataIndex.getResourceId();
    String resourceName = metadataIndex.getFile().getRelativePath();
    ILSMIndex lsmIndex = (ILSMIndex) datasetLifecycleManager.get(resourceName);
    try {
        datasetLifecycleManager.open(resourceName);
        // prepare a Callback for logging
        IModificationOperationCallback modCallback = createIndexModificationCallback(jobId, resourceID, metadataIndex, lsmIndex, Operation.INSERT);
        ILSMIndexAccessor indexAccessor = lsmIndex.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
        ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        txnCtx.setWriteTxn(true);
        txnCtx.registerIndexAndCallback(resourceID, lsmIndex, (AbstractOperationCallback) modCallback, metadataIndex.isPrimaryIndex());
        LSMIndexUtil.checkAndSetFirstLSN((AbstractLSMIndex) lsmIndex, transactionSubsystem.getLogManager());
        // TODO: fix exceptions once new BTree exception model is in hyracks.
        indexAccessor.forceInsert(tuple);
        //by the job commit log event
        if (!((TransactionContext) txnCtx).getPrimaryIndexOpTracker().equals(lsmIndex.getOperationTracker())) {
            lsmIndex.getOperationTracker().completeOperation(lsmIndex, LSMOperationType.FORCE_MODIFICATION, null, modCallback);
        }
    } finally {
        datasetLifecycleManager.close(resourceName);
    }
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) TransactionContext(org.apache.asterix.transaction.management.service.transaction.TransactionContext) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback)

Example 2 with TransactionContext

use of org.apache.asterix.transaction.management.service.transaction.TransactionContext in project asterixdb by apache.

the class MetadataNode method deleteTupleFromIndex.

private void deleteTupleFromIndex(JobId jobId, IMetadataIndex metadataIndex, ITupleReference tuple) throws ACIDException, HyracksDataException {
    long resourceID = metadataIndex.getResourceId();
    String resourceName = metadataIndex.getFile().getRelativePath();
    ILSMIndex lsmIndex = (ILSMIndex) datasetLifecycleManager.get(resourceName);
    try {
        datasetLifecycleManager.open(resourceName);
        // prepare a Callback for logging
        IModificationOperationCallback modCallback = createIndexModificationCallback(jobId, resourceID, metadataIndex, lsmIndex, Operation.DELETE);
        ILSMIndexAccessor indexAccessor = lsmIndex.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
        ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        txnCtx.setWriteTxn(true);
        txnCtx.registerIndexAndCallback(resourceID, lsmIndex, (AbstractOperationCallback) modCallback, metadataIndex.isPrimaryIndex());
        LSMIndexUtil.checkAndSetFirstLSN((AbstractLSMIndex) lsmIndex, transactionSubsystem.getLogManager());
        indexAccessor.forceDelete(tuple);
        //by the job commit log event
        if (!((TransactionContext) txnCtx).getPrimaryIndexOpTracker().equals(lsmIndex.getOperationTracker())) {
            lsmIndex.getOperationTracker().completeOperation(lsmIndex, LSMOperationType.FORCE_MODIFICATION, null, modCallback);
        }
    } finally {
        datasetLifecycleManager.close(resourceName);
    }
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) TransactionContext(org.apache.asterix.transaction.management.service.transaction.TransactionContext) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback)

Aggregations

ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)2 AMutableString (org.apache.asterix.om.base.AMutableString)2 AString (org.apache.asterix.om.base.AString)2 TransactionContext (org.apache.asterix.transaction.management.service.transaction.TransactionContext)2 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)2 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)2 IModificationOperationCallback (org.apache.hyracks.storage.common.IModificationOperationCallback)2