Detailed AOF

AOF command synchronizes

Synchronization commands to the whole process of AOF files can be divided into three stages:

1: command propagation: the Redis finished the execution command, command parameters, and other parameters of the number of transmitting information to a program command AOF.

2: additional cache: AOF program according to the received command data, the command to convert the format of the network protocol, and then appended to the agreement AOF cache server.

3: file write and save: AOF cache contents are written to the end of AOF documents, if set AOF preservation conditions are satisfied, then, fsync fdatasync function or a function is called, the contents will be written to truly save disk. flushAppendOnlyFile function will be called, this function performs two tasks:

WRITE: The condition of the cache written to aof_buf file AOF

SAVE: Depending on conditions, call fsync or fdatasync function, save the file to disk AOF

AOF saving mode

1: AOF_FSYNC_NO, do not save

Each call flushAppendOnlyFile function, WRITE will be executed, but SAVE will be skipped.

SAVE will only be executed in any of the following situations:

Redis is closed

AOF function is turned off

System write cache is flushed (possibly cache has been filled, or save operation is performed on a regular basis)

SAVE operation will be in all three cases the main cause Redis process blocked

 

2: AOF_FSYNC_EVERYSEC: every second saved once.

Because the SAVE operation is called by the child thread the background, so it does not cause the main server process blocked.

In actual operation, the program in this mode once the call is not fsync or fdatasync per second, and it Redis state in which the function is invoked flushAppendOnlyFile related.

Whenever flushAppendOnlyFile function is called, it may appear the following four cases:

  • Sub-thread is executing SAVE, and:
    1. The execution time of the SAVE is not more than 2 seconds, then return to the program directly, or does not perform WRITE new SAVE.
    2. The SAVE has performed more than 2 seconds, then the program execution WRITE, but does not perform the new SAVE. Note that since then written WRITE thread must wait for the child to complete (old) SAVE, so here WRITE blocked longer than usual.
  • Child thread is not executing SAVE, and:
    1. Last successful execution SAVE dating back no more than one second, then program execution WRITE, but does not perform SAVE.
    2. Last successful execution SAVE ago has more than one second, then program execution WRITE and SAVE.

3: AOF_FSYNC_ALWAYS: each execute a command to save time.

Published 50 original articles · won praise 2 · Views 2283

Guess you like

Origin blog.csdn.net/eafun_888/article/details/104738569