Skip to content

Commit

Permalink
Add PostgreSQL as backend database for kyuubi metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tigrulya-exe committed Jan 29, 2024
1 parent d474768 commit b638c89
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 19 deletions.
36 changes: 18 additions & 18 deletions docs/configuration/settings.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ object JdbcUtils extends Logging {
val duplicatedKeyKeywords = Seq(
"duplicate key value in a unique or primary key constraint or unique index", // Derby
"Duplicate entry", // MySQL
"duplicate key value violates unique constraint", // PostgreSQL
"A UNIQUE constraint failed" // SQLite
)
duplicatedKeyKeywords.exists(cause.getMessage.contains)
Expand Down
5 changes: 5 additions & 0 deletions kyuubi-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<artifactId>sqlite-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CREATE TABLE IF NOT EXISTS metadata(
key_id bigserial PRIMARY KEY,
identifier varchar(36) NOT NULL,
session_type varchar(32) NOT NULL,
real_user varchar(255) NOT NULL,
user_name varchar(255) NOT NULL,
ip_address varchar(128),
kyuubi_instance varchar(1024),
state varchar(128) NOT NULL,
resource varchar(1024),
class_name varchar(1024),
request_name varchar(1024),
request_conf text,
request_args text,
create_time bigint NOT NULL,
engine_type varchar(32) NOT NULL,
cluster_manager varchar(128),
engine_open_time bigint,
engine_id varchar(128),
engine_name text,
engine_url varchar(1024),
engine_state varchar(32),
engine_error text,
end_time bigint,
priority int NOT NULL DEFAULT 10,
peer_instance_closed boolean DEFAULT FALSE
);

COMMENT ON COLUMN metadata.key_id IS 'the auto increment key id';
COMMENT ON COLUMN metadata.identifier IS 'the identifier id, which is an UUID';
COMMENT ON COLUMN metadata.session_type IS 'the session type, SQL or BATCH';
COMMENT ON COLUMN metadata.real_user IS 'the real user';
COMMENT ON COLUMN metadata.user_name IS 'the user name, might be a proxy user';
COMMENT ON COLUMN metadata.ip_address IS 'the client ip address';
COMMENT ON COLUMN metadata.kyuubi_instance IS 'the kyuubi instance that creates this';
COMMENT ON COLUMN metadata.state IS 'the session state';
COMMENT ON COLUMN metadata.resource IS 'the main resource';
COMMENT ON COLUMN metadata.class_name IS 'the main class name';
COMMENT ON COLUMN metadata.request_name IS 'the request name';
COMMENT ON COLUMN metadata.request_conf IS 'the request config map';
COMMENT ON COLUMN metadata.request_args IS 'the request arguments';
COMMENT ON COLUMN metadata.create_time IS 'the metadata create time';
COMMENT ON COLUMN metadata.engine_type IS 'the engine type';
COMMENT ON COLUMN metadata.cluster_manager IS 'the engine cluster manager';
COMMENT ON COLUMN metadata.engine_open_time IS 'the engine open time';
COMMENT ON COLUMN metadata.engine_id IS 'the engine application id';
COMMENT ON COLUMN metadata.engine_name IS 'the engine application name';
COMMENT ON COLUMN metadata.engine_url IS 'the engine tracking url';
COMMENT ON COLUMN metadata.engine_state IS 'the engine application state';
COMMENT ON COLUMN metadata.engine_error IS 'the engine application diagnose';
COMMENT ON COLUMN metadata.end_time IS 'the metadata end time';
COMMENT ON COLUMN metadata.priority IS 'the application priority, high value means high priority';
COMMENT ON COLUMN metadata.peer_instance_closed IS 'closed by peer kyuubi instance';

CREATE UNIQUE INDEX unique_identifier_index ON metadata(identifier);
CREATE INDEX user_name_index ON metadata(user_name);
CREATE INDEX engine_type_index ON metadata(engine_type);
CREATE INDEX create_time_index ON metadata(create_time);
CREATE INDEX priority_create_time_index ON metadata(priority DESC, create_time ASC);
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ package org.apache.kyuubi.server.metadata.jdbc
object DatabaseType extends Enumeration {
type DatabaseType = Value

val DERBY, MYSQL, CUSTOM, SQLITE = Value
val DERBY, MYSQL, CUSTOM, SQLITE, POSTGRESQL = Value
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
case SQLITE => driverClassOpt.getOrElse("org.sqlite.JDBC")
case DERBY => driverClassOpt.getOrElse("org.apache.derby.jdbc.AutoloadedDriver")
case MYSQL => driverClassOpt.getOrElse(mysqlDriverClass)
case POSTGRESQL => driverClassOpt.getOrElse("org.postgresql.Driver")
case CUSTOM => driverClassOpt.getOrElse(
throw new IllegalArgumentException("No jdbc driver defined"))
}
Expand All @@ -65,6 +66,7 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
case DERBY => new DerbyDatabaseDialect
case SQLITE => new SQLiteDatabaseDialect
case MYSQL => new MySQLDatabaseDialect
case POSTGRESQL => new PostgreSQLDatabaseDialect
case CUSTOM => new GenericDatabaseDialect
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ object JDBCMetadataStoreConf {
"`org.apache.derby.jdbc.AutoloadedDriver`.</li>" +
" <li>SQLITE: SQLite3, JDBC driver `org.sqlite.JDBC`.</li>" +
" <li>MYSQL: MySQL, JDBC driver `com.mysql.cj.jdbc.Driver` " +
" <li>POSTGRESQL: PostgreSQL, JDBC driver `org.postgresql.Driver` " +
"(fallback `com.mysql.jdbc.Driver`).</li>" +
" <li>CUSTOM: User-defined database type, need to specify corresponding JDBC driver.</li>" +
" Note that: The JDBC datasource is powered by HiKariCP, for datasource properties," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ class GenericDatabaseDialect extends JdbcDatabaseDialect {

class SQLiteDatabaseDialect extends GenericDatabaseDialect {}
class MySQLDatabaseDialect extends GenericDatabaseDialect {}
class PostgreSQLDatabaseDialect extends GenericDatabaseDialect {}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class JDBCMetadataStoreSuite extends KyuubiFunSuite {
test("test get init schema stream") {
assert(jdbcMetadataStore.getInitSchema(DatabaseType.DERBY).isDefined)
assert(jdbcMetadataStore.getInitSchema(DatabaseType.MYSQL).isDefined)
assert(jdbcMetadataStore.getInitSchema(DatabaseType.POSTGRESQL).isDefined)
assert(jdbcMetadataStore.getInitSchema(DatabaseType.CUSTOM).isEmpty)
}

Expand Down

0 comments on commit b638c89

Please sign in to comment.