Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanvuong2021 committed Dec 18, 2024
1 parent 966a317 commit 85bf04d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 72 deletions.
6 changes: 0 additions & 6 deletions imports/java/io/r2dbc/pool/BUILD.bazel

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ kt_jvm_library(
srcs = ["PostgresConnectionFactories.kt"],
deps = [
"//imports/java/com/google/cloud/sql:r2dbc-core",
"//imports/java/io/r2dbc/pool",
"//imports/java/org/postgresql:r2dbc",
"//src/main/kotlin/org/wfanet/measurement/gcloud/postgres:flags",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,24 @@
package org.wfanet.measurement.gcloud.postgres

import com.google.cloud.sql.core.GcpConnectionFactoryProvider
import io.r2dbc.pool.ConnectionPool
import io.r2dbc.pool.ConnectionPoolConfiguration
import io.r2dbc.spi.ConnectionFactories
import io.r2dbc.spi.ConnectionFactory
import io.r2dbc.spi.ConnectionFactoryOptions

object PostgresConnectionFactories {
@JvmStatic
fun buildConnectionFactory(flags: PostgresFlags): ConnectionFactory {
val connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(ConnectionFactoryOptions.DRIVER, "gcp")
.option(ConnectionFactoryOptions.PROTOCOL, "postgresql")
.option(ConnectionFactoryOptions.USER, flags.user)
// a non-empty password is required, but the value doesn't matter
.option(ConnectionFactoryOptions.PASSWORD, "UNUSED")
.option(ConnectionFactoryOptions.DATABASE, flags.database)
.option(ConnectionFactoryOptions.HOST, flags.cloudSqlInstance)
.option(ConnectionFactoryOptions.STATEMENT_TIMEOUT, flags.statementTimeout)
.option(GcpConnectionFactoryProvider.ENABLE_IAM_AUTH, true)
.build()
)

val configuration: ConnectionPoolConfiguration =
ConnectionPoolConfiguration.builder(connectionFactory)
.maxIdleTime(flags.maxIdleTime)
.maxSize(flags.maxPoolSize)
.acquireRetry(flags.acquireRetry)
return ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(ConnectionFactoryOptions.DRIVER, "gcp")
.option(ConnectionFactoryOptions.PROTOCOL, "postgresql")
.option(ConnectionFactoryOptions.USER, flags.user)
// a non-empty password is required, but the value doesn't matter
.option(ConnectionFactoryOptions.PASSWORD, "UNUSED")
.option(ConnectionFactoryOptions.DATABASE, flags.database)
.option(ConnectionFactoryOptions.HOST, flags.cloudSqlInstance)
.option(GcpConnectionFactoryProvider.ENABLE_IAM_AUTH, true)
.build()

return ConnectionPool(configuration)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,31 @@

package org.wfanet.measurement.gcloud.postgres

import java.time.Duration
import kotlin.properties.Delegates
import picocli.CommandLine

/** Common command-line flags for connecting to a single Postgres database. */
class PostgresFlags {
@CommandLine.Option(
names = ["--postgres-database"],
description = ["Name of the Postgres database."],
required = true,
required = true
)
lateinit var database: String
private set

@CommandLine.Option(
names = ["--postgres-cloud-sql-connection-name"],
description = ["Instance connection name of the Postgres database."],
required = true,
required = true
)
lateinit var cloudSqlInstance: String
private set

@CommandLine.Option(
names = ["--postgres-user"],
description = ["User of the Postgres database."],
required = true,
required = true
)
lateinit var user: String
private set

@CommandLine.Option(
names = ["--statement-timeout"],
description = ["Statement timeout duration."],
required = false,
defaultValue = "120s",
)
lateinit var statementTimeout: Duration
private set

@CommandLine.Option(
names = ["--max-idle-time"],
description = ["Maximum duration a connection can be idle before being closed."],
required = false,
defaultValue = "5m",
)
lateinit var maxIdleTime: Duration
private set

@set:CommandLine.Option(
names = ["--max-connection-pool-size"],
description = ["Maximum number of connections in pool."],
required = false,
defaultValue = "16",
)
var maxPoolSize by Delegates.notNull<Int>()
private set

@set:CommandLine.Option(
names = ["--acquire-retry"],
description = ["Maximum number of retries when acquiring a connection from the pool."],
required = false,
defaultValue = "10",
)
var acquireRetry by Delegates.notNull<Int>()
private set
}

0 comments on commit 85bf04d

Please sign in to comment.