use of com.couchbase.client.core.cnc.events.io.UnknownResponseStatusReceivedEvent 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);
}
}
}
Aggregations