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
292df99a
Commit
292df99a
authored
Jan 11, 2023
by
Vitaly Arbuzov
Browse files
Cache current slot specific dictionary
Add comment Populate current dictionary in the right place
parent
83103f83
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
292df99a
...
@@ -244,6 +244,9 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
...
@@ -244,6 +244,9 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
/* Return slot-specific dictionary for key based on key's hash slot in CME, or 0 in CMD.*/
/* Return slot-specific dictionary for key based on key's hash slot in CME, or 0 in CMD.*/
dict
*
getDict
(
redisDb
*
db
,
sds
key
)
{
dict
*
getDict
(
redisDb
*
db
,
sds
key
)
{
if
(
db
->
current_dict
)
{
return
db
->
current_dict
;
}
return
db
->
dict
[(
server
.
cluster_enabled
?
keyHashSlot
(
key
,
(
int
)
sdslen
(
key
))
:
0
)];
return
db
->
dict
[(
server
.
cluster_enabled
?
keyHashSlot
(
key
,
(
int
)
sdslen
(
key
))
:
0
)];
}
}
...
...
src/server.c
View file @
292df99a
...
@@ -2593,6 +2593,7 @@ void initServer(void) {
...
@@ -2593,6 +2593,7 @@ void initServer(void) {
server
.
db
[
j
].
defrag_later
=
listCreate
();
server
.
db
[
j
].
defrag_later
=
listCreate
();
server
.
db
[
j
].
rehashing
=
listCreate
();
server
.
db
[
j
].
rehashing
=
listCreate
();
server
.
db
[
j
].
dict_count
=
slotCount
;
server
.
db
[
j
].
dict_count
=
slotCount
;
server
.
db
[
j
].
current_dict
=
NULL
;
listSetFreeMethod
(
server
.
db
[
j
].
defrag_later
,(
void
(
*
)(
void
*
))
sdsfree
);
listSetFreeMethod
(
server
.
db
[
j
].
defrag_later
,(
void
(
*
)(
void
*
))
sdsfree
);
}
}
evictionPoolAlloc
();
/* Initialize the LRU keys pool. */
evictionPoolAlloc
();
/* Initialize the LRU keys pool. */
...
@@ -4098,7 +4099,8 @@ int processCommand(client *c) {
...
@@ -4098,7 +4099,8 @@ int processCommand(client *c) {
blockPostponeClient
(
c
);
blockPostponeClient
(
c
);
return
C_OK
;
return
C_OK
;
}
}
/* Set current dictionary for the command, this optimization helps avoid redundant CRC hash calculations to determine key slot. */
if
(
c
->
slot
>=
0
)
c
->
db
->
current_dict
=
c
->
db
->
dict
[
c
->
slot
];
/* Exec the command */
/* Exec the command */
if
(
c
->
flags
&
CLIENT_MULTI
&&
if
(
c
->
flags
&
CLIENT_MULTI
&&
c
->
cmd
->
proc
!=
execCommand
&&
c
->
cmd
->
proc
!=
execCommand
&&
...
@@ -4116,7 +4118,7 @@ int processCommand(client *c) {
...
@@ -4116,7 +4118,7 @@ int processCommand(client *c) {
if
(
listLength
(
server
.
ready_keys
))
if
(
listLength
(
server
.
ready_keys
))
handleClientsBlockedOnKeys
();
handleClientsBlockedOnKeys
();
}
}
c
->
db
->
current_dict
=
NULL
;
return
C_OK
;
return
C_OK
;
}
}
...
...
src/server.h
View file @
292df99a
...
@@ -959,6 +959,7 @@ typedef struct redisDb {
...
@@ -959,6 +959,7 @@ typedef struct redisDb {
list
*
defrag_later
;
/* List of key names to attempt to defrag one by one, gradually. */
list
*
defrag_later
;
/* List of key names to attempt to defrag one by one, gradually. */
list
*
rehashing
;
/* List of dictionaries in this DB that are currently rehashing. */
list
*
rehashing
;
/* List of dictionaries in this DB that are currently rehashing. */
int
dict_count
;
/* Indicates total number of dictionaires owned by this DB, 1 dict per slot in cluster mode. */
int
dict_count
;
/* Indicates total number of dictionaires owned by this DB, 1 dict per slot in cluster mode. */
dict
*
current_dict
;
/* Slot specific dictionary used in the current command, in cluster mode. */
}
redisDb
;
}
redisDb
;
/* forward declaration for functions ctx */
/* forward declaration for functions ctx */
...
...
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