Introduce writeCommandsDeniedByDiskError().

This commit is contained in:
antirez 2018-07-31 13:09:38 +02:00
parent ac3c012a7f
commit 5401fe7fb9
2 changed files with 24 additions and 0 deletions

View File

@ -2805,6 +2805,25 @@ int prepareForShutdown(int flags) {
/*================================== Commands =============================== */ /*================================== Commands =============================== */
/* Sometimes Redis cannot accept write commands because there is a perstence
* error with the RDB or AOF file, and Redis is configured in order to stop
* accepting writes in such situation. This function returns if such a
* condition is active, and the type of the condition. */
int writeCommandsDeniedByDiskError(void) {
if (server.stop_writes_on_bgsave_err &&
server.saveparamslen > 0 &&
server.lastbgsave_status == C_ERR)
{
return DISK_ERROR_TYPE_AOF;
} else if (server.aof_state != AOF_OFF &&
server.aof_last_write_status == C_ERR)
{
return DISK_ERROR_TYPE_RDB;
} else {
return DISK_ERROR_TYPE_NONE;
}
}
/* Return zero if strings are the same, non-zero if they are not. /* Return zero if strings are the same, non-zero if they are not.
* The comparison is performed in a way that prevents an attacker to obtain * The comparison is performed in a way that prevents an attacker to obtain
* information about the nature of the strings just monitoring the execution * information about the nature of the strings just monitoring the execution

View File

@ -1591,6 +1591,11 @@ void startLoading(FILE *fp);
void loadingProgress(off_t pos); void loadingProgress(off_t pos);
void stopLoading(void); void stopLoading(void);
#define DISK_ERROR_TYPE_AOF 1 /* Don't accept writes: AOF errors. */
#define DISK_ERROR_TYPE_RDB 2 /* Don't accept writes: RDB errors. */
#define DISK_ERROR_TYPE_NONE 0 /* No problems, we can accept writes. */
int writeCommandsDeniedByDiskError(void);
/* RDB persistence */ /* RDB persistence */
#include "rdb.h" #include "rdb.h"
int rdbSaveRio(rio *rdb, int *error, int flags, rdbSaveInfo *rsi); int rdbSaveRio(rio *rdb, int *error, int flags, rdbSaveInfo *rsi);