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());
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations