知识库

了解逻辑日志以及参数 keep_logical_logs 和 logical_log_rotation_threshold 的作用

Neo4j 维护逻辑日志用于增量备份和集群一致性。逻辑日志的命名如下:

2.2 之前

data/graph.db/nioneo_logical.log*

2.2 及以后

data/graph.db/neostore.transaction.db*

当通过 bin/neo4j-backup 运行数据库备份时,如果 -to <target directory> 中存在之前的备份,则备份将是增量备份而不是完整备份。如果自上次完整备份以来逻辑日志已被轮换出,则备份将被强制执行为完整备份。

在集群环境中,逻辑日志用于确保新发现的从属节点通过正确的事务进行更新。如果逻辑日志已被轮换出,那么新从属节点将不会简单地通过逻辑日志进行更新,而是会发生完整的存储复制。

conf/neo4j.properties 中,可以配置以下两个参数:

logical_log_rotation_threshold
keep_logical_logs

这些参数在 Neo4j 文档中都有说明。简而言之,logical_log_rotation_threshold 决定了当前逻辑日志文件在轮换前可以增长到的大小。例如,2.3.0 版本中 logical_log_rotation_threshold 的默认值为 250M。因此,预计 data/graph.db/neostore.transaction.db 下的文件不会超过 250M。当 neostore.transaction.db.<N> 达到 250M 时,neostore.transaction.db.<N> 将轮换为 neostore.transaction.db.<N+1>,然后会查询 keep_logical_logs 参数,以确定是否应自动删除之前的 neostore.transaction.db.<N> 文件。

例如,如果:

logical_log_rotation_threshold=250M
keep_logical_logs=3 days

neostore.transaction.db.<N> 超过 250M 时,我们将创建一个 neostore.transaction.db.<N+1>,然后自动删除任何超过 3 天的 neostore.transaction.db.<N>。需要记住的重要一点是,根据 keep_logical_logs 参数删除文件只在达到 logical_log_rotation_threshold 时才会被考虑。

此外,如果最初:

logical_log_rotation_threshold=250M
keep_logical_logs=10 days

然后编辑 conf/neo4j.properties 并将

keep_logical_logs=10 days

更改为

keep_logical_logs=5 days

并重新启动 Neo4j,那么过去 10 天的 neostore.transaction.db.<N> 仍然会存在。当当前的 neostore.transaction.db 达到 250M 时,我们将删除除最近五天之外的所有逻辑日志。

© . All rights reserved.