Skip to content

Commit

Permalink
[misc] remove unused access of @@sql_mode during connection time
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Sep 5, 2017
1 parent bc0eb9e commit 9cf3906
Showing 1 changed file with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public abstract class AbstractConnectProtocol implements Protocol {
private static final byte[] SESSION_QUERY = ("SELECT @@max_allowed_packet,"
+ "@@system_time_zone,"
+ "@@time_zone,"
+ "@@sql_mode,"
+ "@@auto_increment_increment").getBytes(StandardCharsets.UTF_8);
private static final byte[] IS_MASTER_QUERY = "show global variables like 'innodb_read_only'".getBytes(StandardCharsets.UTF_8);
private static final Logger logger = LoggerFactory.getLogger(AbstractConnectProtocol.class);
Expand Down Expand Up @@ -148,7 +147,6 @@ public abstract class AbstractConnectProtocol implements Protocol {
private int majorVersion;
private int minorVersion;
private int patchVersion;
private Map<String, String> serverData;
private TimeZone timeZone;
private final LruTraceCache traceCache = new LruTraceCache();

Expand Down Expand Up @@ -405,7 +403,6 @@ private void connect(String host, int port) throws SQLException, IOException {
handleConnectionPhases(host);

connected = true;
serverData = new TreeMap<>();

if (options.useCompression) {
writer = new CompressPacketOutputStream(writer.getOutputStream(), options.maxQuerySizeToLog);
Expand All @@ -416,29 +413,29 @@ private void connect(String host, int port) throws SQLException, IOException {
}
}

Map<String, String> serverData = new TreeMap<>();
if (options.usePipelineAuth && !options.createDatabaseIfNotExist) {
try {
sendPipelineAdditionalData();
readPipelineAdditionalData();
readPipelineAdditionalData(serverData);
} catch (SQLException sqle) {
//in case pipeline is not supported
//(proxy flush socket after reading first packet)
additionalData();
additionalData(serverData);
}
} else additionalData();
} else additionalData(serverData);

// Extract socketTimeout URL parameter
if (options.socketTimeout != null) socket.setSoTimeout(options.socketTimeout);

writer.setMaxAllowedPacket(Integer.parseInt(serverData.get("max_allowed_packet")));
autoIncrementIncrement = Integer.parseInt(serverData.get("auto_increment_increment"));

loadCalendar();
loadCalendar(serverData);

reader.setServerThreadId(this.serverThreadId, isMasterConnection());
writer.setServerThreadId(this.serverThreadId, isMasterConnection());

serverData = null;
activeStreamingResult = null;
hostFailed = false;
} catch (IOException | SQLException ioException) {
Expand Down Expand Up @@ -495,7 +492,7 @@ private void sendRequestSessionVariables() throws IOException {
writer.flush();
}

private void readRequestSessionVariables() throws SQLException {
private void readRequestSessionVariables(Map<String, String> serverData) throws SQLException {
Results results = new Results();
getResult(results);

Expand All @@ -507,8 +504,7 @@ private void readRequestSessionVariables() throws SQLException {
serverData.put("max_allowed_packet", resultSet.getString(1));
serverData.put("system_time_zone", resultSet.getString(2));
serverData.put("time_zone", resultSet.getString(3));
serverData.put("sql_mode", resultSet.getString(4));
serverData.put("auto_increment_increment", resultSet.getString(5));
serverData.put("auto_increment_increment", resultSet.getString(4));

} else {
throw new SQLException("Error reading SessionVariables results. Socket is connected ? "
Expand All @@ -530,7 +526,7 @@ private void sendUseDatabaseIfNotExist(String quotedDb) throws IOException {
writer.flush();
}

private void readPipelineAdditionalData() throws SQLException {
private void readPipelineAdditionalData(Map<String, String> serverData) throws SQLException {

SQLException resultingException = null;
//read set session OKPacket
Expand All @@ -543,7 +539,7 @@ private void readPipelineAdditionalData() throws SQLException {

boolean canTrySessionWithShow = false;
try {
readRequestSessionVariables();
readRequestSessionVariables(serverData);
} catch (SQLException sqlException) {
if (resultingException == null) {
resultingException = new SQLException("could not load system variables",
Expand All @@ -564,22 +560,21 @@ private void readPipelineAdditionalData() throws SQLException {
if (canTrySessionWithShow) {
//fallback in case of galera non primary nodes that permit only show / set command,
//not SELECT when not part of quorum
requestSessionDataWithShow();
requestSessionDataWithShow(serverData);
}

if (resultingException != null) throw resultingException;
connected = true;

}

private void requestSessionDataWithShow() throws SQLException {
private void requestSessionDataWithShow(Map<String, String> serverData) throws SQLException {
try {
Results results = new Results();
executeQuery(true, results, "SHOW VARIABLES WHERE Variable_name in ("
+ "'max_allowed_packet',"
+ "'system_time_zone',"
+ "'time_zone',"
+ "'sql_mode',"
+ "'auto_increment_increment')");
results.commandEnd();
ResultSet resultSet = results.getResultSet();
Expand All @@ -597,16 +592,16 @@ private void requestSessionDataWithShow() throws SQLException {
}
}

private void additionalData() throws IOException, SQLException {
private void additionalData(Map<String, String> serverData) throws IOException, SQLException {

sendSessionInfos();
getResult(new Results());

try {
sendRequestSessionVariables();
readRequestSessionVariables();
readRequestSessionVariables(serverData);
} catch (SQLException sqlException) {
requestSessionDataWithShow();
requestSessionDataWithShow(serverData);
}

//for aurora, check that connection is master
Expand Down Expand Up @@ -842,7 +837,7 @@ private long initializeClientCapabilities(long serverCapabilities) {
return capabilities;
}

private void loadCalendar() throws SQLException {
private void loadCalendar(Map<String, String> serverData) throws SQLException {
if (options.useLegacyDatetimeCode) {
//legacy use client timezone
timeZone = Calendar.getInstance().getTimeZone();
Expand Down Expand Up @@ -884,10 +879,6 @@ private void loadCalendar() throws SQLException {

}

public String getServerData(String code) {
return serverData.get(code);
}

/**
* Check that current connection is a master connection (not read-only)
*
Expand Down

0 comments on commit 9cf3906

Please sign in to comment.