Print the number of abnormal line in AOF (#8823)

When redis-check-aof finds an error, it prints the line number for faster troubleshooting.
This commit is contained in:
bugwz 2021-04-21 02:51:24 +08:00 committed by GitHub
parent 080d4579db
commit 761d7d2771
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -39,12 +39,14 @@
static char error[1044]; static char error[1044];
static off_t epos; static off_t epos;
static long long line = 1;
int consumeNewline(char *buf) { int consumeNewline(char *buf) {
if (strncmp(buf,"\r\n",2) != 0) { if (strncmp(buf,"\r\n",2) != 0) {
ERROR("Expected \\r\\n, got: %02x%02x",buf[0],buf[1]); ERROR("Expected \\r\\n, got: %02x%02x",buf[0],buf[1]);
return 0; return 0;
} }
line += 1;
return 1; return 1;
} }
@ -201,8 +203,8 @@ int redis_check_aof_main(int argc, char **argv) {
off_t pos = process(fp); off_t pos = process(fp);
off_t diff = size-pos; off_t diff = size-pos;
printf("AOF analyzed: size=%lld, ok_up_to=%lld, diff=%lld\n", printf("AOF analyzed: size=%lld, ok_up_to=%lld, ok_up_to_line=%lld, diff=%lld\n",
(long long) size, (long long) pos, (long long) diff); (long long) size, (long long) pos, line, (long long) diff);
if (diff > 0) { if (diff > 0) {
if (fix) { if (fix) {
char buf[2]; char buf[2];

View File

@ -158,6 +158,18 @@ tags {"aof"} {
assert_match "*not valid*" $result assert_match "*not valid*" $result
} }
test "Short read: Utility should show the abnormal line num in AOF" {
create_aof {
append_to_aof [formatCommand set foo hello]
append_to_aof "!!!"
}
catch {
exec src/redis-check-aof $aof_path
} result
assert_match "*ok_up_to_line=8*" $result
}
test "Short read: Utility should be able to fix the AOF" { test "Short read: Utility should be able to fix the AOF" {
set result [exec src/redis-check-aof --fix $aof_path << "y\n"] set result [exec src/redis-check-aof --fix $aof_path << "y\n"]
assert_match "*Successfully truncated AOF*" $result assert_match "*Successfully truncated AOF*" $result