Skip to content

Commit

Permalink
obtain lock before initializing tables
Browse files Browse the repository at this point in the history
  • Loading branch information
pm47 committed Apr 19, 2021
1 parent e8872f0 commit 38dba58
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions eclair-core/src/main/scala/fr/acinq/eclair/db/Databases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ object Databases extends Logging {
implicit val ds: HikariDataSource = new HikariDataSource(hikariConfig)
implicit val implicitLock: PgLock = lock

lock match {
case PgLock.NoLock => ()
case l: PgLock.LeaseLock =>
// we obtain a lock right now...
l.obtainExclusiveLock(ds)
// ...and renew the lease regularly
import system.dispatcher
system.scheduler.scheduleWithFixedDelay(l.leaseRenewInterval, l.leaseRenewInterval)(() => l.obtainExclusiveLock(ds))
}

val databases = PostgresDatabases(
network = new PgNetworkDb,
audit = new PgAuditDb,
Expand All @@ -113,16 +123,6 @@ object Databases extends Logging {
dataSource = ds,
lock = lock)

lock match {
case PgLock.NoLock => ()
case l: PgLock.LeaseLock =>
// we obtain a lock right now...
databases.obtainExclusiveLock()
// ...and renew the lease regularly
import system.dispatcher
system.scheduler.scheduleWithFixedDelay(l.leaseRenewInterval, l.leaseRenewInterval)(() => databases.obtainExclusiveLock())
}

readOnlyUser_opt.foreach { readOnlyUser =>
PgUtils.inTransaction { connection =>
using(connection.createStatement()) { statement =>
Expand Down

0 comments on commit 38dba58

Please sign in to comment.