Search in sources :

Example 1 with ChangeRecord

use of com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord in project openmq by eclipse-ee4j.

the class RaptorProtocol method sendNewMasterBrokerPrepareAndWaitReply.

private String sendNewMasterBrokerPrepareAndWaitReply(BrokerAddress newmaster) throws Exception {
    if (DEBUG) {
        logger.log(logger.INFO, "RaptorProtocol.sendNewMasterBrokerPrepare, to = " + newmaster);
    }
    String uuid = null;
    List<ChangeRecordInfo> records = store.getConfigChangeRecordsSince(-1);
    // long now = System.currentTimeMillis();
    ArrayList<ChangeRecord> recordList = ChangeRecord.compressRecords(records);
    records.clear();
    records = new ArrayList<>();
    records.add(ChangeRecord.makeResetRecord(false));
    ChangeRecord cr = null;
    ChangeRecordInfo cri = null;
    for (int i = 0; i < recordList.size(); i++) {
        cr = recordList.get(i);
        if (!cr.isDiscard()) {
            cri = new ChangeRecordInfo();
            cri.setRecord(cr.getBytes());
            records.add(cri);
        }
    }
    Long xid = newMasterBrokerReplyTracker.addWaiter(new UnicastReplyWaiter(newmaster, ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE_REPLY));
    try {
        ClusterNewMasterBrokerPrepareInfo nmpi = ClusterNewMasterBrokerPrepareInfo.newInstance(newmaster, records, xid, c);
        GPacket gp = nmpi.getGPacket();
        logger.log(logger.INFO, br.getKString(br.I_CLUSTER_UNICAST, ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + "[" + nmpi + "]", newmaster.toString()));
        uuid = nmpi.getUUID();
        c.unicast(newmaster, gp);
        ReplyStatus reply = null;
        try {
            reply = newMasterBrokerReplyTracker.waitForReply(xid, changeMasterBrokerWaitTimeout);
        } catch (BrokerException e) {
            BrokerException e1 = e;
            if (e.getStatusCode() == Status.GONE) {
                e1 = new BrokerException(br.getKString(br.X_CLUSTER_BROKER_LINK_DOWN, newmaster.toString()), Status.GONE);
            } else if (e.getStatusCode() == Status.TIMEOUT) {
                String[] args = new String[] { String.valueOf(changeMasterBrokerWaitTimeout), ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE_REPLY), newmaster.toString() };
                e1 = new BrokerException(br.getKString(br.X_CLUSTER_WAIT_REPLY_TIMEOUT, args), Status.TIMEOUT);
            }
            throw e1;
        }
        if (reply.getStatus() != Status.OK) {
            String[] args = new String[] { reply.getReason(), ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE), newmaster.toString() };
            String emsg = br.getKString(br.E_CLUSTER_RECEIVED_ERROR_REPLY_FROM_BROKER, args);
            throw new BrokerException(emsg, reply.getStatus());
        }
    } finally {
        newMasterBrokerReplyTracker.removeWaiter(xid);
    }
    return uuid;
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) DestinationUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.DestinationUpdateChangeRecord) InterestUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord) ChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)

Example 2 with ChangeRecord

use of com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord in project openmq by eclipse-ee4j.

the class JDBCShareConfigChangeStore method migrateOldTableData.

private void migrateOldTableData(Connection conn, String oldTable) throws BrokerException {
    ShareConfigRecordDAO dao = dbmgr.getDAOFactory().getShareConfigRecordDAO();
    long totalwait = 30000L;
    ChangeRecordInfo resetcri = ChangeRecord.makeResetRecord(true);
    while (true) {
        try {
            dbmgr.lockTables(conn, true, resetcri);
            break;
        } catch (BrokerException e) {
            String ecode = e.getErrorCode();
            if (ecode != null && ecode.equals(br.E_SHARECC_TABLE_LOCKED_BY)) {
                if (!dbmgr.getIsClosing() && totalwait > 0L) {
                    try {
                        Thread.sleep(5000L);
                    } catch (Exception ee) {
                    }
                    totalwait -= 5000L;
                    continue;
                }
                throw e;
            }
            if (ecode != null && ecode.equals(br.E_SHARECC_TABLE_NOT_EMPTY)) {
                // someone else migrated
                return;
            }
            throw e;
        }
    }
    Object[] logargs = { "", oldTable, dao.getTableName() };
    logger.log(logger.INFO, br.getKString(br.I_SHARECC_MIGRATING_DB, logargs));
    ArrayList<ChangeRecordInfo> newcris = new ArrayList<>();
    try {
        String sql = "SELECT * FROM " + oldTable;
        List<ChangeRecordInfo> cris = dao.getAllRecords(conn, sql);
        List<ChangeRecord> records = ChangeRecord.compressRecords(cris);
        ChangeRecordInfo newcri = null;
        ChangeRecord rec = null;
        Iterator<ChangeRecord> itr = records.iterator();
        while (itr.hasNext()) {
            rec = itr.next();
            if (rec.isDiscard()) {
                continue;
            }
            newcri = new ChangeRecordInfo((Long) null, rec.getUUID(), rec.getBytes(), rec.getOperation(), rec.getUniqueKey(), System.currentTimeMillis());
            newcri.setDuraAdd(rec.isDuraAdd());
            newcri.setResetUUID(resetcri.getUUID());
            newcris.add(newcri);
        }
        Object[] args = { newcris.size() + "(" + cris.size() + ")", oldTable, dao.getTableName() };
        logger.log(logger.INFO, br.getKString(br.I_SHARECC_MIGRATING_DB, args));
    } catch (Exception e) {
        String emsg = br.getKString(br.X_SHARECC_PROCESS_DATA_FOR_MIGRATION, oldTable);
        logger.logStack(logger.ERROR, emsg, e);
        throw new BrokerException(emsg, e);
    }
    dao.insertAll(newcris, oldTable);
    logger.log(logger.INFO, br.getKString(br.I_SHARECC_MIGRATED_DB, oldTable, dao.getTableName()));
    try {
        String[] olds = new String[1];
        olds[0] = oldTable;
        DBTool.dropTables(conn, olds, true, true, dbmgr);
        logger.log(logger.INFO, br.getKString(br.I_DB_TABLE_DELETED, oldTable));
    } catch (Exception e) {
        logger.log(logger.WARNING, e.getMessage(), e);
    } finally {
        try {
            dbmgr.lockTables(conn, false);
        } catch (Exception e) {
            String emsg = br.getKString(br.X_SHARECC_UNLOCK_TABLE_AFTER_MIGRATION, e.getMessage());
            logger.logStack(logger.ERROR, emsg, e);
            throw new BrokerException(emsg, e);
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) ChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)

Example 3 with ChangeRecord

use of com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord in project openmq by eclipse-ee4j.

the class RaptorProtocol method receiveConfigChangeEvent.

public void receiveConfigChangeEvent(BrokerAddress sender, Long xidProp, byte[] eventData) {
    if (DEBUG) {
        logger.log(logger.INFO, "RaptorProtocol.receiveConfigChangeEvent(xid=" + xidProp + ") from " + sender);
    }
    int status = ProtocolGlobals.G_EVENT_LOG_SUCCESS;
    String reason = null;
    boolean nologstack = false;
    try {
        setConfigOpInProgressIfNotBlocked();
        try {
            BrokerAddress configServer = c.getConfigServer();
            if (configServer == null) {
                throw new BrokerException("Unexpected: there is no master broker");
            }
            if (!configServer.equals(selfAddress)) {
                String[] args = new String[] { ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_CONFIG_CHANGE_EVENT), sender.toString(), configServer.toString() };
                throw new BrokerException(br.getKString(br.X_CLUSTER_UNABLE_PROCESS_NOT_MASTER_BROKER, args), Status.PRECONDITION_FAILED);
            }
            ChangeRecord cr = ChangeRecord.makeChangeRecord(eventData);
            if (Globals.nowaitForMasterBroker()) {
                if (cr.getOperation() == ProtocolGlobals.G_REM_DESTINATION) {
                    if (DestType.isQueue(((DestinationUpdateChangeRecord) cr).getType())) {
                        HashSet bmas = new HashSet();
                        synchronized (brokerList) {
                            Iterator itr = brokerList.keySet().iterator();
                            while (itr.hasNext()) {
                                BrokerMQAddress bma = ((BrokerAddress) itr.next()).getMQAddress();
                                bmas.add(bma);
                            }
                        }
                        Iterator itr = Globals.getClusterManager().getConfigBrokers();
                        ClusteredBroker cb = null;
                        while (itr.hasNext()) {
                            cb = (ClusteredBroker) itr.next();
                            if (!bmas.contains(cb.getBrokerURL()) && !cb.isLocalBroker()) {
                                String[] args = { ((DestinationUpdateChangeRecord) cr).getName(), sender.toString(), ServiceRestriction.NO_SYNC_WITH_MASTERBROKER.toString(), cb.getBrokerURL().toString() };
                                nologstack = true;
                                throw new BrokerException(br.getKString(BrokerResources.X_SERVICE_RESTRICTION_DELETE_QUEUE, args));
                            }
                        }
                    }
                }
            }
            if (cr.getOperation() == ProtocolGlobals.G_REM_DURABLE_INTEREST) {
                inDSubToBrokerMap.remove(cr.getUniqueKey());
            } else if (cr.getOperation() == ProtocolGlobals.G_NEW_INTEREST) {
                Subscription sub = Subscription.findDurableSubscription(((InterestUpdateChangeRecord) cr).getSubscriptionKey());
                if (sub != null) {
                    inDSubToBrokerMap.remove(cr.getUniqueKey());
                    String emsg = br.getKString(br.I_RECORD_DURA_SUB_EXIST_ALREADY, "[" + cr.getUniqueKey() + "]" + sub.getDSubLongLogString(), sender);
                    logger.log(logger.INFO, emsg);
                    if (sub.getShared() != ((InterestUpdateChangeRecord) cr).getShared() || sub.getJMSShared() != ((InterestUpdateChangeRecord) cr).getJMSShared()) {
                        throw new BrokerException(emsg);
                    }
                } else {
                    synchronized (inDSubToBrokerMap) {
                        InterestUpdateChangeRecord existcr = (InterestUpdateChangeRecord) inDSubToBrokerMap.get(cr.getUniqueKey());
                        if (existcr != null) {
                            Object[] args = { "[" + cr.getUniqueKey() + "]", existcr.getBroker(), sender };
                            String emsg = br.getKString(br.I_RECORD_DURA_SUB_CONCURRENT, args) + "[" + existcr.getFlagString() + "]";
                            logger.log(logger.INFO, emsg);
                            if (((InterestUpdateChangeRecord) cr).getShared() != existcr.getShared() || ((InterestUpdateChangeRecord) cr).getJMSShared() != existcr.getJMSShared()) {
                                throw new BrokerException(emsg);
                            }
                        } else {
                            ((InterestUpdateChangeRecord) cr).setBroker(sender);
                            inDSubToBrokerMap.put(cr.getUniqueKey(), cr);
                        }
                    }
                }
            }
            try {
                store.storeConfigChangeRecord(System.currentTimeMillis(), eventData, false);
            } catch (Exception e) {
                inDSubToBrokerMap.remove(cr.getUniqueKey());
                throw e;
            }
        } finally {
            setConfigOpInProgress(false);
        }
    } catch (Exception e) {
        reason = e.getMessage();
        status = ProtocolGlobals.G_EVENT_LOG_FAILURE;
        if (e instanceof BrokerException) {
            status = ((BrokerException) e).getStatusCode();
        }
        if (nologstack) {
            logger.log(logger.ERROR, e.getMessage(), e);
        } else {
            logger.logStack(logger.ERROR, e.getMessage(), e);
        }
    }
    sendConfigChangeEventAck(sender, xidProp, status, reason);
}
Also used : InterestUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord) HandshakeInProgressException(com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException) DestinationUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.DestinationUpdateChangeRecord) InterestUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord) ChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)

Aggregations

ChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)3 DestinationUpdateChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.DestinationUpdateChangeRecord)2 InterestUpdateChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord)2 ChangeRecordInfo (com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)2 HandshakeInProgressException (com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1