Skip to content

Commit

Permalink
fix docker mysql ci not stable (#1710)
Browse files Browse the repository at this point in the history
Change-Id: I8795ddcd9598829375801a06eb539634197fc3e4
Co-authored-by: imbajin <[email protected]>
  • Loading branch information
javeme and imbajin authored Dec 27, 2021
1 parent 0580bae commit 1d031c5
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ private void tryOpen() {

@Override
public void open() {
this.opened = true;
assert this.session == null;
this.session = cluster().connect(keyspace());
this.opened = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public synchronized void open() throws IOException {
String hbaseSite = config.get(HbaseOptions.HBASE_HBASE_SITE);
hConfig.addResource(new Path(hbaseSite));

if(isEnableKerberos) {
if (isEnableKerberos) {
String krb5Conf = config.get(HbaseOptions.HBASE_KRB5_CONF);
System.setProperty("java.security.krb5.conf", krb5Conf);
String principal = config.get(HbaseOptions.HBASE_KERBEROS_PRINCIPAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,12 @@ public synchronized void open(HugeConfig config) {
try {
// NOTE: won't throw error even if connection refused
this.sessions.open();
} catch (Exception e) {
if (!e.getMessage().contains("Column family not found")) {
LOG.error("Failed to open HBase '{}'", this.store, e);
throw new ConnectionException("Failed to connect to HBase", e);
}
if (this.isSchemaStore()) {
LOG.info("Failed to open HBase '{}' with database '{}', " +
"try to init CF later", this.store, this.namespace);
}
} catch (Throwable e) {
LOG.error("Failed to open HBase '{}'", this.store, e);
throw new ConnectionException("Failed to connect to HBase", e);
}

this.sessions.session();
this.sessions.session().open();
LOG.debug("Store opened: {}", this.store);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public static synchronized MysqlOptions instance() {
"******"
);

public static final ConfigOption<Boolean> JDBC_FORCED_AUTO_RECONNECT =
new ConfigOption<>(
"jdbc.forced_auto_reconnect",
"Whether to forced auto reconnect to the database even " +
"if the connection fails at the first time. Note that " +
"forced_auto_reconnect=true will disable fail-fast.",
disallowEmpty(),
false
);

public static final ConfigOption<Integer> JDBC_RECONNECT_MAX_TIMES =
new ConfigOption<>(
"jdbc.reconnect_max_times",
Expand All @@ -98,10 +108,11 @@ public static synchronized MysqlOptions instance() {
"false"
);

public static final ConfigOption<String> STORAGE_ENGINE =
public static final ConfigOption<String> JDBC_STORAGE_ENGINE =
new ConfigOption<>(
"jdbc.storage_engine",
"The storage engine of backend store database, like InnoDB/MyISAM/RocksDB for MySQL.",
"The storage engine of backend store database, " +
"like InnoDB/MyISAM/RocksDB for MySQL.",
disallowEmpty(),
"InnoDB"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ protected String buildUri(boolean withConnParams, boolean withDB,
boolean autoReconnect, Integer timeout) {
String url = this.buildUrlPrefix(withDB);

boolean forcedAutoReconnect = this.config.get(
MysqlOptions.JDBC_FORCED_AUTO_RECONNECT);
int maxTimes = this.config.get(MysqlOptions.JDBC_RECONNECT_MAX_TIMES);
int interval = this.config.get(MysqlOptions.JDBC_RECONNECT_INTERVAL);
String sslMode = this.config.get(MysqlOptions.JDBC_SSL_MODE);
Expand All @@ -235,8 +237,11 @@ protected String buildUri(boolean withConnParams, boolean withDB,
} catch (URISyntaxException e) {
throw new BackendException("Invalid url '%s'", e, url);
}
builder.setParameter("useSSL", sslMode);
if (withConnParams) {

if (forcedAutoReconnect) {
autoReconnect = true;
}
if (withConnParams || forcedAutoReconnect) {
builder.setParameter("characterEncoding", "utf-8")
.setParameter("rewriteBatchedStatements", "true")
.setParameter("useServerPrepStmts", "false")
Expand All @@ -247,6 +252,9 @@ protected String buildUri(boolean withConnParams, boolean withDB,
if (timeout != null) {
builder.setParameter("socketTimeout", String.valueOf(timeout));
}

builder.setParameter("useSSL", sslMode);

return JDBC_PREFIX + builder.toString();
}

Expand Down Expand Up @@ -317,11 +325,11 @@ private void tryOpen() {
}

private void doOpen() throws SQLException {
this.opened = true;
if (this.conn != null && !this.conn.isClosed()) {
return;
}
this.conn = MysqlSessions.this.open(true);
this.opened = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,30 @@ public synchronized void open(HugeConfig config) {

this.sessions = this.openSessionPool(config);

LOG.debug("Store connect with database: {}", this.database);
try {
this.sessions.open();
} catch (Exception e) {
if (!e.getMessage().startsWith("Unknown database") &&
!e.getMessage().endsWith("does not exist")) {
if (this.sessions.existsDatabase()) {
LOG.debug("Store connect with database: {}", this.database);
try {
this.sessions.open();
} catch (Throwable e) {
throw new ConnectionException("Failed to connect to MySQL", e);
}

try {
this.sessions.session().open();
} catch (Throwable e) {
try {
this.sessions.close();
} catch (Throwable e2) {
LOG.warn("Failed to close connection after an error", e2);
}
throw new BackendException("Failed to open database", e);
}
} else {
if (this.isSchemaStore()) {
LOG.info("Failed to open database '{}', " +
"try to init database later", this.database);
}
}

try {
this.sessions.session();
} catch (Throwable e) {
try {
this.sessions.close();
} catch (Throwable e2) {
LOG.warn("Failed to close connection after an error", e2);
}
throw new BackendException("Failed to open database", e);
}

LOG.debug("Store opened: {}", this.store);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void createTable(Session session, TableDefine tableDefine) {
}

protected String engine(Session session) {
String engine = session.config().get(MysqlOptions.STORAGE_ENGINE);
String engine = session.config().get(MysqlOptions.JDBC_STORAGE_ENGINE);
return " ENGINE=" + engine;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ protected RocksDBSessions open(HugeConfig config, String dataPath,
if (sessions != null) {
// May override the original session pool
this.dbs.put(dataPath, sessions);
sessions.session();
sessions.session().open();
LOG.debug("Store opened: {}", dataPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testIntFixedSetBySegments() {
}

@Test
public void testIntFixedSeConcurrent() {
public void testIntFixedSetConcurrent() {
IntSet set = fixed(eachCount);
testIntSetConcurrent(set);
}
Expand Down Expand Up @@ -149,7 +149,7 @@ private void testIntSetConcurrent(IntSet set) {
set.add(k);
}
set.contains(i);
Assert.assertEquals(eachCount, set.size());
set.size();
}
});

Expand Down
1 change: 1 addition & 0 deletions hugegraph-test/src/main/resources/hugegraph.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306
jdbc.username=root
jdbc.password=******
jdbc.forced_auto_reconnect=true
jdbc.reconnect_max_times=3
jdbc.reconnect_interval=3
jdbc.sslmode=disable
Expand Down

0 comments on commit 1d031c5

Please sign in to comment.