Modify `shards_local` to avoid additional table types, handle a flag `sharded` instead.
cabol opened this issue · comments
Carlos Andres Bolaños R.A. commented
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.
Carlos Andres Bolaños R.A. commented
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:
Carlos Andres Bolaños R.A. commented
Done