Search in sources :

Example 46 with ACIDException

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

the class LogManagerWithReplication method syncAppendToLogTail.

@Override
protected synchronized void syncAppendToLogTail(ILogRecord logRecord) throws ACIDException {
    if (logRecord.getLogSource() == LogSource.LOCAL && logRecord.getLogType() != LogType.FLUSH) {
        ITransactionContext txnCtx = logRecord.getTxnCtx();
        if (txnCtx.getTxnState() == ITransactionManager.ABORTED && logRecord.getLogType() != LogType.ABORT) {
            throw new ACIDException("Aborted job(" + txnCtx.getJobId() + ") tried to write non-abort type log record.");
        }
    }
    final int logRecordSize = logRecord.getLogSize();
    // Make sure the log will not exceed the log file size
    if (getLogFileOffset(appendLSN.get()) + logRecordSize >= logFileSize) {
        prepareNextLogFile();
        prepareNextPage(logRecordSize);
    } else if (!appendPage.hasSpace(logRecordSize)) {
        prepareNextPage(logRecordSize);
    }
    appendPage.append(logRecord, appendLSN.get());
    if (logRecord.getLogType() == LogType.FLUSH) {
        logRecord.setLSN(appendLSN.get());
    }
    appendLSN.addAndGet(logRecordSize);
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 47 with ACIDException

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

the class LogReader method fillLogReadBuffer.

private boolean fillLogReadBuffer(int readSize, ByteBuffer readBuffer) throws ACIDException {
    int size = 0;
    int read = 0;
    readBuffer.position(0);
    readBuffer.limit(readSize);
    try {
        logFile.position(readLSN % logFileSize);
        //Therefore we want to break out only when either the buffer is full, or we reach EOF.
        while (size < readSize && read != -1) {
            read = logFile.read(readBuffer);
            if (read > 0) {
                size += read;
            }
        }
    } catch (IOException e) {
        throw new ACIDException(e);
    }
    readBuffer.position(0);
    readBuffer.limit(size);
    if (size == 0 && read == -1) {
        //EOF
        return false;
    }
    bufferBeginLSN = readLSN;
    return true;
}
Also used : IOException(java.io.IOException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 48 with ACIDException

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

the class LogReader method getLogFile.

private void getLogFile() throws ACIDException {
    try {
        logFile = logMgr.getLogFile(readLSN);
        fileBeginLSN = logFile.getFileBeginLSN();
    } catch (IOException e) {
        throw new ACIDException(e);
    }
}
Also used : IOException(java.io.IOException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 49 with ACIDException

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

the class CommitRuntime method open.

@Override
public void open() throws HyracksDataException {
    try {
        transactionContext = transactionManager.getTransactionContext(jobId, false);
        transactionContext.setWriteTxn(isWriteTransaction);
        ILogMarkerCallback callback = TaskUtil.get(ILogMarkerCallback.KEY_MARKER_CALLBACK, ctx);
        logRecord = new LogRecord(callback);
        if (isSink) {
            return;
        }
        initAccessAppend(ctx);
        writer.open();
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : LogRecord(org.apache.asterix.common.transactions.LogRecord) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ILogMarkerCallback(org.apache.asterix.common.transactions.ILogMarkerCallback) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 50 with ACIDException

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

the class SecondaryIndexModificationOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    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);
        DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
        IModificationOperationCallback modCallback = new SecondaryIndexModificationOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, false);
        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)

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