Created
July 9, 2012 22:54
-
-
Save emzeq/3079571 to your computer and use it in GitHub Desktop.
Consistent Shard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Append shard ranges as new shard groups are brought online | |
# Format: [Cutoff User ID, Min Shard, Max Shard] | |
USER_ID_SHARD_MAPPING = [ | |
[0, 1, 10], | |
[30000, 11, 20], | |
[500000, 21, 50], | |
] | |
# Consistent shard that falls within a shard range by the user’s ID | |
def consistent_shard(user) | |
*, min, max = USER_ID_SHARD_MAPPING. | |
select { |s| s[0] < user.id }.last | |
(user.id % max - min) + min | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment