Search in sources :

Example 21 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class UpsertOperationCallback method found.

@Override
public void found(ITupleReference before, ITupleReference after) throws HyracksDataException {
    try {
        int pkHash = computePrimaryKeyHashValue(after, primaryKeyFields);
        log(pkHash, after, before);
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 22 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class UpsertOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
    ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx);
    IResourceLifecycleManager indexLifeCycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath());
    if (index == null) {
        throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered.");
    }
    try {
        ITransactionContext txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        IModificationOperationCallback modCallback = new UpsertOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, true);
        return modCallback;
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ITransactionSubsystem(org.apache.asterix.common.transactions.ITransactionSubsystem) IResourceLifecycleManager(org.apache.hyracks.storage.common.IResourceLifecycleManager) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) DatasetId(org.apache.asterix.common.transactions.DatasetId) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 23 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class PrimaryIndexModificationOperationCallback method before.

@Override
public void before(ITupleReference tuple) throws HyracksDataException {
    int pkHash = computePrimaryKeyHashValue(tuple, primaryKeyFields);
    try {
        if (operatorNodePushable != null) {
            /**********************************************************************************
                 * In order to achieve deadlock-free locking protocol during any write (insert/delete/upsert) operations,
                 * the following logic is implemented.
                 * See https://cwiki.apache.org/confluence/display/ASTERIXDB/Deadlock-Free+Locking+Protocol for more details.
                 * 1. for each entry in a frame
                 * 2. returnValue = tryLock() for an entry
                 * 3. if returnValue == false
                 * 3-1. flush all entries (which already acquired locks) to the next operator
                 * : this will make all those entries reach commit operator so that corresponding commit logs will be created.
                 * 3-2. create a WAIT log and wait until logFlusher thread will flush the WAIT log and gives notification
                 * : this notification guarantees that all locks acquired by this transactor (or all locks acquired for the entries)
                 * were released.
                 * 3-3. acquire lock using lock() instead of tryLock() for the failed entry
                 * : we know for sure this lock call will not cause deadlock since the transactor doesn't hold any other locks.
                 * 4. create an update log and insert the entry
                 * From the above logic, step 2 and 3 are implemented in this before() method.
                 **********************/
            //release all locks held by this actor (which is a thread) by flushing partial frame.
            boolean tryLockSucceed = lockManager.tryLock(datasetId, pkHash, LockMode.X, txnCtx);
            if (!tryLockSucceed) {
                //flush entries which have been inserted already to release locks hold by them
                operatorNodePushable.flushPartialFrame();
                //create WAIT log and wait until the WAIT log is flushed and notified by LogFlusher thread
                logWait();
                //acquire lock
                lockManager.lock(datasetId, pkHash, LockMode.X, txnCtx);
            }
        } else {
            //operatorNodePushable can be null when metadata node operation is executed
            lockManager.lock(datasetId, pkHash, LockMode.X, txnCtx);
        }
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 24 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class PrimaryIndexModificationOperationCallback method found.

@Override
public void found(ITupleReference before, ITupleReference after) throws HyracksDataException {
    try {
        int pkHash = computePrimaryKeyHashValue(after, primaryKeyFields);
        log(pkHash, after, before);
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 25 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class SecondaryIndexModificationOperationCallback method found.

@Override
public void found(ITupleReference before, ITupleReference after) throws HyracksDataException {
    try {
        int pkHash = computePrimaryKeyHashValue(after, primaryKeyFields);
        this.log(pkHash, after, before);
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)566 IOException (java.io.IOException)209 DataOutput (java.io.DataOutput)96 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)78 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)75 IPointable (org.apache.hyracks.data.std.api.IPointable)73 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)70 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)67 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)67 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)64 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)61 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)60 ArrayList (java.util.ArrayList)57 ACIDException (org.apache.asterix.common.exceptions.ACIDException)56 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)56 ATypeTag (org.apache.asterix.om.types.ATypeTag)39 AsterixException (org.apache.asterix.common.exceptions.AsterixException)36 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)32 ByteBuffer (java.nio.ByteBuffer)30 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)27