@@ -128,31 +128,40 @@ cb_Backend_document_get_any_replica(VALUE self,
128
128
VALUE id,
129
129
VALUE options)
130
130
{
131
- auto cluster = cb_backend_to_public_api_cluster (self);
131
+ auto cluster = cb_backend_to_core_api_cluster (self);
132
132
133
133
Check_Type (bucket, T_STRING);
134
134
Check_Type (scope, T_STRING);
135
135
Check_Type (collection, T_STRING);
136
136
Check_Type (id, T_STRING);
137
137
138
138
try {
139
- couchbase::get_any_replica_options opts;
140
- set_timeout (opts, options);
139
+ core::document_id doc_id{
140
+ cb_string_new (bucket),
141
+ cb_string_new (scope),
142
+ cb_string_new (collection),
143
+ cb_string_new (id),
144
+ };
141
145
142
- auto f = cluster.bucket (cb_string_new (bucket))
143
- .scope (cb_string_new (scope))
144
- .collection (cb_string_new (collection))
145
- .get_any_replica (cb_string_new (id), opts);
146
- auto [ctx, resp] = cb_wait_for_future (f);
147
- if (ctx.ec ()) {
148
- cb_throw_error (ctx, " unable to get replica of the document" );
146
+ core::operations::get_any_replica_request req{ doc_id };
147
+ cb_extract_timeout (req, options);
148
+ cb_extract_read_preference (req, options);
149
+
150
+ std::promise<core::operations::get_any_replica_response> promise;
151
+ auto f = promise.get_future ();
152
+ cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
153
+ promise.set_value (std::forward<decltype (resp)>(resp));
154
+ });
155
+ auto resp = cb_wait_for_future (f);
156
+ if (resp.ctx .ec ()) {
157
+ cb_throw_error (resp.ctx , " unable to get replica of the document" );
149
158
}
150
159
151
- auto value = resp.content_as <passthrough_transcoder>();
152
160
VALUE res = rb_hash_new ();
153
- rb_hash_aset (res, rb_id2sym (rb_intern (" content" )), cb_str_new (value.data ));
154
- rb_hash_aset (res, rb_id2sym (rb_intern (" cas" )), cb_cas_to_num (resp.cas ()));
155
- rb_hash_aset (res, rb_id2sym (rb_intern (" flags" )), UINT2NUM (value.flags ));
161
+ rb_hash_aset (res, rb_id2sym (rb_intern (" content" )), cb_str_new (resp.value ));
162
+ rb_hash_aset (res, rb_id2sym (rb_intern (" cas" )), cb_cas_to_num (resp.cas ));
163
+ rb_hash_aset (res, rb_id2sym (rb_intern (" flags" )), UINT2NUM (resp.flags ));
164
+ rb_hash_aset (res, rb_id2sym (rb_intern (" replica" )), resp.replica ? Qtrue : Qfalse);
156
165
return res;
157
166
} catch (const std::system_error& se) {
158
167
rb_exc_raise (cb_map_error_code (
@@ -171,33 +180,43 @@ cb_Backend_document_get_all_replicas(VALUE self,
171
180
VALUE id,
172
181
VALUE options)
173
182
{
174
- auto cluster = cb_backend_to_public_api_cluster (self);
183
+ auto cluster = cb_backend_to_core_api_cluster (self);
175
184
176
185
Check_Type (bucket, T_STRING);
177
186
Check_Type (scope, T_STRING);
178
187
Check_Type (collection, T_STRING);
179
188
Check_Type (id, T_STRING);
180
189
181
190
try {
182
- couchbase::get_all_replicas_options opts;
183
- set_timeout (opts, options);
191
+ core::document_id doc_id{
192
+ cb_string_new (bucket),
193
+ cb_string_new (scope),
194
+ cb_string_new (collection),
195
+ cb_string_new (id),
196
+ };
184
197
185
- auto f = cluster.bucket (cb_string_new (bucket))
186
- .scope (cb_string_new (scope))
187
- .collection (cb_string_new (collection))
188
- .get_all_replicas (cb_string_new (id), opts);
189
- auto [ctx, resp] = cb_wait_for_future (f);
190
- if (ctx.ec ()) {
191
- cb_throw_error (ctx, " unable to get all replicas for the document" );
198
+ core::operations::get_all_replicas_request req{ doc_id };
199
+ cb_extract_timeout (req, options);
200
+ cb_extract_read_preference (req, options);
201
+
202
+ std::promise<core::operations::get_all_replicas_response> promise;
203
+ auto f = promise.get_future ();
204
+ cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
205
+ promise.set_value (std::forward<decltype (resp)>(resp));
206
+ });
207
+ auto resp = cb_wait_for_future (f);
208
+ if (resp.ctx .ec ()) {
209
+ cb_throw_error (resp.ctx , " unable to get all replicas for the document" );
192
210
}
193
211
194
- VALUE res = rb_ary_new_capa (static_cast <long >(resp.size ()));
195
- for (const auto & entry : resp) {
212
+ VALUE res = rb_ary_new_capa (static_cast <long >(resp.entries .size ()));
213
+
214
+ for (const auto & entry : resp.entries ) {
196
215
VALUE response = rb_hash_new ();
197
- auto value = entry.content_as <passthrough_transcoder>( );
198
- rb_hash_aset (response, rb_id2sym (rb_intern (" content " )), cb_str_new (value. data ));
199
- rb_hash_aset (response, rb_id2sym (rb_intern (" cas " )), cb_cas_to_num (entry.cas () ));
200
- rb_hash_aset (response, rb_id2sym (rb_intern (" flags " )), UINT2NUM (value. flags ) );
216
+ rb_hash_aset (response, rb_id2sym ( rb_intern ( " content " )), cb_str_new ( entry.value ) );
217
+ rb_hash_aset (response, rb_id2sym (rb_intern (" cas " )), cb_cas_to_num (entry. cas ));
218
+ rb_hash_aset (response, rb_id2sym (rb_intern (" flags " )), UINT2NUM (entry.flags ));
219
+ rb_hash_aset (response, rb_id2sym (rb_intern (" replica " )), entry. replica ? Qtrue : Qfalse );
201
220
rb_ary_push (res, response);
202
221
}
203
222
return res;
@@ -1107,6 +1126,7 @@ cb_Backend_document_lookup_in_any_replica(VALUE self,
1107
1126
1108
1127
core::operations::lookup_in_any_replica_request req{ doc_id };
1109
1128
cb_extract_timeout (req, options);
1129
+ cb_extract_read_preference (req, options);
1110
1130
1111
1131
static VALUE xattr_property = rb_id2sym (rb_intern (" xattr" ));
1112
1132
static VALUE path_property = rb_id2sym (rb_intern (" path" ));
@@ -1234,6 +1254,7 @@ cb_Backend_document_lookup_in_all_replicas(VALUE self,
1234
1254
1235
1255
core::operations::lookup_in_all_replicas_request req{ doc_id };
1236
1256
cb_extract_timeout (req, options);
1257
+ cb_extract_read_preference (req, options);
1237
1258
1238
1259
static VALUE xattr_property = rb_id2sym (rb_intern (" xattr" ));
1239
1260
static VALUE path_property = rb_id2sym (rb_intern (" path" ));
0 commit comments