Fix error code in 3.2 branch (#11199)

* Fix error code in 3.2 branch

* Fix error code in 3.2 branch
This commit is contained in:
Albumen Kevin 2022-12-25 20:33:15 +08:00 committed by GitHub
parent 459a0f915b
commit 2a7dd3dc29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 72 additions and 62 deletions

View File

@ -75,6 +75,8 @@ public interface LoggerCodeConstants {
String COMMON_METADATA_PROCESSOR = "0-26";
String COMMON_ISOLATED_EXECUTOR_CONFIGURATION_ERROR = "0-27";
// registry module
String REGISTRY_ADDRESS_INVALID = "1-1";
@ -156,6 +158,8 @@ public interface LoggerCodeConstants {
String REGISTRY_ROUTER_WAIT_LONG = "1-40";
String REGISTRY_ISTIO_EXCEPTION = "1-41";
// cluster module 2-x
String CLUSTER_FAILED_SITE_SELECTION = "2-1";

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.config;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.Assert;
@ -110,7 +111,7 @@ public class DubboShutdownHook extends Thread {
}
}
} catch (InterruptedException e) {
logger.warn(e.getMessage(), e);
logger.warn(LoggerCodeConstants.INTERNAL_INTERRUPTED, "", "", e.getMessage(), e);
Thread.currentThread().interrupt();
}
}

View File

@ -74,6 +74,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SERVICE_EXECUTOR;
import static org.apache.dubbo.common.constants.CommonConstants.SERVICE_NAME_MAPPING_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_ISOLATED_EXECUTOR_CONFIGURATION_ERROR;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_EXPORT_SERVICE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_NO_METHOD_FOUND;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_SERVER_DISCONNECTED;
@ -431,7 +432,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
if (getExecutor() != null) {
String mode = application.getExecutorManagementMode();
if (!EXECUTOR_MANAGEMENT_MODE_ISOLATION.equals(mode)) {
logger.warn("The current executor management mode is " + mode +
logger.warn(COMMON_ISOLATED_EXECUTOR_CONFIGURATION_ERROR, "", "", "The current executor management mode is " + mode +
", the configured service executor cannot take effect unless the mode is configured as " + EXECUTOR_MANAGEMENT_MODE_ISOLATION);
return;
}

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.common.config.ReferenceCache;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
import org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.deploy.AbstractDeployer;
import org.apache.dubbo.common.deploy.ApplicationDeployListener;
import org.apache.dubbo.common.deploy.ApplicationDeployer;
@ -722,7 +723,8 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
try {
metricsServiceExporter.export();
} catch (Exception e) {
logger.error("exportMetricsService an exception occurred when handle starting event", e);
logger.error(LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION, "", "",
"exportMetricsService an exception occurred when handle starting event", e);
}
}

View File

@ -16,7 +16,8 @@
*/
package org.apache.dubbo.config.deploy;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.metrics.service.MetricsService;
import org.apache.dubbo.common.metrics.service.MetricsServiceExporter;
@ -28,6 +29,7 @@ import org.apache.dubbo.rpc.model.ScopeModelAware;
import java.util.Optional;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION;
import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS;
/**
@ -35,7 +37,7 @@ import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMET
*/
public class DefaultMetricsServiceExporter implements MetricsServiceExporter, ScopeModelAware {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
private ApplicationModel applicationModel;
private MetricsService metricsService;
@ -53,7 +55,7 @@ public class DefaultMetricsServiceExporter implements MetricsServiceExporter, Sc
if (PROTOCOL_PROMETHEUS.equals(metricsConfig.getProtocol()) ) {
this.metricsService = applicationModel.getExtensionLoader(MetricsService.class).getDefaultExtension();
} else {
logger.warn("Protocol " + metricsConfig.getProtocol() + " not support for new metrics mechanism. " +
logger.warn(COMMON_METRICS_COLLECTOR_EXCEPTION, "", "", "Protocol " + metricsConfig.getProtocol() + " not support for new metrics mechanism. " +
"Using old metrics mechanism instead.");
}
}
@ -85,12 +87,12 @@ public class DefaultMetricsServiceExporter implements MetricsServiceExporter, Sc
this.serviceConfig = serviceConfig;
} else {
if (logger.isWarnEnabled()) {
logger.warn("The MetricsService has been exported : " + serviceConfig.getExportedUrls());
logger.warn(LoggerCodeConstants.INTERNAL_ERROR, "", "", "The MetricsService has been exported : " + serviceConfig.getExportedUrls());
}
}
} else {
if (logger.isWarnEnabled()) {
logger.warn("The MetricsConfig not exist, will not export metrics service.");
if (logger.isInfoEnabled()) {
logger.info("The MetricsConfig not exist, will not export metrics service.");
}
}

View File

@ -41,6 +41,7 @@ import java.util.concurrent.locks.ReentrantLock;
import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY;
@ -207,7 +208,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
mappingByUrl = serviceNameMapping.getAndListen(this.getUrl(), url, mappingListener);
mappingListeners.put(url.getProtocolServiceKey(), mappingListener);
} catch (Exception e) {
logger.warn("Cannot find app mapping for service " + url.getServiceInterface() + ", will not migrate.", e);
logger.warn(INTERNAL_ERROR, "", "", "Cannot find app mapping for service " + url.getServiceInterface() + ", will not migrate.", e);
}
if (CollectionUtils.isEmpty(mappingByUrl)) {

View File

@ -17,7 +17,7 @@
package org.apache.dubbo.remoting.api.connection;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.RemotingException;
@ -28,9 +28,11 @@ import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_ERROR_CLOSE_CLIENT;
public abstract class AbstractConnectionClient extends AbstractClient {
private static final Logger logger = LoggerFactory.getLogger(AbstractConnectionClient.class);
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(AbstractConnectionClient.class);
protected WireProtocol protocol;
@ -72,7 +74,7 @@ public abstract class AbstractConnectionClient extends AbstractClient {
destroy();
return true;
} else if (remainingCount <= -1) {
logger.warn("This instance has been destroyed");
logger.warn(PROTOCOL_ERROR_CLOSE_CLIENT, "", "", "This instance has been destroyed");
return false;
} else {
return false;

View File

@ -17,7 +17,7 @@
package org.apache.dubbo.remoting.transport.netty;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
@ -49,6 +49,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.BACKLOG_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CLOSE;
import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_BOSS_POOL_NAME;
import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_WORKER_POOL_NAME;
@ -57,7 +58,7 @@ import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_WORKER_POOL_NAME;
*/
public class NettyPortUnificationServer extends AbstractPortUnificationServer {
private static final Logger logger = LoggerFactory.getLogger(NettyPortUnificationServer.class);
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(NettyPortUnificationServer.class);
private Map<String, Channel> dubboChannels = new ConcurrentHashMap<>();// <ip:port, channel>
@ -138,7 +139,7 @@ public class NettyPortUnificationServer extends AbstractPortUnificationServer {
channel.close();
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e);
}
try {
Collection<Channel> channels = getChannels();
@ -147,12 +148,12 @@ public class NettyPortUnificationServer extends AbstractPortUnificationServer {
try {
channel.close();
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e);
}
}
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e);
}
for (WireProtocol protocol : getProtocols()) {
protocol.close();
@ -164,14 +165,14 @@ public class NettyPortUnificationServer extends AbstractPortUnificationServer {
bootstrap.releaseExternalResources();
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e);
}
try {
if (dubboChannels != null) {
dubboChannels.clear();
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
logger.warn(TRANSPORT_FAILED_CLOSE, "", "", e.getMessage(), e);
}
}

View File

@ -25,9 +25,9 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.transport.netty4.ssl.SslClientTlsHandler;
import org.apache.dubbo.remoting.api.WireProtocol;
import org.apache.dubbo.remoting.api.connection.AbstractConnectionClient;
import org.apache.dubbo.remoting.transport.netty4.ssl.SslClientTlsHandler;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.PooledByteBufAllocator;
@ -52,6 +52,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.SSL_ENABLED_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_CLIENT_CONNECT_TIMEOUT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_CONNECT_PROVIDER;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_RECONNECT;
import static org.apache.dubbo.remoting.transport.netty4.NettyEventLoopFactory.socketChannelClass;
public class NettyConnectionClient extends AbstractConnectionClient {
@ -267,7 +268,7 @@ public class NettyConnectionClient extends AbstractConnectionClient {
try {
doConnect();
} catch (RemotingException e) {
LOGGER.error("Failed to connect to server: " + getConnectAddress());
LOGGER.error(TRANSPORT_FAILED_RECONNECT, "", "", "Failed to connect to server: " + getConnectAddress());
}
}
@ -345,7 +346,7 @@ public class NettyConnectionClient extends AbstractConnectionClient {
try {
connectionClient.doConnect();
} catch (RemotingException e) {
LOGGER.error("Failed to connect to server: " + getConnectAddress());
LOGGER.error(TRANSPORT_FAILED_RECONNECT, "", "", "Failed to connect to server: " + getConnectAddress());
}
}, 1L, TimeUnit.SECONDS);
}

View File

@ -31,6 +31,7 @@ import io.netty.util.AttributeKey;
import java.util.concurrent.TimeUnit;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_RECONNECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
@ChannelHandler.Sharable
@ -80,7 +81,7 @@ public class NettyConnectionHandler extends ChannelInboundHandlerAdapter impleme
try {
connectionClient.doConnect();
} catch (Throwable e) {
LOGGER.error("Fail to connect to " + connectionClient.getChannel(), e);
LOGGER.error(TRANSPORT_FAILED_RECONNECT, "", "", "Fail to connect to " + connectionClient.getChannel(), e);
}
}, 1, TimeUnit.SECONDS);
}

View File

@ -40,6 +40,7 @@ import org.apache.dubbo.rpc.model.FrameworkModel;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_ISOLATION;
@ -66,6 +67,8 @@ public class DubboCodec extends ExchangeCodec {
public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
private static final ErrorTypeAwareLogger log = LoggerFactory.getErrorTypeAwareLogger(DubboCodec.class);
private static final AtomicBoolean decodeInUserThreadLogged = new AtomicBoolean(false);
private CallbackServiceCodec callbackServiceCodec;
private FrameworkModel frameworkModel;
@ -174,7 +177,7 @@ public class DubboCodec extends ExchangeCodec {
boolean decodeDataInIoThread = channel.getUrl().getParameter(DECODE_IN_IO_THREAD_KEY, DEFAULT_DECODE_IN_IO_THREAD);
String mode = ExecutorRepository.getMode(channel.getUrl().getOrDefaultApplicationModel());
if (EXECUTOR_MANAGEMENT_MODE_ISOLATION.equals(mode)) {
if (!decodeDataInIoThread) {
if (!decodeDataInIoThread && decodeInUserThreadLogged.compareAndSet(false, true)) {
log.info("Because thread pool isolation is enabled on the dubbo protocol, the body can only be decoded " +
"on the io thread, and the parameter[" + DECODE_IN_IO_THREAD_KEY + "] will be ignored");
// Why? because obtaining the isolated thread pool requires the serviceKey of the service,

View File

@ -43,21 +43,15 @@ public class DubboIsolationExecutorSupport extends AbstractIsolationExecutorSupp
return null;
}
try {
Request request = (Request) data;
if (request.getData() == null || !(request.getData() instanceof Invocation)) {
return null;
}
Invocation inv = (Invocation) request.getData();
Map<String, String> attachments = inv.getAttachments();
String interfaceName = attachments.get(PATH_KEY);
String version = attachments.get(VERSION_KEY);
String group = attachments.get(GROUP_KEY);
return new ServiceKey(interfaceName, version, group);
} catch (Throwable e) {
logger.error("failed to get service key, maybe the build rule for data is wrong, data = " + data, e);
Request request = (Request) data;
if (!(request.getData() instanceof Invocation)) {
return null;
}
return null;
Invocation inv = (Invocation) request.getData();
Map<String, String> attachments = inv.getAttachments();
String interfaceName = attachments.get(PATH_KEY);
String version = attachments.get(VERSION_KEY);
String group = attachments.get(GROUP_KEY);
return new ServiceKey(interfaceName, version, group);
}
}

View File

@ -16,13 +16,14 @@
*/
package org.apache.dubbo.rpc.protocol.tri.transport;
import io.netty.handler.codec.http2.Http2Headers;
import org.apache.dubbo.common.ServiceKey;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.rpc.protocol.tri.TripleHeaderEnum;
import org.apache.dubbo.rpc.executor.AbstractIsolationExecutorSupport;
import org.apache.dubbo.rpc.protocol.tri.TripleHeaderEnum;
import io.netty.handler.codec.http2.Http2Headers;
public class TripleIsolationExecutorSupport extends AbstractIsolationExecutorSupport {
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(TripleIsolationExecutorSupport.class);
@ -37,21 +38,15 @@ public class TripleIsolationExecutorSupport extends AbstractIsolationExecutorSup
return null;
}
try {
Http2Headers headers = (Http2Headers) data;
String path = headers.path().toString();
String[] parts = path.split("/"); // path like /{interfaceName}/{methodName}
String interfaceName = parts[1];
String version = headers.contains(TripleHeaderEnum.SERVICE_VERSION.getHeader()) ?
headers.get(TripleHeaderEnum.SERVICE_VERSION.getHeader()).toString() : null;
String group = headers.contains(TripleHeaderEnum.SERVICE_GROUP.getHeader()) ?
headers.get(TripleHeaderEnum.SERVICE_GROUP.getHeader()).toString() : null;
return new ServiceKey(interfaceName, version, group);
} catch (Throwable e) {
logger.error("failed to get service key, maybe the build rule for data is wrong, data = " + data, e);
}
return null;
Http2Headers headers = (Http2Headers) data;
String path = headers.path().toString();
String[] parts = path.split("/"); // path like /{interfaceName}/{methodName}
String interfaceName = parts[1];
String version = headers.contains(TripleHeaderEnum.SERVICE_VERSION.getHeader()) ?
headers.get(TripleHeaderEnum.SERVICE_VERSION.getHeader()).toString() : null;
String group = headers.contains(TripleHeaderEnum.SERVICE_GROUP.getHeader()) ?
headers.get(TripleHeaderEnum.SERVICE_GROUP.getHeader()).toString() : null;
return new ServiceKey(interfaceName, version, group);
}

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.registry.xds.istio;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.registry.xds.XdsEnv;
@ -115,7 +116,7 @@ public class IstioEnv implements XdsEnv {
try {
return FileUtils.readFileToString(saFile, StandardCharsets.UTF_8);
} catch (IOException e) {
logger.error("Unable to read token file.", e);
logger.error(LoggerCodeConstants.REGISTRY_ISTIO_EXCEPTION, "File Read Failed", "", "Unable to read token file.", e);
}
}
@ -171,7 +172,7 @@ public class IstioEnv implements XdsEnv {
try {
return FileUtils.readFileToString(caFile, StandardCharsets.UTF_8);
} catch (IOException e) {
logger.error("read ca file error", e);
logger.error(LoggerCodeConstants.REGISTRY_ISTIO_EXCEPTION, "File Read Failed", "", "read ca file error", e);
}
}
return null;

View File

@ -16,7 +16,8 @@
*/
package org.apache.dubbo.rpc.cluster.router.xds;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.cluster.router.xds.rule.ClusterWeight;
@ -40,7 +41,7 @@ import java.util.stream.Collectors;
public class RdsVirtualHostListener {
private static final Logger LOGGER = LoggerFactory.getLogger(RdsVirtualHostListener.class);
private static final ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(RdsVirtualHostListener.class);
private final String domain;
@ -70,7 +71,7 @@ public class RdsVirtualHostListener {
// post rules
routeRuleManager.notifyRuleChange(domain, xdsRouteRules);
} catch (Exception e) {
LOGGER.error("parse domain: " + domain + " xds VirtualHost error", e);
LOGGER.error(LoggerCodeConstants.INTERNAL_ERROR, "", "", "parse domain: " + domain + " xds VirtualHost error", e);
}
}