Search in sources :

Example 1 with TransactionLogRecord

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);
    }
}
Also used : TransactionLogRecord(com.sun.messaging.jmq.io.txnlog.TransactionLogRecord)

Example 2 with TransactionLogRecord

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);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionLogRecord(com.sun.messaging.jmq.io.txnlog.TransactionLogRecord) Iterator(java.util.Iterator) SizeString(com.sun.messaging.jmq.util.SizeString) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 3 with TransactionLogRecord

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();
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionLogRecord(com.sun.messaging.jmq.io.txnlog.TransactionLogRecord) SizeString(com.sun.messaging.jmq.util.SizeString) IOException(java.io.IOException)

Example 4 with TransactionLogRecord

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 ");
    }
}
Also used : TransactionLogRecord(com.sun.messaging.jmq.io.txnlog.TransactionLogRecord) ByteBuffer(java.nio.ByteBuffer)

Example 5 with TransactionLogRecord

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();
        }
    }
}
Also used : TransactionLogRecord(com.sun.messaging.jmq.io.txnlog.TransactionLogRecord) IOException(java.io.IOException)

Aggregations

TransactionLogRecord (com.sun.messaging.jmq.io.txnlog.TransactionLogRecord)7 IOException (java.io.IOException)5 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)4 SizeString (com.sun.messaging.jmq.util.SizeString)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 FileTransactionLogWriter (com.sun.messaging.jmq.io.txnlog.file.FileTransactionLogWriter)1 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)1 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ByteBuffer (java.nio.ByteBuffer)1