Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added information about backup controller marker transaction state #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import jetbrains.exodus.env.Environment
import jetbrains.exodus.env.EnvironmentImpl
import jetbrains.exodus.env.Transaction
import jetbrains.exodus.management.MBeanBase
import mu.KLogging
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock

class BackupController(private val env: EnvironmentImpl) : MBeanBase(getObjectName(env)),
BackupControllerMBean {

private var backupTransaction: Transaction? = null
private val backupTransactionLock = ReentrantLock()

override fun prepareBackup() {
override fun prepareBackup() {
backupTransactionLock.lock()
try {
if (backupTransaction != null) {
Expand All @@ -51,11 +53,18 @@ class BackupController(private val env: EnvironmentImpl) : MBeanBase(getObjectNa
backupTransaction!!.abort()
backupTransaction = null
env.finishBackup()
} catch (e: Throwable) {
logger.error("Failed to finish backup on environment ${env.location}", e)
throw e
} finally {
backupTransactionLock.unlock()
}
}

override val backupInProgress get() = backupTransactionLock.withLock {
backupTransaction != null
}

override fun close() {
backupTransactionLock.lock()
try {
Expand All @@ -70,8 +79,8 @@ class BackupController(private val env: EnvironmentImpl) : MBeanBase(getObjectNa
super.close()
}

companion object {
companion object: KLogging() {
internal fun getObjectName(env: Environment) =
"$BACKUP_CONTROLLER_NAME_PREFIX, location=${escapeLocation(env.location)}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ const val BACKUP_CONTROLLER_NAME_PREFIX = "jetbrains.exodus.env: type=BackupCont
interface BackupControllerMBean {
fun prepareBackup()
fun finishBackup()
}

val backupInProgress: Boolean
}
Loading