32
32
33
33
-define (TIMEOUT , 10000 ).
34
34
35
- -spec start_transaction (Pid :: term (), TimeStamp :: term () )
35
+ -spec start_transaction (Pid :: pid (), TimeStamp :: binary () | ignore )
36
36
-> {ok , {interactive , term ()} | {static , {term (), term ()}}} | {error , term ()}.
37
37
start_transaction (Pid , TimeStamp ) ->
38
38
start_transaction (Pid , TimeStamp , []).
39
39
40
- -spec start_transaction (Pid :: term (), TimeStamp :: term () , TxnProperties :: term ())
41
- -> {ok , {interactive , term ()} | {static , {term (), term ()}}} | {error , term ()}.
40
+ -spec start_transaction (Pid :: pid (), TimeStamp :: binary () | ignore , TxnProperties :: term ())
41
+ -> {ok , {interactive , binary ()} | {static , {binary (), term ()}}} | {error , term ()}.
42
42
start_transaction (Pid , TimeStamp , TxnProperties ) ->
43
+ EncTimestamp = case TimeStamp of
44
+ ignore -> term_to_binary (ignore );
45
+ Binary -> Binary
46
+ end ,
43
47
case is_static (TxnProperties ) of
44
48
true ->
45
- {ok , {static , {TimeStamp , TxnProperties }}};
49
+ {ok , {static , {EncTimestamp , TxnProperties }}};
46
50
false ->
47
- EncMsg = antidote_pb_codec :encode (start_transaction ,
48
- {TimeStamp , TxnProperties }),
51
+ EncMsg = antidote_pb_codec :encode_request ({start_transaction , EncTimestamp , TxnProperties }),
49
52
Result = antidotec_pb_socket :call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
50
53
case Result of
51
54
{error , timeout } ->
52
55
{error , timeout };
53
56
_ ->
54
57
case antidote_pb_codec :decode_response (Result ) of
55
- {start_transaction , TxId } ->
58
+ {start_transaction_response , { ok , TxId } } ->
56
59
{ok , {interactive , TxId }};
57
- {error , Reason } ->
60
+ {start_transaction_response , {error , Reason }} ->
61
+ {error , Reason };
62
+ {error_response , Reason } ->
58
63
{error , Reason };
59
64
Other ->
60
65
{error , Other }
61
66
end
62
67
end
63
68
end .
64
69
65
- -spec abort_transaction (Pid :: term (), TxId :: term () ) -> ok | {error , term ()}.
70
+ -spec abort_transaction (Pid :: pid (), { interactive , TxId :: binary ()} ) -> ok | {error , term ()}.
66
71
abort_transaction (Pid , {interactive , TxId }) ->
67
- EncMsg = antidote_pb_codec :encode ( abort_transaction , TxId ),
72
+ EncMsg = antidote_pb_codec :encode_request ({ abort_transaction , TxId } ),
68
73
Result = antidotec_pb_socket :call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
69
74
case Result of
70
75
{error , timeout } -> {error , timeout };
71
76
_ ->
72
77
case antidote_pb_codec :decode_response (Result ) of
73
- {opresponse , ok } -> ok ;
74
- {error , Reason } -> {error , Reason };
78
+ {operation_response , ok } -> ok ;
79
+ {operation_response , {error , Reason }} -> {error , Reason };
80
+ {error_response , Reason } -> {error , Reason };
75
81
Other -> {error , Other }
76
82
end
77
83
end .
78
84
79
- -spec commit_transaction (Pid :: term (), TxId :: {interactive , term ()} | {static , term ()}) ->
80
- {ok , term ()} | {error , term ()}.
85
+ -spec commit_transaction (Pid :: pid (), TxId :: {interactive , binary ()} | {static , binary ()}) ->
86
+ {ok , binary ()} | {error , term ()}.
81
87
commit_transaction (Pid , {interactive , TxId }) ->
82
- EncMsg = antidote_pb_codec :encode ( commit_transaction , TxId ),
88
+ EncMsg = antidote_pb_codec :encode_request ({ commit_transaction , TxId } ),
83
89
Result = antidotec_pb_socket :call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
84
90
case Result of
85
91
{error , timeout } -> {error , timeout };
86
92
_ ->
87
93
case antidote_pb_codec :decode_response (Result ) of
88
- {commit_transaction , CommitTimeStamp } -> {ok , CommitTimeStamp };
89
- {error , Reason } -> {error , Reason };
94
+ {commit_response , {ok , CommitTimeStamp }} -> {ok , CommitTimeStamp };
95
+ {commit_response , {error , Reason }} -> {error , Reason };
96
+ {error_response , Reason } -> {error , Reason };
90
97
Other -> {error , Other }
91
98
end
92
99
end ;
@@ -96,38 +103,40 @@ commit_transaction(Pid, {static, _TxId}) ->
96
103
{ok , CommitTime }
97
104
end .
98
105
99
- -spec update_objects (Pid :: term (), Updates :: [{term (), term (), term ()}], TxId :: term () ) -> ok | {error , term ()}.
106
+ -spec update_objects (Pid :: pid (), Updates :: [{term (), term (), term ()}], { interactive | static , TxId :: binary ()} ) -> ok | {error , term ()}.
100
107
update_objects (Pid , Updates , {interactive , TxId }) ->
101
- EncMsg = antidote_pb_codec : encode ( update_objects , { Updates , TxId }),
108
+ EncMsg = antidote_pb_codec : encode_request ({ update_objects , Updates , TxId }),
102
109
Result = antidotec_pb_socket : call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
103
110
case Result of
104
111
{error , timeout } -> {error , timeout };
105
112
_ ->
106
113
case antidote_pb_codec : decode_response (Result ) of
107
- {opresponse , ok } -> ok ;
108
- {error , Reason } -> {error , Reason };
114
+ {operation_response , ok } -> ok ;
115
+ {operation_response , {error , Reason }} -> {error , Reason };
116
+ {error_response , Reason } -> {error , Reason };
109
117
Other -> {error , Other }
110
118
end
111
119
end ;
112
120
113
121
update_objects (Pid , Updates , {static , TxId }) ->
114
122
{Clock , Properties } = TxId ,
115
- EncMsg = antidote_pb_codec :encode (static_update_objects ,
116
- {Clock , Properties , Updates }),
123
+ EncMsg = antidote_pb_codec :encode_request ({static_update_objects , Clock , Properties , Updates }),
117
124
Result = antidotec_pb_socket :call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
118
125
case Result of
119
126
{error , timeout } -> {error , timeout };
120
127
_ ->
121
128
case antidote_pb_codec :decode_response (Result ) of
122
- {commit_transaction , CommitTimeStamp } ->
129
+ {commit_response , { ok , CommitTimeStamp } } ->
123
130
antidotec_pb_socket :store_commit_time (Pid , CommitTimeStamp ),
124
131
ok ;
125
- {error , Reason } -> {error , Reason };
132
+ {commit_response , {error , Reason }} ->
133
+ {error , Reason };
134
+ {error_response , Reason } -> {error , Reason };
126
135
Other -> {error , Other }
127
136
end
128
137
end .
129
138
130
- -spec read_objects (Pid :: term (), Objects :: [term ()], TxId :: term () ) -> {ok , [term ()]} | {error , term ()}.
139
+ -spec read_objects (Pid :: pid (), Objects :: [term ()], { interactive | static , TxId :: binary ()} ) -> {ok , [term ()]} | {error , term ()}.
131
140
read_objects (Pid , Objects , Transaction ) ->
132
141
case read_values (Pid , Objects , Transaction ) of
133
142
{ok , Values } ->
@@ -141,33 +150,34 @@ read_objects(Pid, Objects, Transaction) ->
141
150
Other
142
151
end .
143
152
144
- -spec read_values (Pid :: term (), Objects :: [term ()], TxId :: term () ) -> {ok , [term ()]} | {error , term ()}.
153
+ -spec read_values (Pid :: pid (), Objects :: [term ()], { interactive | static , TxId :: binary ()} ) -> {ok , [term ()]} | {error , term ()}.
145
154
read_values (Pid , Objects , {interactive , TxId }) ->
146
- EncMsg = antidote_pb_codec :encode ( read_objects , { Objects , TxId }),
155
+ EncMsg = antidote_pb_codec :encode_request ({ read_objects , Objects , TxId }),
147
156
Result = antidotec_pb_socket :call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
148
157
case Result of
149
158
{error , timeout } -> {error , timeout };
150
159
_ ->
151
160
case antidote_pb_codec :decode_response (Result ) of
152
- {read_objects , Values } ->
161
+ {read_objects_response , { ok , Values } } ->
153
162
{ok , Values };
154
- {error , Reason } -> {error , Reason };
163
+ {read_objects_response , {error , Reason }} ->
164
+ {error , Reason };
165
+ {error_response , Reason } -> {error , Reason };
155
166
Other -> {error , Other }
156
167
end
157
168
end ;
158
169
read_values (Pid , Objects , {static , TxId }) ->
159
170
{Clock , Properties } = TxId ,
160
- EncMsg = antidote_pb_codec :encode (static_read_objects ,
161
- {Clock , Properties , Objects }),
171
+ EncMsg = antidote_pb_codec :encode_request ({static_read_objects , Clock , Properties , Objects }),
162
172
Result = antidotec_pb_socket :call_infinity (Pid , {req , EncMsg , ? TIMEOUT }),
163
173
case Result of
164
174
{error , timeout } -> {error , timeout };
165
175
_ ->
166
176
case antidote_pb_codec :decode_response (Result ) of
167
- {static_read_objects_resp , Values , CommitTimeStamp } ->
177
+ {static_read_objects_response , { Values , CommitTimeStamp } } ->
168
178
antidotec_pb_socket :store_commit_time (Pid , CommitTimeStamp ),
169
179
{ok , Values };
170
- {error , Reason } -> {error , Reason }
180
+ {error_response , Reason } -> {error , Reason }
171
181
end
172
182
end .
173
183
0 commit comments