Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
8504bf18
Commit
8504bf18
authored
Sep 03, 2016
by
antirez
Browse files
dict.c clustered buckets.
parent
560e6787
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
src/debug.c
View file @
8504bf18
...
@@ -434,7 +434,7 @@ void debugCommand(client *c) {
...
@@ -434,7 +434,7 @@ void debugCommand(client *c) {
if
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
keys
,
NULL
)
!=
C_OK
)
if
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
keys
,
NULL
)
!=
C_OK
)
return
;
return
;
dictExpand
(
c
->
db
->
dict
,
keys
);
dictExpand
ToOptimalSize
(
c
->
db
->
dict
,
keys
);
for
(
j
=
0
;
j
<
keys
;
j
++
)
{
for
(
j
=
0
;
j
<
keys
;
j
++
)
{
snprintf
(
buf
,
sizeof
(
buf
),
"%s:%lu"
,
snprintf
(
buf
,
sizeof
(
buf
),
"%s:%lu"
,
(
c
->
argc
==
3
)
?
"key"
:
(
char
*
)
c
->
argv
[
3
]
->
ptr
,
j
);
(
c
->
argc
==
3
)
?
"key"
:
(
char
*
)
c
->
argv
[
3
]
->
ptr
,
j
);
...
...
src/dict.c
View file @
8504bf18
This diff is collapsed.
Click to expand it.
src/dict.h
View file @
8504bf18
...
@@ -54,10 +54,11 @@ typedef struct dictEntry {
...
@@ -54,10 +54,11 @@ typedef struct dictEntry {
}
v
;
}
v
;
}
dictEntry
;
}
dictEntry
;
typedef
struct
dictEntrySlot
{
typedef
struct
dictEntryVector
{
unsigned
long
numentries
;
uint32_t
used
;
/* Number of used entries. */
dictEntry
*
entries
;
uint32_t
free
;
/* Number of free entries (with key field = NULL). */
}
dictEntrySlot
;
dictEntry
entry
[];
}
dictEntryVector
;
typedef
struct
dictType
{
typedef
struct
dictType
{
unsigned
int
(
*
hashFunction
)(
const
void
*
key
);
unsigned
int
(
*
hashFunction
)(
const
void
*
key
);
...
@@ -71,7 +72,7 @@ typedef struct dictType {
...
@@ -71,7 +72,7 @@ typedef struct dictType {
/* This is our hash table structure. Every dictionary has two of this as we
/* This is our hash table structure. Every dictionary has two of this as we
* implement incremental rehashing, for the old to the new table. */
* implement incremental rehashing, for the old to the new table. */
typedef
struct
dictht
{
typedef
struct
dictht
{
dictEntry
Slot
**
table
;
dictEntry
Vector
**
table
;
unsigned
long
size
;
unsigned
long
size
;
unsigned
long
sizemask
;
unsigned
long
sizemask
;
unsigned
long
used
;
unsigned
long
used
;
...
@@ -93,7 +94,7 @@ typedef struct dictIterator {
...
@@ -93,7 +94,7 @@ typedef struct dictIterator {
dict
*
d
;
dict
*
d
;
long
index
;
long
index
;
int
table
,
safe
;
int
table
,
safe
;
dictEntry
*
entry
,
*
nextEntry
;
long
entry
;
/* Current entry position in the cluster. */
/* unsafe iterator fingerprint for misuse detection. */
/* unsafe iterator fingerprint for misuse detection. */
long
long
fingerprint
;
long
long
fingerprint
;
}
dictIterator
;
}
dictIterator
;
...
@@ -153,6 +154,7 @@ typedef void (dictScanFunction)(void *privdata, const dictEntry *de);
...
@@ -153,6 +154,7 @@ typedef void (dictScanFunction)(void *privdata, const dictEntry *de);
/* API */
/* API */
dict
*
dictCreate
(
dictType
*
type
,
void
*
privDataPtr
);
dict
*
dictCreate
(
dictType
*
type
,
void
*
privDataPtr
);
int
dictExpand
(
dict
*
d
,
unsigned
long
size
);
int
dictExpand
(
dict
*
d
,
unsigned
long
size
);
int
dictExpandToOptimalSize
(
dict
*
d
,
unsigned
long
entries
);
int
dictAdd
(
dict
*
d
,
void
*
key
,
void
*
val
);
int
dictAdd
(
dict
*
d
,
void
*
key
,
void
*
val
);
dictEntry
*
dictAddRaw
(
dict
*
d
,
void
*
key
);
dictEntry
*
dictAddRaw
(
dict
*
d
,
void
*
key
);
int
dictReplace
(
dict
*
d
,
void
*
key
,
void
*
val
);
int
dictReplace
(
dict
*
d
,
void
*
key
,
void
*
val
);
...
...
src/rdb.c
View file @
8504bf18
...
@@ -1086,7 +1086,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
...
@@ -1086,7 +1086,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
/* It's faster to expand the dict to the right size asap in order
/* It's faster to expand the dict to the right size asap in order
* to avoid rehashing */
* to avoid rehashing */
if
(
len
>
DICT_HT_INITIAL_SIZE
)
if
(
len
>
DICT_HT_INITIAL_SIZE
)
dictExpand
(
o
->
ptr
,
len
);
dictExpand
ToOptimalSize
(
o
->
ptr
,
len
);
}
else
{
}
else
{
o
=
createIntsetObject
();
o
=
createIntsetObject
();
}
}
...
@@ -1105,7 +1105,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
...
@@ -1105,7 +1105,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
o
->
ptr
=
intsetAdd
(
o
->
ptr
,
llval
,
NULL
);
o
->
ptr
=
intsetAdd
(
o
->
ptr
,
llval
,
NULL
);
}
else
{
}
else
{
setTypeConvert
(
o
,
OBJ_ENCODING_HT
);
setTypeConvert
(
o
,
OBJ_ENCODING_HT
);
dictExpand
(
o
->
ptr
,
len
);
dictExpand
ToOptimalSize
(
o
->
ptr
,
len
);
}
}
}
}
...
@@ -1452,8 +1452,8 @@ int rdbLoad(char *filename) {
...
@@ -1452,8 +1452,8 @@ int rdbLoad(char *filename) {
goto
eoferr
;
goto
eoferr
;
if
((
expires_size
=
rdbLoadLen
(
&
rdb
,
NULL
))
==
RDB_LENERR
)
if
((
expires_size
=
rdbLoadLen
(
&
rdb
,
NULL
))
==
RDB_LENERR
)
goto
eoferr
;
goto
eoferr
;
dictExpand
(
db
->
dict
,
db_size
);
dictExpand
ToOptimalSize
(
db
->
dict
,
db_size
);
dictExpand
(
db
->
expires
,
expires_size
);
dictExpand
ToOptimalSize
(
db
->
expires
,
expires_size
);
continue
;
/* Read type again. */
continue
;
/* Read type again. */
}
else
if
(
type
==
RDB_OPCODE_AUX
)
{
}
else
if
(
type
==
RDB_OPCODE_AUX
)
{
/* AUX: generic string-string fields. Use to add state to RDB
/* AUX: generic string-string fields. Use to add state to RDB
...
...
src/t_set.c
View file @
8504bf18
...
@@ -243,7 +243,7 @@ void setTypeConvert(robj *setobj, int enc) {
...
@@ -243,7 +243,7 @@ void setTypeConvert(robj *setobj, int enc) {
sds
element
;
sds
element
;
/* Presize the dict to avoid rehashing */
/* Presize the dict to avoid rehashing */
dictExpand
(
d
,
intsetLen
(
setobj
->
ptr
));
dictExpand
ToOptimalSize
(
d
,
intsetLen
(
setobj
->
ptr
));
/* To add the elements we extract integers and create redis objects */
/* To add the elements we extract integers and create redis objects */
si
=
setTypeInitIterator
(
setobj
);
si
=
setTypeInitIterator
(
setobj
);
...
...
src/t_zset.c
View file @
8504bf18
...
@@ -2268,7 +2268,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
...
@@ -2268,7 +2268,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
if
(
setnum
)
{
if
(
setnum
)
{
/* Our union is at least as large as the largest set.
/* Our union is at least as large as the largest set.
* Resize the dictionary ASAP to avoid useless rehashing. */
* Resize the dictionary ASAP to avoid useless rehashing. */
dictExpand
(
accumulator
,
zuiLength
(
&
src
[
setnum
-
1
]));
dictExpand
ToOptimalSize
(
accumulator
,
zuiLength
(
&
src
[
setnum
-
1
]));
}
}
/* Step 1: Create a dictionary of elements -> aggregated-scores
/* Step 1: Create a dictionary of elements -> aggregated-scores
...
@@ -2313,7 +2313,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
...
@@ -2313,7 +2313,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
/* We now are aware of the final size of the resulting sorted set,
/* We now are aware of the final size of the resulting sorted set,
* let's resize the dictionary embedded inside the sorted set to the
* let's resize the dictionary embedded inside the sorted set to the
* right size, in order to save rehashing time. */
* right size, in order to save rehashing time. */
dictExpand
(
dstzset
->
dict
,
dictSize
(
accumulator
));
dictExpand
ToOptimalSize
(
dstzset
->
dict
,
dictSize
(
accumulator
));
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
sds
ele
=
dictGetKey
(
de
);
sds
ele
=
dictGetKey
(
de
);
...
...
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