Search in sources :

Example 1 with LogRecord

use of org.apache.asterix.common.transactions.LogRecord 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)

Example 2 with LogRecord

use of org.apache.asterix.common.transactions.LogRecord in project asterixdb by apache.

the class TransactionManager method commitTransaction.

@Override
public void commitTransaction(ITransactionContext txnCtx, DatasetId datasetId, int PKHashVal) throws ACIDException {
    //Only job-level commits call this method.
    try {
        if (txnCtx.isWriteTxn()) {
            LogRecord logRecord = ((TransactionContext) txnCtx).getLogRecord();
            TransactionUtil.formJobTerminateLogRecord(txnCtx, logRecord, true);
            txnSubsystem.getLogManager().log(logRecord);
        }
    } catch (Exception ae) {
        if (LOGGER.isLoggable(Level.SEVERE)) {
            LOGGER.severe(" caused exception in commit !" + txnCtx.getJobId());
        }
        throw ae;
    } finally {
        txnSubsystem.getLockManager().releaseLocks(txnCtx);
        transactionContextRepository.remove(txnCtx.getJobId());
        txnCtx.setTxnState(ITransactionManager.COMMITTED);
    }
}
Also used : LogRecord(org.apache.asterix.common.transactions.LogRecord) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 3 with LogRecord

use of org.apache.asterix.common.transactions.LogRecord 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 4 with LogRecord

use of org.apache.asterix.common.transactions.LogRecord in project asterixdb by apache.

the class LogBuffer method notifyFlushTermination.

public void notifyFlushTermination() throws ACIDException {
    LogRecord logRecord = null;
    try {
        logRecord = (LogRecord) flushQ.take();
    } catch (InterruptedException e) {
    //ignore
    }
    synchronized (logRecord) {
        logRecord.isFlushed(true);
        logRecord.notifyAll();
    }
    PrimaryIndexOperationTracker opTracker = logRecord.getOpTracker();
    if (opTracker != null) {
        try {
            opTracker.triggerScheduleFlush(logRecord);
        } catch (HyracksDataException e) {
            throw new ACIDException(e);
        }
    }
}
Also used : ILogRecord(org.apache.asterix.common.transactions.ILogRecord) LogRecord(org.apache.asterix.common.transactions.LogRecord) PrimaryIndexOperationTracker(org.apache.asterix.common.context.PrimaryIndexOperationTracker) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 5 with LogRecord

use of org.apache.asterix.common.transactions.LogRecord in project asterixdb by apache.

the class LogBuffer method notifyReplicationTermination.

public void notifyReplicationTermination() {
    LogRecord logRecord = null;
    try {
        logRecord = (LogRecord) remoteJobsQ.take();
    } catch (InterruptedException e) {
    //ignore
    }
    logRecord.isFlushed(true);
    IReplicationThread replicationThread = logRecord.getReplicationThread();
    if (replicationThread != null) {
        replicationThread.notifyLogReplicationRequester(logRecord);
    }
}
Also used : ILogRecord(org.apache.asterix.common.transactions.ILogRecord) LogRecord(org.apache.asterix.common.transactions.LogRecord) IReplicationThread(org.apache.asterix.common.replication.IReplicationThread)

Aggregations

LogRecord (org.apache.asterix.common.transactions.LogRecord)7 ACIDException (org.apache.asterix.common.exceptions.ACIDException)5 ILogRecord (org.apache.asterix.common.transactions.ILogRecord)3 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 PrimaryIndexOperationTracker (org.apache.asterix.common.context.PrimaryIndexOperationTracker)1 IReplicationThread (org.apache.asterix.common.replication.IReplicationThread)1 ILogMarkerCallback (org.apache.asterix.common.transactions.ILogMarkerCallback)1 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)1 ILSMMemoryComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMMemoryComponent)1 ILSMOperationTracker (org.apache.hyracks.storage.am.lsm.common.api.ILSMOperationTracker)1