use of com.couchbase.client.core.msg.ResponseStatus in project couchbase-jvm-clients by couchbase.
the class ObserveViaCasRequest method decode.
@Override
public ObserveViaCasResponse decode(final ByteBuf response, KeyValueChannelContext ctx) {
ResponseStatus status = decodeStatus(response);
byte observed = ObserveViaCasResponse.ObserveStatus.UNKNOWN.value();
long observedCas = 0;
ResponseStatusDetails statusDetails = null;
if (status.success()) {
ByteBuf content = body(response).get();
short keyLength = content.getShort(2);
observed = content.getByte(keyLength + 4);
observedCas = content.getLong(keyLength + 5);
} else {
// TODO: implement once xerror is fully implemented
// ResponseStatus.convertDetails(datatype(response), );
statusDetails = null;
}
return new ObserveViaCasResponse(status, observedCas, ObserveViaCasResponse.ObserveStatus.valueOf(observed), active, statusDetails);
}
use of com.couchbase.client.core.msg.ResponseStatus in project couchbase-jvm-clients by couchbase.
the class ObserveViaSeqnoRequest method decode.
@Override
public ObserveViaSeqnoResponse decode(final ByteBuf response, final KeyValueChannelContext ctx) {
ResponseStatus status = decodeStatus(response);
if (status.success()) {
ByteBuf content = body(response).get();
byte format = content.readByte();
short vbucketId = content.readShort();
long vbucketUUID = content.readLong();
long lastPersistedSeqno = content.readLong();
long currentSeqno = content.readLong();
switch(format) {
case 0:
return new ObserveViaSeqnoResponse(status, active, vbucketId, vbucketUUID, lastPersistedSeqno, currentSeqno, Optional.empty(), Optional.empty());
case 1:
return new ObserveViaSeqnoResponse(status, active, vbucketId, vbucketUUID, lastPersistedSeqno, currentSeqno, Optional.of(content.readLong()), Optional.of(content.readLong()));
default:
throw new IllegalStateException("Unsupported format 0x" + Integer.toHexString(format));
}
} else {
return new ObserveViaSeqnoResponse(status, active, (short) 0, 0L, 0L, 0L, Optional.empty(), Optional.empty());
}
}
use of com.couchbase.client.core.msg.ResponseStatus in project couchbase-jvm-clients by couchbase.
the class MultiObserveViaCasRequest method decode.
@Override
public MultiObserveViaCasResponse decode(final ByteBuf response, final KeyValueChannelContext ctx) {
final ResponseStatus status = decodeStatus(response);
final Map<byte[], ObserveViaCasResponse.ObserveStatus> observed = new HashMap<>();
if (status.success()) {
Optional<ByteBuf> maybeContent = body(response);
if (maybeContent.isPresent()) {
ByteBuf content = maybeContent.get();
while (content.isReadable()) {
// skip the vbid
content.skipBytes(Short.BYTES);
short keyLength = content.readShort();
if (ctx.collectionsEnabled()) {
int skipped = UnsignedLEB128.skip(content);
keyLength = (short) (keyLength - skipped);
}
byte[] keyEncoded = new byte[keyLength];
content.readBytes(keyEncoded, 0, keyLength);
byte obs = content.readByte();
// skip reading the cas
content.skipBytes(Long.BYTES);
ObserveViaCasResponse.ObserveStatus decoded = ObserveViaCasResponse.ObserveStatus.valueOf(obs);
if (responsePredicate.test(decoded)) {
observed.put(keyEncoded, decoded);
}
}
}
}
return new MultiObserveViaCasResponse(this, status, observed);
}
use of com.couchbase.client.core.msg.ResponseStatus in project couchbase-jvm-clients by couchbase.
the class KeyValueMessageHandler method decode.
/**
* Main method to start dispatching the decode.
*
* @param ctx the channel handler context from netty.
* @param response the response to decode and handle.
*/
private void decode(final ChannelHandlerContext ctx, final ByteBuf response) {
int opaque = MemcacheProtocol.opaque(response);
KeyValueRequest<Response> request = writtenRequests.remove(opaque);
if (request == null) {
handleUnknownResponseReceived(ctx, response);
return;
}
long serverTime = MemcacheProtocol.parseServerDurationFromResponse(response);
request.context().serverLatency(serverTime);
long start = writtenRequestDispatchTimings.remove(opaque);
request.context().dispatchLatency(System.nanoTime() - start);
RequestSpan dispatchSpan = writtenRequestDispatchSpans.remove(opaque);
if (dispatchSpan != null) {
if (!isInternalTracer) {
TracingUtils.setServerDurationAttribute(dispatchSpan, serverTime);
}
dispatchSpan.end();
}
short statusCode = MemcacheProtocol.status(response);
ResponseStatus status = MemcacheProtocol.decodeStatus(statusCode);
ErrorMap.ErrorCode errorCode = status != ResponseStatus.SUCCESS ? decodeErrorCode(statusCode) : null;
if (errorCode != null) {
request.errorCode(errorCode);
}
boolean errorUnknown = false;
if (status == ResponseStatus.UNKNOWN) {
errorUnknown = true;
if (errorCode != null) {
ioContext.environment().eventBus().publish(new KeyValueErrorMapCodeHandledEvent(ioContext, errorCode));
status = handleErrorCode(ctx, errorCode);
}
ioContext.environment().eventBus().publish(new UnknownResponseStatusReceivedEvent(ioContext, statusCode));
}
if (status == ResponseStatus.NOT_MY_VBUCKET) {
handleNotMyVbucket(request, response);
} else if (status == ResponseStatus.UNKNOWN_COLLECTION) {
handleOutdatedCollection(request, RetryReason.KV_COLLECTION_OUTDATED);
} else if (errorUnknown && errorMapIndicatesRetry(errorCode)) {
RetryOrchestrator.maybeRetry(ioContext, request, RetryReason.KV_ERROR_MAP_INDICATED);
} else if (statusIndicatesInvalidChannel(status)) {
closeChannelWithReason(ioContext, ctx, ChannelClosedProactivelyEvent.Reason.KV_RESPONSE_CONTAINED_CLOSE_INDICATION);
} else {
RetryReason retryReason = statusCodeIndicatesRetry(status, request);
if (retryReason == null) {
if (!request.completed()) {
decodeAndComplete(request, response);
} else {
ioContext.environment().orphanReporter().report(request);
}
} else {
RetryOrchestrator.maybeRetry(ioContext, request, retryReason);
}
}
}
use of com.couchbase.client.core.msg.ResponseStatus in project couchbase-jvm-clients by couchbase.
the class ViewChunkResponseParser method error.
@Override
public Optional<CouchbaseException> error() {
return error.map(e -> {
int httpStatus = responseHeader().status().code();
ResponseStatus responseStatus = HttpProtocol.decodeStatus(responseHeader().status());
ViewErrorContext errorContext = new ViewErrorContext(responseStatus, requestContext(), e, httpStatus);
if (responseStatus == ResponseStatus.NOT_FOUND || e.error().equals("not_found") || e.reason().contains("not_found")) {
return new ViewNotFoundException(errorContext);
}
return new CouchbaseException("Unknown view error: " + e.toString(), errorContext);
});
}
Aggregations