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

Dont bind Vitess scale checks if not using Vitess #891

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,20 +37,21 @@ class HibernateTestingModule(
val transacterKey = Transacter::class.toKey(qualifier)
val transacterProvider = getProvider(transacterKey)

if ((config == null || config.type == DataSourceType.VITESS)
&& !disableCrossShardQueryDetector) {
val useVitessChecks = ((config == null || config.type == DataSourceType.VITESS)
&& !disableCrossShardQueryDetector)
if (useVitessChecks) {
bindVitessChecks()
}

multibind<Service>().to(truncateTablesServiceKey)
bind(truncateTablesServiceKey).toProvider(object : Provider<TruncateTablesService> {
@Inject(optional = true) var checks: VitessScaleSafetyChecks? = null
@Inject(optional = true) var vitessScaleSafetyChecks: VitessScaleSafetyChecks? = null

override fun get(): TruncateTablesService = TruncateTablesService(
qualifier = qualifier,
config = configProvider.get(),
transacterProvider = transacterProvider,
checks = checks,
vitessScaleSafetyChecks = if (useVitessChecks) vitessScaleSafetyChecks else null,
startUpStatements = startUpStatements,
shutDownStatements = shutDownStatements
)
Expand Down
Expand Up @@ -29,7 +29,7 @@ class TruncateTablesService(
private val qualifier: KClass<out Annotation>,
private val config: DataSourceConfig,
private val transacterProvider: Provider<Transacter>,
private val checks: VitessScaleSafetyChecks? = null,
private val vitessScaleSafetyChecks: VitessScaleSafetyChecks? = null,
private val startUpStatements: List<String> = listOf(),
private val shutDownStatements: List<String> = listOf()
) : AbstractIdleService(), DependentService {
Expand All @@ -39,22 +39,22 @@ class TruncateTablesService(
override val producedKeys = setOf<Key<*>>(TruncateTablesService::class.toKey(qualifier))

override fun startUp() {
if (checks == null) {
if (vitessScaleSafetyChecks == null) {
truncateUserTables()
executeStatements(startUpStatements, "startup")
} else {
checks.disable {
vitessScaleSafetyChecks.disable {
truncateUserTables()
executeStatements(startUpStatements, "startup")
}
}
}

override fun shutDown() {
if (checks == null) {
if (vitessScaleSafetyChecks == null) {
executeStatements(shutDownStatements, "shutdown")
} else {
checks.disable { executeStatements(shutDownStatements, "shutdown") }
vitessScaleSafetyChecks.disable { executeStatements(shutDownStatements, "shutdown") }
}
}

Expand Down