xd.lck 商店关闭后未删除锁定文件

xd.lck lock file is not removed after store is closed

我对 xodus 数据库锁定的假设是关闭实体存储将关闭数据库。

我使用调用 close:

use 模式通过一个简单示例实现了这一点
package whatever

import jetbrains.exodus.entitystore.Entity
import kotlinx.dnq.XdEntity
import kotlinx.dnq.XdModel
import kotlinx.dnq.XdNaturalEntityType
import kotlinx.dnq.store.container.StaticStoreContainer
import kotlinx.dnq.util.initMetaData
import kotlinx.dnq.xdRequiredStringProp
import org.junit.Test
import java.nio.file.Files

class UnclosedTest {
    private val dbFolder = Files.createTempDirectory(null).toFile()

    private val store = StaticStoreContainer.init(
            dbFolder = dbFolder,
            environmentName = "store"
    ).also {
        XdModel.registerNodes(
                Bogus
        )

        initMetaData(XdModel.hierarchy, it)
    }

    @Test
    fun `lock file is removed when store is closed`() {
        store.use { store ->
            store.transactional {
                Bogus.new {
                    text = "gnarf"
                }
            }
        }

        assert(dbFolder.exists())
        assert(dbFolder.isDirectory)
        assert(!dbFolder.resolve("xd.lck").exists())
    }

    class Bogus(entity: Entity) : XdEntity(entity) {
        companion object : XdNaturalEntityType<Bogus>()

        var text by xdRequiredStringProp()
    }
}

令人惊讶的是,此测试失败,xd.lck 文件仍然存在。

如何关闭所有资源,确保删除锁定文件?

xd.lck 文件在关闭数据库时被释放,而不是被删除,无论您使用哪个 API:环境、EntityStores 或 Xodus-DNQ DSL。参见 how it is implemented