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
742c6750
Commit
742c6750
authored
Jan 19, 2023
by
Vitaly Arbuzov
Browse files
Add comments for db iterator functions
parent
a4b155fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/cluster.h
View file @
742c6750
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
* Redis cluster data structures, defines, exported API.
* Redis cluster data structures, defines, exported API.
*----------------------------------------------------------------------------*/
*----------------------------------------------------------------------------*/
#define CLUSTER_SLOT_MASK_BITS 14
/* Number of bits used for slot id.*/
#define CLUSTER_SLOT_MASK_BITS 14
/* Number of bits used for slot id.
*/
#define CLUSTER_SLOTS (1<<CLUSTER_SLOT_MASK_BITS)
/* Total number of slots in cluster mode. */
#define CLUSTER_SLOTS (1<<CLUSTER_SLOT_MASK_BITS)
/* Total number of slots in cluster mode
, which is 16384
. */
#define CLUSTER_SLOT_MASK ((unsigned long long)(CLUSTER_SLOTS - 1))
/* Bit mask for slot id stored in LSB. */
#define CLUSTER_SLOT_MASK ((unsigned long long)(CLUSTER_SLOTS - 1))
/* Bit mask for slot id stored in LSB. */
#define CLUSTER_OK 0
/* Everything looks ok */
#define CLUSTER_OK 0
/* Everything looks ok */
#define CLUSTER_FAIL 1
/* The cluster can't work */
#define CLUSTER_FAIL 1
/* The cluster can't work */
...
...
src/db.c
View file @
742c6750
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
int expireIfNeeded(redisDb *db, robj *key, int flags);
int expireIfNeeded(redisDb *db, robj *key, int flags);
int keyIsExpired(redisDb *db, robj *key);
int keyIsExpired(redisDb *db, robj *key);
/* Returns next dictionary from the iterator, or NULL if iteration is complete. */
dict *dbNextDict(dbIterator *iter) {
dict *dbNextDict(dbIterator *iter) {
while (iter->index < iter->db->dict_count - 1) {
while (iter->index < iter->db->dict_count - 1) {
iter->index++;
iter->index++;
...
@@ -59,11 +60,7 @@ dict *dbNextDict(dbIterator *iter) {
...
@@ -59,11 +60,7 @@ dict *dbNextDict(dbIterator *iter) {
return NULL;
return NULL;
}
}
dbIterator
*
dbGetIterator
(
redisDb
*
db
)
{
void dbInitIteratorAt(dbIterator *dbit, redisDb *db, int slot) {
return
dbGetIteratorAt
(
db
,
0
);
}
dbIterator
*
dbGetIteratorAt
(
redisDb
*
db
,
int
slot
)
{
serverAssert(slot == 0 || server.cluster_enabled);
serverAssert(slot == 0 || server.cluster_enabled);
dbIterator *iter = zmalloc(sizeof(*iter));
dbIterator *iter = zmalloc(sizeof(*iter));
iter->db = db;
iter->db = db;
...
@@ -71,6 +68,14 @@ dbIterator *dbGetIteratorAt(redisDb *db, int slot) {
...
@@ -71,6 +68,14 @@ dbIterator *dbGetIteratorAt(redisDb *db, int slot) {
return iter;
return iter;
}
}
/* Returns DB iterator that can be used to iterate through sub-dictionaries.
* Primary database contains only one dictionary when node runs without cluster mode,
* or 16k dictionaries (one per slot) when node runs with cluster mode enabled. */
void dbInitIterator(dbIterator *dbit, redisDb *db) {
dbInitIteratorAt(dbit, db, 0);
}
/* Returns next dictionary strictly after provided slot and updates slot id in the supplied reference. */
dict *dbGetNextUnvisitedSlot(redisDb *db, int *slot) {
dict *dbGetNextUnvisitedSlot(redisDb *db, int *slot) {
if (*slot < db->dict_count - 1) {
if (*slot < db->dict_count - 1) {
dbIterator *dbit = dbGetIteratorAt(db, *slot + 1); /* Scan on the current slot has already returned 0, find next non-empty dict. */
dbIterator *dbit = dbGetIteratorAt(db, *slot + 1); /* Scan on the current slot has already returned 0, find next non-empty dict. */
...
@@ -1121,6 +1126,7 @@ cleanup:
...
@@ -1121,6 +1126,7 @@ cleanup:
}
}
void addSlotIdToCursor(int slot, unsigned long long int *cursor) {
void addSlotIdToCursor(int slot, unsigned long long int *cursor) {
/* Slot id can be -1 if there are no more slots to visit. */
if (slot >= 0) {
if (slot >= 0) {
*cursor = (*cursor << CLUSTER_SLOT_MASK_BITS) | slot;
*cursor = (*cursor << CLUSTER_SLOT_MASK_BITS) | slot;
}
}
...
...
src/server.h
View file @
742c6750
...
@@ -2361,12 +2361,10 @@ typedef struct dbIterator {
...
@@ -2361,12 +2361,10 @@ typedef struct dbIterator {
int
index
;
int
index
;
}
dbIterator
;
}
dbIterator
;
/* dbIterator specific functions */
/* DB iterator specific functions */
dict
*
dbNextDict
(
dbIterator
*
iter
);
void
dbInitIterator
(
dbIterator
*
dbit
,
redisDb
*
db
);
dbIterator
*
dbGetIterator
(
redisDb
*
db
);
dict
*
dbNextDict
(
dbIterator
*
dbit
);
dbIterator
*
dbGetIteratorAt
(
redisDb
*
db
,
int
slot
);
dict
*
dbGetNextUnvisitedSlot
(
redisDb
*
db
,
int
*
slot
);
dict
*
dbGetNextUnvisitedSlot
(
redisDb
*
db
,
int
*
slot
);
void
dbReleaseIterator
(
dbIterator
*
iter
);
/* SCAN specific commands for easy cursor manipulation, shared between main code and modules. */
/* SCAN specific commands for easy cursor manipulation, shared between main code and modules. */
int
getAndClearSlotIdFromCursor
(
unsigned
long
long
int
*
cursor
);
int
getAndClearSlotIdFromCursor
(
unsigned
long
long
int
*
cursor
);
...
...
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