Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Basic example:
| **`loopResources`** | permits to share netty EventLoopGroup among multiple async libraries/framework | *LoopResources* | |
| **`sslContextBuilderCustomizer`** | Permits to customized SSL context builder. | *UnaryOperator<SslContextBuilder>* | |
| **`sslTunnelDisableHostVerification`** | Disable hostname verification during SSLHandshake when SslMode.TUNNEL is set | *boolean* | |
| **`permitRedirect`** | Permit server redirection | *boolean* | true |
| **`timezone`** | permits to force session timezone in case of client having a different timezone compare to server. The option `timezone` can have 3 types of value: * 'disabled' (default) : connector doesn't change time_zone. * 'auto': client will use client default timezone. * '<a timezone>': connector will set connection variable to value. Since 1.2.0 | String | 'disabled' |
| **`skipPostCommands`** | Permit to indicate that commands after connections must be skipped. This permit to avoid unnecessary command on connection creation, and when using RDV proxy not to have session pinning. Use with care, because connector expects server to have : 1.connection exchanges to be UT8(mb3/mb4). 2.autocommit set to true. 3.transaction isolation defaulting to REPEATABLE-READ | *boolean* | 'false' |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public Flux<org.mariadb.r2dbc.api.MariadbResult> toResult(
generatedColumns,
client.getVersion().supportReturning(),
configuration))
.flatMap(m -> client.redirect().then(Mono.just(m)))
.cast(org.mariadb.r2dbc.api.MariadbResult.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public final class MariadbConnectionConfiguration {
private final SslConfig sslConfig;
private final boolean useServerPrepStmts;
private final Boolean autocommit;
private final boolean permitRedirect;
private final String[] restrictedAuth;
private final LoopResources loopResources;
private final UnaryOperator<SslContextBuilder> sslContextBuilderCustomizer;
Expand Down Expand Up @@ -78,7 +77,6 @@ private MariadbConnectionConfiguration(
SslMode sslMode,
boolean useServerPrepStmts,
Boolean autocommit,
boolean permitRedirect,
boolean skipPostCommands,
@Nullable Integer prepareCacheSize,
@Nullable CharSequence[] pamOtherPwd,
Expand Down Expand Up @@ -124,7 +122,6 @@ private MariadbConnectionConfiguration(
this.prepareCacheSize = (prepareCacheSize == null) ? 250 : prepareCacheSize;
this.pamOtherPwd = pamOtherPwd;
this.autocommit = (autocommit != null) ? autocommit : Boolean.TRUE;
this.permitRedirect = permitRedirect;
this.skipPostCommands = skipPostCommands;
this.loopResources = loopResources != null ? loopResources : TcpResources.get();
this.useServerPrepStmts = !this.allowMultiQueries && useServerPrepStmts;
Expand Down Expand Up @@ -153,7 +150,6 @@ private MariadbConnectionConfiguration(
SslConfig sslConfig,
boolean useServerPrepStmts,
Boolean autocommit,
boolean permitRedirect,
boolean skipPostCommands,
String[] restrictedAuth,
LoopResources loopResources,
Expand All @@ -179,46 +175,12 @@ private MariadbConnectionConfiguration(
this.sslConfig = sslConfig;
this.useServerPrepStmts = useServerPrepStmts;
this.autocommit = (autocommit != null) ? autocommit : Boolean.TRUE;
this.permitRedirect = permitRedirect;
this.skipPostCommands = skipPostCommands;
this.restrictedAuth = restrictedAuth;
this.loopResources = loopResources;
this.sslContextBuilderCustomizer = sslContextBuilderCustomizer;
}

public MariadbConnectionConfiguration redirectConf(
HostAddress hostAddress, String user, CharSequence password) {
// same connection, but with hostAddress, user and password changed
// + redirection disabled to avoid redirection loop
return new MariadbConnectionConfiguration(
this.database,
Collections.singletonList(hostAddress),
this.haMode,
this.connectTimeout,
this.tcpKeepAlive,
this.tcpAbortiveClose,
this.transactionReplay,
password,
this.timezone,
this.pamOtherPwd,
hostAddress.getPort(),
this.prepareCacheSize,
this.socket,
user,
this.allowMultiQueries,
this.allowPipelining,
this.connectionAttributes,
this.sessionVariables,
this.sslConfig,
this.useServerPrepStmts,
this.autocommit,
this.skipPostCommands,
false,
this.restrictedAuth,
this.loopResources,
this.sslContextBuilderCustomizer);
}

static boolean boolValue(Object value) {
if (value instanceof Boolean) {
return (Boolean) value;
Expand Down Expand Up @@ -325,11 +287,6 @@ public static Builder fromOptions(ConnectionFactoryOptions connectionFactoryOpti
}
}

if (connectionFactoryOptions.hasOption(MariadbConnectionFactoryProvider.PERMIT_REDIRECT)) {
builder.permitRedirect(
boolValue(
connectionFactoryOptions.getValue(MariadbConnectionFactoryProvider.PERMIT_REDIRECT)));
}
if (connectionFactoryOptions.hasOption(MariadbConnectionFactoryProvider.SKIP_POST_COMMANDS)) {
builder.skipPostCommands(
boolValue(
Expand Down Expand Up @@ -529,10 +486,6 @@ public Boolean autocommit() {
return autocommit;
}

public boolean permitRedirect() {
return permitRedirect;
}

public boolean skipPostCommands() {
return skipPostCommands;
}
Expand Down Expand Up @@ -743,7 +696,6 @@ public static final class Builder implements Cloneable {
private boolean allowPipelining = true;
private boolean useServerPrepStmts = false;
private Boolean autocommit = Boolean.TRUE;
private boolean permitRedirect = true;
private boolean skipPostCommands = false;
@Nullable private List<String> tlsProtocol;
@Nullable private String serverSslCert;
Expand Down Expand Up @@ -809,7 +761,6 @@ private MariadbConnectionConfiguration build(boolean checkMandatory) {
this.sslMode,
this.useServerPrepStmts,
this.autocommit,
this.permitRedirect,
this.skipPostCommands,
this.prepareCacheSize,
this.pamOtherPwd,
Expand Down Expand Up @@ -1057,17 +1008,6 @@ public Builder autocommit(Boolean autocommit) {
return this;
}

/**
* Permit to indicate if redirection are allowed. Default value True.
*
* @param permitRedirect use permitRedirect
* @return this {@link Builder}
*/
public Builder permitRedirect(boolean permitRedirect) {
this.permitRedirect = permitRedirect;
return this;
}

/**
* Permit to indicate that commands after connections must be skipped. This permit to avoid
* unnecessary command on connection creation, and when using RDV proxy not to have session
Expand Down Expand Up @@ -1236,8 +1176,6 @@ public String toString() {
+ hiddenPamPwd
+ ", autoCommit="
+ autocommit
+ ", permitRedirect="
+ permitRedirect
+ '}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public final class MariadbConnectionFactoryProvider implements ConnectionFactory
public static final Option<Boolean> ALLOW_PIPELINING = Option.valueOf("allowPipelining");
public static final Option<Boolean> USE_SERVER_PREPARE = Option.valueOf("useServerPrepStmts");
public static final Option<Boolean> AUTO_COMMIT = Option.valueOf("autocommit");
public static final Option<Boolean> PERMIT_REDIRECT = Option.valueOf("permitRedirect");
public static final Option<Boolean> SKIP_POST_COMMANDS = Option.valueOf("skipPostCommands");
public static final Option<Integer> PREPARE_CACHE_SIZE = Option.valueOf("prepareCacheSize");
public static final Option<String> SSL_MODE = Option.valueOf("sslMode");
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/mariadb/r2dbc/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,4 @@ Mono<Void> sendSslRequest(
long getThreadId();

HostAddress getHostAddress();

Mono<Void> redirect();
}
5 changes: 0 additions & 5 deletions src/main/java/org/mariadb/r2dbc/client/FailoverClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,4 @@ public long getThreadId() {
public HostAddress getHostAddress() {
return client.get().getHostAddress();
}

@Override
public Mono<Void> redirect() {
return client.get().redirect();
}
}
71 changes: 0 additions & 71 deletions src/main/java/org/mariadb/r2dbc/client/SimpleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
public class SimpleClient implements Client {

private static final Logger logger = Loggers.getLogger(SimpleClient.class);
private static final Pattern REDIRECT_URL_FORMAT =
Pattern.compile(
"(mariadb|mysql)://(([^/@:]+)?(:([^/]+))?@)?(([^/:]+)(:([0-9]+))?)(/([^?]+)(/?(.*))?)?$",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

protected MariadbConnectionConfiguration configuration;
protected final ReentrantLock lock;
Expand Down Expand Up @@ -144,70 +140,6 @@ protected SimpleClient(
.subscribe();
}

public Mono<Void> redirect() {
if (configuration.permitRedirect() && context.getRedirectValue() != null) {
// redirect only if :
// * when pipelining, having received all waiting responses.
// * not in a transaction
if (this.exchangeQueue.size() <= 1
&& (this.context.getServerStatus() & ServerStatus.IN_TRANSACTION) == 0) {
String redirectValue = context.getRedirectValue();
context.setRedirect(null);
// redirection required
Matcher matcher = REDIRECT_URL_FORMAT.matcher(redirectValue);
if (!matcher.matches()) {
return Mono.error(
new SQLSyntaxErrorException(
"error parsing redirection string '"
+ redirectValue
+ "'. format must be"
+ " 'mariadb/mysql://[<user>[:<password>]@]<host>[:<port>]/[<db>[?<opt1>=<value1>[&<opt2>=<value2>]]]'"));
}

try {
String host =
matcher.group(7) != null
? URLDecoder.decode(matcher.group(7), "UTF-8")
: matcher.group(6);
int port = matcher.group(9) != null ? Integer.parseInt(matcher.group(9)) : 3306;
HostAddress hostAddress = new HostAddress(host, port);

// actually only options accepted are user and password
// there might be additional possible options in the future
String user = (matcher.group(3) != null) ? matcher.group(3) : configuration.getUsername();
CharSequence password =
(matcher.group(5) != null) ? matcher.group(5) : configuration.getPassword();

MariadbConnectionConfiguration redirectConf =
configuration.redirectConf(hostAddress, user, password);

return SimpleClient.connect(
ConnectionProvider.newConnection(),
InetSocketAddress.createUnresolved(hostAddress.getHost(), hostAddress.getPort()),
hostAddress,
redirectConf,
lock)
.delayUntil(client -> AuthenticationFlow.exchange(client, redirectConf, hostAddress))
.doOnError(e -> HaMode.failHost(hostAddress))
.onErrorComplete()
.flatMap(client -> MariadbConnectionFactory.retrieveSingleStoreVersion(redirectConf, client))
.cast(SimpleClient.class)
.flatMap(
client ->
MariadbConnectionFactory.setSessionVariables(redirectConf, client)
.then(Mono.just(client)))
.flatMap(this::refreshClient)
.then();
} catch (UnsupportedEncodingException e) {
// "UTF-8" is known, but String decode(String s, Charset charset) requires java 10+ to get
// rid of catching error
return Mono.error(e);
}
}
}
return Mono.empty();
}

public Mono<Void> refreshClient(SimpleClient client) {
return quitOrClose()
.then(
Expand Down Expand Up @@ -420,7 +352,6 @@ private Mono<Void> executeWhenTransaction(String sql) {
return messages
.doOnDiscard(ReferenceCounted.class, ReferenceCountUtil::release)
.handle(ExceptionFactory.withSql(sql)::handleErrorResponse)
.flatMap(m -> redirect().then(Mono.just(m)))
.then();
}
return Mono.empty();
Expand All @@ -438,7 +369,6 @@ private Mono<Void> executeWhenNotInTransaction(String sql) {
return messages
.doOnDiscard(ReferenceCounted.class, ReferenceCountUtil::release)
.handle(ExceptionFactory.withSql(sql)::handleErrorResponse)
.flatMap(m -> redirect().then(Mono.just(m)))
.then();
}
return Mono.empty();
Expand Down Expand Up @@ -481,7 +411,6 @@ public Mono<Void> setAutoCommit(boolean autoCommit) {
null,
true,
configuration))
.flatMap(m -> redirect().then(Mono.just(m)))
.cast(org.mariadb.r2dbc.api.MariadbResult.class)
.then();
}
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/mariadb/r2dbc/client/SimpleContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class SimpleContext implements Context {
private final long clientCapabilities;
private final ServerVersion version;
private final ByteBufAllocator byteBufAllocator;
private String redirectValue;
private short serverStatus;
private String database;

Expand All @@ -34,7 +33,6 @@ public SimpleContext(
this.version = new ServerVersion(serverVersion, mariaDBServer);
this.database = database;
this.byteBufAllocator = byteBufAllocator;
this.redirectValue = null;
}

public long getThreadId() {
Expand Down Expand Up @@ -73,15 +71,6 @@ public ByteBufAllocator getByteBufAllocator() {
return byteBufAllocator;
}

@Override
public void setRedirect(String redirectValue) {
this.redirectValue = redirectValue;
}

public String getRedirectValue() {
return redirectValue;
}

@Override
public String toString() {
return "ConnectionContext{" + "threadId=" + threadId + ", version=" + version + '}';
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/mariadb/r2dbc/message/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public interface Context {

void setServerStatus(short serverStatus);

void setRedirect(String redirectValue);

String getRedirectValue();

String getDatabase();

void setDatabase(String database);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/mariadb/r2dbc/message/server/OkPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public static OkPacket decode(ByteBuf buf, Context context) {
String variable = BufferUtils.readLengthEncodedString(sessionVariableBuf);
String value = BufferUtils.readLengthEncodedString(sessionVariableBuf);
logger.debug("System variable change : {} = {}", variable, value);

if (variable.equals("redirect_url")) {
context.setRedirect(value.isEmpty() ? null : value);
}
} while (sessionVariableBuf.readableBytes() > 0);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void confStringValue() {
+ " prepareCacheSize=null, tlsProtocol=null, serverSslCert=null,"
+ " clientSslCert=null, clientSslKey=null, clientSslPassword=null, sslMode=TRUST,"
+ " sslTunnelDisableHostVerification=false, pamOtherPwd=*,*,"
+ " autoCommit=true, permitRedirect=true}",
+ " autoCommit=true}",
builder.toString());
builder.tlsProtocol((String) null);
Assertions.assertEquals(
Expand All @@ -370,7 +370,7 @@ void confStringValue() {
+ " prepareCacheSize=null, tlsProtocol=null, serverSslCert=null,"
+ " clientSslCert=null, clientSslKey=null, clientSslPassword=null, sslMode=TRUST,"
+ " sslTunnelDisableHostVerification=false, pamOtherPwd=*,*,"
+ " autoCommit=true, permitRedirect=true}",
+ " autoCommit=true}",
builder.toString());
MariadbConnectionConfiguration conf = builder.build();
Assertions.assertEquals("sslMode=trust", conf.getSslConfig().toString());
Expand Down