Skip to content

Commit

Permalink
INFO loading stats: three fixes.
Browse files Browse the repository at this point in the history
1. Server unxtime may remain not updated while loading AOF, so ETA is
not updated correctly.

2. Number of processed byte was not initialized.

3. Possible division by zero condition (likely cause of issue #1932).
  • Loading branch information
antirez committed Dec 23, 2014
1 parent aad0c51 commit 1e8f157
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/rdb.c
Expand Up @@ -1087,8 +1087,9 @@ void startLoading(FILE *fp) {
/* Load the DB */
server.loading = 1;
server.loading_start_time = time(NULL);
server.loading_loaded_bytes = 0;
if (fstat(fileno(fp), &sb) == -1) {
server.loading_total_bytes = 1; /* just to avoid division by zero */
server.loading_total_bytes = 0;
} else {
server.loading_total_bytes = sb.st_size;
}
Expand Down
6 changes: 3 additions & 3 deletions src/redis.c
Expand Up @@ -2790,14 +2790,14 @@ sds genRedisInfoString(char *section) {
server.loading_loaded_bytes;

perc = ((double)server.loading_loaded_bytes /
server.loading_total_bytes) * 100;
(server.loading_total_bytes+1)) * 100;

elapsed = server.unixtime-server.loading_start_time;
elapsed = time(NULL)-server.loading_start_time;
if (elapsed == 0) {
eta = 1; /* A fake 1 second figure if we don't have
enough info */
} else {
eta = (elapsed*remaining_bytes)/server.loading_loaded_bytes;
eta = (elapsed*remaining_bytes)/(server.loading_loaded_bytes+1);
}

info = sdscatprintf(info,
Expand Down

0 comments on commit 1e8f157

Please sign in to comment.