Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Dynamic sharding implementation #174

Open
wants to merge 10 commits into from

4 participants

@yaourt

Please could you review the following proposal and tell me what do you think about it ?

Currently, Jedis doesn't support dynamic sharding.

If we want to add / remove a Redis server from the available shards, then the only way to achieve this is to stop the application, change the sharding configuration and then restart it.

This implementation allows various things like :

  • to add / remove some servers without downtime for the application
  • to externalize the Redis connectivity monitoring and adapt the sharding configuration in pseudo-realtime
  • to centralize the sharding configuration for a cluster in a DB or something similar
  • etc

This proposal delegates the sharding configuration to a component outside of Jedis and allow to dynamically update the sharding configuration without down time.

JedisDynamicShardsProvider class is doing the bridge between this component and Jedis internals.

The external component manages the sharding configuration the way it wants and when an update is required, it only has to call the relevant method add/removeShard( ) or setShards( ) on JedisDynamicShardsProvider.

Upon such a call, JedisDynamicShardsProvider then notify (when absolutely required) Sharded instances about such a change (inspired from the Observable / Observer pattern)

When Sharded handles such a notification, then all the read access on the shard configuration are blocked until it has finished to change the sharding configuration (ReentrantReadWriteLock usage).

yaourt added some commits
@yaourt yaourt Introduce DynamicShardProvider. 68b9795
@yaourt yaourt DynamicShardProvider with R/W locking mechanism 7a4b47b
@yaourt yaourt Push new constructors in BinaryShardedJedis & ShardedJedis that accep…
…t a JedisDynamicShardsProvider instead of a static shards list
8b790fc
@yaourt yaourt Various fixes and integration tests for dynamic shards updates :
- Use ReentrantReadWriteLock in AbstractDynamicShardsProvider
- Fix read/write locks in Sharded
- Add integration tests with concurrency
2d87bd4
@ib84

nice!

@ib84

Hi yaourt. Did you test this already?

@yaourt

Mmmmh, to be honest, I added several tests for this but I don't remember if I ran all the Jedis test suite ...

So please, gimme some time to confirm, so you will not loose your time ...

@ib84

yes that would be a big help thanks. I'd like your dynamic sharding!

@yaourt

I've your answer :

Results :

Tests run: 215, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

@ib84

nice! I assume it also passed your own custom tests for add/removing shards. forwarding to jonathan

@yaourt

Real life sample usage code .... (DAO impl NOT provided)

https://gist.github.com/1206366

@ib84

ah ok thanks, I just wrote you a personal mail asking just those two things. Have a read anyway for another thing

@yaourt

Up ;-)

Getting started sample available here : https://gist.github.com/1211016

@goldfishy

Will this be merged into Jedis? :)

@allen-servedio allen-servedio commented on the diff
src/main/java/redis/clients/util/Sharded.java
((68 lines not shown))
- nodes = new TreeMap<Long, S>();
-
- for (int i = 0; i != shards.size(); ++i) {
- final S shardInfo = shards.get(i);
- if (shardInfo.getName() == null)
- for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
- nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), shardInfo);
- }
- else
- for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
- nodes.put(this.algo.hash(shardInfo.getName() + "*" + shardInfo.getWeight() + n), shardInfo);
- }
- resources.put(shardInfo, shardInfo.createResource());
- }
+ nodes.clear();
+ resources.clear();

Isn't this leaking resources? Don't you have to close them all rather than just clearing references to them here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@itang itang referenced this pull request in itang/todo.itang.me
Open

Redis, SSDB、Hazelcast 熟悉 [进行中] #48

0 of 12 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 28, 2011
  1. @yaourt

    Introduce DynamicShardProvider.

    yaourt authored
  2. @yaourt
Commits on Jun 29, 2011
  1. @yaourt

    Push new constructors in BinaryShardedJedis & ShardedJedis that accep…

    yaourt authored
    …t a JedisDynamicShardsProvider instead of a static shards list
  2. @yaourt

    Various fixes and integration tests for dynamic shards updates :

    yaourt authored
    - Use ReentrantReadWriteLock in AbstractDynamicShardsProvider
    - Fix read/write locks in Sharded
    - Add integration tests with concurrency
Commits on Sep 6, 2011
  1. @yaourt
Commits on Sep 7, 2011
  1. @yaourt
  2. @yaourt
Commits on Sep 15, 2011
  1. @yaourt

    @Work dummy commit

    yaourt authored
Commits on Sep 16, 2011
  1. @yaourt

    Merge from upstream

    yaourt authored
  2. @yaourt

    Remove distrib mgt in pom.xml

    yaourt authored
Something went wrong with that request. Please try again.