Skip to content

Commit

Permalink
make variable checking much more DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Osheroff committed Sep 18, 2015
1 parent 4752a1d commit bc18866
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/main/java/com/zendesk/maxwell/MaxwellMysqlStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,13 @@ private String getVariableState(String variableName, boolean throwOnMissing) thr
return status;
}

private void ensureNotReadOnly() throws SQLException, MaxwellCompatibilityError {
if (!getVariableState("read_only", true).equals("OFF")) {
throw new MaxwellCompatibilityError("read_only must be OFF.");
private void ensureVariableState(String variable, String state) throws SQLException, MaxwellCompatibilityError
{
if (!getVariableState(variable, true).equals(state)) {
throw new MaxwellCompatibilityError("variable " + variable + " must be set to '" + state + "'");
}
}

private void ensureReplicationOn() throws SQLException, MaxwellCompatibilityError {
if (!getVariableState("log_bin", true).equals("ON")) {
throw new MaxwellCompatibilityError("log_bin status must be ON.");
}
}

private void ensureReplicationFormatROW() throws SQLException, MaxwellCompatibilityError {
if (!getVariableState("binlog_format", true).equals("ROW")) {
throw new MaxwellCompatibilityError("binlog_format must be ROW.");
}
}

private void ensureRowImageFormat() throws SQLException, MaxwellCompatibilityError {
String rowImageFormat = getVariableState("binlog_row_image", false);
Expand All @@ -61,9 +51,10 @@ private void ensureRowImageFormat() throws SQLException, MaxwellCompatibilityErr

public static void ensureMysqlState(Connection c) throws SQLException, MaxwellCompatibilityError {
MaxwellMysqlStatus m = new MaxwellMysqlStatus(c);
m.ensureNotReadOnly();
m.ensureReplicationOn();
m.ensureReplicationFormatROW();

m.ensureVariableState("read_only", "OFF");
m.ensureVariableState("log_bin", "ON");
m.ensureVariableState("binlog_format", "ROW");
m.ensureRowImageFormat();
}
}

0 comments on commit bc18866

Please sign in to comment.