use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.
the class JournalImpl method appendDeleteRecord.
@Override
public void appendDeleteRecord(final long id, final boolean sync, final IOCompletion callback) throws Exception {
if (logger.isTraceEnabled()) {
logger.trace("scheduling appendDeleteRecord::id=" + id);
}
checkJournalIsLoaded();
lineUpContext(callback);
checkKnownRecordID(id);
final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
journalLock.readLock().lock();
try {
JournalRecord record = null;
if (compactor == null) {
record = records.remove(id);
}
JournalInternalRecord deleteRecord = new JournalDeleteRecord(id);
JournalFile usedFile = appendRecord(deleteRecord, false, sync, null, callback);
if (logger.isTraceEnabled()) {
logger.trace("appendDeleteRecord::id=" + id + ", usedFile = " + usedFile);
}
// computing the delete should be done after compacting is done
if (record == null) {
compactor.addCommandDelete(id, usedFile);
} else {
record.delete(usedFile);
}
result.set(true);
} catch (Exception e) {
result.fail(e);
logger.error("appendDeleteRecord:" + e, e);
} finally {
journalLock.readLock().unlock();
}
}
});
result.get();
}
use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord 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.JournalInternalRecord 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.JournalInternalRecord in project activemq-artemis by apache.
the class FileWrapperJournal method appendUpdateRecordTransactional.
@Override
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, Persister persister, Object record) throws Exception {
JournalInternalRecord updateRecordTX = new JournalAddRecordTX(false, txID, id, recordType, persister, record);
writeRecord(updateRecordTX, false, txID, false, null);
}
use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.
the class FileWrapperJournal method appendUpdateRecord.
@Override
public void appendUpdateRecord(long id, byte recordType, Persister persister, Object record, boolean sync, IOCompletion callback) throws Exception {
JournalInternalRecord updateRecord = new JournalAddRecord(false, id, recordType, persister, record);
writeRecord(updateRecord, false, -1, false, callback);
}
Aggregations