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
92b39a0a
Unverified
Commit
92b39a0a
authored
Jul 31, 2018
by
Salvatore Sanfilippo
Committed by
GitHub
Jul 31, 2018
Browse files
Merge pull request #5189 from soloestoy/refactor-dbOverwrite
refactor dbOverwrite to make lazyfree work
parents
db693be0
fddeeae7
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
92b39a0a
...
...
@@ -184,14 +184,19 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) {
dictEntry
*
de
=
dictFind
(
db
->
dict
,
key
->
ptr
);
serverAssertWithInfo
(
NULL
,
key
,
de
!=
NULL
);
dictEntry
auxentry
=
*
de
;
robj
*
old
=
dictGetVal
(
de
);
if
(
server
.
maxmemory_policy
&
MAXMEMORY_FLAG_LFU
)
{
robj
*
old
=
dictGetVal
(
de
);
int
saved_lru
=
old
->
lru
;
dictReplace
(
db
->
dict
,
key
->
ptr
,
val
);
val
->
lru
=
saved_lru
;
}
else
{
dictReplace
(
db
->
dict
,
key
->
ptr
,
val
);
val
->
lru
=
old
->
lru
;
}
dictSetVal
(
db
->
dict
,
de
,
val
);
if
(
server
.
lazyfree_lazy_server_del
)
{
freeObjAsync
(
old
);
dictSetVal
(
db
->
dict
,
&
auxentry
,
NULL
);
}
dictFreeVal
(
db
->
dict
,
&
auxentry
);
}
/* High level Set operation. This function can be used in order to set
...
...
src/lazyfree.c
View file @
92b39a0a
...
...
@@ -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
* create a new empty set of hash tables and scheduling the old ones for
* lazy freeing. */
...
...
src/server.h
View file @
92b39a0a
...
...
@@ -1835,6 +1835,7 @@ int dbAsyncDelete(redisDb *db, robj *key);
void
emptyDbAsync
(
redisDb
*
db
);
void
slotToKeyFlushAsync
(
void
);
size_t
lazyfreeGetPendingObjectsCount
(
void
);
void
freeObjAsync
(
robj
*
o
);
/* API to get key arguments from commands */
int
*
getKeysFromCommand
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
...
...
src/t_set.c
View file @
92b39a0a
...
...
@@ -516,11 +516,7 @@ void spopWithCountCommand(client *c) {
sdsfree
(
sdsele
);
}
/* Assign the new set as the key value. */
incrRefCount
(
set
);
/* Protect the old set value. */
dbOverwrite
(
c
->
db
,
c
->
argv
[
1
],
newset
);
/* Tranfer the old set to the client and release it. */
/* Tranfer the old set to the client. */
setTypeIterator
*
si
;
si
=
setTypeInitIterator
(
set
);
while
((
encoding
=
setTypeNext
(
si
,
&
sdsele
,
&
llele
))
!=
-
1
)
{
...
...
@@ -539,7 +535,9 @@ void spopWithCountCommand(client *c) {
decrRefCount
(
objele
);
}
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
...
...
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