use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.
the class RawManager method callManagement.
private static Mono<RawManagerResponse> callManagement(final Cluster cluster, final RawManagerRequest request, final RawManagerOptions options) {
final ClusterEnvironment environment = cluster.environment();
final RawManagerOptions.Built opts = options.build();
JsonSerializer serializer = opts.serializer() != null ? opts.serializer() : environment.jsonSerializer();
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().managementTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
final GenericManagerRequest req = new GenericManagerRequest(timeout, cluster.core().context(), retryStrategy, () -> {
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, request.method(), request.uri());
for (Map.Entry<String, Object> e : opts.httpHeaders().entrySet()) {
httpRequest.headers().set(e.getKey(), e.getValue());
}
return httpRequest;
}, request.method().equals(HttpMethod.GET), null);
cluster.core().send(req);
return Reactor.wrap(req, req.response(), true).map(res -> new RawManagerResponse(request.serviceType(), serializer, res.httpStatus(), res.content()));
}
use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method touchRequest.
/**
* Helper method to create the touch request.
*
* @param id the id of the document to update.
* @param expiry the new expiry for the document.
* @param options the custom options.
* @return the touch request.
*/
TouchRequest touchRequest(final String id, final Expiry expiry, final TouchOptions options) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(expiry, "Expiry", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(options, "TouchOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
TouchOptions.Built opts = options.build();
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_TOUCH, opts.parentSpan().orElse(null));
long encodedExpiry = expiry.encode();
TouchRequest request = new TouchRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, encodedExpiry, span);
request.context().clientContext(opts.clientContext());
return request;
}
use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method upsertRequest.
/**
* Helper method to generate the upsert request.
*
* @param id the document id to upsert.
* @param content the document content to upsert.
* @param opts custom options to customize the upsert behavior.
* @return the upsert request.
*/
UpsertRequest upsertRequest(final String id, final Object content, final UpsertOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(content, "Content", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_UPSERT, opts.parentSpan().orElse(null));
final RequestSpan encodeSpan = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ENCODING, span);
long start = System.nanoTime();
Transcoder.EncodedValue encoded;
try {
encoded = transcoder.encode(content);
} finally {
encodeSpan.end();
}
long end = System.nanoTime();
long expiry = opts.expiry().encode();
final UpsertRequest request = new UpsertRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext()).encodeLatency(end - start);
return request;
}
use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method fullGetRequest.
/**
* Helper method to create a get request for a full doc fetch.
*
* @param id the document id which is used to uniquely identify it.
* @param opts custom options to change the default behavior.
* @return the get request.
*/
@Stability.Internal
GetRequest fullGetRequest(final String id, final GetOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_GET, opts.parentSpan().orElse(null));
GetRequest request = new GetRequest(id, timeout, coreContext, collectionIdentifier, retryStrategy, span);
request.context().clientContext(opts.clientContext());
return request;
}
use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method subdocGetRequest.
/**
* Helper method to create a get request for a subdoc fetch.
*
* @param id the document id which is used to uniquely identify it.
* @param opts custom options to change the default behavior.
* @return the subdoc get request.
*/
@Stability.Internal
SubdocGetRequest subdocGetRequest(final String id, final GetOptions.Built opts) {
try {
notNullOrEmpty(id, "Id");
if (opts.withExpiry()) {
if (opts.projections().size() > 15) {
throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be " + "projected per request due to a server limitation (includes the expiration macro as one field).");
}
} else {
if (opts.projections().size() > 16) {
throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be " + "projected per request due to a server limitation.");
}
}
} catch (Exception cause) {
throw new InvalidArgumentException("Argument validation failed", cause, ReducedKeyValueErrorContext.create(id, collectionIdentifier));
}
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
List<SubdocGetRequest.Command> commands = new ArrayList<>(16);
if (!opts.projections().isEmpty()) {
if (opts.projections().size() > 16) {
throw new UnsupportedOperationException("Only a maximum of 16 fields can be " + "projected per request.");
}
List<String> projections = opts.projections();
for (int i = 0; i < projections.size(); i++) {
commands.add(new SubdocGetRequest.Command(SubdocCommandType.GET, projections.get(i), false, commands.size()));
}
} else {
commands.add(new SubdocGetRequest.Command(SubdocCommandType.GET_DOC, "", false, commands.size()));
}
if (opts.withExpiry()) {
// xattrs must go first
commands.add(0, new SubdocGetRequest.Command(SubdocCommandType.GET, LookupInMacro.EXPIRY_TIME, true, commands.size()));
// JSON compat flags.
if (opts.projections().isEmpty()) {
commands.add(1, new SubdocGetRequest.Command(SubdocCommandType.GET, LookupInMacro.FLAGS, true, commands.size()));
}
}
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_LOOKUP_IN, opts.parentSpan().orElse(null));
SubdocGetRequest request = new SubdocGetRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, (byte) 0x00, commands, span);
request.context().clientContext(opts.clientContext());
return request;
}
Aggregations