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
5182dcd6
Unverified
Commit
5182dcd6
authored
Dec 14, 2017
by
Salvatore Sanfilippo
Committed by
GitHub
Dec 14, 2017
Browse files
Merge pull request #4498 from soloestoy/aof-safe-write
Aof safe write -- fix the short write
parents
de276b6a
1b5f56d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/aof.c
View file @
5182dcd6
...
...
@@ -266,6 +266,27 @@ int startAppendOnly(void) {
return
C_OK
;
}
ssize_t
safe_write
(
int
fd
,
const
char
*
buf
,
size_t
len
)
{
ssize_t
nwritten
=
0
,
totwritten
=
0
;
while
(
len
)
{
nwritten
=
write
(
fd
,
buf
,
len
);
if
(
nwritten
<
0
)
{
if
(
errno
==
EINTR
)
{
continue
;
}
return
totwritten
?
totwritten
:
-
1
;
}
len
-=
nwritten
;
buf
+=
nwritten
;
totwritten
+=
nwritten
;
}
return
totwritten
;
}
/* Write the append only file buffer on disk.
*
* Since we are required to write the AOF before replying to the client,
...
...
@@ -323,7 +344,7 @@ void flushAppendOnlyFile(int force) {
* or alike */
latencyStartMonitor
(
latency
);
nwritten
=
write
(
server
.
aof_fd
,
server
.
aof_buf
,
sdslen
(
server
.
aof_buf
));
nwritten
=
safe_
write
(
server
.
aof_fd
,
server
.
aof_buf
,
sdslen
(
server
.
aof_buf
));
latencyEndMonitor
(
latency
);
/* We want to capture different events for delayed writes:
* when the delay happens with a pending fsync, or with a saving child
...
...
@@ -342,7 +363,7 @@ void flushAppendOnlyFile(int force) {
/* We performed the write so reset the postponed flush sentinel to zero. */
server
.
aof_flush_postponed_start
=
0
;
if
(
nwritten
!=
(
s
igned
)
sdslen
(
server
.
aof_buf
))
{
if
(
nwritten
!=
(
s
size_t
)
sdslen
(
server
.
aof_buf
))
{
static
time_t
last_write_error_log
=
0
;
int
can_log
=
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