Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
4a701b38
Commit
4a701b38
authored
Feb 14, 2012
by
antirez
Browse files
redis-check-aof is now large files safe also on 32 bit systems.
parent
120a36f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-check-aof.c
View file @
4a701b38
...
@@ -9,11 +9,11 @@
...
@@ -9,11 +9,11 @@
#define ERROR(...) { \
#define ERROR(...) { \
char __buf[1024]; \
char __buf[1024]; \
sprintf(__buf, __VA_ARGS__); \
sprintf(__buf, __VA_ARGS__); \
sprintf(error, "0x%
08
lx: %s", epos, __buf); \
sprintf(error, "0x%
16l
lx: %s",
(long long)
epos, __buf); \
}
}
static
char
error
[
1024
];
static
char
error
[
1024
];
static
long
epos
;
static
off_t
epos
;
int
consumeNewline
(
char
*
buf
)
{
int
consumeNewline
(
char
*
buf
)
{
if
(
strncmp
(
buf
,
"
\r\n
"
,
2
)
!=
0
)
{
if
(
strncmp
(
buf
,
"
\r\n
"
,
2
)
!=
0
)
{
...
@@ -25,7 +25,7 @@ int consumeNewline(char *buf) {
...
@@ -25,7 +25,7 @@ int consumeNewline(char *buf) {
int
readLong
(
FILE
*
fp
,
char
prefix
,
long
*
target
)
{
int
readLong
(
FILE
*
fp
,
char
prefix
,
long
*
target
)
{
char
buf
[
128
],
*
eptr
;
char
buf
[
128
],
*
eptr
;
epos
=
ftell
(
fp
);
epos
=
ftell
o
(
fp
);
if
(
fgets
(
buf
,
sizeof
(
buf
),
fp
)
==
NULL
)
{
if
(
fgets
(
buf
,
sizeof
(
buf
),
fp
)
==
NULL
)
{
return
0
;
return
0
;
}
}
...
@@ -39,7 +39,7 @@ int readLong(FILE *fp, char prefix, long *target) {
...
@@ -39,7 +39,7 @@ int readLong(FILE *fp, char prefix, long *target) {
int
readBytes
(
FILE
*
fp
,
char
*
target
,
long
length
)
{
int
readBytes
(
FILE
*
fp
,
char
*
target
,
long
length
)
{
long
real
;
long
real
;
epos
=
ftell
(
fp
);
epos
=
ftell
o
(
fp
);
real
=
fread
(
target
,
1
,
length
,
fp
);
real
=
fread
(
target
,
1
,
length
,
fp
);
if
(
real
!=
length
)
{
if
(
real
!=
length
)
{
ERROR
(
"Expected to read %ld bytes, got %ld bytes"
,
length
,
real
);
ERROR
(
"Expected to read %ld bytes, got %ld bytes"
,
length
,
real
);
...
@@ -72,13 +72,14 @@ int readArgc(FILE *fp, long *target) {
...
@@ -72,13 +72,14 @@ int readArgc(FILE *fp, long *target) {
return
readLong
(
fp
,
'*'
,
target
);
return
readLong
(
fp
,
'*'
,
target
);
}
}
long
process
(
FILE
*
fp
)
{
off_t
process
(
FILE
*
fp
)
{
long
argc
,
pos
=
0
;
long
argc
;
off_t
pos
=
0
;
int
i
,
multi
=
0
;
int
i
,
multi
=
0
;
char
*
str
;
char
*
str
;
while
(
1
)
{
while
(
1
)
{
if
(
!
multi
)
pos
=
ftell
(
fp
);
if
(
!
multi
)
pos
=
ftell
o
(
fp
);
if
(
!
readArgc
(
fp
,
&
argc
))
break
;
if
(
!
readArgc
(
fp
,
&
argc
))
break
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
...
@@ -148,18 +149,20 @@ int main(int argc, char **argv) {
...
@@ -148,18 +149,20 @@ int main(int argc, char **argv) {
exit
(
1
);
exit
(
1
);
}
}
long
size
=
sb
.
st_size
;
off_t
size
=
sb
.
st_size
;
if
(
size
==
0
)
{
if
(
size
==
0
)
{
printf
(
"Empty file: %s
\n
"
,
filename
);
printf
(
"Empty file: %s
\n
"
,
filename
);
exit
(
1
);
exit
(
1
);
}
}
long
pos
=
process
(
fp
);
off_t
pos
=
process
(
fp
);
long
diff
=
size
-
pos
;
off_t
diff
=
size
-
pos
;
printf
(
"AOF analyzed: size=%lld, ok_up_to=%lld, diff=%lld
\n
"
,
(
long
long
)
size
,
(
long
long
)
pos
,
(
long
long
)
diff
);
if
(
diff
>
0
)
{
if
(
diff
>
0
)
{
if
(
fix
)
{
if
(
fix
)
{
char
buf
[
2
];
char
buf
[
2
];
printf
(
"This will shrink the AOF from %ld bytes, with %ld bytes, to %ld bytes
\n
"
,
size
,
diff
,
pos
);
printf
(
"This will shrink the AOF from %
l
ld bytes, with %
l
ld bytes, to %
l
ld bytes
\n
"
,
(
long
long
)
size
,(
long
long
)
diff
,(
long
long
)
pos
);
printf
(
"Continue? [y/N]: "
);
printf
(
"Continue? [y/N]: "
);
if
(
fgets
(
buf
,
sizeof
(
buf
),
stdin
)
==
NULL
||
if
(
fgets
(
buf
,
sizeof
(
buf
),
stdin
)
==
NULL
||
strncasecmp
(
buf
,
"y"
,
1
)
!=
0
)
{
strncasecmp
(
buf
,
"y"
,
1
)
!=
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment