Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Commit 6d92a48

Browse files
authored
Merge pull request #6 from SmallEndian/master
Adds support for bounded counters
2 parents 2331810 + 05dea1a commit 6d92a48

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

include/antidote_pb.hrl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
-define('APBMAPKEY_PB_H', true).
7171
-record('ApbMapKey',
7272
{key :: iodata(), % = 1
73-
type :: 'COUNTER' | 'ORSET' | 'LWWREG' | 'MVREG' | 'GMAP' | 'RWSET' | 'RRMAP' | 'FATCOUNTER' | 'FLAG_EW' | 'FLAG_DW' | integer() % = 2, enum CRDT_type
73+
type :: 'COUNTER' | 'ORSET' | 'LWWREG' | 'MVREG' | 'GMAP' | 'RWSET' | 'RRMAP' | 'FATCOUNTER' | 'FLAG_EW' | 'FLAG_DW' | 'BCOUNTER' | integer() % = 2, enum CRDT_type
7474
}).
7575
-endif.
7676

@@ -146,7 +146,7 @@
146146
-define('APBBOUNDOBJECT_PB_H', true).
147147
-record('ApbBoundObject',
148148
{key :: iodata(), % = 1
149-
type :: 'COUNTER' | 'ORSET' | 'LWWREG' | 'MVREG' | 'GMAP' | 'RWSET' | 'RRMAP' | 'FATCOUNTER' | 'FLAG_EW' | 'FLAG_DW' | integer(), % = 2, enum CRDT_type
149+
type :: 'COUNTER' | 'ORSET' | 'LWWREG' | 'MVREG' | 'GMAP' | 'RWSET' | 'RRMAP' | 'FATCOUNTER' | 'FLAG_EW' | 'FLAG_DW' | 'BCOUNTER' | integer(), % = 2, enum CRDT_type
150150
bucket :: iodata() % = 3
151151
}).
152152
-endif.

proto/antidote.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum CRDT_type {
1414
FATCOUNTER = 12;
1515
FLAG_EW = 13;
1616
FLAG_DW = 14;
17+
BCOUNTER = 15;
1718
}
1819

1920
// Riak Error response

src/antidote_pb.erl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
-include("gpb.hrl").
2929

3030
%% enumerated types
31-
-type 'CRDT_type'() :: 'COUNTER' | 'ORSET' | 'LWWREG' | 'MVREG' | 'GMAP' | 'RWSET' | 'RRMAP' | 'FATCOUNTER' | 'FLAG_EW' | 'FLAG_DW'.
31+
-type 'CRDT_type'() :: 'COUNTER' | 'ORSET' | 'LWWREG' | 'MVREG' | 'GMAP' | 'RWSET' | 'RRMAP' | 'FATCOUNTER' | 'FLAG_EW' | 'FLAG_DW' | 'BCOUNTER'.
3232
-type 'ApbSetUpdate.SetOpType'() :: 'ADD' | 'REMOVE'.
3333
-export_type(['CRDT_type'/0, 'ApbSetUpdate.SetOpType'/0]).
3434

@@ -1345,6 +1345,8 @@ e_enum_CRDT_type('FLAG_EW', Bin, _TrUserData) ->
13451345
<<Bin/binary, 13>>;
13461346
e_enum_CRDT_type('FLAG_DW', Bin, _TrUserData) ->
13471347
<<Bin/binary, 14>>;
1348+
e_enum_CRDT_type('BCOUNTER', Bin, _TrUserData) ->
1349+
<<Bin/binary, 15>>;
13481350
e_enum_CRDT_type(V, Bin, _TrUserData) ->
13491351
e_varint(V, Bin).
13501352

@@ -6912,6 +6914,7 @@ d_enum_CRDT_type(11) -> 'RRMAP';
69126914
d_enum_CRDT_type(12) -> 'FATCOUNTER';
69136915
d_enum_CRDT_type(13) -> 'FLAG_EW';
69146916
d_enum_CRDT_type(14) -> 'FLAG_DW';
6917+
d_enum_CRDT_type(15) -> 'BCOUNTER';
69156918
d_enum_CRDT_type(V) -> V.
69166919

69176920
'd_enum_ApbSetUpdate.SetOpType'(1) -> 'ADD';
@@ -8382,6 +8385,7 @@ v_enum_CRDT_type('FATCOUNTER', _Path, _TrUserData) ->
83828385
ok;
83838386
v_enum_CRDT_type('FLAG_EW', _Path, _TrUserData) -> ok;
83848387
v_enum_CRDT_type('FLAG_DW', _Path, _TrUserData) -> ok;
8388+
v_enum_CRDT_type('BCOUNTER', _Path, _TrUserData) -> ok;
83858389
v_enum_CRDT_type(V, Path, TrUserData)
83868390
when is_integer(V) ->
83878391
v_type_sint32(V, Path, TrUserData);
@@ -8521,7 +8525,8 @@ get_msg_defs() ->
85218525
[{{enum, 'CRDT_type'},
85228526
[{'COUNTER', 3}, {'ORSET', 4}, {'LWWREG', 5},
85238527
{'MVREG', 6}, {'GMAP', 8}, {'RWSET', 10}, {'RRMAP', 11},
8524-
{'FATCOUNTER', 12}, {'FLAG_EW', 13}, {'FLAG_DW', 14}]},
8528+
{'FATCOUNTER', 12}, {'FLAG_EW', 13}, {'FLAG_DW', 14},
8529+
{'BCOUNTER', 15}]},
85258530
{{enum, 'ApbSetUpdate.SetOpType'},
85268531
[{'ADD', 1}, {'REMOVE', 2}]},
85278532
{{msg, 'ApbErrorResp'},
@@ -9025,7 +9030,8 @@ find_msg_def(_) -> error.
90259030
find_enum_def('CRDT_type') ->
90269031
[{'COUNTER', 3}, {'ORSET', 4}, {'LWWREG', 5},
90279032
{'MVREG', 6}, {'GMAP', 8}, {'RWSET', 10}, {'RRMAP', 11},
9028-
{'FATCOUNTER', 12}, {'FLAG_EW', 13}, {'FLAG_DW', 14}];
9033+
{'FATCOUNTER', 12}, {'FLAG_EW', 13}, {'FLAG_DW', 14},
9034+
{'BCOUNTER', 15}];
90299035
find_enum_def('ApbSetUpdate.SetOpType') ->
90309036
[{'ADD', 1}, {'REMOVE', 2}];
90319037
find_enum_def(_) -> error.
@@ -9052,7 +9058,8 @@ enum_symbol_by_value_CRDT_type(10) -> 'RWSET';
90529058
enum_symbol_by_value_CRDT_type(11) -> 'RRMAP';
90539059
enum_symbol_by_value_CRDT_type(12) -> 'FATCOUNTER';
90549060
enum_symbol_by_value_CRDT_type(13) -> 'FLAG_EW';
9055-
enum_symbol_by_value_CRDT_type(14) -> 'FLAG_DW'.
9061+
enum_symbol_by_value_CRDT_type(14) -> 'FLAG_DW';
9062+
enum_symbol_by_value_CRDT_type(15) -> 'BCOUNTER'.
90569063

90579064

90589065
enum_value_by_symbol_CRDT_type('COUNTER') -> 3;
@@ -9064,7 +9071,8 @@ enum_value_by_symbol_CRDT_type('RWSET') -> 10;
90649071
enum_value_by_symbol_CRDT_type('RRMAP') -> 11;
90659072
enum_value_by_symbol_CRDT_type('FATCOUNTER') -> 12;
90669073
enum_value_by_symbol_CRDT_type('FLAG_EW') -> 13;
9067-
enum_value_by_symbol_CRDT_type('FLAG_DW') -> 14.
9074+
enum_value_by_symbol_CRDT_type('FLAG_DW') -> 14;
9075+
enum_value_by_symbol_CRDT_type('BCOUNTER') -> 15.
90689076

90699077
'enum_symbol_by_value_ApbSetUpdate.SetOpType'(1) ->
90709078
'ADD';

src/antidote_pb_codec.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,12 @@ decode(_Other, _) ->
352352

353353
encode_error_code(unknown) -> 0;
354354
encode_error_code(timeout) -> 1;
355+
encode_error_code(no_permissions) -> 2;
355356
encode_error_code(_Other) -> 0.
356357

357358
decode_error_code(0) -> unknown;
358359
decode_error_code(1) -> timeout;
360+
decode_error_code(2) -> no_permissions;
359361
decode_error_code(C) -> {error_code, C}.
360362

361363

@@ -545,6 +547,7 @@ encode_read_objects(Objects, TxId) ->
545547

546548
encode_type(antidote_crdt_counter_pn) -> 'COUNTER';
547549
encode_type(antidote_crdt_counter_fat) -> 'FATCOUNTER';
550+
encode_type(antidote_crdt_counter_b) -> 'BCOUNTER';
548551
encode_type(antidote_crdt_set_aw) -> 'ORSET';
549552
encode_type(antidote_crdt_register_lww) -> 'LWWREG';
550553
encode_type(antidote_crdt_register_mv) -> 'MVREG';
@@ -558,6 +561,7 @@ encode_type(T) -> erlang:error({unknown_crdt_type, T}).
558561

559562
decode_type('COUNTER') -> antidote_crdt_counter_pn;
560563
decode_type('FATCOUNTER') -> antidote_crdt_counter_fat;
564+
decode_type('BCOUNTER') -> antidote_crdt_counter_b;
561565
decode_type('ORSET') -> antidote_crdt_set_aw;
562566
decode_type('LWWREG') -> antidote_crdt_register_lww;
563567
decode_type('MVREG') -> antidote_crdt_register_mv;
@@ -579,6 +583,8 @@ encode_update_operation(antidote_crdt_counter_pn, Op_Param) ->
579583
#'ApbUpdateOperation'{counterop = encode_counter_update(Op_Param)};
580584
encode_update_operation(antidote_crdt_counter_fat, Op_Param) ->
581585
#'ApbUpdateOperation'{counterop = encode_counter_update(Op_Param)};
586+
encode_update_operation(antidote_crdt_counter_b, Op_Param) ->
587+
#'ApbUpdateOperation'{counterop = encode_counter_update(Op_Param)};
582588
encode_update_operation(antidote_crdt_set_aw, Op_Param) ->
583589
#'ApbUpdateOperation'{setop = encode_set_update(Op_Param)};
584590
encode_update_operation(antidote_crdt_set_rw, Op_Param) ->
@@ -629,6 +635,8 @@ encode_read_object_resp(antidote_crdt_counter_pn, Val) ->
629635
#'ApbReadObjectResp'{counter = #'ApbGetCounterResp'{value = Val}};
630636
encode_read_object_resp(antidote_crdt_counter_fat, Val) ->
631637
#'ApbReadObjectResp'{counter = #'ApbGetCounterResp'{value = Val}};
638+
encode_read_object_resp(antidote_crdt_counter_b, Val) ->
639+
#'ApbReadObjectResp'{counter = #'ApbGetCounterResp'{value = Val}};
632640
encode_read_object_resp(antidote_crdt_set_aw, Val) ->
633641
#'ApbReadObjectResp'{set = #'ApbGetSetResp'{value = Val}};
634642
encode_read_object_resp(antidote_crdt_set_rw, Val) ->
@@ -967,6 +975,10 @@ crdt_encode_decode_test() ->
967975
?TEST_CRDT_OP_CODEC(antidote_crdt_counter_pn, increment, 1),
968976
?TEST_CRDT_RESP_CODEC(antidote_crdt_counter_pn, counter, 42),
969977

978+
% BCounter
979+
?TestCrdtOperationCodec(antidote_crdt_counter_b, increment, 1),
980+
?TestCrdtResponseCodec(antidote_crdt_counter_b, counter, 42),
981+
970982
% lww-register
971983
?TEST_CRDT_OP_CODEC(antidote_crdt_register_lww, assign, <<"hello">>),
972984
?TEST_CRDT_RESP_CODEC(antidote_crdt_register_lww, reg, <<"blub">>),

0 commit comments

Comments
 (0)