From 738714d64fad3a950cb38b4b9dcaf6d1f14b30d0 Mon Sep 17 00:00:00 2001 From: Andrei-Emanuel Vasilescu Date: Thu, 18 Mar 2021 11:54:34 +0200 Subject: [PATCH] [data-catalog] create cuttle "readOnlyConnect" method (#604) In the read only connection, the db lock is bypassed and the transactor is returned as is. --- 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..89d8cd68b 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.info("Allocated new read-only Hikari transactor") + connections.getOrElseUpdate(dbConfig, transactor) + } } private[cuttle] case class Queries(logger: Logger) {