A description
rdb(redis databses)
Under redis One of the persistent data mode (the default), is rdb mode, it simply is will then trigger certain conditions, the child process will start generating dump.rdb (snapshot file)
Second, parsing source code
2.1 src/rdb.c:rdbSaveBackground
Code logic:
1.fork (), to create a child process
2. The child calls rdbSave function, do the actual dump operation
2.2 src/rdb.c:
Code logic:
1. Create a temporary file, tmp- {pid} .rdb
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
2. The snapshot data is written to a temporary file
rioInitWithFile(&rdb,fp);
if (rdbSaveRio(&rdb,&error) == C_ERR) {
errno = error;
goto werr;
}
3. The data is actually written to disk
IF (fflush (FP) == the EOF ) GOTO WERR; // cached data brush into user space kernel space data cache
IF (the fsync (the fileno (FP)) == - . 1 ) GOTO WERR; // the cache data into the kernel space of the brush in the actual physical disk
IF (fclose (FP) == the EOF ) GOTO WERR; // close the file, the write operation is completed
4. The temporary file renamed dump.rdb
rename(tmpfile,filename)
Third, the trigger condition settings
save 900 1
save 300 10
save 60 10000
meaning is:
1 there is secondary data changes which come within 900 seconds
There are 10 data change 300 seconds
10,000 secondary data changes within 60 seconds
A condition which satisfies the above, it will trigger operation generated dump.rdb snapshot file