Commit 383737a9 authored by Vitaly Arbuzov's avatar Vitaly Arbuzov
Browse files

Use LSB for saving slot in SCAN cursor

parent 6fbafbe9
......@@ -1016,7 +1016,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {
if (o == NULL && !cursor) {
ht = dbGetNextUnvisitedSlot(c->db, &slot);
}
} while ((cursor || slot > 0) &&
} while ((cursor || slot > 0) && /* Continue iteration if there are more slots to visit, or cursor hasn't reached the end of dict yet. */
maxiterations-- &&
listLength(keys) < (unsigned long) count);
addSlotIdToCursor(slot, &cursor);
......@@ -1124,14 +1124,14 @@ cleanup:
}
void addSlotIdToCursor(int slot, unsigned long long int *cursor) {
if (slot > 0) {
(*cursor) |= ((unsigned long long) slot) << SLOT_MASK_SHIFT;
if (slot >= 0) {
*cursor = (*cursor << SLOT_MASK_SHIFT) | slot;
}
}
int getAndClearSlotIdFromCursor(unsigned long long int *cursor) {
int slot = (int) ((*cursor & SLOT_MASK) >> SLOT_MASK_SHIFT);
(*cursor) = (*cursor) & ~SLOT_MASK;
int slot = (int) (*cursor & SLOT_MASK);
*cursor = ((*cursor) & ~SLOT_MASK) >> SLOT_MASK_SHIFT;
return slot;
}
......
......@@ -3113,8 +3113,8 @@ sds keyspaceEventsFlagsToString(int flags);
#define MEMORY_CONFIG (1<<0) /* Indicates if this value can be loaded as a memory value */
#define PERCENT_CONFIG (1<<1) /* Indicates if this value can be loaded as a percent (and stored as a negative int) */
#define OCTAL_CONFIG (1<<2) /* This value uses octal representation */
#define SLOT_MASK_SHIFT 48 /* Slot id is stored in high bits of the Scan API cursor, this number defines by how many bits it's shifted. */
#define SLOT_MASK ((unsigned long long)(CLUSTER_SLOTS - 1) << SLOT_MASK_SHIFT)
#define SLOT_MASK_SHIFT 14 /* Slot id is stored in low bits of the Scan API cursor, this number defines by how many bits it's shifted. */
#define SLOT_MASK ((unsigned long long)(CLUSTER_SLOTS - 1))
/* Enum Configs contain an array of configEnum objects that match a string with an integer. */
typedef struct configEnum {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment