-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for MySQL pipelining execution #1168
Changes from 7 commits
df387a1
1c42d9a
14a9a7f
7183c91
cf334e0
c8519e0
511b288
7f77b3e
bc4bd11
5c95c9d
a7c429f
99d61a1
3204c0c
a70e6c8
31e0aff
324d5a9
f71739f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
|
||
package io.vertx.mysqlclient; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@code MySQLBatchException} is thrown if an error occurs during executions when using {@link io.vertx.sqlclient.PreparedQuery#executeBatch(List)}. | ||
* The client will try to execute with all the params no matter if one iteration of the executions fails, the iteration count is calculated from zero. | ||
*/ | ||
public class MySQLBatchException extends RuntimeException { | ||
/** | ||
* A mapping between the iteration count and error message. | ||
*/ | ||
private final Map<Integer, String> iterationError = new HashMap<>(); | ||
|
||
public MySQLBatchException() { | ||
super("Error occurs during batch execution"); | ||
} | ||
|
||
public Map<Integer, String> getIterationError() { | ||
vietj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return iterationError; | ||
} | ||
|
||
public void reportError(int iteration, String errorMessage) { | ||
iterationError.put(iteration, errorMessage); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ public static MySQLConnectOptions fromUri(String connectionUri) throws IllegalAr | |
public static final Map<String, String> DEFAULT_CONNECTION_ATTRIBUTES; | ||
public static final SslMode DEFAULT_SSL_MODE = SslMode.DISABLED; | ||
public static final String DEFAULT_CHARACTER_ENCODING = "UTF-8"; | ||
public static final int DEFAULT_PIPELINING_LIMIT = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use the same value than PgConnectOptions which is 256 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this is for backward compatibility ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I'm trying to avoid introducing breaking changes. |
||
|
||
static { | ||
Map<String, String> defaultAttributes = new HashMap<>(); | ||
|
@@ -79,6 +80,7 @@ public static MySQLConnectOptions fromUri(String connectionUri) throws IllegalAr | |
private String serverRsaPublicKeyPath; | ||
private Buffer serverRsaPublicKeyValue; | ||
private String characterEncoding = DEFAULT_CHARACTER_ENCODING; | ||
private int pipeliningLimit = DEFAULT_PIPELINING_LIMIT; | ||
private MySQLAuthenticationPlugin authenticationPlugin = MySQLAuthenticationPlugin.DEFAULT; | ||
|
||
public MySQLConnectOptions() { | ||
|
@@ -301,6 +303,29 @@ public Buffer getServerRsaPublicKeyValue() { | |
return serverRsaPublicKeyValue; | ||
} | ||
|
||
/** | ||
* Get the pipelining limit count. | ||
* | ||
* @return the pipelining count | ||
*/ | ||
public int getPipeliningLimit() { | ||
return pipeliningLimit; | ||
} | ||
|
||
/** | ||
* Set the pipelining limit count. | ||
* | ||
* @param pipeliningLimit the count to configure | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
public MySQLConnectOptions setPipeliningLimit(int pipeliningLimit) { | ||
if (pipeliningLimit < 1) { | ||
throw new IllegalArgumentException("pipelining limit can not be less than 1"); | ||
} | ||
this.pipeliningLimit = pipeliningLimit; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MySQLConnectOptions setHost(String host) { | ||
return (MySQLConnectOptions) super.setHost(host); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2017 Julien Viet | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
vietj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package io.vertx.mysqlclient.impl; | ||
|
||
import io.vertx.sqlclient.PoolOptions; | ||
|
||
public class MySQLPoolOptions extends PoolOptions { | ||
|
||
public MySQLPoolOptions(PoolOptions other) { | ||
super(other); | ||
} | ||
|
||
private boolean pipelined; | ||
|
||
public boolean isPipelined() { | ||
return pipelined; | ||
} | ||
|
||
public MySQLPoolOptions setPipelined(boolean pipelined) { | ||
this.pipelined = pipelined; | ||
return this; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you think about a way to combine this type with
MySQLException
in a hierarchy? It can be convenient for users to identity where the issue comes from when the exception bubbles up to upper layers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about using a mapping like
Map<Integer, MySQLException>
to represent the errors in a batching process? I think MySQL needs this because it emulates batching by sending multiple requests and might receive multiple error responses which does not behave like Postgres client batching(one request & one response)