Skip to content
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

Modify shards_local to avoid additional table types, handle a flag sharded instead. #10

Closed
cabol opened this issue May 28, 2016 · 2 comments

Comments

@cabol
Copy link
Owner

cabol commented May 28, 2016

Currently, shards_local has two additional table types: sharded_bag and sharded_duplicated_bag. The idea is remove these types, keeps the current ones, and handle a flag sharded instead – to know when the key should be modified to be sharded or not.

@cabol
Copy link
Owner Author

cabol commented Jun 1, 2016

PR #11 related with issue #9 fix this – sharded_bag and sharded_duplicate_bag were removed.

To achieve something like sharded_bag/sharded_duplicate_bag, we only have to override the pick_shard_fun() and pick_node_fun() like this:

pick_shard(write, Key, N) ->
  erlang:phash2({Key, os:timestamp()}, N);
pick_shard(_, _, _) ->
  any.

pick_node(write, Key, Nodes) ->
  NewKey = {Key, os:timestamp()},
  Nth = jumping_hash:compute(erlang:phash2(NewKey), length(Nodes)) + 1,
  lists:nth(Nth, Nodes);
pick_node(_, _, _) ->
  any.

Also, take a look at the tests:

  • Create a table overriding the pick funs HERE.
  • Pick funs HERE.

@cabol
Copy link
Owner Author

cabol commented Jun 1, 2016

Done

@cabol cabol closed this as completed Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant