Handle redis-check-rdb as a standalone program.
This also makes it backward compatible in the usage, but for the command name. However the old command name was less obvious so it is worth to break it probably. With the new setup the program main can perform argument parsing and everything else useful for an RDB check regardless of the Redis server itself.
This commit is contained in:
parent
45102a6f63
commit
7d1e158084
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ dump.rdb
|
||||
redis-benchmark
|
||||
redis-check-aof
|
||||
redis-check-rdb
|
||||
redis-check-dump
|
||||
redis-cli
|
||||
redis-sentinel
|
||||
redis-server
|
||||
|
@ -696,3 +696,15 @@ int redis_check_rdb(char *rdbfilename) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* RDB check main: called form redis.c when Redis is executed with the
|
||||
* redis-check-rdb alias. */
|
||||
int redis_check_rdb_main(char **argv, int argc) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <rdb-file-name>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
redisLog(REDIS_WARNING, "Checking RDB file %s", argv[1]);
|
||||
exit(redis_check_rdb(argv[1]));
|
||||
return 0;
|
||||
}
|
||||
|
24
src/redis.c
24
src/redis.c
@ -3550,17 +3550,6 @@ int checkForSentinelMode(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Returns 1 if there is --check-rdb among the arguments or if
|
||||
* argv[0] is exactly "redis-check-rdb". */
|
||||
int checkForCheckRDBMode(int argc, char **argv) {
|
||||
int j;
|
||||
|
||||
if (strstr(argv[0],"redis-check-rdb") != NULL) return 1;
|
||||
for (j = 1; j < argc; j++)
|
||||
if (!strcmp(argv[j],"--check-rdb")) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Function called at startup to load RDB or AOF file in memory. */
|
||||
void loadDataFromDisk(void) {
|
||||
long long start = ustime();
|
||||
@ -3746,6 +3735,12 @@ int main(int argc, char **argv) {
|
||||
initSentinel();
|
||||
}
|
||||
|
||||
/* Check if we need to start in redis-check-rdb mode. We just execute
|
||||
* the program main. However the program is part of the Redis executable
|
||||
* so that we can easily execute an RDB check on loading errors. */
|
||||
if (strstr(argv[0],"redis-check-rdb") != NULL)
|
||||
exit(redis_check_rdb_main(argv,argc));
|
||||
|
||||
if (argc >= 2) {
|
||||
int j = 1; /* First option to parse in argv[] */
|
||||
sds options = sdsempty();
|
||||
@ -3807,13 +3802,6 @@ int main(int argc, char **argv) {
|
||||
redisLog(REDIS_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis");
|
||||
}
|
||||
|
||||
if (checkForCheckRDBMode(argc, argv)) {
|
||||
redisLog(REDIS_WARNING, "Checking RDB file %s", server.rdb_filename);
|
||||
redisLog(REDIS_WARNING, "To check different RDB file: "
|
||||
"redis-check-rdb --dbfilename <dump.rdb>");
|
||||
exit(redis_check_rdb(server.rdb_filename));
|
||||
}
|
||||
|
||||
server.supervised = redisIsSupervised(server.supervised_mode);
|
||||
int background = server.daemonize && !server.supervised;
|
||||
if (background) daemonize();
|
||||
|
@ -1382,6 +1382,7 @@ void sentinelIsRunning(void);
|
||||
|
||||
/* redis-check-rdb */
|
||||
int redis_check_rdb(char *rdbfilename);
|
||||
int redis_check_rdb_main(char **argv, int argc);
|
||||
|
||||
/* Scripting */
|
||||
void scriptingInit(void);
|
||||
|
Loading…
Reference in New Issue
Block a user