Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[misc] galera complete test integration
  • Loading branch information
rusher committed Dec 15, 2017
1 parent c13206a commit 4eebe7d
Show file tree
Hide file tree
Showing 27 changed files with 219 additions and 205 deletions.
2 changes: 1 addition & 1 deletion .travis/docker-compose.yml
@@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
db:
image: $DB
Expand Down
8 changes: 4 additions & 4 deletions .travis/galera-compose.yml
@@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
node1:
image: mariadb:10.2
Expand All @@ -7,7 +7,7 @@ services:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
ports:
- 3106:3306
command: --max-connections=500 --wsrep_new_cluster --wsrep_cluster_address='gcomm://node1,node2,node3' --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --bind-address=0.0.0.0 --wsrep-new-cluster --binlog-format=ROW --wsrep-provider=/usr/lib/galera/libgalera_smm.so --wsrep-cluster-name=my_super_cluster --wsrep-on=ON --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key
command: --max-connections=500 --wsrep_new_cluster --wsrep_cluster_address='gcomm://node1,node2,node3' --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --bind-address=0.0.0.0 --wsrep-new-cluster --binlog-format=ROW --wsrep-provider=/usr/lib/galera/libgalera_smm.so --wsrep-cluster-name=my_super_cluster --wsrep-on=ON --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key
volumes:
- $SSLCERT:/etc/sslcert
- $ENTRYPOINT:/docker-entrypoint-initdb.d
Expand All @@ -20,7 +20,7 @@ services:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
ports:
- 3107:3306
command: --max-connections=500 --wsrep_cluster_address='gcomm://node1,node2,node3' --wsrep-node-name=node2 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --bind-address=0.0.0.0 --wsrep-new-cluster --binlog-format=ROW --wsrep-provider=/usr/lib/galera/libgalera_smm.so --wsrep-cluster-name=my_super_cluster --wsrep-on=ON --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key
command: --max-connections=500 --wsrep_cluster_address='gcomm://node1,node2,node3' --wsrep-node-name=node2 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --bind-address=0.0.0.0 --binlog-format=ROW --wsrep-provider=/usr/lib/galera/libgalera_smm.so --wsrep-cluster-name=my_super_cluster --wsrep-on=ON --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key
volumes:
- $SSLCERT:/etc/sslcert
- $ENTRYPOINT:/docker-entrypoint-initdb.d
Expand All @@ -33,7 +33,7 @@ services:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
ports:
- 3108:3306
command: --max-connections=500 --wsrep_cluster_address='gcomm://node1,node2,node3' --wsrep-node-name=node3 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --bind-address=0.0.0.0 --wsrep-new-cluster --binlog-format=ROW --wsrep-provider=/usr/lib/galera/libgalera_smm.so --wsrep-cluster-name=my_super_cluster --wsrep-on=ON --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key
command: --max-connections=500 --wsrep_cluster_address='gcomm://node1,node2,node3' --wsrep-node-name=node3 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --bind-address=0.0.0.0 --binlog-format=ROW --wsrep-provider=/usr/lib/galera/libgalera_smm.so --wsrep-cluster-name=my_super_cluster --wsrep-on=ON --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key
volumes:
- $SSLCERT:/etc/sslcert
- $ENTRYPOINT:/docker-entrypoint-initdb.d
2 changes: 1 addition & 1 deletion .travis/maxscale-compose.yml
@@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
maxscale:
depends_on:
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/mariadb/jdbc/MariaDbConnection.java
Expand Up @@ -97,7 +97,6 @@ public class MariaDbConnection implements Connection {
* the protocol to communicate with.
*/
private final Protocol protocol;
private final ClientPrepareStatementCache clientPrepareStatementCache;
public MariaDbPooledConnection pooledConnection;
private CallableStatementCache callableStatementCache;

Expand Down Expand Up @@ -134,11 +133,6 @@ public MariaDbConnection(Protocol protocol) {
}
this.lock = protocol.getLock();

if (options.cachePrepStmts) {
this.clientPrepareStatementCache = ClientPrepareStatementCache.newInstance(options.prepStmtCacheSize);
} else {
clientPrepareStatementCache = null;
}
}

/**
Expand Down Expand Up @@ -1618,10 +1612,6 @@ public void setNetworkTimeout(Executor executor, final int milliseconds) throws
}
}

public ClientPrepareStatementCache getClientPrepareStatementCache() {
return clientPrepareStatementCache;
}

public long getServerThreadId() {
return (protocol != null) ? protocol.getServerThreadId() : -1;
}
Expand Down
Expand Up @@ -94,21 +94,12 @@ public MariaDbPreparedStatementClient(MariaDbConnection connection, String sql,
super(connection, resultSetScrollType, resultSetConcurrency, autoGeneratedKeys);
sqlQuery = sql;

if (options.cachePrepStmts) {
String key = protocol.getDatabase() + "-" + sqlQuery;
prepareResult = connection.getClientPrepareStatementCache().get(key);
}

if (prepareResult == null) {
if (options.rewriteBatchedStatements) {
prepareResult = ClientPrepareResult.rewritableParts(sqlQuery, protocol.noBackslashEscapes());
} else {
prepareResult = ClientPrepareResult.parameterParts(sqlQuery, protocol.noBackslashEscapes());
}
if (options.cachePrepStmts && sql.length() < 1024) {
String key = protocol.getDatabase() + "-" + sqlQuery;
connection.getClientPrepareStatementCache().put(key, prepareResult);
}
}
parameters = new ParameterHolder[prepareResult.getParamCount()];
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/mariadb/jdbc/UrlParser.java
Expand Up @@ -128,6 +128,11 @@ protected UrlParser(String database, List<HostAddress> addresses, Options option
}

DefaultOptions.optionCoherenceValidation(options);
setInitialUrl();
loadMultiMasterValue();
}

private void setInitialUrl() {
StringBuilder sb = new StringBuilder();
sb.append("jdbc:mariadb:");
if (haMode != HaMode.NONE) {
Expand All @@ -149,8 +154,6 @@ protected UrlParser(String database, List<HostAddress> addresses, Options option
if (database != null) sb.append(database);
DefaultOptions.propertyString(options, haMode, sb);
initialUrl = sb.toString();

loadMultiMasterValue();
}

/**
Expand Down Expand Up @@ -230,6 +233,9 @@ private static void parseInternal(UrlParser urlParser, String url, Properties pr

defineUrlParserParameters(urlParser, properties, hostAddressesString, additionalParameters);
setDefaultHostAddressType(urlParser);

if (properties != null && !properties.isEmpty()) urlParser.setInitialUrl();

urlParser.loadMultiMasterValue();
} catch (IllegalArgumentException i) {
throw new SQLException("error parsing url : " + i.getMessage(), i);
Expand Down
Expand Up @@ -139,7 +139,10 @@ public ServerPrepareResult read(PacketInputStream reader, boolean eofDeprecated)
}

ServerPrepareResult serverPrepareResult = new ServerPrepareResult(sql, statementId, columns, params, protocol);
if (protocol.getOptions().cachePrepStmts && sql != null && sql.length() < protocol.getOptions().prepStmtCacheSqlLimit) {
if (protocol.getOptions().cachePrepStmts
&& protocol.getOptions().useServerPrepStmts
&& sql != null
&& sql.length() < protocol.getOptions().prepStmtCacheSqlLimit) {
String key = protocol.getDatabase() + "-" + sql;
ServerPrepareResult cachedServerPrepareResult = protocol.addPrepareInCache(key, serverPrepareResult);
return cachedServerPrepareResult != null ? cachedServerPrepareResult : serverPrepareResult;
Expand Down
Expand Up @@ -169,7 +169,7 @@ public AbstractConnectProtocol(final UrlParser urlParser, final GlobalStateInfo
this.username = (urlParser.getUsername() == null ? "" : urlParser.getUsername());
this.password = (urlParser.getPassword() == null ? "" : urlParser.getPassword());
this.globalInfo = globalInfo;
if (options.cachePrepStmts) {
if (options.cachePrepStmts && options.useServerPrepStmts) {
serverPrepareStatementCache = ServerPrepareStatementCache.newInstance(options.prepStmtCacheSize, this);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public void skip() throws SQLException {
}

private void cleanMemory() {
if (options.cachePrepStmts) serverPrepareStatementCache.clear();
if (options.cachePrepStmts && options.useServerPrepStmts) serverPrepareStatementCache.clear();
if (options.enablePacketDebug) traceCache.clearMemory();
}

Expand Down
Expand Up @@ -174,7 +174,9 @@ public PrepareResult executeBatch() throws SQLException {
if (binaryProtocol) {
if (readPrepareStmtResult) {
parameterTypeHeader = new ColumnType[paramCount];
if (prepareResult == null && protocol.getOptions().cachePrepStmts) {
if (prepareResult == null
&& protocol.getOptions().cachePrepStmts
&& protocol.getOptions().useServerPrepStmts) {
String key = protocol.getDatabase() + "-" + sql;
prepareResult = protocol.prepareStatementCache().get(key);
if (prepareResult != null && !((ServerPrepareResult) prepareResult).incrementShareCounter()) {
Expand Down
Expand Up @@ -150,7 +150,7 @@ public void reset() throws SQLException {
getResult(new Results());

//clear prepare statement cache
if (options.cachePrepStmts) {
if (options.cachePrepStmts && options.useServerPrepStmts) {
serverPrepareStatementCache.clear();
}

Expand Down Expand Up @@ -735,7 +735,7 @@ public ServerPrepareResult prepare(String sql, boolean executeOnMaster) throws S
cmdPrologue();
lock.lock();
try {
if (options.cachePrepStmts) {
if (options.cachePrepStmts && options.useServerPrepStmts) {

ServerPrepareResult pr = serverPrepareStatementCache.get(database + "-" + sql);

Expand Down

This file was deleted.

Expand Up @@ -755,18 +755,16 @@ public static void optionCoherenceValidation(final Options options) {
options.useServerPrepStmts = false;
}

if (!options.useServerPrepStmts) {
options.cachePrepStmts = false;
}

//pipe cannot use read and write socket simultaneously
if (options.pipe != null) {
options.useBatchMultiSend = false;
options.usePipelineAuth = false;
}

//if min pool size default to maximum pool size if not set
options.minPoolSize = options.minPoolSize == null ? options.maxPoolSize : Math.min(options.minPoolSize, options.maxPoolSize);
if (options.pool) {
options.minPoolSize = options.minPoolSize == null ? options.maxPoolSize : Math.min(options.minPoolSize, options.maxPoolSize);
}

}

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/mariadb/jdbc/BaseTest.java
Expand Up @@ -584,6 +584,17 @@ protected Connection openNewConnection(String url, Properties info) throws SQLEx
return DriverManager.getConnection(url, info);
}

protected boolean isGalera() {
try {
Statement st = sharedConnection.createStatement();
ResultSet rs = st.executeQuery("show status like 'wsrep_cluster_status'");
if (rs.next()) return true;
} catch (SQLException sqle) {
//skip
}
return false;
}

/**
* Check if max_allowed_packet value is equal or greater then 8m.
* @param testName test method name
Expand Down Expand Up @@ -996,4 +1007,36 @@ public boolean hasSameHost() {
}
return true;
}

protected int autoInc = 1;
protected int autoIncOffset = 0;

/**
* Get current autoincrement value, since Galera values are automatically set.
* @throws SQLException if any error occur.
*/
public void setAutoInc() throws SQLException {
setAutoInc(1, 0);
}

/**
* Get current autoincrement value, since Galera values are automatically set.
* @see <a href="https://mariadb.org/auto-increments-in-galera/">https://mariadb.org/auto-increments-in-galera/</a>
* @param autoIncInit default increment
* @param autoIncOffsetInit default increment offset
* @throws SQLException if any error occur
*/
public void setAutoInc(int autoIncInit, int autoIncOffsetInit) throws SQLException {

this.autoInc = autoIncInit;
this.autoIncOffset = autoIncOffsetInit;
if (isGalera()) {
ResultSet rs = sharedConnection.createStatement().executeQuery("show variables like '%auto_increment%'");
while (rs.next()) {
if ("auto_increment_increment".equals(rs.getString(1))) autoInc = rs.getInt(2);
if ("auto_increment_offset".equals(rs.getString(1))) autoIncOffset = rs.getInt(2);
}
}
}

}

0 comments on commit 4eebe7d

Please sign in to comment.