use of com.couchbase.client.core.retry.RetryStrategy in project spring-data-couchbase by spring-projects.
the class OptionsBuilder method buildQueryOptions.
static QueryOptions buildQueryOptions(Query query, QueryOptions options, QueryScanConsistency scanConsistency) {
options = options != null ? options : QueryOptions.queryOptions();
if (query.getParameters() != null) {
if (query.getParameters() instanceof JsonArray) {
options.parameters((JsonArray) query.getParameters());
} else {
options.parameters((JsonObject) query.getParameters());
}
}
Meta meta = query.getMeta() != null ? query.getMeta() : new Meta();
QueryOptions.Built optsBuilt = options.build();
JsonObject optsJson = getQueryOpts(optsBuilt);
QueryScanConsistency metaQueryScanConsistency = meta.get(SCAN_CONSISTENCY) != null ? ((ScanConsistency) meta.get(SCAN_CONSISTENCY)).query() : null;
QueryScanConsistency qsc = fromFirst(QueryScanConsistency.NOT_BOUNDED, getScanConsistency(optsJson), scanConsistency, metaQueryScanConsistency);
Duration timeout = fromFirst(Duration.ofSeconds(0), getTimeout(optsBuilt), meta.get(TIMEOUT));
RetryStrategy retryStrategy = fromFirst(null, getRetryStrategy(optsBuilt), meta.get(RETRY_STRATEGY));
if (qsc != null) {
options.scanConsistency(qsc);
}
if (timeout != null) {
options.timeout(timeout);
}
if (retryStrategy != null) {
options.retryStrategy(retryStrategy);
}
if (LOG.isTraceEnabled()) {
LOG.trace("query options: {}", getQueryOpts(options.build()));
}
return options;
}
use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method lookupInRequest.
/**
* Helper method to create the underlying lookup subdoc request.
*
* @param id the outer document ID.
* @param specs the spec which specifies the type of lookups to perform.
* @param opts custom options to modify the lookup options.
* @return the subdoc lookup request.
*/
SubdocGetRequest lookupInRequest(final String id, final List<LookupInSpec> specs, final LookupInOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNullOrEmpty(specs, "LookupInSpecs", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
ArrayList<SubdocGetRequest.Command> commands = new ArrayList<>(specs.size());
for (int i = 0; i < specs.size(); i++) {
LookupInSpec spec = specs.get(i);
commands.add(spec.export(i));
}
// xattrs come first
commands.sort(Comparator.comparing(v -> !v.xattr()));
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
byte flags = 0;
if (opts.accessDeleted()) {
flags |= SubdocMutateRequest.SUBDOC_DOC_FLAG_ACCESS_DELETED;
}
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_LOOKUP_IN, opts.parentSpan().orElse(null));
SubdocGetRequest request = new SubdocGetRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, flags, commands, 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 replaceRequest.
/**
* Helper method to generate the replace request.
*
* @param id the document id to replace.
* @param content the document content to replace.
* @param opts custom options to customize the replace behavior.
* @return the replace request.
*/
ReplaceRequest replaceRequest(final String id, final Object content, final ReplaceOptions.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_REPLACE, 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();
ReplaceRequest request = new ReplaceRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, opts.cas(), 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 unlockRequest.
/**
* Helper method to create the unlock request.
*
* @param id the id of the document.
* @param cas the CAS value which is needed to unlock it.
* @param options the options to customize.
* @return the unlock request.
*/
UnlockRequest unlockRequest(final String id, final long cas, final UnlockOptions options) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(options, "UnlockOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
if (cas == 0) {
throw new InvalidArgumentException("CAS cannot be 0", null, ReducedKeyValueErrorContext.create(id, collectionIdentifier));
}
UnlockOptions.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_UNLOCK, opts.parentSpan().orElse(null));
UnlockRequest request = new UnlockRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, cas, 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 AsyncScope method analyticsRequest.
/**
* Helper method to craft an analytics request.
*
* @param statement the statement to use.
* @param opts the built analytics options.
* @return the created analytics request.
*/
AnalyticsRequest analyticsRequest(final String statement, final AnalyticsOptions.Built opts) {
notNullOrEmpty(statement, "Statement", () -> new ReducedAnalyticsErrorContext(statement));
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().analyticsTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
JsonObject query = JsonObject.create();
query.put("statement", statement);
query.put("timeout", encodeDurationToMs(timeout));
query.put("query_context", AnalyticsRequest.queryContext(bucketName, scopeName));
opts.injectParams(query);
final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
final String clientContextId = query.getString("client_context_id");
final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ANALYTICS, opts.parentSpan().orElse(null));
AnalyticsRequest request = new AnalyticsRequest(timeout, core.context(), retryStrategy, core.context().authenticator(), queryBytes, opts.priority(), opts.readonly(), clientContextId, statement, span, bucketName, scopeName);
request.context().clientContext(opts.clientContext());
return request;
}
Aggregations