我正在使用Scala,Hikari,Doobie,Fiber和Timer,Monix Task。
我会定期运行SQL查询,然后处理结果。 定期任务永远运行。
import cats.effect.{Fiber, Timer}
import cats.implicits._
import monix.eval.Task
import monix.reactive.Observable
// ....
def run(xa: Transactor[Task]): Task[Fiber[Task, Nothing]] = {
logger.info(s"Starting, delay: ${config.delay}")
(execute(xa) *> timer.sleep(config.delay)).foreverM.start
}
private def execute(xa: Transactor[Task]): Task[List[Option[CallResult]]] = {
callModel
.findPending(config.maxTries)
.transact(xa)
.flatMap { calls =>
logger.debug(s"executing: ${calls.size}")
Observable(calls: _*)
.mapParallelUnordered(config.parallelism) {
case (call, callDetails) => executeCall(call, callDetails)
}
.toListL
.orElse {
logger.debug(s"fallbacking to empty list...")
Task.now(List.empty)
}
}
}
private def executeCall(call: Call, callDetails: CallDetails): Task[Option[CallResult]] = ???
问题在于,每次使用HikariTransaction处理查询时,它都会打印到Connection具有Reset autoCommit值的日志中。
16:48:41.350 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:48:41.355 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:48:41.592 [HikariPool-1 housekeeper] DEBUG c.z.h.p.HikariPool - HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)
16:48:46.355 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:48:46.359 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:48:51.361 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:48:51.365 [pool-3-thread-116] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@6cf8c3b4
16:48:56.367 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:48:56.370 [pool-3-thread-116] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@6cf8c3b4
16:49:01.374 [pool-3-thread-114] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1b3168db
16:49:01.374 [pool-3-thread-116] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@6cf8c3b4
16:49:05.166 [HikariPool-1 connection closer] DEBUG c.z.h.p.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@942b76d: (connection has passed maxLifetime)
16:49:05.186 [HikariPool-1 connection adder] DEBUG c.z.h.p.HikariPool - HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@41905dfe
但是我没有在任何地方修改autoCommit值。 我正在使用HikariCP的默认值作为autoCommit = true
09:00:02.184 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - HikariPool-1 - configuration:
09:00:02.190 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - allowPoolSuspension.............false
09:00:02.191 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - autoCommit......................true
09:00:02.191 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - catalog.........................none
09:00:02.192 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - connectionInitSql...............none
09:00:02.192 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - connectionTestQuery.............none
09:00:02.193 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - connectionTimeout...............30000
09:00:02.193 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - dataSource......................none
09:00:02.193 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - dataSourceClassName.............none
09:00:02.194 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - dataSourceJNDI..................none
09:00:02.196 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - dataSourceProperties............{password=<masked>}
09:00:02.197 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - driverClassName.................none
09:00:02.197 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - healthCheckProperties...........{}
09:00:02.198 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - healthCheckRegistry.............none
09:00:02.198 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - idleTimeout.....................600000
09:00:02.198 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - initializationFailTimeout.......1
09:00:02.199 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - isolateInternalQueries..........false
09:00:02.199 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - jdbcUrl.........................jdbc:postgresql://database:5432/carsdb
09:00:02.200 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - leakDetectionThreshold..........0
09:00:02.200 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - maxLifetime.....................1800000
09:00:02.200 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - maximumPoolSize.................10
09:00:02.201 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - metricRegistry..................none
09:00:02.201 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - metricsTrackerFactory...........none
09:00:02.201 [pool-2-thread-1] DEBUG c.z.h.HikariConfig - minimumIdle.....................10
问题
我不知道为什么光会打印这样的日志。
我没有在任何地方修改连接autoCommit
字段。
我有什么想念的吗?
似乎在调用transact(xa)
之后,连接立即返回到池中,这很好。但是由于某些原因,它们似乎改变了autoCommit的值。
我使用的版本: