知识库

了解逻辑日志以及 keep_logical_logs 和 logical_log_rotation_threshold 参数的影响

Neo4j 为增量备份和集群一致性维护逻辑日志。这些逻辑日志的命名如下

pre 2.2

data/graph.db/nioneo_logical.log*

2.2 forward

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>。需要记住的关键点是,只有在满足 logical_log_rotation_threshold 时,才会根据 keep_logical_logs 参数考虑删除文件。

此外,如果最初

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 时,我们会删除除最近五天之外的所有逻辑日志。

© . This site is unofficial and not affiliated with Neo4j, Inc.