-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use other module for default partitioner
- Loading branch information
Showing
3 changed files
with
13 additions
and
12 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Klife.DefaultPartitioner do | ||
@behaviour Klife.Partitioner | ||
alias Klife.Record | ||
|
||
@impl Klife.Partitioner | ||
def get_partition(%Record{key: nil}, max_partition), | ||
do: Enum.random(0..max_partition) | ||
|
||
def get_partition(%Record{key: key}, max_partition), | ||
do: :erlang.phash2(key, max_partition + 1) | ||
end |
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 |
---|---|---|
@@ -1,13 +1,3 @@ | ||
defmodule Klife.Partitioner do | ||
alias Klife.Record | ||
|
||
@callback get_partition(record :: %Record{}, max_partition :: integer) :: integer | ||
|
||
@behaviour __MODULE__ | ||
|
||
@impl __MODULE__ | ||
def get_partition(%Record{key: nil}, max_partition), | ||
do: Enum.random(0..max_partition) | ||
|
||
def get_partition(%Record{key: key}, max_partition), do: :erlang.phash2(key, max_partition + 1) | ||
@callback get_partition(record :: %Klife.Record{}, max_partition :: integer) :: integer | ||
end |
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