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
af1bb938
Commit
af1bb938
authored
Mar 23, 2023
by
Vitaly Arbuzov
Browse files
Use zcalloc instead of zmalloc for binary_index creation and swap buffers when needed
parent
4d4a7c73
Changes
2
Show whitespace changes
Inline
Side-by-side
src/db.c
View file @
af1bb938
...
...
@@ -622,6 +622,8 @@ long long emptyDbStructure(redisDb *dbarray, int dbnum, int async,
dbarray
[
j
].
resize_cursor
=
0
;
dbarray
[
j
].
key_count
=
0
;
if
(
server
.
cluster_enabled
)
{
zfree
(
dbarray
[
j
].
binary_index
);
dbarray
[
j
].
binary_index
=
zcalloc
(
sizeof
(
unsigned
long
long
)
*
(
CLUSTER_SLOTS
+
1
));
zfree
(
dbarray
[
j
].
non_empty_dicts
);
dbarray
[
j
].
non_empty_dicts
=
intsetNew
();
}
...
...
@@ -693,6 +695,7 @@ redisDb *initTempDb(void) {
tempDb
[
i
].
dict
=
dictCreateMultiple
(
&
dbDictType
,
tempDb
[
i
].
dict_count
);
tempDb
[
i
].
expires
=
dictCreate
(
&
dbExpiresDictType
);
tempDb
[
i
].
non_empty_dicts
=
server
.
cluster_enabled
?
intsetNew
()
:
NULL
;
tempDb
[
i
].
binary_index
=
server
.
cluster_enabled
?
zcalloc
(
sizeof
(
unsigned
long
long
)
*
(
CLUSTER_SLOTS
+
1
))
:
NULL
;
}
return
tempDb
;
...
...
@@ -710,7 +713,10 @@ void discardTempDb(redisDb *tempDb, void(callback)(dict*)) {
}
zfree
(
tempDb
[
i
].
dict
);
dictRelease
(
tempDb
[
i
].
expires
);
if
(
server
.
cluster_enabled
)
zfree
(
tempDb
[
i
].
non_empty_dicts
);
if
(
server
.
cluster_enabled
)
{
zfree
(
tempDb
[
i
].
binary_index
);
zfree
(
tempDb
[
i
].
non_empty_dicts
);
}
}
zfree
(
tempDb
);
...
...
@@ -1655,6 +1661,7 @@ int dbSwapDatabases(int id1, int id2) {
db1
->
dict_count
=
db2
->
dict_count
;
db1
->
key_count
=
db2
->
key_count
;
db1
->
non_empty_dicts
=
db2
->
non_empty_dicts
;
db1
->
binary_index
=
db2
->
binary_index
;
db2
->
dict
=
aux
.
dict
;
db2
->
expires
=
aux
.
expires
;
...
...
@@ -1664,6 +1671,7 @@ int dbSwapDatabases(int id1, int id2) {
db2
->
dict_count
=
aux
.
dict_count
;
db2
->
key_count
=
aux
.
key_count
;
db2
->
non_empty_dicts
=
aux
.
non_empty_dicts
;
db2
->
binary_index
=
aux
.
binary_index
;
/* Now we need to handle clients blocked on lists: as an effect
* of swapping the two DBs, a client that was waiting for list
...
...
@@ -1705,6 +1713,7 @@ void swapMainDbWithTempDb(redisDb *tempDb) {
activedb
->
dict_count
=
newdb
->
dict_count
;
activedb
->
key_count
=
newdb
->
key_count
;
activedb
->
non_empty_dicts
=
newdb
->
non_empty_dicts
;
activedb
->
binary_index
=
newdb
->
binary_index
;
newdb
->
dict
=
aux
.
dict
;
newdb
->
expires
=
aux
.
expires
;
...
...
@@ -1714,6 +1723,7 @@ void swapMainDbWithTempDb(redisDb *tempDb) {
newdb
->
dict_count
=
aux
.
dict_count
;
newdb
->
key_count
=
aux
.
key_count
;
newdb
->
non_empty_dicts
=
aux
.
non_empty_dicts
;
newdb
->
binary_index
=
aux
.
binary_index
;
/* Now we need to handle clients blocked on lists: as an effect
* of swapping the two DBs, a client that was waiting for list
...
...
src/server.c
View file @
af1bb938
...
...
@@ -2634,7 +2634,7 @@ void initServer(void) {
server
.
db
[
j
].
dict_count
=
slotCount
;
server
.
db
[
j
].
key_count
=
0
;
server
.
db
[
j
].
non_empty_dicts
=
server
.
cluster_enabled
?
intsetNew
()
:
NULL
;
server
.
db
[
j
].
binary_index
=
server
.
cluster_enabled
?
z
m
alloc
(
sizeof
(
unsigned
long
long
)
*
(
CLUSTER_SLOTS
+
1
))
:
NULL
;
server
.
db
[
j
].
binary_index
=
server
.
cluster_enabled
?
z
c
alloc
(
sizeof
(
unsigned
long
long
)
*
(
CLUSTER_SLOTS
+
1
))
:
NULL
;
listSetFreeMethod
(
server
.
db
[
j
].
defrag_later
,(
void
(
*
)(
void
*
))
sdsfree
);
}
evictionPoolAlloc
();
/* Initialize the LRU keys pool. */
...
...
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