Source:
<code>private HostAddress searchForMasterHostAddress(Protocol protocol, List<HostAddress> loopAddress) throws QueryException { String masterHostName = null; proxy.lock.lock(); try { Date date = new Date(); TimeZone.setDefault(TimeZone.getTimeZone(protocol.getServerData("system_time_zone"))); <START> int IGNORE_TIME_IN_MINUTES = 3; <END> Timestamp currentTime = new Timestamp(date.getTime() - IGNORE_TIME_IN_MINUTES*60*1000); SingleExecutionResult executionResult = new SingleExecutionResult(null, 0, true, false); protocol.executeQuery(executionResult, "select server_id from " + dbName + ".replica_host_status " + "where session_id = 'MASTER_SESSION_ID' " + "and last_update_timestamp = (" + "select max(last_update_timestamp) from " + dbName + ".replica_host_status " + "where session_id = 'MASTER_SESSION_ID' " + "and last_update_timestamp > '" + currentTime + "')", ResultSet.TYPE_FORWARD_ONLY); MariaSelectResultSet queryResult = executionResult.getResult(); if (!queryResult.isBeforeFirst()) { return null; } else { queryResult.next(); masterHostName = queryResult.getString(1); } } catch (SQLException sqle) { } finally { proxy.lock.unlock(); } if (masterHostName != null) { for (HostAddress hostAddress: loopAddress) { if (hostAddress.host.startsWith(masterHostName) && hostAddress.host.indexOf(CLUSTER_IDENTIFIER) < 0) { return hostAddress; } } HostAddress masterHostAddress; String urlEndStr; if (getClusterHostAddress() != null) { urlEndStr = "." + getClusterHostAddress().host.substring(getClusterHostAddress().host.indexOf(CLUSTER_IDENTIFIER) + CLUSTER_IDENTIFIER.length()); } else if (protocol.getHost().indexOf(".") > -1) { urlEndStr = protocol.getHost().substring(protocol.getHost().indexOf(".")); } else { return null; } masterHostAddress = new HostAddress(masterHostName + urlEndStr, protocol.getPort(), null); loopAddress.add(masterHostAddress); urlParser.setHostAddresses(loopAddress); return masterHostAddress; } return null; }</code><technical_language>remark previous TimeZone.setDefault</technical_language>

Target:
private HostAddress searchForMasterHostAddress(Protocol protocol, List<HostAddress> loopAddress) throws QueryException { String masterHostName = null; proxy.lock.lock(); try { Date date = new Date(); int IGNORE_TIME_IN_MINUTES = 3; Timestamp currentTime = new Timestamp(date.getTime() - IGNORE_TIME_IN_MINUTES*60*1000); sqlDateFormat.setTimeZone(TimeZone.getTimeZone(protocol.getServerData("system_time_zone"))); SingleExecutionResult executionResult = new SingleExecutionResult(null, 0, true, false); protocol.executeQuery(executionResult, "select server_id from " + dbName + ".replica_host_status " + "where session_id = 'MASTER_SESSION_ID' " + "and last_update_timestamp = (" + "select max(last_update_timestamp) from " + dbName + ".replica_host_status " + "where session_id = 'MASTER_SESSION_ID' " + "and last_update_timestamp > '" + currentTime + "')", ResultSet.TYPE_FORWARD_ONLY); MariaSelectResultSet queryResult = executionResult.getResult(); if (!queryResult.isBeforeFirst()) { return null; } else { queryResult.next(); masterHostName = queryResult.getString(1); } } catch (SQLException sqle) { } finally { proxy.lock.unlock(); } Matcher matcher; if (masterHostName != null) { for (HostAddress hostAddress: loopAddress) { matcher = clusterPattern.matcher(hostAddress.host); if (hostAddress.host.startsWith(masterHostName) && !matcher.find()) { return hostAddress; } } HostAddress masterHostAddress; if (urlEndStr.equals("") && protocol.getHost().indexOf(".") > -1) { urlEndStr = protocol.getHost().substring(protocol.getHost().indexOf(".")); } else { return null; } masterHostAddress = new HostAddress(masterHostName + urlEndStr, protocol.getPort(), null); loopAddress.add(masterHostAddress); urlParser.setHostAddresses(loopAddress); return masterHostAddress; } return null; }