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
ddbc81af
Commit
ddbc81af
authored
Dec 29, 2010
by
antirez
Browse files
diskstore directory structure creation
parent
f63f0928
Changes
3
Show whitespace changes
Inline
Side-by-side
src/diskstore.c
View file @
ddbc81af
...
@@ -74,10 +74,26 @@
...
@@ -74,10 +74,26 @@
#include <fcntl.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/stat.h>
int
create256dir
(
char
*
prefix
)
{
char
buf
[
1024
];
int
j
;
for
(
j
=
0
;
j
<
256
;
j
++
)
{
snprintf
(
buf
,
sizeof
(
buf
),
"%s%02x"
,
prefix
,
j
);
if
(
mkdir
(
buf
,
0755
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Error creating dir %s for diskstore: %s"
,
buf
,
strerror
(
errno
));
return
REDIS_ERR
;
}
}
return
REDIS_OK
;
}
int
dsOpen
(
void
)
{
int
dsOpen
(
void
)
{
struct
stat
sb
;
struct
stat
sb
;
int
retval
;
int
retval
,
j
;
char
*
path
=
server
.
ds_path
;
char
*
path
=
server
.
ds_path
;
char
buf
[
1024
];
if
((
retval
=
stat
(
path
,
&
sb
)
==
-
1
)
&&
errno
!=
ENOENT
)
{
if
((
retval
=
stat
(
path
,
&
sb
)
==
-
1
)
&&
errno
!=
ENOENT
)
{
redisLog
(
REDIS_WARNING
,
"Error opening disk store at %s: %s"
,
redisLog
(
REDIS_WARNING
,
"Error opening disk store at %s: %s"
,
...
@@ -97,11 +113,20 @@ int dsOpen(void) {
...
@@ -97,11 +113,20 @@ int dsOpen(void) {
/* New disk store, create the directory structure now, as creating
/* New disk store, create the directory structure now, as creating
* them in a lazy way is not a good idea, after very few insertions
* them in a lazy way is not a good idea, after very few insertions
* we'll need most of the 65536 directories anyway. */
* we'll need most of the 65536 directories anyway. */
if
(
mkdir
(
path
,
0
644
)
==
-
1
)
{
if
(
mkdir
(
path
,
0
755
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Disk store init failed creating dir %s: %s"
,
redisLog
(
REDIS_WARNING
,
"Disk store init failed creating dir %s: %s"
,
path
,
strerror
(
errno
));
path
,
strerror
(
errno
));
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
/* Create the top level 256 directories */
snprintf
(
buf
,
sizeof
(
buf
),
"%s/"
,
path
);
if
(
create256dir
(
buf
)
==
REDIS_ERR
)
return
REDIS_ERR
;
/* For every 256 top level dir, create 256 nested dirs */
for
(
j
=
0
;
j
<
256
;
j
++
)
{
snprintf
(
buf
,
sizeof
(
buf
),
"%s/%02x/"
,
path
,
j
);
if
(
create256dir
(
buf
)
==
REDIS_ERR
)
return
REDIS_ERR
;
}
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
...
src/dscache.c
View file @
ddbc81af
...
@@ -457,6 +457,7 @@ void cacheScheduleForFlush(redisDb *db, robj *key) {
...
@@ -457,6 +457,7 @@ void cacheScheduleForFlush(redisDb *db, robj *key) {
val
->
storage
=
REDIS_DS_DIRTY
;
val
->
storage
=
REDIS_DS_DIRTY
;
}
}
redisLog
(
REDIS_DEBUG
,
"Scheduling key %s for saving"
,
key
->
ptr
);
dk
=
zmalloc
(
sizeof
(
*
dk
));
dk
=
zmalloc
(
sizeof
(
*
dk
));
dk
->
db
=
db
;
dk
->
db
=
db
;
dk
->
key
=
key
;
dk
->
key
=
key
;
...
@@ -477,6 +478,8 @@ void cacheCron(void) {
...
@@ -477,6 +478,8 @@ void cacheCron(void) {
struct
dictEntry
*
de
;
struct
dictEntry
*
de
;
robj
*
val
;
robj
*
val
;
redisLog
(
REDIS_DEBUG
,
"Creating IO Job to save key %s"
,
dk
->
key
->
ptr
);
/* Lookup the key. We need to check if it's still here and
/* Lookup the key. We need to check if it's still here and
* possibly access to the value. */
* possibly access to the value. */
de
=
dictFind
(
dk
->
db
->
dict
,
dk
->
key
->
ptr
);
de
=
dictFind
(
dk
->
db
->
dict
,
dk
->
key
->
ptr
);
...
...
src/redis.c
View file @
ddbc81af
...
@@ -1493,7 +1493,9 @@ int main(int argc, char **argv) {
...
@@ -1493,7 +1493,9 @@ int main(int argc, char **argv) {
linuxOvercommitMemoryWarning
();
linuxOvercommitMemoryWarning
();
#endif
#endif
start
=
time
(
NULL
);
start
=
time
(
NULL
);
if
(
server
.
appendonly
)
{
if
(
server
.
ds_enabled
)
{
redisLog
(
REDIS_NOTICE
,
"Running with disk back end"
);
}
else
if
(
server
.
appendonly
)
{
if
(
loadAppendOnlyFile
(
server
.
appendfilename
)
==
REDIS_OK
)
if
(
loadAppendOnlyFile
(
server
.
appendfilename
)
==
REDIS_OK
)
redisLog
(
REDIS_NOTICE
,
"DB loaded from append only file: %ld seconds"
,
time
(
NULL
)
-
start
);
redisLog
(
REDIS_NOTICE
,
"DB loaded from append only file: %ld seconds"
,
time
(
NULL
)
-
start
);
}
else
{
}
else
{
...
...
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