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
31222292
Commit
31222292
authored
Dec 30, 2010
by
antirez
Browse files
handled DEL command as a special optimized case for disk store
parent
8d51fb6a
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
31222292
...
@@ -205,10 +205,22 @@ void delCommand(redisClient *c) {
...
@@ -205,10 +205,22 @@ void delCommand(redisClient *c) {
int
deleted
=
0
,
j
;
int
deleted
=
0
,
j
;
for
(
j
=
1
;
j
<
c
->
argc
;
j
++
)
{
for
(
j
=
1
;
j
<
c
->
argc
;
j
++
)
{
if
(
server
.
ds_enabled
)
{
lookupKeyRead
(
c
->
db
,
c
->
argv
[
j
]);
/* FIXME: this can be optimized a lot, no real need to load
* a possibly huge value. */
}
if
(
dbDelete
(
c
->
db
,
c
->
argv
[
j
]))
{
if
(
dbDelete
(
c
->
db
,
c
->
argv
[
j
]))
{
signalModifiedKey
(
c
->
db
,
c
->
argv
[
j
]);
signalModifiedKey
(
c
->
db
,
c
->
argv
[
j
]);
server
.
dirty
++
;
server
.
dirty
++
;
deleted
++
;
deleted
++
;
}
else
if
(
server
.
ds_enabled
)
{
if
(
cacheKeyMayExist
(
c
->
db
,
c
->
argv
[
j
])
&&
dsExists
(
c
->
db
,
c
->
argv
[
j
]))
{
cacheScheduleForFlush
(
c
->
db
,
c
->
argv
[
j
]);
deleted
=
1
;
}
}
}
}
}
addReplyLongLong
(
c
,
deleted
);
addReplyLongLong
(
c
,
deleted
);
...
...
src/diskstore.c
View file @
31222292
...
@@ -262,6 +262,10 @@ int dsDel(redisDb *db, robj *key) {
...
@@ -262,6 +262,10 @@ int dsDel(redisDb *db, robj *key) {
}
}
int
dsExists
(
redisDb
*
db
,
robj
*
key
)
{
int
dsExists
(
redisDb
*
db
,
robj
*
key
)
{
char
buf
[
1024
];
dsKeyToPath
(
db
,
buf
,
key
);
return
access
(
buf
,
R_OK
)
==
0
;
}
}
int
dsFlushDb
(
int
dbid
)
{
int
dsFlushDb
(
int
dbid
)
{
...
...
src/dscache.c
View file @
31222292
...
@@ -304,8 +304,10 @@ void vmThreadedIOCompletedJob(aeEventLoop *el, int fd, void *privdata,
...
@@ -304,8 +304,10 @@ void vmThreadedIOCompletedJob(aeEventLoop *el, int fd, void *privdata,
handleClientsBlockedOnSwappedKey
(
j
->
db
,
j
->
key
);
handleClientsBlockedOnSwappedKey
(
j
->
db
,
j
->
key
);
freeIOJob
(
j
);
freeIOJob
(
j
);
}
else
if
(
j
->
type
==
REDIS_IOJOB_SAVE
)
{
}
else
if
(
j
->
type
==
REDIS_IOJOB_SAVE
)
{
redisAssert
(
j
->
val
->
storage
==
REDIS_DS_SAVING
);
if
(
j
->
val
)
{
j
->
val
->
storage
=
REDIS_DS_MEMORY
;
redisAssert
(
j
->
val
->
storage
==
REDIS_DS_SAVING
);
j
->
val
->
storage
=
REDIS_DS_MEMORY
;
}
freeIOJob
(
j
);
freeIOJob
(
j
);
}
}
processed
++
;
processed
++
;
...
@@ -362,11 +364,12 @@ void *IOThreadEntryPoint(void *arg) {
...
@@ -362,11 +364,12 @@ void *IOThreadEntryPoint(void *arg) {
j
->
val
=
dsGet
(
j
->
db
,
j
->
key
,
&
expire
);
j
->
val
=
dsGet
(
j
->
db
,
j
->
key
,
&
expire
);
if
(
j
->
val
)
j
->
expire
=
expire
;
if
(
j
->
val
)
j
->
expire
=
expire
;
}
else
if
(
j
->
type
==
REDIS_IOJOB_SAVE
)
{
}
else
if
(
j
->
type
==
REDIS_IOJOB_SAVE
)
{
redisAssert
(
j
->
val
->
storage
==
REDIS_DS_SAVING
);
if
(
j
->
val
)
{
if
(
j
->
val
)
redisAssert
(
j
->
val
->
storage
==
REDIS_DS_SAVING
);
dsSet
(
j
->
db
,
j
->
key
,
j
->
val
);
dsSet
(
j
->
db
,
j
->
key
,
j
->
val
);
else
}
else
{
dsDel
(
j
->
db
,
j
->
key
);
dsDel
(
j
->
db
,
j
->
key
);
}
}
}
/* Done: insert the job into the processed queue */
/* Done: insert the job into the processed queue */
...
@@ -540,6 +543,15 @@ void cacheCron(void) {
...
@@ -540,6 +543,15 @@ void cacheCron(void) {
}
}
}
}
/* ============ Negative caching for diskstore objects ====================== */
/* Since accesses to keys that don't exist with disk store cost us a disk
* access, we need to cache names of keys that do not exist but are frequently
* accessed. */
int
cacheKeyMayExist
(
redisDb
*
db
,
robj
*
key
)
{
/* FIXME: for now we just always return true. */
return
1
;
}
/* ============ Virtual Memory - Blocking clients on missing keys =========== */
/* ============ Virtual Memory - Blocking clients on missing keys =========== */
/* This function makes the clinet 'c' waiting for the key 'key' to be loaded.
/* This function makes the clinet 'c' waiting for the key 'key' to be loaded.
...
...
src/redis.h
View file @
31222292
...
@@ -808,6 +808,7 @@ void handleClientsBlockedOnSwappedKey(redisDb *db, robj *key);
...
@@ -808,6 +808,7 @@ void handleClientsBlockedOnSwappedKey(redisDb *db, robj *key);
int
cacheFreeOneEntry
(
void
);
int
cacheFreeOneEntry
(
void
);
void
cacheScheduleForFlush
(
redisDb
*
db
,
robj
*
key
);
void
cacheScheduleForFlush
(
redisDb
*
db
,
robj
*
key
);
void
cacheCron
(
void
);
void
cacheCron
(
void
);
int
cacheKeyMayExist
(
redisDb
*
db
,
robj
*
key
);
/* Set data type */
/* Set data type */
robj
*
setTypeCreate
(
robj
*
value
);
robj
*
setTypeCreate
(
robj
*
value
);
...
...
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