0

在更新这个庞大的集合时,以下迁移代码似乎卡住了。

@ChangeSet(order = "010", id = "add_tenant_to_product", author = "pn")
fun addTenantToProduct(mongoTemplate: MongoTemplate) {
    log.info("Adding tenants to products")
    val query = Query()
    val update = Update()
    update.set("tenants", arrayOf("shared"))

    mongoTemplate.updateMulti(query, update, Product::class.java)
}

@ChangeSet(order = "011", id = "add_tenant_to_product_version", author = "pn")
fun addTenantToProductVersion(mongoTemplate: MongoTemplate) {
    log.info("Adding tenants to product-version")
    val query = Query()
    val update = Update()
    ...

应用程序日志的最后几行表明变更集被调用,但后续的没有被调用。

2021-05-11 08:00:29.385 INFO [product-service,,,] 1 --- [
main] caamongock.changelog.Migration:向产品添加租户

2021-05-11 08:00:29.576 INFO [product-service,,,] 1 --- [
main] org.mongodb.driver.connection:打开的连接

因此,Spring 执行器运行状况探测失败,并且容器不断重新启动。是否有更好的 API 可以更快地使用?

笔记:

  1. 使用的版本:'com.github.cloudyrock:mongock:1.12'
  2. 下面是配置
@Profile("!tenant")
@Configuration
class MongockConfig : AbstractMongoConfiguration() {

    @Value("\${spring.data.mongodb.uri}")
    private lateinit var uri: String

    @Value("\${spring.data.mongodb.database}")
    private lateinit var database: String

    override fun mongoClient(): MongoClient {
        return MongoClient(MongoClientURI(uri))
    }

    override fun getDatabaseName(): String {
        return database
    }

    @Bean
    fun mongock(): Mongock {
        return MongockBuilder(mongoClient(), databaseName, "com.somepackage.mongock.changelog")
            .setMongoTemplate(mongoTemplate())
            .setLockQuickConfig()
            .build()
    }
}

这是日志


2021-05-10 10:59:33.406 INFO [product-service,,,] 1 --- [main] org.mongodb.driver.connection:打开连接 [connectionId{localValue:16, serverValue:26359638}] 到虚拟-clusterr-39649.servers.mongodirector.com:27017 2021-05-10 10:59:33.525 信息 [product-service,,,] 1 --- [main] c.github.cloudyrock.mongock.LockChecker : Mongbee 尝试获取锁 2021-05-10 10:59:33.574 INFO [product-service,,,] 1 --- [main] c.github.cloudyrock.mongock.LockChecker :锁定被其他进程占用,直到:Mon May 10 11:01:03 GMT 2021 2021-05-10 10:59:33.574 INFO [product-service,,,] 1 --- [main] c.github.cloudyrock.mongock.LockChecker:Mongock 要睡觉了等待锁定:90265 毫秒(1 分钟)2021-05-10 11:01:03.839 INFO [product-service,,,] 1 --- [main] c.github.cloudyrock.mongock.LockChecker : Mongbee 试图获取锁 2021-05-10 11:01:03.844 INFO [product-service,,,] 1 --- [main] c.github.cloudyrock.mongock.LockChecker : Mongbee 获得锁定到: 2021 年 5 月 10 日星期一 11:04:03 GMT 2021-05-10 11:01:03.844 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock.mongock.Mongock : Mongock 开始数据迁移序列.. 2021-05-10 11:01:03.982 INFO [product-service,,,] 1 --- [main] org.reflections.Reflections :Reflections 花了 60 毫秒扫描 1 个 url,产生2 个键和 3 个值 2021-05-10 11:01:04.038 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry @7abd0e71 通过 2021-05-10 11:01:04.046 INFO [product-service,,,] 1 --- [main] com。github.cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@6635f36 pass over 2021-05-10 11:01:04.047 INFO [product-service,,,] 1 --- [main] com.github .cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@61352a80 通过 2021-05-10 11:01:04.052 INFO [product-service,,,] 1 --- [main] com.github。 cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@7576ed14 通过 2021-05-10 11:01:04.054 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock .mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@b0302179 通过 2021-05-10 11:01:04.068 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock。 mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@e6caade0 通过 2021-05-10 11:01:04。071 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@2688129a 通过 2021-05-10 11:01:04.073 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@e46af677 通过 2021-05-10 11:01:04.075 INFO [product-service,,,] 1 --- [main] com.github.cloudyrock.mongock.Mongock : com.github.cloudyrock.mongock.ChangeEntry@d788b92f 通过 2021-05-10 11:01:04.077 INFO [ product-service,,,] 1 --- [main] caamongock.changelog.Migration:将组织添加到问题 2021-05-10 11:01:04.158 INFO [product-service,,,] 1 --- [main] org.mongodb.driver.connection :打开的连接 [connectionId{localValue:17, serverValue:26359725}] 到 dummy-clusterr-39649.servers.mongodirector.com:27017

4

1 回答 1

0

您能否提供更多信息,例如您正在使用的 mongock 版本、日志跟踪(您显示的内容不足以进行诊断)、mongock 配置等?

另一方面,您应该MongockTempalte直接使用MongoTemplate。它是相同的 API,你不会错过任何东西。实际上直接使用 MongoTemplate 应该会抛出异常。

有关更多信息,请查看Mongock 的文档

于 2021-05-11T08:33:46.360 回答