Skip to content

Instantly share code, notes, and snippets.

View goncalotomas's full-sized avatar

Gonçalo Tomás goncalotomas

View GitHub Profile
(fmk@127.0.0.1)1>rpc:call('antidote@127.0.0.1',antidote,append,
[patients,riak_dt_map,{update,
[{add, {key, riak_dt_lwwreg}},
{add, {val, riak_dt_pncounter}}
]
}]).
{error,
{type_check,
{update,
{patients,riak_dt_map,
@goncalotomas
goncalotomas / transaction-with-map.erl
Created May 2, 2016 20:59
Map read fails after write, no idea why... :(
(goncalo@127.0.0.1)1> Node = 'antidote@127.0.0.1'.
'antidote@127.0.0.1'
(goncalo@127.0.0.1)2> StartTxn = fun() -> rpc:call(Node,antidote,start_transaction,[ignore, []]) end.
#Fun<erl_eval.20.50752066>
(goncalo@127.0.0.1)3> AddRead = fun(Bucket,Txn) -> rpc:call(Node, antidote, read_objects, [[Bucket],Txn]) end.
#Fun<erl_eval.12.50752066>
(goncalo@127.0.0.1)4> AddWrite = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects, [[{Bucket,Op,Param}], Txn]) end.
#Fun<erl_eval.4.50752066>
(goncalo@127.0.0.1)5> CommitTxn = fun(Txn) -> rpc:call(Node,antidote,commit_transaction,[Txn]) end.
#Fun<erl_eval.6.50752066>
@goncalotomas
goncalotomas / tracedump.txt
Created May 2, 2016 21:03
Antidote trace dump
21:57:49.860 [error] gen_server '11890602560248518965780370444936484965102833893376antidote@127.0.0.1' terminated with reason: no match of right hand value [{tx_id,1462222378056234,<0.3403.0>}] in riak_dt_vclock:descends/2 line 66
21:57:49.861 [error] CRASH REPORT Process <0.2165.0> with 0 neighbours exited with reason: no match of right hand value [{tx_id,1462222378056234,<0.3403.0>}] in riak_dt_vclock:descends/2 line 66 in gen_server:terminate/6 line 744
21:57:49.861 [error] Exception caught: {{{badmatch,[{tx_id,1462222378056234,<0.3403.0>}]},[{riak_dt_vclock,descends,2,[{file,"src/riak_dt_vclock.erl"},{line,66}]},{riak_dt_map,is_dot_unseen,2,[{file,"src/riak_dt_map.erl"},{line,517}]},{dict,filter_bucket,4,[{file,"dict.erl"},{line,482}]},{dict,filter_bkt_list,4,[{file,"dict.erl"},{line,476}]},{dict,filter_seg_list,4,[{file,"dict.erl"},{line,470}]},{dict,filter_dict,2,[{file,"dict.erl"},{line,465}]},{riak_dt_map,'-filter_unique/4-fun-1-',4,[{file,"src/riak_dt_map.erl"},{line,489}]},{sets,fold_bucket,3,[{file
@goncalotomas
goncalotomas / trace.erl
Created May 3, 2016 09:31
Antidote map usage trace with commit times
(goncalo@127.0.0.1)1> Node = 'antidote@127.0.0.1'.
'antidote@127.0.0.1'
(goncalo@127.0.0.1)2> StartTxn = fun() -> rpc:call(Node,antidote,start_transaction,[ignore, []]) end.
#Fun<erl_eval.20.50752066>
(goncalo@127.0.0.1)3> StartTxnWTS = fun(TimeStamp) -> rpc:call(Node,antidote,start_transaction,[TimeStamp, []]) end.
#Fun<erl_eval.6.50752066>
(goncalo@127.0.0.1)4> AddRead = fun(Bucket,Txn) -> rpc:call(Node, antidote, read_objects, [[Bucket],Txn]) end.
#Fun<erl_eval.12.50752066>
(goncalo@127.0.0.1)5> AddWrite = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects, [[{Bucket,Op,Param}], Txn]) end.
#Fun<erl_eval.4.50752066>
@goncalotomas
goncalotomas / code.erl
Created June 29, 2016 19:24
Non-working code for new API
Node = 'antidote@127.0.0.1'.
StartTxn = fun() -> rpc:call(Node,antidote,start_transaction,[ignore, []]) end.
AddRead = fun(Bucket,Txn) -> rpc:call(Node, antidote, read_objects, [[Bucket],Txn]) end.
AddWrite = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects, [[{Bucket,Op,Param}], Txn]) end.
CommitTxn = fun(Txn) -> rpc:call(Node,antidote,commit_transaction,[Txn]) end.
%% riak_dt:actor() :: term(), hardcodedactor is a term
AddWriteWithActor = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects,[[{Bucket,Op,{Param,hardcodedactor}}], Txn]) end.
%% This is working, and so far it makes a lot of sense...
@goncalotomas
goncalotomas / working.erl
Last active July 6, 2016 13:34
working code with new API
Node = 'antidote@127.0.0.1'.
StartTxn = fun() -> rpc:call(Node,antidote,start_transaction,[ignore, []]) end.
AddRead = fun(Bucket,Txn) -> rpc:call(Node, antidote, read_objects, [[Bucket],Txn]) end.
AddWrite = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects, [[{Bucket,Op,Param}], Txn]) end.
CommitTxn = fun(Txn) -> rpc:call(Node,antidote,commit_transaction,[Txn]) end.
%% riak_dt:actor() :: term(), hardcodedactor is a term
AddWriteWithActor = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects,[[{Bucket,Op,{Param,hardcodedactor}}], Txn]) end.
%% This is working, and so far it makes a lot of sense...
{ok, TxnId1} = StartTxn().
CounterBucket = {counter,antidote_crdt_counter,bucket}.
@goncalotomas
goncalotomas / max_atom_test.erl
Created July 15, 2016 12:45
This illustrates the issue with the Erlang Virtual Machine not handling over 1,048,576 atoms
%% Single node cluster -> antidote@127.0.0.1. Multi-node cluster -> dev1@127.0.0.1
%% Node = 'antidote@127.0.0.1'.
Node = 'dev1@127.0.0.1'.
StartTxn = fun() -> rpc:call(Node,antidote,start_transaction,[ignore, []]) end.
AddRead = fun(Bucket,Txn) -> rpc:call(Node, antidote, read_objects, [[Bucket],Txn]) end.
AddWrite = fun(Bucket,Op,Param,Txn) -> rpc:call(Node, antidote, update_objects, [[{Bucket,Op,Param}], Txn]) end.
CommitTxn = fun(Txn) -> rpc:call(Node,antidote,commit_transaction,[Txn]) end.
WriteValue = fun(V) -> {ok,Tx} = StartTxn(), ok = AddWrite({V,antidote_crdt_counter,bucket},increment,1,Tx), CommitTxn(Tx) end.
FloodGates3 = fun(F,0) -> WriteValue(key0); (F,V) -> WriteValue(list_to_atom(lists:flatten(io_lib:format("key~p", [V])))), F(F,V-1) end.
@goncalotomas
goncalotomas / .zshrc
Created August 8, 2016 18:37
My git aliases for ZSH
alias _add="git add"
alias _checkout="git checkout"
alias _checkoutnbranch="git checkout -b"
alias _commit="git commit -m"
alias _pull="git pull"
alias _pullmaster="git pull origin master"
alias _push="git push"
alias _pushmaster="git push origin master"
alias _status="git status"
alias _init="git init"
@goncalotomas
goncalotomas / trace.txt
Created September 4, 2016 00:13
antidote trace when performing counter increments - using the examples shown on the doc pages
00:55:39.812 [error] Exception caught: {noproc,{gen_server,call,[{global,'3730750818665451459101842416358141509827966271488antidote@127.0.0.1'},{perform_read,{<<"patient1">>,bucket},antidote_crdt_map,{transaction,1472946939749222,undefined,{dict,1,16,16,8,80,48,{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},{{[],[],[[{'antidote@127.0.0.1',{1472,946692,80751}}|1472946939749222]],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},{tx_id,1472946939749222,<0.2102.0>}}},infinity]}}, starting read server to fix
00:55:39.845 [error] Exception caught: {noproc,{gen_server,call,[{global,'12548063113999088594326381812268606132370974703616antidote@127.0.0.1'},{perform_read,{<<"patient_name_index">>,bucket},antidote_crdt_orset,{transaction,1472946939827244,undefined,{dict,1,16,16,8,80,48,{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},{{[],[],[[{'antidote@127.0.0.1',{1472,946692,80751}}|1472946939827244]],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},{tx_id,1472946939827244,<0.2127.0>}}},infinity]}}, starting read server to fix
0
@goncalotomas
goncalotomas / fmk_test_setup.erl
Created September 10, 2016 21:06
FMK setup for testing operations - paste it on a erl shell running fmk
fmk_core:create_facility(1,"Weill Cornell Medical Center","New York NY,USA","Hospital").
fmk_core:create_facility(2,"Florida Hospital Orlando","Orlando FL, USA","Hospital").
fmk_core:create_facility(3,"Jackson Memorial Hospital","Miami FL, USA","Hospital").
fmk_core:create_pharmacy(1,"Chai Pharmacy","Costa da Caparica, Portugal").
fmk_core:create_pharmacy(2,"Carlos Pharmacy","Costa da Caparica, Portugal").
fmk_core:create_pharmacy(3,"Definitely not an online scam!","Lisbon, Portugal").
fmk_core:create_staff(1,"Paula Pinto","Lisboa","Alergologia").
fmk_core:create_staff(2,"Gonçalo Tomás","Costa da Caparica","Shenanigans").
fmk_core:create_staff(3,"Tânia Pires","Pragal","Enfermagem").
fmk_core:create_patient(1,"Goncalo Tomas","Somewhere over the rainbow").