Skip to content
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 conf entry jdbc.storage_engine to change storage engine #555

Merged
merged 7 commits into from
Jun 5, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ public static synchronized MysqlOptions instance() {
disallowEmpty(),
"disable"
);

public static final ConfigOption<String> STORAGE_ENGINE =
new ConfigOption<>(
"jdbc.storage_engine",
"The storage engine of backend store database, like InnoDB/MyISAM/RocksDB for MySQL.",
disallowEmpty(),
"InnoDB"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,25 @@ public class Session extends BackendSession {
private Map<String, PreparedStatement> statements;
private boolean opened;
private int count;
private HugeConfig config;

public Session() {
this.conn = null;
this.statements = new HashMap<>();
this.opened = false;
this.count = 0;
this.config = MysqlSessions.this.config();
wenzhenghu marked this conversation as resolved.
Show resolved Hide resolved
try {
this.open();
} catch (SQLException ignored) {
// Ignore
}
}

public HugeConfig config() {
return this.config;
wenzhenghu marked this conversation as resolved.
Show resolved Hide resolved
}

public void open() throws SQLException {
if (this.conn != null && !this.conn.isClosed()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void createTable(Session session, TableDefine tableDefine) {
}
}
sql.append("))");
sql.append(this.engine());
sql.append(this.engine(session));
sql.append(";");

LOG.debug("Create table: {}", sql);
Expand All @@ -116,6 +116,11 @@ protected void createTable(Session session, TableDefine tableDefine) {
}
}

protected String engine(Session session) {
wenzhenghu marked this conversation as resolved.
Show resolved Hide resolved
String engine = session.config().get(MysqlOptions.STORAGE_ENGINE);
return " ENGINE=" + engine;
}

wenzhenghu marked this conversation as resolved.
Show resolved Hide resolved
protected String engine() {
return " ENGINE=InnoDB";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.baidu.hugegraph.backend.store.mysql.MysqlBackendEntry;
import com.baidu.hugegraph.backend.store.mysql.MysqlTable;
import com.baidu.hugegraph.backend.store.mysql.MysqlSessions.Session;
import com.baidu.hugegraph.type.define.HugeKeys;

public abstract class PostgresqlTable extends MysqlTable {
Expand All @@ -50,6 +51,11 @@ protected String engine() {
return Strings.EMPTY;
}

@Override
protected String engine(Session session) {
return Strings.EMPTY;
}

wenzhenghu marked this conversation as resolved.
Show resolved Hide resolved
@Override
protected List<Object> buildInsertObjects(MysqlBackendEntry.Row entry) {
List<Object> objects = new ArrayList<>();
Expand Down