if (!strcasecmp(argv[0],"appendonly") && argc == 2) {int yes;if ((yes = yesnotoi(argv[1])) == -1) {err = "argument must be 'yes' or 'no'"; goto loaderr;}server.aof_state = yes ? REDIS_AOF_ON : REDIS_AOF_OFF;}
appendfsync everysec 支援延遲fsync
# appendfsync no 不需要fsync
config.c中解析代碼
if (!strcasecmp(argv[0],"no-appendfsync-on-rewrite") && argc == 2) {if ((server.aof_no_fsync_on_rewrite= yesnotoi(argv[1])) == -1) {err = "argument must be 'yes' or 'no'"; goto loaderr;}}
server.aof_no_fsync_on_rewrite控制該機制的實現代碼在aof.c的flushAppendOnlyFile函數中,具體代碼為//如果不支援fsync,或者aof rdb子進程正在運行,那麼直接返回,//但是資料已經寫到aof檔案中,只是沒有重新整理到硬碟if (server.aof_no_fsync_on_rewrite &&(server.aof_child_pid != -1 || server.rdb_child_pid != -1))return;
auto-aof-rewrite-min-size 64mb
server.aof_state = REDIS_AOF_OFF; //AOF檔案是否開啟server.aof_fsync = REDIS_DEFAULT_AOF_FSYNC; //fsync策略,預設為每秒fsyncserver.aof_no_fsync_on_rewrite = REDIS_DEFAULT_AOF_NO_FSYNC_ON_REWRITE;//aof rdb子進程運行中是否支援fsync,即寫入AOF檔案後,將資料重新整理到硬碟server.aof_rewrite_perc = REDIS_AOF_REWRITE_PERC; //自動rewrite增量值server.aof_rewrite_min_size = REDIS_AOF_REWRITE_MIN_SIZE; //AOF檔案最小位元組數server.aof_rewrite_base_size = 0; //自動rewrite計算aof檔案增量的基數,等於上一次aof檔案的位元組數server.aof_rewrite_scheduled = 0; //rewrite任務計劃,當用戶端發送bgrewriteaof指令,如果當前rewrite子進程正在執行,那麼將用戶端請求的bgrewriteaof變為計劃任務,待AOF子進程結束後執行rewriteserver.aof_last_fsync = time(NULL); //最近fsync資料到硬碟時間server.aof_rewrite_time_last = -1; //rewrite持續的時間server.aof_rewrite_time_start = -1; //rewrite開始的時間server.aof_lastbgrewrite_status = REDIS_OK; //rewrite後的狀態server.aof_delayed_fsync = 0; //延遲fsync到硬碟的次數server.aof_fd = -1; //AOF檔案描述符server.aof_selected_db = -1; /* Make sure the first time will not match */server.aof_flush_postponed_start = 0; //上次延遲fsync到硬碟的時間server.aof_rewrite_incremental_fsync = REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC;//rewrite AOF檔案時是否採用增量式fsync
其中aof_current_size參數未初始化,該值的初始化在Server啟動載入AOF檔案資料時初始化。