From 1ef4ec34e2c27ba6d15121cd0f2f3ecd6965fefa Mon Sep 17 00:00:00 2001 From: Andrei Vasilescu Date: Thu, 18 Mar 2021 11:29:42 +0200 Subject: [PATCH] [data-catalog] create cuttle "readOnlyConnect" method In the read only connection, the db lock is bypassed and the transactor is returned as is. JIRA: DPT-2819 --- core/src/main/scala/com/criteo/cuttle/Database.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/scala/com/criteo/cuttle/Database.scala b/core/src/main/scala/com/criteo/cuttle/Database.scala index 229ac6d8a..64f1b1951 100644 --- a/core/src/main/scala/com/criteo/cuttle/Database.scala +++ b/core/src/main/scala/com/criteo/cuttle/Database.scala @@ -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) {