Exemplo n.º 1
0
  private void getTheLastBinlogAndPos() {
    try {
      MySQLDbHelper mhelper = new MySQLDbHelper(masterDb);
      ResultSet rs = mhelper.getRS("show master logs");
      String binlog = "";
      Long pos = 0L;
      while (rs.next()) {
        binlog = rs.getString("log_name");
      }
      rs.close();
      rs = mhelper.getRS("show binlog events in '" + binlog + "'");
      while (rs.next()) {
        pos = rs.getLong("pos");
      }
      rs.close();
      masterDb.binlog = binlog;
      masterDb.pos = pos;
      slaveDb.binlog = binlog;
      slaveDb.pos = pos;

    } catch (Exception e) {
      ErrorHelper.errExit("Get binlog filename " + Infos.Failed + ": " + e.getMessage());
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean doDelete(ColumnTypeHelper helper, DeleteRowsEvent event) {
    boolean need = false;
    String[] sqls = null;
    int index = 0;
    doBeforeDelete(helper, event);
    for (int i = 0; i < tables.size(); i++) {
      RDBSchnauzer rep = (RDBSchnauzer) tables.get(i);
      if (notEqualS(helper.databaseName, masterDb.dbname)) continue;
      if (notEqualS(helper.tableName, rep.getMasterTableName())) continue;
      List<Row> rows = event.getRows();
      for (int j = 0; j < rows.size(); j++) {
        Row row = rows.get(j);
        List<Column> columns = row.getColumns();
        if (sqls == null) {
          sqls = new String[rows.size() * tables.size() + 1];
          sqls[0] = getStatusUpdateSql(helper);
        }
        need = true;
        try {
          sqls[++index] = rep.getDelete() + getWhereStr(rep, columns, helper);
        } catch (Exception e) {
          mailAndLog(Infos.Create + Infos.DoDelete + Infos.Failed, e.getMessage());
          return false;
        }
      }
    }

    String[] errInfo = new String[1];

    if (!need || !logSql(sqls)) {
      autoSetPosition(helper);
      return true;
    }

    if (dbhelper.excuteSqlByTransaction(sqls, errInfo)) {
      slaveDb.binlog = this.getBinLogName(helper);
      slaveDb.pos = helper.position;
      slaveDb.tablepos = helper.tableMapPos;
      LOGGER.info(Infos.DoDelete + Infos.OK);
      return true;
    }

    String sInfo = getWarning(sqls, errInfo);
    mailAndLog(Infos.DoDelete + Infos.Failed, sInfo);
    rollBackToTableEvent(helper);
    return false;
  }