Skip to content

Commit

Permalink
kvs
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Sep 3, 2016
1 parent c6801f4 commit 567b3cf
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 52 deletions.
8 changes: 4 additions & 4 deletions include/acl.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
-record(acl, {?CONTAINER}).

-record(access, {?ITERATOR(acl),
entry_id,
acl_id,
accessor,
action}).
entry_id=[],
acl_id=[],
accessor=[],
action=[]}).

-endif.
12 changes: 6 additions & 6 deletions include/comment.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
-include("kvs.hrl").

-record(comment, {?ITERATOR(feed), % {comment_id, entry_id, feed_id}
comment_id,
entry_id,
content,
from,
created,
comment_id=[],
entry_id=[],
content=[],
from=[],
created=[],
media = [],
parent}).
parent=[]}).

-endif.
2 changes: 1 addition & 1 deletion include/config.hrl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-ifndef(CONFIG_HRL).
-define(CONFIG_HRL, true).

-record(config, {key, value}).
-record(config, {key, value=[]}).

-define(DBA, kvs:config(dba)).
-define(MQ, (kvs:config(kvs,mq,kvs))).
Expand Down
22 changes: 10 additions & 12 deletions include/entry.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
-include("kvs.hrl").

-record(entry, {?ITERATOR(feed), % {entry_id, feed_id}
entry_id,
from,
to,
title,
description,
created,
hidden,
access,
shared,
starred,
deleted,
entry_id=[],
from=[],
to=[],
title=[],
description=[],
created=[],
access=[],
shared=[],
starred=[],
media = [],
type = {user, normal}}).
type = []}).

-endif.
14 changes: 7 additions & 7 deletions include/group.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
-include("kvs.hrl").

-record(group,{?ITERATOR(feed),
name,
description,
scope :: public | private,
creator,
created,
owner,
users_count = 0 :: integer(),
name=[],
description=[],
scope=[],
creator=[],
created=[],
owner=[],
users_count = 0,
entries_count = 0}).

-endif.
4 changes: 2 additions & 2 deletions include/kvs.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

-record(id_seq, {thing, id}).
-record(container, {?CONTAINER}).
-record(iterator, {?ITERATOR(undefined)}).
-record(iterator, {?ITERATOR([])}).
-record(block, {left,right,name,last}).
-record(log, {?CONTAINER, name, acc}).
-record(operation, {?ITERATOR(log), body, name, status}).
-record(operation, {?ITERATOR(log), body=[], name=[], status=[]}).
-record(kvs, {mod,cx}).

-compile({no_auto_import,[put/2]}).
Expand Down
14 changes: 7 additions & 7 deletions include/subscription.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
-define(SUBSCRIPTION_HRL, true).

-record(subscription,{
key,
who,
whom,
what,
how,
date,
note}).
key=[],
who=[],
whom=[],
what=[],
how=[],
date=[],
note=[]}).

-endif.
30 changes: 17 additions & 13 deletions src/kvs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ generation(Table,Key) ->
norm({A,B},Table,Key) -> A:B(Table,Key);
norm(_,Table,Key) -> limit(Table,Key).

limit(user,_Key) -> 2;
limit(comment,_Key) -> 2;
limit(_Table,_Key) -> 250000.
limit(user,_Key) -> 25000;
limit(comment,_Key) -> 25000;
limit(_Table,_Key) -> 25000.

forbid(user) -> 3;
forbid(comment) -> 3;
forbid(____) -> 100000.
forbid(user) -> 5;
forbid(comment) -> 5;
forbid(____) -> 5.

% Implementation

Expand Down Expand Up @@ -347,9 +347,11 @@ rotate(Table) ->
Ranges = kvs:config(Table),
{M,F} = application:get_env(kvs,forbidding,{?MODULE,forbid}),
New = lists:sublist(Ranges,M:F(Table)),

Delete = Ranges -- New,
[ mnesia:change_table_copy_type(Name, node(), disc_only_copies) || #block{name=Name}
<- shd(Delete) ],
io:format("Delete: ~p~n",[Delete]),
% [ mnesia:change_table_copy_type(Name, node(), disc_only_copies) || #block{name=Name} <- shd(Delete) ],
[ mnesia:delete_table(Name) || #block{name=Name} <- Delete ],
rotate(kvs:table(Table)), ok.
load_partitions() ->
[ case kvs:get(config,Table) of
Expand Down Expand Up @@ -386,10 +388,12 @@ fold_tables() -> lists:foldl(fun(#table{name=X},Acc) ->
[], kvs:tables()).
range(L,R,Name) -> #block{left=L,right=R,name=Name,last=last_table(rname(Name))}.
update_config(Table,Name) ->
kvs:put(#config{key = Table,
value = store(Table,case kvs:get(config,Table) of
Store = store(Table,case kvs:get(config,Table) of
{error,not_found} -> update_list(Table,[],Name);
{ok,#config{value=List}} -> update_list(Table,List,Name) end)}).
{ok,#config{value=List}} -> update_list(Table,List,Name) end),
% {M,F} = application:get_env(kvs,forbidding,{?MODULE,forbid}),
New = Store, %lists:sublist(Store,M:F(Table)),
kvs:put(#config{key = Table, value = New }).

update_list(Table,[],Name) -> [ range(top(Table)+1,limit(),Name) ];
update_list(Table,[#block{}=CI|Tail],Name) -> [ range(top(Table)+1,limit(),Name) ] ++
Expand All @@ -405,6 +409,6 @@ test() -> test(#user{}).
test(Proto) ->
kvs:join(),
Table = element(1,Proto),
[ kvs:add(setelement(2,Proto,kvs:next_id(Table,1))) || _ <- lists:seq(1,20) ],
[ kvs:add(setelement(2,Proto,kvs:next_id(Table,1))) || _ <- lists:seq(1,20000) ],
io:format("Config: ~p~n",[kvs:all(config)]),
io:format("Fetch: ~p~n",[kvs:entries(kvs:get(feed,Table),Table,infinity)]).
io:format("Fetch: ~p~n",[kvs:entries(kvs:get(feed,Table),Table,10)]).

0 comments on commit 567b3cf

Please sign in to comment.