Search in sources :

Example 16 with ACIDException

use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.

the class MetadataNode method addDatatype.

@Override
public void addDatatype(JobId jobId, Datatype datatype) throws MetadataException, RemoteException {
    try {
        DatatypeTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getDataTypeTupleTranslator(jobId, this, true);
        ITupleReference tuple = tupleReaderWriter.getTupleFromMetadataEntity(datatype);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.DATATYPE_DATASET, tuple);
    } catch (HyracksDataException e) {
        if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.DUPLICATE_KEY) {
            throw new MetadataException("A datatype with name '" + datatype.getDatatypeName() + "' already exists.", e);
        } else {
            throw new MetadataException(e);
        }
    } catch (ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : DatatypeTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.DatatypeTupleTranslator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 17 with ACIDException

use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.

the class MetadataNode method addEntity.

// TODO(amoudi): make all metadata operations go through the generic methods
/**
     * Add entity to index
     *
     * @param jobId
     * @param entity
     * @param tupleTranslator
     * @param index
     * @throws MetadataException
     */
private <T> void addEntity(JobId jobId, T entity, IMetadataEntityTupleTranslator<T> tupleTranslator, IMetadataIndex index) throws MetadataException {
    try {
        ITupleReference tuple = tupleTranslator.getTupleFromMetadataEntity(entity);
        insertTupleIntoIndex(jobId, index, tuple);
    } catch (HyracksDataException | ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 18 with ACIDException

use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.

the class MetadataNode method updateDataset.

@Override
public void updateDataset(JobId jobId, Dataset dataset) throws MetadataException, RemoteException {
    try {
        // This method will delete previous entry of the dataset and insert the new one
        // Delete entry from the 'datasets' dataset.
        ITupleReference searchKey;
        searchKey = createTuple(dataset.getDataverseName(), dataset.getDatasetName());
        // Searches the index for the tuple to be deleted. Acquires an S
        // lock on the 'dataset' dataset.
        ITupleReference datasetTuple = getTupleToBeDeleted(jobId, MetadataPrimaryIndexes.DATASET_DATASET, searchKey);
        deleteTupleFromIndex(jobId, MetadataPrimaryIndexes.DATASET_DATASET, datasetTuple);
        // Previous tuple was deleted
        // Insert into the 'dataset' dataset.
        DatasetTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getDatasetTupleTranslator(true);
        datasetTuple = tupleReaderWriter.getTupleFromMetadataEntity(dataset);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.DATASET_DATASET, datasetTuple);
    } catch (HyracksDataException | ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : DatasetTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.DatasetTupleTranslator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 19 with ACIDException

use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.

the class TransactionManager method getTransactionContext.

@Override
public ITransactionContext getTransactionContext(JobId jobId, boolean createIfNotExist) throws ACIDException {
    setMaxJobId(jobId.getId());
    ITransactionContext txnCtx = transactionContextRepository.get(jobId);
    if (txnCtx == null) {
        if (createIfNotExist) {
            synchronized (this) {
                txnCtx = transactionContextRepository.get(jobId);
                if (txnCtx == null) {
                    txnCtx = new TransactionContext(jobId);
                    transactionContextRepository.put(jobId, txnCtx);
                }
            }
        } else {
            throw new ACIDException("TransactionContext of " + jobId + " doesn't exist.");
        }
    }
    return txnCtx;
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 20 with ACIDException

use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.

the class TransactionManager method abortTransaction.

@Override
public void abortTransaction(ITransactionContext txnCtx, DatasetId datasetId, int PKHashVal) throws ACIDException {
    if (txnCtx.getTxnState() != ITransactionManager.ABORTED) {
        txnCtx.setTxnState(ITransactionManager.ABORTED);
    }
    try {
        if (txnCtx.isWriteTxn()) {
            LogRecord logRecord = ((TransactionContext) txnCtx).getLogRecord();
            TransactionUtil.formJobTerminateLogRecord(txnCtx, logRecord, false);
            txnSubsystem.getLogManager().log(logRecord);
            txnSubsystem.getRecoveryManager().rollbackTransaction(txnCtx);
        }
    } catch (Exception ae) {
        String msg = "Could not complete rollback! System is in an inconsistent state";
        if (LOGGER.isLoggable(Level.SEVERE)) {
            LOGGER.severe(msg);
        }
        ae.printStackTrace();
        throw new ACIDException(msg, ae);
    } finally {
        ((TransactionContext) txnCtx).cleanupForAbort();
        txnSubsystem.getLockManager().releaseLocks(txnCtx);
        transactionContextRepository.remove(txnCtx.getJobId());
    }
}
Also used : LogRecord(org.apache.asterix.common.transactions.LogRecord) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

ACIDException (org.apache.asterix.common.exceptions.ACIDException)70 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)54 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)31 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)14 IOException (java.io.IOException)9 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)9 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)6 DatasetId (org.apache.asterix.common.transactions.DatasetId)5 ITransactionSubsystem (org.apache.asterix.common.transactions.ITransactionSubsystem)5 LogRecord (org.apache.asterix.common.transactions.LogRecord)5 RemoteException (java.rmi.RemoteException)4 Checkpoint (org.apache.asterix.common.transactions.Checkpoint)4 ILogRecord (org.apache.asterix.common.transactions.ILogRecord)4 IModificationOperationCallback (org.apache.hyracks.storage.common.IModificationOperationCallback)4 HashMap (java.util.HashMap)3 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)3 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)3 ITransactionManager (org.apache.asterix.common.transactions.ITransactionManager)3 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)3 IIndex (org.apache.hyracks.storage.common.IIndex)3