BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename), ex);
}
// reconstruct persistence store if needed
try {
TransactionLogRecord rec;
byte[] data;
ByteArrayInputStream bis;
DataInputStream dis;
HashSet dstLoadedSet = new HashSet(); // Keep track of loaded dst
// 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
Destination.init();
Subscription.initSubscriptions();
int count = 0;
Iterator itr = msgLogWriter.iterator();
while (itr.hasNext()) {
count++; // Keep track the number of records processed
// 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);
long tid = dis.readLong(); // Transaction ID
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);
int state = tidList.getTransactionStateValue(tuid);
if (state != TransactionState.NULL &&
state != TransactionState.COMMITTED) {
logger.log(logger.FORCE,
BrokerResources.I_COMMIT_TXNLOG_RECORD, tidStr);
tidList.updateTransactionState(tuid,
TransactionState.COMMITTED, false);
}
}
dis.close();
bis.close();
}
logger.log(logger.FORCE, BrokerResources.I_LOAD_MSG_TXNLOG,
String.valueOf(count));
logger.flush();
}
// Note: the ack log file contains message(s) consume but
// it can also contains message(s) produce and consume in the
// same txn. Instead of creating another log file for this type
// 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
Destination.init();
Subscription.initSubscriptions();
int count = 0;
Iterator itr = ackLogWriter.iterator();
while (itr.hasNext()) {
count++; // Keep track the number of records processed
// 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);
long tid = dis.readLong(); // Transaction ID
String tidStr = String.valueOf(tid);