| 1421 | } |
| 1422 | |
| 1423 | int rdbSaveBackground(char *filename, rdbSaveInfo *rsi) { |
| 1424 | pid_t childpid; |
| 1425 | |
| 1426 | if (hasActiveChildProcess()) return C_ERR; |
| 1427 | |
| 1428 | server.dirty_before_bgsave = server.dirty; |
| 1429 | server.lastbgsave_try = time(NULL); |
| 1430 | |
| 1431 | if ((childpid = redisFork(CHILD_TYPE_RDB)) == 0) { |
| 1432 | int retval; |
| 1433 | |
| 1434 | /* Child */ |
| 1435 | redisSetProcTitle("redis-rdb-bgsave"); |
| 1436 | // resetCpuAffinity(); |
| 1437 | redisSetCpuAffinity(server.bgsave_cpulist); |
| 1438 | retval = rdbSave(filename,rsi); |
| 1439 | if (retval == C_OK) { |
| 1440 | sendChildCowInfo(CHILD_INFO_TYPE_RDB_COW_SIZE, "RDB"); |
| 1441 | } |
| 1442 | exitFromChild((retval == C_OK) ? 0 : 1); |
| 1443 | } else { |
| 1444 | /* Parent */ |
| 1445 | if (childpid == -1) { |
| 1446 | server.lastbgsave_status = C_ERR; |
| 1447 | serverLog(LL_WARNING,"Can't save in background: fork: %s", |
| 1448 | strerror(errno)); |
| 1449 | return C_ERR; |
| 1450 | } |
| 1451 | serverLog(LL_NOTICE,"Background saving started by pid %ld",(long) childpid); |
| 1452 | server.rdb_save_time_start = time(NULL); |
| 1453 | server.rdb_child_type = RDB_CHILD_TYPE_DISK; |
| 1454 | return C_OK; |
| 1455 | } |
| 1456 | return C_OK; /* unreached */ |
| 1457 | } |
| 1458 | |
| 1459 | /* Note that we may call this function in signal handle 'sigShutdownHandler', |
| 1460 | * so we need guarantee all functions we call are async-signal-safe. |
no test coverage detected