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
8b41e19e
You need to sign in or sign up before continuing.
Commit
8b41e19e
authored
Apr 03, 2013
by
antirez
Browse files
rio.c: added ability to fdatasync() from time to time while writing.
parent
cf7b2c32
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/rio.c
View file @
8b41e19e
...
@@ -48,8 +48,11 @@
...
@@ -48,8 +48,11 @@
#include "fmacros.h"
#include "fmacros.h"
#include <string.h>
#include <string.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include "rio.h"
#include "rio.h"
#include "util.h"
#include "util.h"
#include "config.h"
#include "redis.h"
uint64_t
crc64
(
uint64_t
crc
,
const
unsigned
char
*
s
,
uint64_t
l
);
uint64_t
crc64
(
uint64_t
crc
,
const
unsigned
char
*
s
,
uint64_t
l
);
...
@@ -76,7 +79,18 @@ static off_t rioBufferTell(rio *r) {
...
@@ -76,7 +79,18 @@ static off_t rioBufferTell(rio *r) {
/* Returns 1 or 0 for success/failure. */
/* Returns 1 or 0 for success/failure. */
static
size_t
rioFileWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
static
size_t
rioFileWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
return
fwrite
(
buf
,
len
,
1
,
r
->
io
.
file
.
fp
);
size_t
retval
;
retval
=
fwrite
(
buf
,
len
,
1
,
r
->
io
.
file
.
fp
);
r
->
io
.
file
.
buffered
+=
len
;
if
(
r
->
io
.
file
.
autosync
&&
r
->
io
.
file
.
buffered
>=
r
->
io
.
file
.
autosync
)
{
aof_fsync
(
fileno
(
r
->
io
.
file
.
fp
));
r
->
io
.
file
.
buffered
=
0
;
}
return
retval
;
}
}
/* Returns 1 or 0 for success/failure. */
/* Returns 1 or 0 for success/failure. */
...
@@ -110,6 +124,8 @@ static const rio rioFileIO = {
...
@@ -110,6 +124,8 @@ static const rio rioFileIO = {
void
rioInitWithFile
(
rio
*
r
,
FILE
*
fp
)
{
void
rioInitWithFile
(
rio
*
r
,
FILE
*
fp
)
{
*
r
=
rioFileIO
;
*
r
=
rioFileIO
;
r
->
io
.
file
.
fp
=
fp
;
r
->
io
.
file
.
fp
=
fp
;
r
->
io
.
file
.
buffered
=
0
;
r
->
io
.
file
.
autosync
=
0
;
}
}
void
rioInitWithBuffer
(
rio
*
r
,
sds
s
)
{
void
rioInitWithBuffer
(
rio
*
r
,
sds
s
)
{
...
@@ -124,6 +140,19 @@ void rioGenericUpdateChecksum(rio *r, const void *buf, size_t len) {
...
@@ -124,6 +140,19 @@ void rioGenericUpdateChecksum(rio *r, const void *buf, size_t len) {
r
->
cksum
=
crc64
(
r
->
cksum
,
buf
,
len
);
r
->
cksum
=
crc64
(
r
->
cksum
,
buf
,
len
);
}
}
/* Set the file-based rio object to auto-fsync every 'bytes' file written.
* By default this is set to zero that means no automatic file sync is
* performed.
*
* This feature is useful in a few contexts since when we rely on OS write
* buffers sometimes the OS buffers way too much, resulting in too many
* disk I/O concentrated in very little time. When we fsync in an explicit
* way instead the I/O pressure is more distributed across time. */
void
rioSetAutoSync
(
rio
*
r
,
off_t
bytes
)
{
redisAssert
(
r
->
read
==
rioFileIO
.
read
);
r
->
io
.
file
.
autosync
=
bytes
;
}
/* ------------------------------ Higher level interface ---------------------------
/* ------------------------------ Higher level interface ---------------------------
* The following higher level functions use lower level rio.c functions to help
* The following higher level functions use lower level rio.c functions to help
* generating the Redis protocol for the Append Only File. */
* generating the Redis protocol for the Append Only File. */
...
...
src/rio.h
View file @
8b41e19e
...
@@ -61,6 +61,8 @@ struct _rio {
...
@@ -61,6 +61,8 @@ struct _rio {
}
buffer
;
}
buffer
;
struct
{
struct
{
FILE
*
fp
;
FILE
*
fp
;
off_t
buffered
;
/* Bytes written since last fsync. */
off_t
autosync
;
/* fsync after 'autosync' bytes written. */
}
file
;
}
file
;
}
io
;
}
io
;
};
};
...
@@ -97,5 +99,6 @@ size_t rioWriteBulkLongLong(rio *r, long long l);
...
@@ -97,5 +99,6 @@ size_t rioWriteBulkLongLong(rio *r, long long l);
size_t
rioWriteBulkDouble
(
rio
*
r
,
double
d
);
size_t
rioWriteBulkDouble
(
rio
*
r
,
double
d
);
void
rioGenericUpdateChecksum
(
rio
*
r
,
const
void
*
buf
,
size_t
len
);
void
rioGenericUpdateChecksum
(
rio
*
r
,
const
void
*
buf
,
size_t
len
);
void
rioSetAutoSync
(
rio
*
r
,
off_t
bytes
);
#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