@Override public boolean doWrite(ColumnTypeHelper helper, WriteRowsEvent event) { try { boolean doOne = false; for (int i = 0; i < tables.size(); i++) { RedisSchnauzer table = tables.get(i); if (StrHelp.notEqual(helper.databaseName, masterDb.dbname)) continue; if (StrHelp.notEqual(helper.tableName, table.getMasterTableName())) continue; doOne = true; try { innerWrite(helper, event, table); } catch (Exception e) { ErrorHelper.errExit( "[" + table.table.SlaveKey + "]" + Infos.DoInsert + Infos.Failed + e.getMessage()); } } if (!doOne) dbhelper.setBinlogKey( getBinLogName(helper), Long.toString(helper.position), helper.tableName); } catch (Exception e) { ErrorHelper.errExit(Infos.RepFailed + e.getMessage()); } return true; }
private void innerDelete(ColumnTypeHelper helper, DeleteRowsEvent event, RedisSchnauzer table) throws UnsupportedEncodingException { List<Row> rows = event.getRows(); LOGGER.info(rows.size() + Infos.Row); int scoreIndex = table.getMemberIndex(); int memberIndex = table.getScoreIndex(); int valueIndex = table.getValueIndex(); Double score = 0.0; String member = ""; String value = ""; for (int j = 0; j < rows.size(); j++) { Row row = rows.get(j); List<Column> columns = row.getColumns(); if (!table.needReplicate(columns, helper)) continue; switch (table.getType()) { case String: dbhelper.delete(table.getKey(columns)); dbhelper.setBinlogKey( getBinLogName(helper), Long.toString(helper.position), helper.tableName); break; case Set: score = -1.00; value = helper.getColStr( valueIndex, columns.get(valueIndex), (byte) 1, table.masterfields.get(valueIndex)); dbhelper.zincrby(table.getKey(columns), score, value); dbhelper.setBinlogKey( getBinLogName(helper), Long.toString(helper.position), helper.tableName); break; case SortedSet: score = Double.parseDouble( helper.getColStr( scoreIndex, columns.get(scoreIndex), (byte) 1, table.masterfields.get(scoreIndex))) * table.scorefield.multiplier; member = helper.getColStr( memberIndex, columns.get(memberIndex), (byte) 1, table.masterfields.get(memberIndex)); dbhelper.zincrby(table.getKey(columns), -1 * score, member); dbhelper.setBinlogKey( getBinLogName(helper), Long.toString(helper.position), helper.tableName); break; case List: ErrorHelper.errExit( "innerDelete====" + Infos.Illegal + "RedisStructure:" + table.getType().toString()); break; default: ErrorHelper.errExit( "innerDelete====" + Infos.Illegal + "RedisStructure:" + table.getType().toString()); break; } } }