Skip to content

Commit 534948b

Browse files
committed
Add CHANGELOG.
Minor changes/fixes in some modules.
1 parent 24b4172 commit 534948b

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log
2+
3+
## [0.1.0](https://github.com/cabol/shards/tree/0.1.0) (2016-05-18)
4+
**Closed issues:**
5+
6+
- Operation of the `shards:info/2` does not match [\#8](https://github.com/cabol/shards/issues/8)
7+
8+
**Merged pull requests:**
9+
10+
- Fix README. [\#7](https://github.com/cabol/shards/pull/7) ([cabol](https://github.com/cabol))
11+
- Refactor `shards_local` to handle `state` and avoid to call ETS control table. [\#6](https://github.com/cabol/shards/pull/6) ([cabol](https://github.com/cabol))
12+
- Implemented distributed shards. [\#5](https://github.com/cabol/shards/pull/5) ([cabol](https://github.com/cabol))
13+
14+
15+
16+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

src/shards.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
{licenses, ["MIT"]},
1111
{links, [
1212
{"GitHub", "https://github.com/cabol/shards"},
13-
{"Docs", "http://cabol.github.io/shards"}
13+
{"Docs", "http://cabol.github.io/posts/2016/04/14/sharding-support-for-ets.html"}
1414
]}
1515
]}.

src/shards.erl

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979

8080
-export([
8181
state/1,
82-
type/1,
82+
module/1,
83+
tab_type/1,
8384
n_shards/1,
8485
list/1
8586
]).
@@ -992,34 +993,43 @@ pick_one(Key, Nodes) ->
992993
-spec state(TabName) -> State when
993994
TabName :: atom(),
994995
State :: state().
995-
state(TabName) ->
996-
shards_local:state(TabName).
996+
state(TabName) -> shards_local:state(TabName).
997+
998+
%% @doc
999+
%% Returns the module used by the given table.
1000+
%% <ul>
1001+
%% <li>`TabNameOrState': Table name or State.</li>
1002+
%% </ul>
1003+
%% @end
1004+
-spec module(TabNameOrState) -> Type when
1005+
TabNameOrState :: state() | atom(),
1006+
Type :: shards_local:type().
1007+
module({Module, _, _}) -> Module;
1008+
module(TabName) -> module(state(TabName)).
9971009

9981010
%% @doc
9991011
%% Returns the table type.
10001012
%% <ul>
1001-
%% <li>`TabName': Table name.</li>
1013+
%% <li>`TabNameOrState': Table name or State.</li>
10021014
%% </ul>
10031015
%% @end
1004-
-spec type(TabName) -> Type when
1005-
TabName :: atom(),
1006-
Type :: atom().
1007-
type(TabName) ->
1008-
{_, Type, _} = state(TabName),
1009-
Type.
1016+
-spec tab_type(TabNameOrState) -> Type when
1017+
TabNameOrState :: state() | atom(),
1018+
Type :: shards_local:type().
1019+
tab_type({_, Type, _}) -> Type;
1020+
tab_type(TabName) -> tab_type(state(TabName)).
10101021

10111022
%% @doc
10121023
%% Returns the number of shards.
10131024
%% <ul>
1014-
%% <li>`TabName': Table name.</li>
1025+
%% <li>`TabNameOrState': Table name or State.</li>
10151026
%% </ul>
10161027
%% @end
1017-
-spec n_shards(TabName) -> NumShards when
1018-
TabName :: atom(),
1019-
NumShards :: pos_integer().
1020-
n_shards(TabName) ->
1021-
{_, _, NumShards} = state(TabName),
1022-
NumShards.
1028+
-spec n_shards(TabNameOrState) -> NumShards when
1029+
TabNameOrState :: state() | atom(),
1030+
NumShards :: pos_integer().
1031+
n_shards({_, _, NumShards}) -> NumShards;
1032+
n_shards(TabName) -> n_shards(state(TabName)).
10231033

10241034
%% @doc
10251035
%% Returns the list of shard names associated to the given `TabName'.
@@ -1031,5 +1041,4 @@ n_shards(TabName) ->
10311041
-spec list(TabName) -> ShardTabNames when
10321042
TabName :: atom(),
10331043
ShardTabNames :: [atom()].
1034-
list(TabName) ->
1035-
shards_local:list(TabName, n_shards(TabName)).
1044+
list(TabName) -> shards_local:list(TabName, n_shards(TabName)).

src/shards_local.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@
141141
%% Defines the `shards' local state:
142142
%% <ul>
143143
%% <li>`Module': Module to use: `shards_local' | `shards_dist'.</li>
144-
%% <li>`Type': Table type.</li>
144+
%% <li>`TableType': Table type.</li>
145145
%% <li>`NumShards': Number of ETS shards/fragments.</li>
146146
%% </ul>
147147
-type state() :: {
148148
Module :: shards_local | shards_dist,
149-
Type :: type(),
149+
TableType :: type(),
150150
NumShards :: pos_integer()
151151
}.
152152

@@ -1229,7 +1229,7 @@ list(TabName, NumShards) ->
12291229
%% </ul>
12301230
%% @end
12311231
-spec state(TabName :: atom()) -> state().
1232-
state(TabName) ->
1232+
state(TabName) when is_atom(TabName) ->
12331233
ets:lookup_element(TabName, '$shards_state', 2).
12341234

12351235
%%%===================================================================

test/test_helper.erl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,17 @@ init_shards(Scope) ->
432432
{n_shards, 5}, {scope, Scope}, sharded_duplicate_bag
433433
]),
434434

435+
Mod = case Scope of
436+
g -> shards_dist;
437+
_ -> shards_local
438+
end,
439+
435440
DefaultShards = ?N_SHARDS,
436441
shards_created(?SHARDS_TABS),
437-
{_, set, 2} = shards:state(?SET),
438-
{_, duplicate_bag, 5} = shards:state(?DUPLICATE_BAG),
439-
{_, ordered_set, DefaultShards} = shards:state(?ORDERED_SET),
440-
{_, sharded_duplicate_bag, 5} =
442+
{Mod, set, 2} = shards:state(?SET),
443+
{Mod, duplicate_bag, 5} = shards:state(?DUPLICATE_BAG),
444+
{Mod, ordered_set, DefaultShards} = shards:state(?ORDERED_SET),
445+
{Mod, sharded_duplicate_bag, 5} =
441446
shards:state(?SHARDED_DUPLICATE_BAG),
442447
duplicate_bag =
443448
ets:info(shards_local:shard_name(?SHARDED_DUPLICATE_BAG, 0), type),
@@ -453,7 +458,7 @@ init_shards(Scope) ->
453458
ok.
454459

455460
cleanup_shards() ->
456-
{Mod, _, _} = shards:state(?SET),
461+
Mod = shards:module(?SET),
457462
cleanup_shards_(Mod).
458463

459464
cleanup_shards_(shards_local) ->

0 commit comments

Comments
 (0)