Skip to content

Commit

Permalink
Merge branch 'release/1.5.1-RC'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Aug 15, 2016
2 parents 41910e8 + 55bfa3d commit 8bcfb76
Show file tree
Hide file tree
Showing 45 changed files with 1,123 additions and 292 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ env:
- MYSQL_VERSION=5.6 MAX_ALLOWED_PACKET=8M INNODB_LOG_FILE_SIZE=80M SINGLEHOST=true
- MYSQL_VERSION=5.6 MAX_ALLOWED_PACKET=20M INNODB_LOG_FILE_SIZE=200M SINGLEHOST=true
- MYSQL_VERSION=5.6 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true
script: mvn test $URLSTRING -DtestSingleHost=$SINGLEHOST $ADDITIONNAL_VARIABLES -DjobId=$TRAVIS_JOB_ID -DkeystorePath="/etc/mysql/client-keystore.p12" -DkeystorePassword="kspass"
cache:
directories:
- $HOME/.m2
- /var/cache/apt/archives
script: mvn clean test $URLSTRING -DtestSingleHost=$SINGLEHOST $ADDITIONNAL_VARIABLES -DjobId=$TRAVIS_JOB_ID -DkeystorePath="/etc/mysql/client-keystore.p12" -DkeystorePassword="kspass"
38 changes: 36 additions & 2 deletions documentation/changelog.creole
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Changelog
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#150|1.5.0]] RC1 released on 28-07-2016
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#151|1.5.1]] RC released on 15-08-2016
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#150|1.5.0]] RC released on 28-07-2016
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#146|1.4.6]] Released on 13 june 2016
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#146|1.4.5]] Released on 18 mai 2016
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#144|1.4.4]] Released on 04 mai 2016
Expand All @@ -9,8 +10,41 @@
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#140|1.4.0]] Released on 31 march 2016
---
== 1.5.0
== 1.5.1
Release candidate version
=== Evolution
==== Aurora host auto-discovery
(CONJ-325)

Aurora now auto discover nodes from cluster endpoint.

===== Aurora endpoints

Every aurora instance has a specific endpoint, i.e. an URL that identify the host. Those endpoints look like `xxx.yyy.zzz.rds.amazonaws.com`.

There is another endpoint named "cluster endpoint" (format `xxx.cluster-yyy.zzz.rds.amazonaws.com`) which is assigned to the current master instance and will change when a new master is promoted.

In previous version, cluster endpoint use was discouraged, since when a failover occur, this cluster endpoint can point for a limited time to a host that isn't the current master anymore. Old recommandation was to list all specific end-points, like : \\
{{{
jdbc:mysql:aurora://a.yyy.zzz.rds.amazonaws.com.com,b.yyy.zzz.rds.amazonaws.com.com/db
}}}
This kind of url string will still work, but now, recommended url string has to use only cluster endpoint :<br/>
{{{
jdbc:mysql:aurora://xxx.cluster-yyy.zzz.rds.amazonaws.com/db
}}}

Driver will automatically discover master and slaves of this cluster from current cluster end-point during connection time. This permit to add new replicas to the cluster instance will be discovered without changing driver configuration.

This discovery append at connection time, so if you are using pool framework, check if this framework as a property that controls the maximum lifetime of a connection in the pool, and set a value to avoid infinite lifetime. When this lifetime is reached, pool will discarded the current connection, and create a new one (if needed). New connections will use the new replicas.
(If connections are never discarded, new replicas will begin be used only when a failover occur)


=== Bugfix
* CONJ-329 and CONJ-330 : rewriteBatchedStatements execute single query exceptions correction.
\\\\
== 1.5.0
Release candidate version
=== Use native SSPI windows implementation
CONJ-295.\\

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,40 +206,38 @@ Aurora failover management steps :
==Aurora configuration

===Aurora endpoints
===Aurora endpoints and discovery

Every instance has a specific endpoint, ie an URL that identify the host. Those endpoints look like “xxxx.yyyy.us-east-1.rds.amazonaws.com.
Every aurora instance has a specific endpoint, i.e. an URL that identify the host. Those endpoints look like `xxx.yyy.zzz.rds.amazonaws.com`.

There is another endpoint named cluster endpoint which is assigned to the current master instance and will change when a new master is promoted.
There is another endpoint named "cluster endpoint" (format `xxx.cluster-yyy.zzz.rds.amazonaws.com`) which is assigned to the current master instance and will change when a new master is promoted.

This cluster endpoint must never be used in the URL connection string for 2 reasons:
* When a failover occurs, a new master is promoted. The cluster endpoint change to this new master is not immediately effective. The connector doesn’t use this cluster endpoint. Instead it points to the new master immediately.
* More important, an instance will not be used, and load will be poorly distributed. \\Example :
\\Normally JDBC url string must be like :\\
{{{
jdbc:mysql:aurora://A.XX.com,B.XX.com,C.XX.com/db
}}}
In version before 1.5.1, cluster endpoint use was discouraged, since when a failover occur, this cluster endpoint can point for a limited time to a host that isn't the current master anymore. Old recommandation was to list all specific end-points.
This kind of url string will still work, but now, recommended url string has to use only cluster endpoint.

if the master endpoint is used : \\
{{{
jdbc:mysql:aurora://master.XX.com,B.XX.com,C.XX.com/db
}}} \\
If B become master, A will not be used at all and C will receive all the read queries.
Driver will automatically discover master and slaves of this cluster from current cluster end-point during connection time. This permit to add new replicas to the cluster instance will be discovered without changing driver configuration.

This discovery append at connection time, so if you are using pool framework, check if this framework as a property that controls the maximum lifetime of a connection in the pool, and set a value to avoid infinite lifetime. When this lifetime is reached, pool will discarded the current connection, and create a new one (if needed). New connections will use the new replicas.
(If connections are never discarded, new replicas will begin be used only when a failover occur)

===JDBC connection string

The implementation is activated by specifying the “aurora” failover parameter.
Recommended connection string is using cluster end-point:
{{{
jdbc:(mysql|mariadb):aurora://[instanceEndPoint[:port]][,instanceEndPoint[:port]...]/[database][?<key1>=<value1>[&<key2>=<value2>]...]
jdbc:(mysql|mariadb):aurora://[clusterInstanceEndPoint[:port]]/[database][?<key1>=<value1>[&<key2>=<value2>]...]
}}}

Host declaration use instance endpoint (never cluster endpoint).
Before driver version 1.5.1, connection string has to list all end-point:
{{{
jdbc:(mysql|mariadb):aurora://[instanceEndPoint[:port]][,instanceEndPoint[:port]...]/[database][?<key1>=<value1>[&<key2>=<value2>]...]
}}}

The replication role of each instance must not be defined for Aurora, because the role of each instance changes over time. The driver will check the instance role after connection initialisation.
If setting many endpoint, the replication role of each instance must not be defined for Aurora, because the role of each instance changes over time. The driver will check the instance role after connection initialisation.

Example of connection string
{{{
jdbc:mysql:aurora://host1.xxxx.us-east-1.rds.amazonaws.com,host2.xxxx.us-east-1.rds.amazonaws.com/db
jdbc:mysql:aurora://cluster.cluster-xxxx.us-east-1.rds.amazonaws.com/db
}}}

Another difference is the option "socketTimeout" that defaults to 10 seconds, meaning that - if not changed - queries exceeding 10 seconds will throw exceptions.
Expand Down
23 changes: 7 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>1.5.0-RC1</version>
<version>1.5.1-RC</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>

Expand Down Expand Up @@ -196,7 +196,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<version>3.5.1</version>

<configuration>
<compilerArgs>
Expand All @@ -209,7 +209,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<version>3.0.2</version>
<!--phase package-->
<configuration>
<excludes>
Expand All @@ -233,7 +233,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<version>3.0.1</version>
<executions>
<execution>
<!--package phase-->
Expand All @@ -246,7 +246,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<version>1.12</version>
<executions>
<execution>
<!--validate phase-->
Expand Down Expand Up @@ -305,7 +305,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -360,7 +360,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<version>1.1.7</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -376,15 +376,6 @@
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
</plugin>
</plugins>
</reporting>

<parent>
<groupId>org.sonatype.oss</groupId>
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/org/mariadb/jdbc/HostAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS

package org.mariadb.jdbc;

import org.mariadb.jdbc.internal.util.constant.ParameterConstant;
import org.mariadb.jdbc.internal.logging.Logger;
import org.mariadb.jdbc.internal.logging.LoggerFactory;
import org.mariadb.jdbc.internal.util.constant.HaMode;
import org.mariadb.jdbc.internal.util.constant.ParameterConstant;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HostAddress {
private static Logger logger = LoggerFactory.getLogger(HostAddress.class);

public String host;
public int port;
public String type = null;
Expand Down Expand Up @@ -107,11 +113,23 @@ public static List<HostAddress> parse(String spec, HaMode haMode) {
String[] tokens = spec.trim().split(",");
List<HostAddress> arr = new ArrayList<>(tokens.length);

for (int i = 0; i < tokens.length; i++) {
if (tokens[i].startsWith("address=")) {
arr.add(parseParameterHostAddress(tokens[i]));
// Aurora using cluster end point mustn't have any other host
if (haMode == HaMode.AURORA) {
Pattern clusterPattern = Pattern.compile("(.+)\\.cluster-([a-z0-9]+\\.[a-z0-9\\-]+\\.rds\\.amazonaws\\.com)");
Matcher matcher = clusterPattern.matcher(spec);

if (!matcher.find()) {
logger.warn("Aurora recommended connection URL must only use cluster end-point like "
+ "\"jdbc:mariadb://xx.cluster-yy.zz.rds.amazonaws.com\". "
+ "Using end-point permit auto-discovery of new replicas");
}
}

for (String token : tokens) {
if (token.startsWith("address=")) {
arr.add(parseParameterHostAddress(token));
} else {
arr.add(parseSimpleHostAddress(tokens[i]));
arr.add(parseSimpleHostAddress(token));
}
}

Expand Down Expand Up @@ -242,13 +260,8 @@ public boolean equals(Object obj) {

HostAddress that = (HostAddress) obj;

if (port != that.port) {
return false;
}
if (host != null ? !host.equals(that.host) : that.host != null) {
return false;
}
return !(type != null ? !type.equals(that.type) : that.type != null);
return port == that.port && (host != null ? host.equals(that.host) : that.host == null
&& !(type != null ? !type.equals(that.type) : that.type != null));

}

Expand All @@ -261,4 +274,3 @@ public int hashCode() {


}

Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ public int[] executeBatch() throws SQLException {
} finally {
if (exception != null) {
if (options.rewriteBatchedStatements) {
if (prepareResult.isRewritableValuesQuery()) {
if (prepareResult.isQueryMultiValuesRewritable()) {
internalExecutionResult.updateResultsForRewrite(size, true);
} else if (prepareResult.isRewritableMultipleQuery()) {
} else if (prepareResult.isQueryMultipleRewritable()) {
internalExecutionResult.updateResultsMultiple(size, true);
}
}
Expand Down Expand Up @@ -336,14 +336,14 @@ public int[] executeBatch() throws SQLException {
private void executeInternalBatch(MultiExecutionResult internalExecutionResult, int size) throws QueryException {

if (options.rewriteBatchedStatements) {
if (prepareResult.isRewritableValuesQuery()) {
if (prepareResult.isQueryMultiValuesRewritable()) {
//values rewritten in one query :
// INSERT INTO X(a,b) VALUES (1,2), (3,4), ...
protocol.executeBatchRewrite(protocol.isMasterConnection(), internalExecutionResult, prepareResult,
parameterList, resultSetScrollType, true);
internalExecutionResult.updateResultsForRewrite(size, false);
return;
} else if (prepareResult.isRewritableMultipleQuery()) {
} else if (prepareResult.isQueryMultipleRewritable()) {
//multi rewritten in one query :
// INSERT INTO X(a,b) VALUES (1,2);INSERT INTO X(a,b) VALUES (3,4); ...
protocol.executeBatchRewrite(protocol.isMasterConnection(), internalExecutionResult, prepareResult,
Expand Down
44 changes: 18 additions & 26 deletions src/main/java/org/mariadb/jdbc/MariaDbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,24 @@ public PreparedStatement prepareStatement(final String sql, final String[] colum
public PreparedStatement internalPrepareStatement(final String sql, final int resultSetScrollType)
throws SQLException {
checkConnection();
if (!options.rewriteBatchedStatements
&& options.useServerPrepStmts
&& checkIfPreparable(sql)) {

boolean canUsePrepareStatement = false;
if (options.rewriteBatchedStatements) {
//in case of CALL statement, handling INOUT parameter is better with Prepare protocol
String cleanSql = sql.toUpperCase().trim();
canUsePrepareStatement = cleanSql.contains("CALL");
} else if (options.useServerPrepStmts && sql != null) {
String cleanSql = sql.toUpperCase().trim();
canUsePrepareStatement = (cleanSql.contains("SELECT")
|| cleanSql.contains("CALL")
|| cleanSql.contains("UPDATE")
|| cleanSql.contains("INSERT")
|| cleanSql.contains("DELETE")
|| cleanSql.contains("REPLACE")
|| cleanSql.contains("DO"));
}

if (canUsePrepareStatement) {
try {
return new MariaDbServerPreparedStatement(this, sql, resultSetScrollType, false);
} catch (SQLNonTransientConnectionException e) {
Expand All @@ -419,29 +434,6 @@ && checkIfPreparable(sql)) {
return new MariaDbClientPreparedStatement(this, sql, resultSetScrollType);
}


/**
* Check if SQL request is "preparable" and has parameter.
*
* @param sql sql query
* @return true if preparable
*/
private boolean checkIfPreparable(String sql) {
if (sql == null) {
return true;
}

String cleanSql = sql.toUpperCase().trim();
return (cleanSql.contains("SELECT")
|| cleanSql.contains("CALL")
|| cleanSql.contains("UPDATE")
|| cleanSql.contains("INSERT")
|| cleanSql.contains("DELETE")
|| cleanSql.contains("REPLACE")
|| cleanSql.contains("DO"));

}

/**
* Creates a <code>CallableStatement</code> object for calling
* database stored procedures.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public int getScale(final int column) throws SQLException {
* @throws SQLException if a database access error occurs
*/
public String getTableName(final int column) throws SQLException {
if (returnTableAlias == true) {
if (returnTableAlias) {
return getColumnInformation(column).getTable();
} else {
return getColumnInformation(column).getOriginalTable();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/mariadb/jdbc/MariaDbStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,15 @@ public ResultSet getGeneratedKeys() throws SQLException {
data[i] = ((SingleExecutionResult) executionResult).getInsertId() + i * autoIncrementIncrement;
}
} else {
MultiVariableIntExecutionResult multiExecution = (MultiVariableIntExecutionResult) executionResult;
MultiExecutionResult multiExecution = (MultiExecutionResult) executionResult;
int size = 0;
int affectedRowslength = multiExecution.getAffectedRows().length;
for (int i = 0; i < affectedRowslength; i++) {
size += multiExecution.getAffectedRows()[i];
}
data = new long[size];
for (int affectedRows = 0; affectedRows < affectedRowslength; affectedRows++) {
for (int i = 0; i < affectedRows; i++) {
for (int i = 0; i < multiExecution.getAffectedRows()[affectedRows]; i++) {
data[i] = multiExecution.getInsertIds()[affectedRows] + i * autoIncrementIncrement;
}
}
Expand Down Expand Up @@ -832,7 +832,7 @@ public int getUpdateCount() throws SQLException {
if (executionResult.isSingleExecutionResult()) {
return (int) ((SingleExecutionResult) executionResult).getAffectedRows();
} else {
return ((MultiExecutionResult) executionResult).getAffectedRows()[0];
return ((MultiExecutionResult) executionResult).getFirstAffectedRows();
}
}

Expand Down
Loading

0 comments on commit 8bcfb76

Please sign in to comment.