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

Commit 05dea1a

Browse files
committed
Adds support for bounded counters
1 parent e8c0fbc commit 05dea1a

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
@@ -340,10 +340,12 @@ decode(_Other, _) ->
340340

341341
encode_error_code(unknown) -> 0;
342342
encode_error_code(timeout) -> 1;
343+
encode_error_code(no_permissions) -> 2;
343344
encode_error_code(_Other) -> 0.
344345

345346
decode_error_code(0) -> unknown;
346347
decode_error_code(1) -> timeout;
348+
decode_error_code(2) -> no_permissions;
347349
decode_error_code(C) -> {error_code, C}.
348350

349351

@@ -529,6 +531,7 @@ encode_read_objects(Objects, TxId) ->
529531

530532
encode_type(antidote_crdt_counter_pn) -> 'COUNTER';
531533
encode_type(antidote_crdt_counter_fat) -> 'FATCOUNTER';
534+
encode_type(antidote_crdt_counter_b) -> 'BCOUNTER';
532535
encode_type(antidote_crdt_set_aw) -> 'ORSET';
533536
encode_type(antidote_crdt_register_lww) -> 'LWWREG';
534537
encode_type(antidote_crdt_register_mv) -> 'MVREG';
@@ -542,6 +545,7 @@ encode_type(T) -> erlang:error({unknown_crdt_type, T}).
542545

543546
decode_type('COUNTER') -> antidote_crdt_counter_pn;
544547
decode_type('FATCOUNTER') -> antidote_crdt_counter_fat;
548+
decode_type('BCOUNTER') -> antidote_crdt_counter_b;
545549
decode_type('ORSET') -> antidote_crdt_set_aw;
546550
decode_type('LWWREG') -> antidote_crdt_register_lww;
547551
decode_type('MVREG') -> antidote_crdt_register_mv;
@@ -563,6 +567,8 @@ encode_update_operation(antidote_crdt_counter_pn, Op_Param) ->
563567
#'ApbUpdateOperation'{counterop = encode_counter_update(Op_Param)};
564568
encode_update_operation(antidote_crdt_counter_fat, Op_Param) ->
565569
#'ApbUpdateOperation'{counterop = encode_counter_update(Op_Param)};
570+
encode_update_operation(antidote_crdt_counter_b, Op_Param) ->
571+
#'ApbUpdateOperation'{counterop = encode_counter_update(Op_Param)};
566572
encode_update_operation(antidote_crdt_set_aw, Op_Param) ->
567573
#'ApbUpdateOperation'{setop = encode_set_update(Op_Param)};
568574
encode_update_operation(antidote_crdt_set_rw, Op_Param) ->
@@ -613,6 +619,8 @@ encode_read_object_resp(antidote_crdt_counter_pn, Val) ->
613619
#'ApbReadObjectResp'{counter = #'ApbGetCounterResp'{value = Val}};
614620
encode_read_object_resp(antidote_crdt_counter_fat, Val) ->
615621
#'ApbReadObjectResp'{counter = #'ApbGetCounterResp'{value = Val}};
622+
encode_read_object_resp(antidote_crdt_counter_b, Val) ->
623+
#'ApbReadObjectResp'{counter = #'ApbGetCounterResp'{value = Val}};
616624
encode_read_object_resp(antidote_crdt_set_aw, Val) ->
617625
#'ApbReadObjectResp'{set = #'ApbGetSetResp'{value = Val}};
618626
encode_read_object_resp(antidote_crdt_set_rw, Val) ->
@@ -946,6 +954,10 @@ crdt_encode_decode_test() ->
946954
?TestCrdtOperationCodec(antidote_crdt_counter_pn, increment, 1),
947955
?TestCrdtResponseCodec(antidote_crdt_counter_pn, counter, 42),
948956

957+
% BCounter
958+
?TestCrdtOperationCodec(antidote_crdt_counter_b, increment, 1),
959+
?TestCrdtResponseCodec(antidote_crdt_counter_b, counter, 42),
960+
949961
% lww-register
950962
?TestCrdtOperationCodec(antidote_crdt_register_lww, assign, <<"hello">>),
951963
?TestCrdtResponseCodec(antidote_crdt_register_lww, reg, <<"blub">>),

0 commit comments

Comments
 (0)