Skip to content

Commit

Permalink
R2dbcExecutor internal stable api
Browse files Browse the repository at this point in the history
* and utility to retrieve connection factory names
  • Loading branch information
patriknw committed Feb 1, 2024
1 parent 5158835 commit 6045de1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
22 changes: 18 additions & 4 deletions core/src/main/scala/akka/persistence/r2dbc/R2dbcSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ object R2dbcSettings {
cfg.root.unwrapped.asScala.toMap.map { case (k, v) => k -> v.toString }
}

/**
* The config paths for the connection factories that are used for the given number of data partitions and databases.
*/
def connectionFactoryConfigPaths(
baseConfigPath: String,
numberOfDataPartitions: Int,
numberOfDatabases: Int): immutable.IndexedSeq[String] = {
if (numberOfDatabases == 1) {
Vector(baseConfigPath)
} else {
val rangeSize = numberOfDataPartitions / numberOfDatabases
(0 until numberOfDatabases).map { i =>
s"$baseConfigPath-${i * rangeSize}-${i * rangeSize + rangeSize - 1}"
}
}
}

}

/**
Expand Down Expand Up @@ -242,10 +259,7 @@ final class R2dbcSettings private (
}
}

/**
* INTERNAL API
*/
@InternalApi private[akka] val numberOfDatabases: Int = _connectionFactorySettings.size
val numberOfDatabases: Int = _connectionFactorySettings.size

val dataPartitionSliceRanges: immutable.IndexedSeq[Range] = {
val rangeSize = NumberOfSlices / numberOfDataPartitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import org.slf4j.Logger
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

import akka.annotation.InternalApi
import akka.persistence.r2dbc.ConnectionFactoryProvider
import akka.persistence.r2dbc.R2dbcSettings

Expand Down Expand Up @@ -392,7 +391,7 @@ class R2dbcExecutor(
/**
* INTERNAL API
*/
@InternalApi private[akka] class R2dbcExecutorProvider(
@InternalStableApi class R2dbcExecutorProvider(
val settings: R2dbcSettings,
connectionFactoryBaseConfigPath: String,
log: Logger)(implicit ec: ExecutionContext, system: ActorSystem[_]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ class R2dbcSettingsSpec extends AnyWordSpec with TestSuite with Matchers {
settings.connectionFactorSliceRanges.size shouldBe 2
settings.connectionFactorSliceRanges(0) should be(0 until 512)
settings.connectionFactorSliceRanges(1) should be(512 until 1024)

val configPaths =
R2dbcSettings.connectionFactoryConfigPaths(
"a.b.connection-factory",
numberOfDataPartitions = 8,
numberOfDatabases = 2)
configPaths.size shouldBe 2
configPaths(0) shouldBe "a.b.connection-factory-0-3"
configPaths(1) shouldBe "a.b.connection-factory-4-7"
}

"use default connection-factory config property when one database" in {
Expand Down

0 comments on commit 6045de1

Please sign in to comment.