Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
cb8ae3c8
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cb8ae3c8
编写于
5月 05, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow AOF to be fixed by truncating to the portion of the file that is valid
上级
b4bd0524
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
8 deletion
+33
-8
redis-check-aof.c
redis-check-aof.c
+33
-8
未找到文件。
redis-check-aof.c
浏览文件 @
cb8ae3c8
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include "config.h"
#include "config.h"
...
@@ -126,34 +127,58 @@ long process(FILE *fp) {
...
@@ -126,34 +127,58 @@ long process(FILE *fp) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
/* expect the first argument to be the dump file */
/* expect the first argument to be the dump file */
if
(
argc
<=
1
)
{
if
(
argc
<=
1
)
{
printf
(
"Usage: %s <file.aof>
\n
"
,
argv
[
0
]);
printf
(
"Usage: %s
[--fix]
<file.aof>
\n
"
,
argv
[
0
]);
exit
(
0
);
exit
(
0
);
}
}
FILE
*
fp
=
fopen
(
argv
[
1
],
"r"
);
char
*
filename
;
int
fix
=
0
;
if
(
argc
==
3
)
{
if
(
strcmp
(
argv
[
1
],
"--fix"
)
!=
0
)
{
printf
(
"Invalid argument: %s
\n
"
,
argv
[
1
]);
exit
(
1
);
}
fix
=
1
;
filename
=
argv
[
2
];
}
else
if
(
argc
==
2
)
{
filename
=
argv
[
1
];
}
else
{
printf
(
"Invalid argument"
);
exit
(
1
);
}
FILE
*
fp
=
fopen
(
filename
,
"r+"
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
printf
(
"Cannot open file: %s
\n
"
,
argv
[
1
]
);
printf
(
"Cannot open file: %s
\n
"
,
filename
);
exit
(
1
);
exit
(
1
);
}
}
struct
redis_stat
sb
;
struct
redis_stat
sb
;
if
(
redis_fstat
(
fileno
(
fp
),
&
sb
)
==
-
1
)
{
if
(
redis_fstat
(
fileno
(
fp
),
&
sb
)
==
-
1
)
{
printf
(
"Cannot stat file: %s
\n
"
,
argv
[
1
]
);
printf
(
"Cannot stat file: %s
\n
"
,
filename
);
exit
(
1
);
exit
(
1
);
}
}
long
size
=
sb
.
st_size
;
long
size
=
sb
.
st_size
;
if
(
size
==
0
)
{
if
(
size
==
0
)
{
printf
(
"Empty file: %s
\n
"
,
argv
[
1
]
);
printf
(
"Empty file: %s
\n
"
,
filename
);
exit
(
1
);
exit
(
1
);
}
}
long
pos
=
process
(
fp
);
long
pos
=
process
(
fp
);
if
(
pos
<
size
)
{
if
(
pos
<
size
)
{
printf
(
"First invalid operation at offset %ld.
\n
"
,
pos
);
if
(
fix
)
{
exit
(
1
);
if
(
ftruncate
(
fileno
(
fp
),
pos
)
==
-
1
)
{
printf
(
"Could not truncate AOF to size %ld
\n
"
,
pos
);
exit
(
1
);
}
else
{
printf
(
"AOF succesfully truncated to %ld bytes
\n
"
,
pos
);
}
}
else
{
printf
(
"First invalid operation at offset %ld
\n
"
,
pos
);
}
}
else
{
}
else
{
printf
(
"AOF is valid
.
\n
"
);
printf
(
"AOF is valid
\n
"
);
}
}
fclose
(
fp
);
fclose
(
fp
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录