-
Notifications
You must be signed in to change notification settings - Fork 38
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
Prefix based router support #12
Open
tschellenbach
wants to merge
10
commits into
disqus:master
Choose a base branch
from
tschellenbach:f98d64b6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2ae32d
added support for a prefix based router, including tests
tschellenbach f98d64b
added support for a prefix based router, including tests
tschellenbach eb3da71
added support for silently failing redis servers, by setting host:dic…
tschellenbach 31cd00e
upgraded version number
tschellenbach 4021606
slightly udpated docs
tschellenbach db79807
fail silently support for .map()
tschellenbach bc905a7
updated router example
tschellenbach 1bdefc0
improved error reporting when not able to find hosts
tschellenbach 965170d
more testing and better errors for prefix partition routing
tschellenbach 04f22ba
upgraded the version
tschellenbach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
|
||
from .base import BaseRouter, RoundRobinRouter | ||
|
||
from .prefix_partition import PrefixPartitionRouter |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from nydus.db.routers import BaseRouter | ||
|
||
class PrefixPartitionRouter(BaseRouter): | ||
''' | ||
Routes based on the configured prefixes | ||
|
||
Example config: | ||
|
||
'redis': { | ||
'engine': 'nydus.db.backends.redis.Redis', | ||
'router': 'nydus.db.routers.redis.PrefixPartitionRouter', | ||
'hosts': { | ||
'default': {'db': 0, 'host': 'default.redis.goteam.be', 'port': 6379}, | ||
'user:loves:': {'db': 1, 'host': 'default.redis.goteam.be', 'port': 6379}, | ||
'loves:': {'db': 2, 'host': 'default.redis.goteam.be', 'port': 6379}, | ||
'hash:entity:': {'db': 0, 'host': 'entities.redis.goteam.be', 'port': 6379}, | ||
} | ||
} | ||
|
||
We route to one and only one redis. | ||
Use a seperate config if you want hashing based partitioning. | ||
''' | ||
|
||
def _pre_routing(self, cluster, attr, key, *args, **kwargs): | ||
""" | ||
Requesting a pipeline without a key to partition on is just plain wrong. | ||
We raise a valueError if you try | ||
""" | ||
if not key and attr == 'pipeline': | ||
raise ValueError('Pipelines requires a key for proper routing') | ||
return key | ||
|
||
def _route(self, cluster, attr, key, *args, **kwargs): | ||
""" | ||
Perform routing and return db_nums | ||
""" | ||
if 'default' not in cluster.hosts: | ||
error_message = 'The prefix router requires a default host' | ||
raise ValueError(error_message) | ||
hosts = None | ||
if key: | ||
for host in cluster.hosts: | ||
if key.startswith(str(host)): | ||
hosts = [host] | ||
if not hosts: | ||
hosts = ['default'] | ||
|
||
#sanity check, dont see how this can happen | ||
if not hosts: | ||
error_message = 'The prefix partition router couldnt find a host for command %s and key %s' % (attr, key) | ||
raise ValueError(error_message) | ||
|
||
return hosts | ||
|
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For consistency, can you move the imports to the top of the file?