Search in sources :

Example 1 with ShareConfigRecordDAO

use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigRecordDAO in project openmq by eclipse-ee4j.

the class DBTool method doBackupSharecc.

/**
 * Backup the shared table for cluster config change record to a file
 */
private void doBackupSharecc() throws BrokerException {
    Properties props = System.getProperties();
    String clusterID = Globals.getClusterID();
    String backupfile = (String) props.get(ShareConfigChangeStore.CLUSTER_SHARECC_PROP_PREFIX + ".backupfile");
    logger.logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP, clusterID, backupfile));
    ShareConfigChangeDBManager mgr = ShareConfigChangeDBManager.getDBManager();
    ShareConfigRecordDAO dao = mgr.getDAOFactory().getShareConfigRecordDAO();
    try {
        List<ChangeRecordInfo> records = null;
        Util.RetryStrategy retry = null;
        do {
            try {
                records = dao.getAllRecords(null, null);
                break;
            } catch (Exception e) {
                if (retry == null) {
                    retry = new Util.RetryStrategy(mgr);
                }
                retry.assertShouldRetry(e);
            }
        } while (true);
        Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP_RECORDS, String.valueOf(records.size()), dao.getTableName()));
        ChangeRecord.backupRecords(records, backupfile, true);
        Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP_RECORDS_SUCCESS, Globals.getClusterID(), backupfile));
    } catch (BrokerException e) {
        String emsg = br.getKString(br.E_SHARECC_BACKUP_RECORDS_FAIL, e.getMessage());
        Globals.getLogger().logToAll(Logger.ERROR, emsg, e);
        throw e;
    }
}
Also used : ShareConfigRecordDAO(com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigRecordDAO) ShareConfigChangeDBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) StringUtil(com.sun.messaging.jmq.util.StringUtil)

Example 2 with ShareConfigRecordDAO

use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigRecordDAO in project openmq by eclipse-ee4j.

the class DBTool method doRestoreSharecc.

/**
 * Restore the shared table for cluster config change record from a file
 */
private void doRestoreSharecc() throws BrokerException {
    Properties props = System.getProperties();
    String clusterID = Globals.getClusterID();
    String backupfile = (String) props.get(ShareConfigChangeStore.CLUSTER_SHARECC_PROP_PREFIX + ".backupfile");
    logger.logToAll(Logger.INFO, br.getKString(br.I_SHARECC_RESTORE, clusterID, backupfile));
    ShareConfigChangeDBManager mgr = ShareConfigChangeDBManager.getDBManager();
    Connection conn = null;
    Exception myex = null;
    try {
        List<ChangeRecordInfo> records = ChangeRecord.prepareRestoreRecords(backupfile);
        ShareConfigRecordDAO dao = mgr.getDAOFactory().getShareConfigRecordDAO();
        Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_RESTORE_RECORDS, String.valueOf(records.size()), backupfile));
        conn = mgr.getConnection(true);
        ChangeRecordInfo resetcri = ChangeRecord.makeResetRecord(true);
        try {
            mgr.lockTables(conn, true, resetcri);
            Connection myconn = null;
            Exception myee = null;
            try {
                myconn = mgr.getConnection(false);
                Util.RetryStrategy retry = null;
                do {
                    try {
                        Iterator itr = records.iterator();
                        ChangeRecordInfo cri = null;
                        while (itr.hasNext()) {
                            cri = (ChangeRecordInfo) itr.next();
                            if (cri.getType() == ChangeRecordInfo.TYPE_RESET_PERSISTENCE) {
                                itr.remove();
                                continue;
                            }
                            cri.setResetUUID(resetcri.getUUID());
                            cri.setTimestamp(System.currentTimeMillis());
                            dao.insert(myconn, cri);
                        }
                        myconn.commit();
                        break;
                    } catch (Exception e) {
                        if (retry == null) {
                            retry = new Util.RetryStrategy(mgr);
                        }
                        retry.assertShouldRetry(e);
                    }
                } while (true);
            } catch (BrokerException e) {
                myee = e;
                throw e;
            } finally {
                Util.close(null, null, myconn, myee, mgr);
            }
        } finally {
            try {
                mgr.lockTables(conn, false);
            } catch (Exception e) {
                logger.log(Logger.WARNING, br.getKString(br.X_SHARECC_UNLOCK_TABLE, e.toString()), e);
            }
        }
        logger.logToAll(Logger.INFO, br.getKString(br.I_SHARECC_RESTORE_RECORDS_SUCCESS, Globals.getClusterID(), backupfile));
    } catch (Exception e) {
        myex = e;
        String emsg = br.getKString(br.E_SHARECC_RESTORE_RECORDS_FAIL, e.getMessage());
        Globals.getLogger().logToAll(Logger.ERROR, emsg, e);
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        }
        throw new BrokerException(emsg, e);
    } finally {
        Util.close(null, null, conn, myex, mgr);
    }
}
Also used : StringUtil(com.sun.messaging.jmq.util.StringUtil) ShareConfigRecordDAO(com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigRecordDAO) ShareConfigChangeDBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)

Aggregations

ChangeRecordInfo (com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)2 ShareConfigChangeDBManager (com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager)2 ShareConfigRecordDAO (com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigRecordDAO)2 StringUtil (com.sun.messaging.jmq.util.StringUtil)2