use of com.sun.messaging.jmq.io.txnlog.file.FileTransactionLogWriter in project openmq by eclipse-ee4j.
the class TransactionLogManager method initTransactionLogOnStartUp.
private void initTransactionLogOnStartUp() throws BrokerException {
if (Store.getDEBUG()) {
String msg = getPrefix() + " initTransactionLogOnStartUp";
logger.log(Logger.DEBUG, msg);
}
logger.log(Logger.INFO, "new transaction log enabled");
logger.log(Logger.INFO, "sync writes to disk = " + Destination.PERSIST_SYNC);
logger.log(Logger.INFO, "logNonTransactedMsgSend = " + logNonTransactedMsgSend);
logger.log(Logger.INFO, "logNonTransactedMsgAck = " + logNonTransactedMsgAck);
// create txn log writers
String filename = null;
try {
BrokerConfig config = Globals.getConfig();
SizeString filesize = config.getSizeProperty(TXNLOG_FILE_SIZE_PROP, DEFAULT_TXNLOG_FILE_SIZE_KB);
filename = MSG_LOG_FILENAME;
String mode = "rwd";
boolean synch = true;
if (!Destination.PERSIST_SYNC) {
mode = "rw";
synch = false;
}
logger.log(Logger.INFO, br.getKString(BrokerResources.I_OPEN_TXNLOG, mode, Long.valueOf(filesize.getBytes())));
FileTransactionLogWriter ftlw = new FileTransactionLogWriter(rootDir, filename, filesize.getBytes(), mode, synch, isTxnLogGroupCommits, BaseTransaction.CURRENT_FORMAT_VERSION);
long existingFormatVersion = ftlw.getExistingAppCookie();
// so this is just a sanity check.
if (existingFormatVersion != BaseTransaction.CURRENT_FORMAT_VERSION) {
throw new BrokerException("Unexpected transaction log format. Format on file = " + existingFormatVersion + " Current software version = " + BaseTransaction.CURRENT_FORMAT_VERSION);
}
msgLogWriter = ftlw;
msgLogWriter.setCheckPointListener(this);
if (Store.getDEBUG()) {
logger.log(Logger.DEBUG, "created txn log");
}
} catch (IOException ex) {
logger.logStack(Logger.ERROR, BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename, ex);
throw new BrokerException(br.getString(BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename), ex);
}
}
use of com.sun.messaging.jmq.io.txnlog.file.FileTransactionLogWriter in project openmq by eclipse-ee4j.
the class FileStore method initTxnLogger.
// Initialize txn logging class
@Override
public boolean initTxnLogger() throws BrokerException {
boolean storeNeedsRestart = false;
if (removeStore || !Globals.txnLogEnabled()) {
return storeNeedsRestart;
}
logger.log(logger.INFO, BrokerResources.I_TXNLOG_ENABLED);
// create txn log writers
String filename = null;
try {
SizeString filesize = config.getSizeProperty(TXNLOG_FILE_SIZE_PROP, DEFAULT_TXNLOG_FILE_SIZE);
filename = MSG_LOG_FILENAME;
msgLogWriter = new FileTransactionLogWriter(rootDir, filename, filesize.getBytes());
msgLogWriter.setCheckPointListener(this);
filename = ACK_LOG_FILENAME;
ackLogWriter = new FileTransactionLogWriter(rootDir, filename, filesize.getBytes());
ackLogWriter.setCheckPointListener(this);
if (resetMessage || resetStore) {
msgLogWriter.reset();
ackLogWriter.reset();
txnLoggerInited = true;
return storeNeedsRestart;
}
} catch (IOException ex) {
logger.logStack(Logger.ERROR, BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename, ex);
throw new BrokerException(br.getString(BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename), ex);
}
// reconstruct persistence store if needed
try {
TransactionLogRecord rec;
byte[] data;
ByteArrayInputStream bis;
DataInputStream dis;
// Keep track of loaded dst
HashSet dstLoadedSet = new HashSet();
// Check to see if we need to process log files
if (msgLogWriter.playBackRequired()) {
storeNeedsRestart = true;
logger.log(logger.FORCE, BrokerResources.I_PROCESS_MSG_TXNLOG);
// All destinations need to be loaded
Globals.getCoreLifecycle().initDestinations();
Globals.getCoreLifecycle().initSubscriptions();
int count = 0;
Iterator itr = msgLogWriter.iterator();
while (itr.hasNext()) {
// Keep track the number of records processed
count++;
// Read in the messages
rec = (TransactionLogRecord) itr.next();
int recType = rec.getType();
if (recType != TransactionLogType.PRODUCE_TRANSACTION) {
// Shouldn't happens
logger.log(logger.ERROR, BrokerResources.E_PROCESS_TXNLOG_RECORD_FAILED, String.valueOf(rec.getSequence()), "record type " + recType + " is invalid");
continue;
}
data = rec.getBody();
bis = new ByteArrayInputStream(data);
dis = new DataInputStream(bis);
// Transaction ID
long tid = dis.readLong();
String tidStr = String.valueOf(tid);
logger.log(logger.FORCE, BrokerResources.I_PROCESS_TXNLOG_RECORD, tidStr, String.valueOf(recType));
// Process all msgs in the txn
processTxnRecMsgPart(dis, dstLoadedSet);
// Check to see if we need to commit the txn
if (tid > 0) {
TransactionUID tuid = new TransactionUID(tid);
TransactionState state = tidList.getTransactionState(tuid);
if (state.getState() != TransactionState.NULL && state.getState() != TransactionState.COMMITTED) {
logger.log(logger.FORCE, BrokerResources.I_COMMIT_TXNLOG_RECORD, tidStr);
tidList.updateTransactionState(tuid, state, false);
}
}
dis.close();
bis.close();
}
logger.log(logger.FORCE, BrokerResources.I_LOAD_MSG_TXNLOG, String.valueOf(count));
logger.flush();
}
// of record, we'll just store it the same file for simplicity.
if (ackLogWriter.playBackRequired()) {
storeNeedsRestart = true;
logger.log(logger.FORCE, BrokerResources.I_PROCESS_ACK_TXNLOG);
// All destinations need to be loaded
Globals.getCoreLifecycle().initDestinations();
Globals.getCoreLifecycle().initSubscriptions();
int count = 0;
Iterator itr = ackLogWriter.iterator();
while (itr.hasNext()) {
// Keep track the number of records processed
count++;
// Read in the acks or msgs & acks
rec = (TransactionLogRecord) itr.next();
int recType = rec.getType();
if (!(recType == TransactionLogType.CONSUME_TRANSACTION || recType == TransactionLogType.PRODUCE_AND_CONSUME_TRANSACTION)) {
// shouldn't happens
logger.log(logger.ERROR, BrokerResources.E_PROCESS_TXNLOG_RECORD_FAILED, String.valueOf(rec.getSequence()), "record type " + recType + " is invalid");
continue;
}
data = rec.getBody();
bis = new ByteArrayInputStream(data);
dis = new DataInputStream(bis);
// Transaction ID
long tid = dis.readLong();
String tidStr = String.valueOf(tid);
logger.log(logger.FORCE, BrokerResources.I_PROCESS_TXNLOG_RECORD, tidStr, String.valueOf(recType));
if (recType == TransactionLogType.PRODUCE_AND_CONSUME_TRANSACTION) {
// Process all msgs in the txn first!
processTxnRecMsgPart(dis, dstLoadedSet);
}
// Process all acks in the txn
processTxnRecAckPart(dis, dstLoadedSet);
// Check to see if we need to commit the txn
TransactionUID tuid = new TransactionUID(tid);
TransactionState state = tidList.getTransactionState(tuid);
if (state.getState() != TransactionState.NULL && state.getState() != TransactionState.COMMITTED) {
logger.log(logger.FORCE, BrokerResources.I_COMMIT_TXNLOG_RECORD, tidStr);
tidList.updateTransactionState(tuid, state, false);
}
dis.close();
bis.close();
}
logger.log(logger.FORCE, BrokerResources.I_LOAD_ACK_TXNLOG, String.valueOf(count));
logger.flush();
}
if (storeNeedsRestart) {
// Now unload all the destinations that we've loaded so msgs can be routed correctly later on by the broker
Iterator itr = dstLoadedSet.iterator();
while (itr.hasNext()) {
Destination d = (Destination) itr.next();
// Sync changes to disk
syncDestination(d);
d.unload(true);
}
dstLoadedSet = null;
// Sync changes to txn tables
tidList.sync(null);
tidList.syncTransactionAck(null);
// Reset the txn log after the store is updated & synced
msgLogWriter.reset();
ackLogWriter.reset();
logger.log(logger.FORCE, BrokerResources.I_RECONSTRUCT_STORE_DONE);
logger.flush();
}
} catch (Throwable t) {
logger.logStack(Logger.ERROR, BrokerResources.E_RECONSTRUCT_STORE_FAILED, t);
throw new BrokerException(br.getString(BrokerResources.E_RECONSTRUCT_STORE_FAILED), t);
}
txnLoggerInited = true;
return storeNeedsRestart;
}
Aggregations