diff options
author | Wang Yuan <wangyuan21@baidu.com> | 2023-03-19 18:51:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-19 12:51:34 +0200 |
commit | c9466b24a60df4254dd2ab4ba71048c30b49076f (patch) | |
tree | 1ca23d8bc0ad99fb0ac4c6613f169c27e049bcbf /src/sentinel.c | |
parent | d69109834999c9f06fb31ea4472e0eb3b99d8dc8 (diff) | |
download | redis-c9466b24a60df4254dd2ab4ba71048c30b49076f.tar.gz |
Remove unnecessary `fsync` when sentinel flushs config file (#11910)
`rewriteConfig` already calls `fsync` to make sure changes are committed to disk.
so it is no need to call `fsync` again here.
this was added here when rewriteConfigOverwriteFile used the ftruncate approach and didn't fsync
Diffstat (limited to 'src/sentinel.c')
-rw-r--r-- | src/sentinel.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/sentinel.c b/src/sentinel.c index 035776781..c7e6e3ef2 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2272,12 +2272,8 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) { /* This function uses the config rewriting Redis engine in order to persist * the state of the Sentinel in the current configuration file. * - * Before returning the function calls fsync() against the generated - * configuration file to make sure changes are committed to disk. - * * On failure the function logs a warning on the Redis log. */ int sentinelFlushConfig(void) { - int fd = -1; int saved_hz = server.hz; int rewrite_status; @@ -2285,17 +2281,13 @@ int sentinelFlushConfig(void) { rewrite_status = rewriteConfig(server.configfile, 0); server.hz = saved_hz; - if (rewrite_status == -1) goto werr; - if ((fd = open(server.configfile,O_RDONLY)) == -1) goto werr; - if (fsync(fd) == -1) goto werr; - if (close(fd) == EOF) goto werr; - serverLog(LL_NOTICE,"Sentinel new configuration saved on disk"); - return C_OK; - -werr: - serverLog(LL_WARNING,"WARNING: Sentinel was not able to save the new configuration on disk!!!: %s", strerror(errno)); - if (fd != -1) close(fd); - return C_ERR; + if (rewrite_status == -1) { + serverLog(LL_WARNING,"WARNING: Sentinel was not able to save the new configuration on disk!!!: %s", strerror(errno)); + return C_ERR; + } else { + serverLog(LL_NOTICE,"Sentinel new configuration saved on disk"); + return C_OK; + } } /* Call sentinelFlushConfig() produce a success/error reply to the |