AOF策略译文

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.

appendonly no

# The name of the append only file (default: "appendonly.aof")
appendfilename "appendonly.aof"
在默认情况下,redis是异步备份数据集到磁盘上。这个模式适合大部分的应用。但是有些问题,比如停电可能会导致几分钟之类的写操作丢失,
(这个是因为快照的局限性)

AOF是一个替代的持久化模式,提供了更好的可用性。如果使用默认的数据同步策略,redis只会丢失一秒中的写操作。

AOF和RDB持久化能够同时的使用,不会产生任何问题。
AOF如果开启,Redis在启动的过程中并会加载AOF文件,这个文件对数据有更好的保证。

# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log. Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# appendfsync always
appendfsync everysec
# appendfsync no

fsync()函数调用会告诉操作系统我要真正的写入数据到磁盘中,而不是等待更多的数据进入输出缓存中。
一些操作系统会真正的冲刷数据到磁盘中,还有一些则只是尽快地做这个工作

Redis支持三种不同的模式
    no:这个不会调用fsync函数,只是把这个写入磁盘的工作完全交给操作系统。更快!
    always:每次进行写操作的时候多会调用fsync函数,写入aof文件中。慢,但是数据是最安全的。
    everysec:每一秒调用一次。这个都做了妥协。默认,没有什么特殊情况则使用这个。
# appendfsync always
appendfsync everysec
# appendfsync no


# When the AOF fsync policy is set to always or everysec, and a background
# saving process (a background save or AOF log background rewriting) is
# performing a lot of I/O against the disk, in some Linux configurations
# Redis may block too long on the fsync() call. Note that there is no fix for
# this currently, as even performing fsync in a different thread will block
# our synchronous write(2) call.
#
# In order to mitigate this problem it's possible to use the following option
# that will prevent fsync() from being called in the main process while a
# BGSAVE or BGREWRITEAOF is in progress.
#
# This means that while another child is saving, the durability of Redis is
# the same as "appendfsync none". In practical terms, this means that it is
# possible to lose up to 30 seconds of log in the worst scenario (with the
# default Linux settings).
#
# If you have latency problems turn this to "yes". Otherwise leave it as
# "no" that is the safest pick from the point of view of durability.
no-appendfsync-on-rewrite no

当aof同步策略设置成always或者everysec,同时在后台的保存进程中有大量的针对磁盘的io操作(比如针对aof的重写操作),在一些linux配置中,redis可能会在调用fsync函数上长时间阻塞。注意这个是不可能解决的,即使调用fsync和阻塞我们同步的写操作不在一个线程当中。
为了缓解这个问题,当一个BGSAVE和BGREWRITEAOF在进行中时,使用下面的选项来阻止fsync在主进程中的调用。
这就意味着当进行这些操作时,redis的能力跟就配置appendfsync none一样,在实际的情况下,这个意味着在发生糟糕的问题时,可能会丢失超过30秒的日志记录。



# Automatic rewrite of the append only file.
# Redis is able to automatically rewrite the log file implicitly calling
# BGREWRITEAOF when the AOF log size grows by the specified percentage.
#
# This is how it works: Redis remembers the size of the AOF file after the
# latest rewrite (if no rewrite has happened since the restart, the size of
# the AOF at startup is used).
#
# This base size is compared to the current size. If the current size is
# bigger than the specified percentage, the rewrite is triggered. Also
# you need to specify a minimal size for the AOF file to be rewritten, this
# is useful to avoid rewriting the AOF file even if the percentage increase
# is reached but it is still pretty small.
#
# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
关于自动重写AOF文件
Redis会自动重写这个日志文件,通过显式的调用BGREWRITEAOF命令。
什么情况下会发生呢?当AOF文件的大小的增长速度超过某一个百分比时发生。
怎么做的呢?Redis会记住最近的一次Rewrite操作的aof文件大小(没有则是启动时aof的大小),然后他会跟当前的大小进行对比,如果超过了指定的比例,
那么rewrite操作将会触发
另外也需要指定一个最小的文件大小,因为有可能文件增长很快,但是文件本身很小。
如果设置这个比例为零的话,那么就是将这个特性置为不可用,不会去重写aof文件。
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb


# An AOF file may be found to be truncated at the end during the Redis
# startup process, when the AOF data gets loaded back into memory.
# This may happen when the system where Redis is running
# crashes, especially when an ext4 filesystem is mounted without the
# data=ordered option (however this can't happen when Redis itself
# crashes or aborts but the operating system still works correctly).
#
# Redis can either exit with an error when this happens, or load as much
# data as possible (the default now) and start if the AOF file is found
# to be truncated at the end. The following option controls this behavior.
#
# If aof-load-truncated is set to yes, a truncated AOF file is loaded and
# the Redis server starts emitting a log to inform the user of the event.
# Otherwise if the option is set to no, the server aborts with an error
# and refuses to start. When the option is set to no, the user requires
# to fix the AOF file using the "redis-check-aof" utility before to restart
# the server.
#
# Note that if the AOF file will be found to be corrupted in the middle
# the server will still exit with an error. This option only applies when
# Redis will try to read more data from the AOF file but not enough bytes
# will be found.
aof-load-truncated yes

当Redis启动时发现AOF文件在最后被缩短了,当这个情况发生时,Redis有可能会带着一个退出或者尽可能的多加载数据,使用下面的选项控制它的行为

如果aof-load-truncated被设置成yes,这个被缩短的AOF文件会被加载,并在服务启动的时候发送一个日志来通知用户这个事件
否则,用户需要在重新启动服务之前需要使用redis-check-aof工具来修复这个AOF文件,。

注意如果这个AOF文件在读取过程发生错误,则redis直接就退出了.这个选项只是当redis试图读取更多数据的时候,发现aof文件里面没有更多的数据时发生。
所以强调了是在AOF文件的末尾。
aof-load-truncated yes


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值