Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] do not show the warning at first replaceWithLazyClient() #8814

Merged
merged 11 commits into from
Sep 20, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public interface Constants {
*/
boolean DEFAULT_LAZY_CONNECT_INITIAL_STATE = true;

/**
* when this warning rises from invocation, program probably have bug.
*/
String LAZY_REQUEST_WITH_WARNING_KEY = "lazyclient_request_with_warning";

boolean DEFAULT_LAZY_REQUEST_WITH_WARNING = false;

String OPTIMIZER_KEY = "optimizer";

String ON_CONNECT_KEY = "onconnect";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@

import static org.apache.dubbo.remoting.Constants.SEND_RECONNECT_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_LAZY_CONNECT_INITIAL_STATE;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_LAZY_REQUEST_WITH_WARNING;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_CONNECT_INITIAL_STATE_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_REQUEST_WITH_WARNING_KEY;

/**
* dubbo protocol support class.
*/
@SuppressWarnings("deprecation")
final class LazyConnectExchangeClient implements ExchangeClient {

/**
* when this warning rises from invocation, program probably have bug.
*/
protected static final String REQUEST_WITH_WARNING_KEY = "lazyclient_request_with_warning";
private final static Logger logger = LoggerFactory.getLogger(LazyConnectExchangeClient.class);
protected final boolean requestWithWarning;
private final URL url;
Expand All @@ -66,7 +64,7 @@ public LazyConnectExchangeClient(URL url, ExchangeHandler requestHandler) {
this.url = url.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
this.requestHandler = requestHandler;
this.initialState = url.getParameter(LAZY_CONNECT_INITIAL_STATE_KEY, DEFAULT_LAZY_CONNECT_INITIAL_STATE);
this.requestWithWarning = url.getParameter(REQUEST_WITH_WARNING_KEY, false);
this.requestWithWarning = url.getParameter(LAZY_REQUEST_WITH_WARNING_KEY, DEFAULT_LAZY_REQUEST_WITH_WARNING);
}

private void initClient() throws RemotingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,19 @@ public void startClose() {
* @return
*/
private void replaceWithLazyClient() {
// this is a defensive operation to avoid client is closed by accident, the initial state of the client is false
URL lazyUrl = url.addParameter(LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE)
//.addParameter(RECONNECT_KEY, Boolean.FALSE)
.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
//.addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true);

if (disconnectCount.getAndIncrement() % maxDisconnectCount == 0) {
if (disconnectCount.getAndIncrement() % maxDisconnectCount == 1) {
zrlw marked this conversation as resolved.
Show resolved Hide resolved
logger.warn(url.getAddress() + " " + url.getServiceKey() + " safe guard client , should not be called ,must have a bug.");
}

/**
* the order of judgment in the if statement cannot be changed.
*/
if (!(client instanceof LazyConnectExchangeClient) || client.isClosed()) {
// this is a defensive operation to avoid client is closed by accident, the initial state of the client is false
URL lazyUrl = url.addParameter(LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE)
//.addParameter(RECONNECT_KEY, Boolean.FALSE)
.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
//.addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true);
client = new LazyConnectExchangeClient(lazyUrl, client.getExchangeHandler());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import java.util.Objects;

import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_REQUEST_WITH_WARNING_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.SHARE_CONNECTIONS_KEY;


public class ReferenceCountExchangeClientTest {

public static ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Expand Down Expand Up @@ -164,7 +164,7 @@ public void test_counter_error() {
Assertions.assertEquals("hello", helloService.hello());
Assertions.assertEquals(0, LogUtil.findMessage(errorMsg), "should not warning message");

// generally a client can only be closed once, here it is closed twice, counter is incorrect
// close twice, counter counts down from 1 to 0, no warning occurs
client.close();

// wait close done.
Expand Down Expand Up @@ -211,8 +211,11 @@ private void init(int connections, int shareConnections) {
Assertions.assertTrue(shareConnections >= 1);

int port = NetUtils.getAvailablePort();
URL demoUrl = URL.valueOf("dubbo://127.0.0.1:" + port + "/demo?" + CONNECTIONS_KEY + "=" + connections + "&" + SHARE_CONNECTIONS_KEY + "=" + shareConnections);
URL helloUrl = URL.valueOf("dubbo://127.0.0.1:" + port + "/hello?" + CONNECTIONS_KEY + "=" + connections + "&" + SHARE_CONNECTIONS_KEY + "=" + shareConnections);
String params = CONNECTIONS_KEY + "=" + connections
+ "&" + SHARE_CONNECTIONS_KEY + "=" + shareConnections
+ "&" + LAZY_REQUEST_WITH_WARNING_KEY + "=" + "true";
URL demoUrl = URL.valueOf("dubbo://127.0.0.1:" + port + "/demo?" + params);
URL helloUrl = URL.valueOf("dubbo://127.0.0.1:" + port + "/hello?" + params);

demoExporter = export(new DemoServiceImpl(), IDemoService.class, demoUrl);
helloExporter = export(new HelloServiceImpl(), IHelloService.class, helloUrl);
Expand Down