Skip to content

Commit

Permalink
[data-catalog] create cuttle "readOnlyConnect" method
Browse files Browse the repository at this point in the history
In the read only connection, the db lock is bypassed and the transactor is
returned as is.

JIRA: DPT-2819
  • Loading branch information
Andrei Vasilescu committed Mar 18, 2021
1 parent 4e4cf48 commit 1ef4ec3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/src/main/scala/com/criteo/cuttle/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ object Database {
}
)
}

/* To be used only with a read-only db user as the mandatory lock check / creation is bypassed. */
def readOnlyConnect(dbConfig: DatabaseConfig)(implicit logger: Logger): XA = {
// FIXME we shouldn't use allocated as it's unsafe instead we have to flatMap on the Resource[HikariTransactor]
val (transactor, _) = newHikariTransactor(dbConfig).allocated.unsafeRunSync
logger.debug("Allocated new read-only Hikari transactor")
connections.getOrElseUpdate(dbConfig, transactor)
}
}

private[cuttle] case class Queries(logger: Logger) {
Expand Down

0 comments on commit 1ef4ec3

Please sign in to comment.