Skip to content

Commit

Permalink
[data-catalog] create cuttle "readOnlyConnect" method (#604)
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.
  • Loading branch information
Andrei-Emanuel Vasilescu authored Mar 18, 2021
1 parent 4e4cf48 commit 738714d
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.info("Allocated new read-only Hikari transactor")
connections.getOrElseUpdate(dbConfig, transactor)
}
}

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

0 comments on commit 738714d

Please sign in to comment.