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
543e25ef
Commit
543e25ef
authored
Aug 11, 2016
by
antirez
Browse files
RDB AOF preamble: WIP 4 (Mixed RDB/AOF loading).
parent
f1c32f0d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/aof.c
View file @
543e25ef
...
@@ -616,19 +616,23 @@ int loadAppendOnlyFile(char *filename) {
...
@@ -616,19 +616,23 @@ int loadAppendOnlyFile(char *filename) {
struct
redis_stat
sb
;
struct
redis_stat
sb
;
int
old_aof_state
=
server
.
aof_state
;
int
old_aof_state
=
server
.
aof_state
;
long
loops
=
0
;
long
loops
=
0
;
off_t
valid_up_to
=
0
;
/* Offset of
the
latest well-formed command loaded. */
off_t
valid_up_to
=
0
;
/* Offset of latest well-formed command loaded. */
if
(
fp
==
NULL
)
{
serverLog
(
LL_WARNING
,
"Fatal error: can't open the append log file for reading: %s"
,
strerror
(
errno
));
exit
(
1
);
}
/* Handle a zero-length AOF file as a special case. An emtpy AOF file
* is a valid AOF because an empty server with AOF enabled will create
* a zero length file at startup, that will remain like that if no write
* operation is received. */
if
(
fp
&&
redis_fstat
(
fileno
(
fp
),
&
sb
)
!=
-
1
&&
sb
.
st_size
==
0
)
{
if
(
fp
&&
redis_fstat
(
fileno
(
fp
),
&
sb
)
!=
-
1
&&
sb
.
st_size
==
0
)
{
server
.
aof_current_size
=
0
;
server
.
aof_current_size
=
0
;
fclose
(
fp
);
fclose
(
fp
);
return
C_ERR
;
return
C_ERR
;
}
}
if
(
fp
==
NULL
)
{
serverLog
(
LL_WARNING
,
"Fatal error: can't open the append log file for reading: %s"
,
strerror
(
errno
));
exit
(
1
);
}
/* Temporarily disable AOF, to prevent EXEC from feeding a MULTI
/* Temporarily disable AOF, to prevent EXEC from feeding a MULTI
* to the same file we're about to read. */
* to the same file we're about to read. */
server
.
aof_state
=
AOF_OFF
;
server
.
aof_state
=
AOF_OFF
;
...
@@ -636,6 +640,28 @@ int loadAppendOnlyFile(char *filename) {
...
@@ -636,6 +640,28 @@ int loadAppendOnlyFile(char *filename) {
fakeClient
=
createFakeClient
();
fakeClient
=
createFakeClient
();
startLoading
(
fp
);
startLoading
(
fp
);
/* Check if this AOF file has an RDB preamble. In that case we need to
* load the RDB file and later continue loading the AOF tail. */
char
sig
[
5
];
/* "REDIS" */
if
(
fread
(
sig
,
1
,
5
,
fp
)
!=
5
||
memcmp
(
sig
,
"REDIS"
,
5
)
!=
0
)
{
/* No RDB preamble, seek back at 0 offset. */
if
(
fseek
(
fp
,
0
,
SEEK_SET
)
==
-
1
)
goto
readerr
;
}
else
{
/* RDB preamble. Pass loading the RDB functions. */
rio
rdb
;
serverLog
(
LL_NOTICE
,
"Reading RDB preamble from AOF file..."
);
if
(
fseek
(
fp
,
0
,
SEEK_SET
)
==
-
1
)
goto
readerr
;
rioInitWithFile
(
&
rdb
,
fp
);
if
(
rdbLoadRio
(
&
rdb
)
!=
C_OK
)
{
serverLog
(
LL_WARNING
,
"Error reading the RDB preamble of the AOF file, AOF loading aborted"
);
goto
readerr
;
}
else
{
serverLog
(
LL_NOTICE
,
"Reading the remaining AOF tail..."
);
}
}
/* Read the actual AOF file, in REPL format, command by command. */
while
(
1
)
{
while
(
1
)
{
int
argc
,
j
;
int
argc
,
j
;
unsigned
long
len
;
unsigned
long
len
;
...
...
src/rdb.h
View file @
543e25ef
...
@@ -134,5 +134,6 @@ ssize_t rdbSaveRawString(rio *rdb, unsigned char *s, size_t len);
...
@@ -134,5 +134,6 @@ ssize_t rdbSaveRawString(rio *rdb, unsigned char *s, size_t len);
void
*
rdbGenericLoadStringObject
(
rio
*
rdb
,
int
flags
,
size_t
*
lenptr
);
void
*
rdbGenericLoadStringObject
(
rio
*
rdb
,
int
flags
,
size_t
*
lenptr
);
int
rdbSaveBinaryDoubleValue
(
rio
*
rdb
,
double
val
);
int
rdbSaveBinaryDoubleValue
(
rio
*
rdb
,
double
val
);
int
rdbLoadBinaryDoubleValue
(
rio
*
rdb
,
double
*
val
);
int
rdbLoadBinaryDoubleValue
(
rio
*
rdb
,
double
*
val
);
int
rdbLoadRio
(
rio
*
rdb
);
#endif
#endif
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