Skip to content

Commit

Permalink
ignore slice if data partitions are not used
Browse files Browse the repository at this point in the history
  • Loading branch information
patriknw committed Feb 9, 2024
1 parent a42a479 commit 2c104c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion core/src/main/scala/akka/persistence/r2dbc/internal/Sql.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,32 @@ object Sql {
}
}

final class Cache {
object Cache {
def apply(dataPartitionsEnabled: Boolean): Cache =
if (dataPartitionsEnabled) new CacheBySlice
else new CacheIgnoringSlice
}

sealed trait Cache {
def get(slice: Int, key: Any)(orCreate: => String): String
}

private final class CacheIgnoringSlice extends Cache {
private var entries: Map[Any, String] = Map.empty

def get(slice: Int, key: Any)(orCreate: => String): String = {
entries.get(key) match {
case Some(value) => value
case None =>
// it's just a cache so no need for guarding concurrent updates
val entry = orCreate
entries = entries.updated(key, entry)
entry
}
}
}

private final class CacheBySlice extends Cache {
private var entriesPerSlice: IntMap[Map[Any, String]] = IntMap.empty

def get(slice: Int, key: Any)(orCreate: => String): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private[r2dbc] class PostgresJournalDao(executorProvider: R2dbcExecutorProvider)

protected val persistenceExt: Persistence = Persistence(system)

private val sqlCache = new Sql.Cache
private val sqlCache = Sql.Cache(settings.numberOfDataPartitions > 1)

protected def journalTable(slice: Int): String = settings.journalTableWithSchema(slice)

Expand Down

0 comments on commit 2c104c1

Please sign in to comment.