-
Notifications
You must be signed in to change notification settings - Fork 56
INTERNAL: Add get_shard_key for hash_ketama #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
jhpark816
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 μλ£
cluster_config.c
Outdated
| return NULL; | ||
| } | ||
|
|
||
| uint32_t remaining = nkey - (left - key) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remaining λ³μλ μ κ±°ν©μλ€.
| *nshardkey = right - left - 1; | ||
| if (*nshardkey == 0) { | ||
| return NULL; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ ν€λ€μ λͺ¨λ ν€ μ μ²΄κ° shard keyκ° λλμ?
redisλ λμΌν μ§ κΆκΈν©λλ€.
- "aaa{}bbb}ccc"
- "add{}{bbb}ccc"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν€ μ μ²΄κ° shard keyκ° λλμ?
λ§μ΅λλ€. μλ λ΄μ©μΌλ‘ λ΅λ³μ΄ λ κ² κ°μ΅λλ€.
https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec/#hash-tags
Examples:
- The two keys
{user1000}.followingand{user1000}.followerswill hash to the same hash slot since only the substringuser1000will be hashed in order to compute the hash slot.- For the key
foo{}{bar}the whole key will be hashed as usual since the first occurrence of{is followed by}on the right without characters in the middle.- For the key
foo{{bar}}zapthe substring{barwill be hashed, because it is the substring between the first occurrence of{and the first occurrence of}on its right.- For the key
foo{bar}{zap}the substringbarwill be hashed, since the algorithm stops at the first valid or invalid (without bytes inside) match of{and}.- What follows from the algorithm is that if the key starts with
{}, it is guaranteed to be hashed as a whole. This is useful when using binary data as key names.
cluster_config.c
Outdated
| hash_md5(shardkey, nshardkey, digest); | ||
| #else | ||
| hash_md5(key, nkey, digest); | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ ννμ μ½λλ‘ νλ©΄ μ’κ² μ΅λλ€.
#ifdef SHARD_KEY
uint32_t nshardkey;
const char *shardkey = get_shard_key(key, nkey, &nshardkey);
if (shardkey) {
key = shardkey;
nkey = nshardkey;
}
#endif
hash_md5(key, nkey, digest);|
μλμ κ°μ΄ μμ λμμ΅λλ€.
|
π Related Issue
β¨οΈ What I did
{μ}μ¬μ΄ λ¬Έμμ΄μ hashμ μ¬μ©ν©λλ€.{ν¬ν¨{λ€μμ}μ‘΄μ¬{, μ²μ λ±μ₯νλ}λ¬Έμ μ¬μ΄μ νλ μ΄μμ λ¬Έμ μ‘΄μ¬