use of com.sun.messaging.jmq.io.txnlog.TransactionLogRecord in project openmq by eclipse-ee4j.
the class FileStore method logTxn.
@Override
public void logTxn(int type, byte[] data) throws IOException {
if (Store.getDEBUG()) {
logger.log(Logger.INFO, "FileStore.logTxn(type=" + type + ") called");
}
// we don't log to the log files during playbacked!
if (!txnLoggerInited) {
return;
}
if (type == TransactionLogType.PRODUCE_TRANSACTION) {
TransactionLogRecord record = msgLogWriter.newTransactionLogRecord();
record.setType(type);
record.setBody(data);
msgLogWriter.write(record);
} else {
TransactionLogRecord record = ackLogWriter.newTransactionLogRecord();
record.setType(type);
record.setBody(data);
ackLogWriter.write(record);
}
}
use of com.sun.messaging.jmq.io.txnlog.TransactionLogRecord in project openmq by eclipse-ee4j.
the class TransactionLogManager method replayTransactionLogOnStartup.
public void replayTransactionLogOnStartup() throws BrokerException {
if (Store.getDEBUG()) {
logger.log(Logger.DEBUG, getPrefix() + " replayTransactionLogOnStartup");
}
try {
setReplayInProgress(true);
if (msgLogWriter.playBackRequired()) {
if (Store.getDEBUG()) {
String msg = getPrefix() + " replayTransactionLogOnStartup: playBackRequired";
logger.log(Logger.DEBUG, msg);
}
logger.log(Logger.FORCE, BrokerResources.I_PROCESS_MSG_TXNLOG);
// All destinations need to be loaded
Globals.getDestinationList().loadDestinations(store);
Globals.getCoreLifecycle().initSubscriptions();
// Keep track of loaded
HashSet dstLoadedSet = new HashSet();
// dst
Iterator itr = msgLogWriter.iterator();
while (itr.hasNext()) {
// Read in the acks or msgs & acks
TransactionLogRecord rec = (TransactionLogRecord) itr.next();
byte[] data = rec.getBody();
TransactionEvent txnEvent = readTransactionEvent(data);
int type = txnEvent.getType();
if (Store.getDEBUG()) {
String msg = getPrefix() + " replayTransactionLogOnStartup() recordSeq= " + rec.getSequence() + " txnEvent= " + txnEvent;
logger.log(Logger.DEBUG, msg);
}
if (type == BaseTransaction.NON_TRANSACTED_MSG_TYPE) {
transactionLogReplayer.replayNonTxnMsg((NonTransactedMsgEvent) txnEvent, dstLoadedSet);
} else if (type == BaseTransaction.NON_TRANSACTED_ACK_TYPE) {
transactionLogReplayer.replayNonTxnMsgAck((NonTransactedMsgAckEvent) txnEvent, dstLoadedSet);
} else if (type == BaseTransaction.MSG_REMOVAL_TYPE) {
transactionLogReplayer.replayMessageRemoval((MsgRemovalEvent) txnEvent, dstLoadedSet);
} else {
BaseTransactionManager tm = getTransactionManager(type);
tm.replayTransactionEvent(txnEvent, dstLoadedSet);
}
}
} else {
if (Store.getDEBUG()) {
logger.log(Logger.DEBUG, "no playBackRequired");
}
}
} catch (IOException e) {
logger.log(Logger.ERROR, "exception in playback", e);
throw new BrokerException("exception in playback", e);
} finally {
setReplayInProgress(false);
}
}
use of com.sun.messaging.jmq.io.txnlog.TransactionLogRecord in project openmq by eclipse-ee4j.
the class TransactionLogManager method logMsgRemoval.
public void logMsgRemoval(DestinationUID dstID, SysMessageID mid) throws BrokerException {
if (Store.getDEBUG()) {
String msg = getPrefix() + " logMsgRemoval() dstID=" + dstID + " mid=" + mid;
logger.log(Logger.DEBUG, msg);
}
try {
store.txnLogSharedLock.lock();
MsgRemovalEvent txnEvent = new MsgRemovalEvent(dstID, mid);
byte[] data = txnEvent.writeToBytes();
TransactionLogRecord record = msgLogWriter.newTransactionLogRecord();
record.setBody(data);
msgLogWriter.write(record);
} catch (IOException ioe) {
throw new BrokerException("error logging transaction", ioe);
} finally {
store.txnLogSharedLock.unlock();
}
}
use of com.sun.messaging.jmq.io.txnlog.TransactionLogRecord in project openmq by eclipse-ee4j.
the class FileTransactionLogWriter method writeCompoundRecord.
void writeCompoundRecord(TransactionLogRecord[] records) throws IOException {
synchronized (txnLogSyncObj) {
if (closed) {
// don't write record if txnLog has been closed
return;
}
int numRecords = records.length;
// log("writeCompoundRecord list size = "+records.length);
TransactionLogRecord entry = new FileTransactionLogRecord();
entry.setType(TransactionLogType.COMPOUND_TRANSACTION);
// get bytes
// calculate compoundBody size;
int compoundBodySize = 4;
for (int i = 0; i < numRecords; i++) {
compoundBodySize += 8;
compoundBodySize += records[i].getBody().length;
}
byte[] compoundBody = new byte[compoundBodySize];
ByteBuffer subBuf = ByteBuffer.wrap(compoundBody);
subBuf.putInt(numRecords);
for (int i = 0; i < numRecords; i++) {
subBuf.putInt(records[i].getType());
subBuf.putInt(records[i].getBody().length);
subBuf.put(records[i].getBody());
}
entry.setBody(compoundBody);
// write entry, we need to sync from this point
// First come first serve
entry.setCheckPointSequence(checkpointSequence);
// set timestamp
entry.setTimestamp(System.currentTimeMillis());
// set entry sequence. increase 1 after addition.
entry.setSequence(entrySequence++);
// 1. calculate record size
int size = RECORD_HEADER_SIZE + entry.getBody().length;
// 2. allocate byte buffer
byte[] bytes = new byte[size];
ByteBuffer buf = ByteBuffer.wrap(bytes);
// 3. write record header
writeRecordHeader(buf, entry);
// 4. write body
buf.put(entry.getBody());
// write (and sync) bytes to disk
// raf.write(bytes);
doWrite(bytes);
// check if we need to notify CP listener.
if (raf.getFilePointer() > cpSize) {
// we only call the listener once
if (this.isListenerCalled == false) {
if (debug) {
log("calling check point listener, fpointer: " + raf.getFilePointer());
}
callback.checkpoint();
// set flag to true so that we only call the listener once.
this.isListenerCalled = true;
}
}
// last record added to the log file
this.lastEntry = entry;
// log("wroteCompoundRecord list ");
}
}
use of com.sun.messaging.jmq.io.txnlog.TransactionLogRecord in project openmq by eclipse-ee4j.
the class FileTransactionLogWriter method processTransactionLogRecordList.
private void processTransactionLogRecordList() {
TransactionLogRecord[] records = null;
synchronized (recordListMutex) {
while (transactionLogRecordList.isEmpty() && !closed) {
try {
// log("waiting for transactionLogRecordList to be >0 ");
recordListMutex.wait(1000);
// log("waking up from recordListMutex.wait()");
} catch (InterruptedException e) {
}
}
records = new TransactionLogRecord[transactionLogRecordList.size()];
records = transactionLogRecordList.toArray(records);
transactionLogRecordList.clear();
}
if (debug) {
numrecordsArray[sampleNum] = records.length;
sampleNum++;
int totalCount = 0;
if (sampleNum == sampleCount) {
sampleNum = 0;
for (int i = 0; i < sampleCount; i++) {
totalCount += numrecordsArray[i];
System.out.print(numrecordsArray[i] + ",");
}
float averageCount = ((float) totalCount) / sampleCount;
log(" average records in compound txn record = " + averageCount);
}
}
if (records.length == 1) {
// log("transactionLogRecordList ==1 ");
// only a single record so just save it normally
TransactionLogRecord entry = records[0];
try {
writeRecord(entry);
} catch (IOException e) {
entry.setException(e);
}
// log("synchronized (entry) ");
synchronized (entry) {
// log("notifying entry ");
entry.setWritten(true);
entry.notifyAll();
}
return;
}
try {
writeCompoundRecord(records);
} catch (IOException ioe) {
for (int i = 0; i < records.length; i++) {
TransactionLogRecord e = records[i];
e.setException(ioe);
}
}
for (int i = 0; i < records.length; i++) {
TransactionLogRecord e = records[i];
// log("synchronized (entry) ");
synchronized (e) {
// log("notifying entry ");
e.setWritten(true);
e.notifyAll();
}
}
}
Aggregations