use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX in project activemq-artemis by apache.
the class FileWrapperJournal method appendCommitRecord.
@Override
public void appendCommitRecord(long txID, boolean sync, IOCompletion callback, boolean lineUpContext) throws Exception {
JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, txID, null);
writeRecord(commitRecord, true, txID, true, callback);
}
use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX in project activemq-artemis by apache.
the class JournalCompactor method onReadCommitRecord.
@Override
public void onReadCommitRecord(final long transactionID, final int numberOfRecords) throws Exception {
if (logger.isTraceEnabled()) {
logger.trace("onReadCommitRecord " + transactionID);
}
if (pendingTransactions.get(transactionID) != null) {
// Sanity check, this should never happen
ActiveMQJournalLogger.LOGGER.inconsistencyDuringCompacting(transactionID);
} else {
JournalTransaction newTransaction = newTransactions.remove(transactionID);
if (newTransaction != null) {
JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, transactionID, null);
checkSize(commitRecord.getEncodeSize());
writeEncoder(commitRecord, newTransaction.getCounter(currentFile));
newTransaction.commit(currentFile);
}
}
}
use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX in project activemq-artemis by apache.
the class JournalImpl method appendPrepareRecord.
/**
* <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction
* back to a state it could be committed. </p>
* <p> transactionData allows you to store any other supporting user-data related to the transaction</p>
* <p> This method also uses the same logic applied on {@link JournalImpl#appendCommitRecord(long, boolean)}
*
* @param txID
* @param transactionData extra user data for the prepare
* @throws Exception
*/
@Override
public void appendPrepareRecord(final long txID, final EncodingSupport transactionData, final boolean sync, final IOCompletion callback) throws Exception {
checkJournalIsLoaded();
lineUpContext(callback);
if (logger.isTraceEnabled()) {
logger.trace("scheduling appendPrepareRecord::txID=" + txID);
}
final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
journalLock.readLock().lock();
final JournalTransaction tx = getTransactionInfo(txID);
try {
tx.checkErrorCondition();
JournalInternalRecord prepareRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.PREPARE, txID, transactionData);
JournalFile usedFile = appendRecord(prepareRecord, true, sync, tx, callback);
if (logger.isTraceEnabled()) {
logger.trace("appendPrepareRecord::txID=" + txID + ", usedFile = " + usedFile);
}
tx.prepare(usedFile);
} catch (Exception e) {
result.fail(e);
logger.error("appendPrepareRecord:" + e, e);
setErrorCondition(callback, tx, e);
} finally {
journalLock.readLock().unlock();
result.set(tx);
}
}
});
JournalTransaction tx = result.get();
if (tx != null) {
tx.checkErrorCondition();
}
}
use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX in project activemq-artemis by apache.
the class JournalImpl method appendCommitRecord.
/**
* Regarding the number of operations in a given file see {@link JournalCompleteRecordTX}.
*/
@Override
public void appendCommitRecord(final long txID, final boolean sync, final IOCompletion callback, final boolean lineUpContext) throws Exception {
checkJournalIsLoaded();
if (lineUpContext) {
lineUpContext(callback);
}
if (logger.isTraceEnabled()) {
logger.trace("scheduling appendCommitRecord::txID=" + txID);
}
JournalTransaction txcheck = transactions.get(txID);
if (txcheck != null) {
txcheck.checkErrorCondition();
}
final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
journalLock.readLock().lock();
// cannot remove otherwise compact may get lost
final JournalTransaction tx = transactions.remove(txID);
try {
if (tx == null) {
throw new IllegalStateException("Cannot find tx with id " + txID);
}
JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, txID, null);
JournalFile usedFile = appendRecord(commitRecord, true, sync, tx, callback);
tx.commit(usedFile);
} catch (Throwable e) {
result.fail(e);
logger.error("appendCommitRecord:" + e, e);
setErrorCondition(callback, tx, e);
} finally {
journalLock.readLock().unlock();
result.set(tx);
}
}
});
JournalTransaction tx = result.get();
if (tx != null) {
tx.checkErrorCondition();
}
}
use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX in project activemq-artemis by apache.
the class FileWrapperJournal method appendPrepareRecord.
@Override
public void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync, IOCompletion callback) throws Exception {
JournalInternalRecord prepareRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.PREPARE, txID, transactionData);
writeRecord(prepareRecord, true, txID, false, callback);
}
Aggregations