Skip to content

Commit

Permalink
* mysql: patched mysql jdbc driver to support virtual thread and gclo…
Browse files Browse the repository at this point in the history
…ud auth

  > use "core.framework.mysql:mysql-connector-j:8.2.0-p1"

Signed-off-by: neo <[email protected]>
  • Loading branch information
neowu committed Dec 11, 2023
1 parent e083892 commit 85c8c92
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 141 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## Change log

### 9.0.2 (12/7/2023 - )
### 9.0.2-b0 (12/7/2023 - )

* stats: dump virtual threads on high cpu
* http: response "connection: keep-alive" header if client sends keep-alive header
> to be compatible with http/1.0 client, like ab (apache benchmark) with "-k"
* mysql: patched mysql jdbc driver to support virtual thread and gcloud auth
> use "core.framework.mysql:mysql-connector-j:8.2.0-p1"
### 9.0.1 (12/01/2023 - 12/7/2023)

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply(plugin = "project")

subprojects {
group = "core.framework"
version = "9.0.2"
version = "9.0.2-b0"

repositories {
maven {
Expand Down Expand Up @@ -43,7 +43,7 @@ project("core-ng") {
implementation("io.undertow:undertow-core:2.3.10.Final")
implementation("org.apache.kafka:kafka-clients:${kafkaVersion}@jar")
implementation("org.xerial.snappy:snappy-java:1.1.10.5") // used by kafka message compression
compileOnly("com.mysql:mysql-connector-j:${mysqlVersion}")
compileOnly("core.framework.mysql:mysql-connector-j:8.2.0-p1")
compileOnly("org.jboss.logging:jboss-logging-annotations:2.2.1.Final")
compileOnly("com.github.spotbugs:spotbugs-annotations:4.8.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
Expand Down
126 changes: 0 additions & 126 deletions core-ng/src/main/java/com/mysql/cj/CancelQueryTaskImpl.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core.framework.internal.db.cloud;
package core.framework.db;

/**
* @author neo
Expand All @@ -7,4 +7,8 @@ public interface CloudAuthProvider {
String user();

String accessToken();

class Registry {
public static CloudAuthProvider INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.mysql.cj.conf.PropertyDefinitions;
import com.mysql.cj.conf.PropertyKey;
import core.framework.db.CloudAuthProvider;
import core.framework.db.Database;
import core.framework.db.IsolationLevel;
import core.framework.db.Repository;
import core.framework.db.Transaction;
import core.framework.db.UncheckedSQLException;
import core.framework.internal.db.cloud.CloudAuthProvider;
import core.framework.internal.db.cloud.GCloudAuthProvider;
import core.framework.internal.log.ActionLog;
import core.framework.internal.log.LogManager;
Expand Down Expand Up @@ -36,8 +36,6 @@
* @author neo
*/
public final class DatabaseImpl implements Database {
public static final String PROPERTY_KEY_AUTH_PROVIDER = "authProvider";

static {
// disable unnecessary mysql connection cleanup thread to reduce overhead
System.setProperty(PropertyDefinitions.SYSP_disableAbandonedConnectionCleanup, "true");
Expand Down Expand Up @@ -135,7 +133,6 @@ Properties driverProperties(String url) {
// refer to https://cloud.google.com/sql/docs/mysql/authentication
if (authProvider != null) {
properties.setProperty(PropertyKey.sslMode.getKeyName(), PropertyDefinitions.SslMode.PREFERRED.name());
properties.setProperty(PROPERTY_KEY_AUTH_PROVIDER, "gcloud");
} else if (index == -1 || url.indexOf("sslMode=", index + 1) == -1) {
properties.setProperty(PropertyKey.sslMode.getKeyName(), PropertyDefinitions.SslMode.DISABLED.name());
}
Expand Down Expand Up @@ -165,7 +162,8 @@ public void timeout(Duration timeout) {
public void authProvider(String provider) {
logger.info("use cloud auth provider, provider={}", provider);
if ("gcloud".equals(provider)) {
authProvider = GCloudAuthProvider.INSTANCE;
authProvider = new GCloudAuthProvider();
CloudAuthProvider.Registry.INSTANCE = authProvider;
} else {
throw new Error("unsupported cloud auth provider, provider=" + provider);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package core.framework.internal.db.cloud;

import core.framework.db.CloudAuthProvider;
import core.framework.http.HTTPClient;
import core.framework.http.HTTPMethod;
import core.framework.http.HTTPRequest;
Expand All @@ -11,9 +12,6 @@
* @author neo
*/
public final class GCloudAuthProvider implements CloudAuthProvider {
// in cloud env, only need one instance per pod, and will be accessed by MySQL CancelQueryTaskImpl
public static final GCloudAuthProvider INSTANCE = new GCloudAuthProvider();

// for timeout settings, refer to gcloud sdk com.google.auth.oauth2.ComputeEngineCredentials#runningOnComputeEngine
private final HTTPClient httpClient = HTTPClient.builder()
.connectTimeout(Duration.ofMillis(500))
Expand All @@ -26,9 +24,6 @@ public final class GCloudAuthProvider implements CloudAuthProvider {
String accessToken;
long expirationTime;

GCloudAuthProvider() {
}

@Override
public String user() {
// email won't change once pod created
Expand Down

0 comments on commit 85c8c92

Please sign in to comment.