[feature-usage-database] even less logging

GitOrigin-RevId: bf5c59211b4dc18d2b843a6a1373580ec523e96f
This commit is contained in:
Sasha Blashenkov
2024-04-15 20:26:55 +00:00
committed by intellij-monorepo-bot
parent d8be147b78
commit dbcbef97aa
@@ -95,7 +95,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe
try {
withTimeout(timeout) {
withContext(closeDispatcher) {
closeDatabaseImpl(isFinal)?.join()
closeDatabaseImpl(isFinal, shouldLog)?.join()
if (shouldLog) {
logger.info("Saving completed (reason: $reason)")
}
@@ -133,7 +133,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe
}
@Suppress("OPT_IN_USAGE")
private fun closeDatabaseImpl(isFinal: Boolean): Job? {
private fun closeDatabaseImpl(isFinal: Boolean, shouldLog: Boolean): Job? {
// service scope is dead at this point, need to use GlobalScope
// todo: not true on temp close
fun launchJob(action: suspend CoroutineScope.() -> Unit): Job =
@@ -148,7 +148,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe
val connection = getConn2(this)
if (connection != null) {
logger.info("Connection opened, performing termination.")
close(connection, isFinal = true)
close(connection, isFinal = true, shouldLog = shouldLog)
} else {
logger.info("Connection open failure.")
}
@@ -156,7 +156,7 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe
}
is State.Active -> {
val job = launchJob {
close(state.def.await(), isFinal)
close(state.def.await(), isFinal, shouldLog = shouldLog)
}
val newState = State.Cancelling(state.def, job)
if (myConnection.compareAndSet(state, newState)) {
@@ -249,13 +249,17 @@ class SqliteLazyInitializedDatabase(private val cs: CoroutineScope) : ISqliteExe
}
}
private suspend fun close(connectionHolder: ConnectionHolder, isFinal: Boolean) {
logger.info("close start")
private suspend fun close(connectionHolder: ConnectionHolder, isFinal: Boolean, shouldLog: Boolean) {
if (shouldLog) {
logger.info("close start")
}
connectionHolder.connection.use {
doExecuteBeforeConnectionClosed(isFinal)
}
check(connectionHolder.connection.isClosed)
logger.info("close end")
if (shouldLog) {
logger.info("close end")
}
}
private fun createDatabasePath(): Path? {