在 mapdb 中使用 `checksumHeaderBypass` 的成本是多少?

what is the cost of using `checksumHeaderBypass` in mapdb?

我们正在使用 mapdb 来存储在一个漫长的 运行 进程中访问过的文件列表,这样如果我们需要中止或进程崩溃,我们可以从中断的地方继续。

我们希望防止崩溃损坏我们的 mapdb 文件存储。

所以我们正在使用我们定期将更改提交到磁盘的事务。

但后来我注意到一些有趣的事情,如果我们在某些时候使进程崩溃,我们仍然会收到错误

Header checksum broken. Store was not closed correctly and might be corrupted. Use DBMaker.checksumHeaderBypass() to recover your data. Use clean shutdown or enable transactions to protect the store in the future.

但确实设置 checksumHeaderBypass 会使错误消失。使用此 checksumHeaderBypass 设置的成本是多少?

这里没有任何流量,因为 sof 上有很多 mapdb 人员。所以我会post我认为最好的答案

基本上,如果您允许校验和 header 绕过,您可以加载 mapdb,但它可能在 mapdb 中包含无效条目。因为如果校验和不匹配,则表示内容不正确。所以你可能会在 mapdb 中有一些坏数据。取决于您提交存储的频率,可能会导致大量或少量数据损坏。

如果您在 spring boot 应用程序中使用 @postcontruct 中的 mapdb,则会抛出此错误。避免在应用程序启动前初始化 mapdb(不要从 @postconstruct 初始化)。