Search in sources :

Example 1 with PHashMapLoadException

use of com.sun.messaging.jmq.io.disk.PHashMapLoadException in project openmq by eclipse-ee4j.

the class FileTxLogImpl method loadClientData.

private void loadClientData() throws PHashMapLoadException {
    if (!useMmap) {
        return;
    }
    PHashMapLoadException loadException = null;
    Iterator itr = _gxidMap.entrySet().iterator();
    while (itr.hasNext()) {
        Throwable ex = null;
        Map.Entry entry = (Map.Entry) itr.next();
        Object key = entry.getKey();
        LogRecord value = (LogRecord) entry.getValue();
        int cnt = value.getBranchCount();
        if (cnt <= 0) {
            continue;
        }
        byte[] cdata = null;
        try {
            cdata = ((PHashMapMMF) _gxidMap).getClientData(key);
            if (cdata != null && cdata.length > 0) {
                value.updateBranchFromClientData(cdata);
            }
        } catch (Throwable e) {
            ex = e;
        }
        if (ex != null) {
            PHashMapLoadException le = new PHashMapLoadException("Failed to load client data [cdata=" + Arrays.toString(cdata) + "]");
            le.setKey(key);
            le.setValue(value);
            le.setNextException(loadException);
            le.initCause(ex);
            loadException = le;
        }
    }
    if (loadException != null) {
        throw loadException;
    }
}
Also used : PHashMapLoadException(com.sun.messaging.jmq.io.disk.PHashMapLoadException) Iterator(java.util.Iterator) Map(java.util.Map) PHashMap(com.sun.messaging.jmq.io.disk.PHashMap)

Example 2 with PHashMapLoadException

use of com.sun.messaging.jmq.io.disk.PHashMapLoadException in project openmq by eclipse-ee4j.

the class TidList method loadClientData.

/**
 * When update optimization is enabled, we'll only write out the modified transaction state as client data instead of
 * the whole record (key and value) to improve I/O performance. So when the broker start up and the persisted
 * transaction states are loaded from file, we need to update the TransactionState object with the modified value that
 * is stored in the client data section of the record.
 *
 * @throws PHashMapLoadException if an error occurs while loading data
 */
private void loadClientData() throws PHashMapLoadException {
    if (!updateOptimization) {
        // nothing to do
        return;
    }
    PHashMapLoadException loadException = null;
    Iterator itr = tidMap.entrySet().iterator();
    while (itr.hasNext()) {
        Throwable ex = null;
        Map.Entry entry = (Map.Entry) itr.next();
        Object key = entry.getKey();
        TransactionInfo value = (TransactionInfo) entry.getValue();
        byte[] cData = null;
        try {
            cData = ((PHashMapMMF) tidMap).getClientData(key);
            if (cData != null && cData.length > 0) {
                // 1st byte is the modified state
                int state = cData[0];
                // update txn state
                value.getTransactionState().setState(state);
                // Now read in modified txn broker states
                TransactionBroker[] bkrs = value.getTransactionBrokers();
                if (bkrs != null) {
                    for (int i = 0, len = bkrs.length; i < len; i++) {
                        TransactionBroker bkr = bkrs[i];
                        // update bkr's state
                        // 1 == true
                        boolean isComplete = (cData[i + 1] == 1);
                        bkr.setCompleted(isComplete);
                    }
                }
            }
        } catch (Throwable e) {
            ex = e;
        }
        if (ex != null) {
            PHashMapLoadException le = new PHashMapLoadException("Failed to load client data [cData=" + Arrays.toString(cData) + "]");
            le.setKey(key);
            le.setValue(value);
            le.setNextException(loadException);
            le.initCause(ex);
            loadException = le;
        }
    }
    if (loadException != null) {
        throw loadException;
    }
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PHashMapLoadException(com.sun.messaging.jmq.io.disk.PHashMapLoadException) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) PHashMap(com.sun.messaging.jmq.io.disk.PHashMap)

Example 3 with PHashMapLoadException

use of com.sun.messaging.jmq.io.disk.PHashMapLoadException in project openmq by eclipse-ee4j.

the class TidList method loadClientDataOldFormat.

private void loadClientDataOldFormat() throws PHashMapLoadException {
    if (!updateOptimization) {
        // nothing to do
        return;
    }
    PHashMapLoadException loadException = null;
    Iterator itr = tidMap.entrySet().iterator();
    while (itr.hasNext()) {
        Throwable ex = null;
        Map.Entry entry = (Map.Entry) itr.next();
        Object key = entry.getKey();
        TransactionState value = (TransactionState) entry.getValue();
        byte[] cData = null;
        try {
            cData = ((PHashMapMMF) tidMap).getClientData(key);
            if (cData != null && cData.length > 0) {
                // 1st byte is the modified state
                int state = cData[0];
                // update txn state
                value.setState(state);
            }
        } catch (Throwable e) {
            ex = e;
        }
        if (ex != null) {
            PHashMapLoadException le = new PHashMapLoadException("Failed to load client data [cData=" + Arrays.toString(cData) + "]");
            le.setKey(key);
            le.setValue(value);
            le.setNextException(loadException);
            le.initCause(ex);
            loadException = le;
        }
    }
    if (loadException != null) {
        throw loadException;
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) PHashMapLoadException(com.sun.messaging.jmq.io.disk.PHashMapLoadException) PHashMap(com.sun.messaging.jmq.io.disk.PHashMap)

Example 4 with PHashMapLoadException

use of com.sun.messaging.jmq.io.disk.PHashMapLoadException in project openmq by eclipse-ee4j.

the class FileTxLogImpl method init.

@Override
public void init(Properties props, boolean reset) throws Exception {
    if (_logger == null) {
        throw new IllegalStateException("No logger set");
    }
    super.init(props, reset);
    if (props != null) {
        Enumeration en = props.propertyNames();
        String name = null;
        String value = null;
        while (en.hasMoreElements()) {
            name = (String) en.nextElement();
            value = props.getProperty(name);
            _logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_SET_PROP, name + "=" + value, _tmname));
            setProperty(name, value);
        }
    }
    if (_txlogdir == null) {
        throw new IllegalStateException("Property txlogDir not set");
    }
    String fname = (txlogSuffix == null ? FILENAME_BASE : (FILENAME_BASE + "." + txlogSuffix));
    if (reset) {
        _logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_INIT_WITH_RESET, fname));
        if (_txlogdirParent != null) {
            String fn = _txlogdirParent + File.separator + FILENAME_JMSBRIDGES;
            File f = new File(fn);
            if (f.exists()) {
                if (!f.delete()) {
                    _logger.log(Level.WARNING, "Failed to delete file " + fn + " on reset");
                    File dfn = new File(_txlogdirParent, FILENAME_JMSBRIDGES + ".deleted");
                    if (!f.renameTo(dfn)) {
                        _logger.log(Level.WARNING, "Failed rename file " + fn + " to " + dfn + " after deletion failure");
                    }
                }
            }
        }
    } else {
        _logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_INIT, fname));
    }
    _backFile = new File(_txlogdir, fname);
    if (useMmap) {
        _gxidMap = new PHashMapMMF(_backFile, _logsize, 1024, false, reset, false, false);
        ((PHashMapMMF) _gxidMap).intClientData(_clientDataSize);
    } else {
        _gxidMap = new PHashMap(_backFile, _logsize, 1024, false, reset, false, false);
    }
    try {
        _gxidMap.load(this);
        if (_clientDataSize > 0) {
            loadClientData();
        }
    } catch (PHashMapLoadException pe) {
        _logger.log(Level.WARNING, "Exception in loading txlog " + _backFile, pe);
        throw pe;
    }
    VRFileWarning w = _gxidMap.getWarning();
    if (w != null) {
        _logger.log(Level.WARNING, "Warning in loading txlog, possible loss of record", w);
    }
    _logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_LOADED, _backFile, String.valueOf(_gxidMap.size())));
}
Also used : Enumeration(java.util.Enumeration) VRFileWarning(com.sun.messaging.jmq.io.disk.VRFileWarning) PHashMapMMF(com.sun.messaging.jmq.io.disk.PHashMapMMF) PHashMap(com.sun.messaging.jmq.io.disk.PHashMap) PHashMapLoadException(com.sun.messaging.jmq.io.disk.PHashMapLoadException) SizeString(com.sun.messaging.jmq.util.SizeString) File(java.io.File)

Aggregations

PHashMap (com.sun.messaging.jmq.io.disk.PHashMap)4 PHashMapLoadException (com.sun.messaging.jmq.io.disk.PHashMapLoadException)4 PHashMapMMF (com.sun.messaging.jmq.io.disk.PHashMapMMF)1 VRFileWarning (com.sun.messaging.jmq.io.disk.VRFileWarning)1 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)1 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)1 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)1 SizeString (com.sun.messaging.jmq.util.SizeString)1 File (java.io.File)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1