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
fddeeae7
Commit
fddeeae7
authored
Jul 31, 2018
by
zhaozhao.zz
Browse files
refactor dbOverwrite to make lazyfree work
parent
fd174cca
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
fddeeae7
...
@@ -184,14 +184,19 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) {
...
@@ -184,14 +184,19 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) {
dictEntry
*
de
=
dictFind
(
db
->
dict
,
key
->
ptr
);
dictEntry
*
de
=
dictFind
(
db
->
dict
,
key
->
ptr
);
serverAssertWithInfo
(
NULL
,
key
,
de
!=
NULL
);
serverAssertWithInfo
(
NULL
,
key
,
de
!=
NULL
);
dictEntry
auxentry
=
*
de
;
robj
*
old
=
dictGetVal
(
de
);
if
(
server
.
maxmemory_policy
&
MAXMEMORY_FLAG_LFU
)
{
if
(
server
.
maxmemory_policy
&
MAXMEMORY_FLAG_LFU
)
{
robj
*
old
=
dictGetVal
(
de
);
val
->
lru
=
old
->
lru
;
int
saved_lru
=
old
->
lru
;
}
dictReplace
(
db
->
dict
,
key
->
ptr
,
val
);
dictSetVal
(
db
->
dict
,
de
,
val
);
val
->
lru
=
saved_lru
;
}
else
{
if
(
server
.
lazyfree_lazy_server_del
)
{
dictReplace
(
db
->
dict
,
key
->
ptr
,
val
);
freeObjAsync
(
old
);
dictSetVal
(
db
->
dict
,
&
auxentry
,
NULL
);
}
}
dictFreeVal
(
db
->
dict
,
&
auxentry
);
}
}
/* High level Set operation. This function can be used in order to set
/* High level Set operation. This function can be used in order to set
...
...
src/lazyfree.c
View file @
fddeeae7
...
@@ -90,6 +90,17 @@ int dbAsyncDelete(redisDb *db, robj *key) {
...
@@ -90,6 +90,17 @@ int dbAsyncDelete(redisDb *db, robj *key) {
}
}
}
}
/* Free an object, if the object is huge enough, free it in async way. */
void
freeObjAsync
(
robj
*
o
)
{
size_t
free_effort
=
lazyfreeGetFreeEffort
(
o
);
if
(
free_effort
>
LAZYFREE_THRESHOLD
&&
o
->
refcount
==
1
)
{
atomicIncr
(
lazyfree_objects
,
1
);
bioCreateBackgroundJob
(
BIO_LAZY_FREE
,
o
,
NULL
,
NULL
);
}
else
{
decrRefCount
(
o
);
}
}
/* Empty a Redis DB asynchronously. What the function does actually is to
/* Empty a Redis DB asynchronously. What the function does actually is to
* create a new empty set of hash tables and scheduling the old ones for
* create a new empty set of hash tables and scheduling the old ones for
* lazy freeing. */
* lazy freeing. */
...
...
src/server.h
View file @
fddeeae7
...
@@ -1824,6 +1824,7 @@ int dbAsyncDelete(redisDb *db, robj *key);
...
@@ -1824,6 +1824,7 @@ int dbAsyncDelete(redisDb *db, robj *key);
void
emptyDbAsync
(
redisDb
*
db
);
void
emptyDbAsync
(
redisDb
*
db
);
void
slotToKeyFlushAsync
(
void
);
void
slotToKeyFlushAsync
(
void
);
size_t
lazyfreeGetPendingObjectsCount
(
void
);
size_t
lazyfreeGetPendingObjectsCount
(
void
);
void
freeObjAsync
(
robj
*
o
);
/* API to get key arguments from commands */
/* API to get key arguments from commands */
int
*
getKeysFromCommand
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
getKeysFromCommand
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
...
...
src/t_set.c
View file @
fddeeae7
...
@@ -516,11 +516,7 @@ void spopWithCountCommand(client *c) {
...
@@ -516,11 +516,7 @@ void spopWithCountCommand(client *c) {
sdsfree
(
sdsele
);
sdsfree
(
sdsele
);
}
}
/* Assign the new set as the key value. */
/* Tranfer the old set to the client. */
incrRefCount
(
set
);
/* Protect the old set value. */
dbOverwrite
(
c
->
db
,
c
->
argv
[
1
],
newset
);
/* Tranfer the old set to the client and release it. */
setTypeIterator
*
si
;
setTypeIterator
*
si
;
si
=
setTypeInitIterator
(
set
);
si
=
setTypeInitIterator
(
set
);
while
((
encoding
=
setTypeNext
(
si
,
&
sdsele
,
&
llele
))
!=
-
1
)
{
while
((
encoding
=
setTypeNext
(
si
,
&
sdsele
,
&
llele
))
!=
-
1
)
{
...
@@ -539,7 +535,9 @@ void spopWithCountCommand(client *c) {
...
@@ -539,7 +535,9 @@ void spopWithCountCommand(client *c) {
decrRefCount
(
objele
);
decrRefCount
(
objele
);
}
}
setTypeReleaseIterator
(
si
);
setTypeReleaseIterator
(
si
);
decrRefCount
(
set
);
/* Assign the new set as the key value. */
dbOverwrite
(
c
->
db
,
c
->
argv
[
1
],
newset
);
}
}
/* Don't propagate the command itself even if we incremented the
/* Don't propagate the command itself even if we incremented the
...
...
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