Skip to content

Commit

Permalink
Fix the build (#1945)
Browse files Browse the repository at this point in the history
* disable pg lock auto-release in tests

It relies on akka's coordinated shutdown and causes the test jvm to
halt.

* fixup! Remove  `messageFlags` from `ChannelUpdate` (#1941)
  • Loading branch information
pm47 authored Sep 9, 2021
1 parent 64f33ba commit 24dd613
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
5 changes: 1 addition & 4 deletions eclair-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ eclair {
interval = 5 minutes // lease-interval must be greater than lease-renew-interval
renew-interval = 1 minute
lock-timeout = 5 seconds // timeout for the lock statement on the lease table
auto-release-at-shutdown = true // automatically release the lock when eclair is stopping
}
}
}
Expand Down Expand Up @@ -430,10 +431,6 @@ akka {
}
}

// we rely on coordinated shutdown to gracefully release the postgres lock
coordinated-shutdown.terminate-actor-system = on
coordinated-shutdown.exit-jvm = on

cluster {
role {
backend.min-nr-of-members = 1
Expand Down
24 changes: 14 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 @@ -115,15 +115,18 @@ object Databases extends Logging {
import system.dispatcher
val leaseLockTask = system.scheduler.scheduleWithFixedDelay(l.leaseRenewInterval, l.leaseRenewInterval)(() => l.obtainExclusiveLock(ds))

CoordinatedShutdown(system).addTask(CoordinatedShutdown.PhaseActorSystemTerminate, "release-postgres-lock") { () =>
Future {
logger.info("cancelling the pg lock renew task...")
leaseLockTask.cancel()
logger.info("releasing the curent pg lock...")
l.releaseExclusiveLock(ds)
logger.info("closing the connection pool...")
ds.close()
Done
if (l.autoReleaseAtShutdown) {
CoordinatedShutdown(system).addTask(CoordinatedShutdown.PhaseActorSystemTerminate, "release-postgres-lock") { () =>
Future {
logger.info("cancelling the pg lock renew task...")
leaseLockTask.cancel()
logger.info("releasing the curent pg lock...")
l.releaseExclusiveLock(ds)
Thread.sleep(3000)
logger.info("closing the connection pool...")
ds.close()
Done
}
}
}
}
Expand Down Expand Up @@ -235,7 +238,8 @@ object Databases extends Logging {
// by other threads. That timeout gives time for other transactions to complete, then ours can take the lock
val lockTimeout = dbConfig.getDuration("postgres.lease.lock-timeout").toSeconds.seconds
hikariConfig.setConnectionInitSql(s"SET lock_timeout TO '${lockTimeout.toSeconds}s'")
PgLock.LeaseLock(instanceId, leaseInterval, leaseRenewInterval, lockExceptionHandler)
val autoReleaseAtShutdown = dbConfig.getBoolean("postgres.lease.auto-release-at-shutdown")
PgLock.LeaseLock(instanceId, leaseInterval, leaseRenewInterval, lockExceptionHandler, autoReleaseAtShutdown)
case unknownLock => throw new RuntimeException(s"unknown postgres lock type: `$unknownLock`")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object PgUtils extends JdbcUtils {
*
* `lockExceptionHandler` provides a lock exception handler to customize the behavior when locking errors occur.
*/
case class LeaseLock(instanceId: UUID, leaseDuration: FiniteDuration, leaseRenewInterval: FiniteDuration, lockFailureHandler: LockFailureHandler) extends PgLock {
case class LeaseLock(instanceId: UUID, leaseDuration: FiniteDuration, leaseRenewInterval: FiniteDuration, lockFailureHandler: LockFailureHandler, autoReleaseAtShutdown: Boolean) extends PgLock {

import LeaseLock._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object TestDatabases {
val datasource: DataSource = pg.getPostgresDatabase
val hikariConfig = new HikariConfig
hikariConfig.setDataSource(datasource)
val lock: PgLock.LeaseLock = PgLock.LeaseLock(UUID.randomUUID(), 10 minutes, 8 minute, LockFailureHandler.logAndThrow)
val lock: PgLock.LeaseLock = PgLock.LeaseLock(UUID.randomUUID(), 10 minutes, 8 minute, LockFailureHandler.logAndThrow, autoReleaseAtShutdown = false)

val jdbcUrlFile: File = new File(TestUtils.BUILD_DIRECTORY, s"jdbcUrlFile_${UUID.randomUUID()}.tmp")
jdbcUrlFile.deleteOnExit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class PgUtilsSpec extends TestKitBaseClass with AnyFunSuiteLike with Eventually
val pg = EmbeddedPostgres.start()
val ds: DataSource = pg.getPostgresDatabase

val lock1 = LeaseLock(UUID.randomUUID(), 2 minutes, 1 minute, LockFailureHandler.logAndThrow)
val lock2 = LeaseLock(UUID.randomUUID(), 2 minutes, 1 minute, LockFailureHandler.logAndThrow)
val lock1 = LeaseLock(UUID.randomUUID(), 2 minutes, 1 minute, LockFailureHandler.logAndThrow, autoReleaseAtShutdown = false)
val lock2 = LeaseLock(UUID.randomUUID(), 2 minutes, 1 minute, LockFailureHandler.logAndThrow, autoReleaseAtShutdown = false)

lock1.obtainExclusiveLock(ds)
intercept[LockFailureHandler.LockException] {
Expand Down Expand Up @@ -216,6 +216,7 @@ object PgUtilsSpec extends Logging {
| interval = 5 seconds // lease-interval must be greater than lease-renew-interval
| renew-interval = 2 seconds
| lock-timeout = 5 seconds // timeout for the lock statement on the lease table
| auto-release-at-shutdown = false // automatically release the lock when eclair is stopping
| }
|}
|""".stripMargin
Expand Down
Loading

0 comments on commit 24dd613

Please sign in to comment.