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
This commit is contained in:
Wang Yuan 2023-03-19 18:51:34 +08:00 committed by GitHub
parent d691098349
commit c9466b24a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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