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

Triple set resolve fallback enable as default #12575

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
@SPI(value = CommonConstants.TRIPLE, scope = ExtensionScope.FRAMEWORK)
public interface PathResolver {

void add(String path, Invoker<?> invoker);
Invoker<?> add(String path, Invoker<?> invoker);

Invoker<?> addIfAbsent(String path, Invoker<?> invoker);

Invoker<?> resolve(String path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ public class TriplePathResolver implements PathResolver {
private final ConcurrentHashMap<String, Object> nativeStub = new ConcurrentHashMap<>();

@Override
public void add(String path, Invoker<?> invoker) {
path2Invoker.put(path, invoker);
public Invoker<?> add(String path, Invoker<?> invoker) {
return path2Invoker.put(path, invoker);
}

@Override
public Invoker<?> addIfAbsent(String path, Invoker<?> invoker) {
return path2Invoker.putIfAbsent(path, invoker);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import java.util.Set;
import java.util.concurrent.ExecutorService;

import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
import static org.apache.dubbo.rpc.Constants.H2_IGNORE_1_0_0_KEY;
import static org.apache.dubbo.rpc.Constants.H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY;
import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME;
import static org.apache.dubbo.rpc.Constants.H2_SUPPORT_NO_LOWER_HEADER_KEY;

public class TripleProtocol extends AbstractProtocol {
Expand All @@ -65,7 +65,7 @@ public class TripleProtocol extends AbstractProtocol {

public static boolean IGNORE_1_0_0_VERSION = false;

public static boolean RESOLVE_FALLBACK_TO_DEFAULT = false;
public static boolean RESOLVE_FALLBACK_TO_DEFAULT = true;

public TripleProtocol(FrameworkModel frameworkModel) {
this.frameworkModel = frameworkModel;
Expand All @@ -77,7 +77,7 @@ public TripleProtocol(FrameworkModel frameworkModel) {
IGNORE_1_0_0_VERSION = ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel())
.getBoolean(H2_IGNORE_1_0_0_KEY, false);
RESOLVE_FALLBACK_TO_DEFAULT = ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel())
.getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, false);
.getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, true);
Set<String> supported = frameworkModel.getExtensionLoader(DeCompressor.class)
.getSupportedExtensions();
this.acceptEncodings = String.join(",", supported);
Expand Down Expand Up @@ -113,9 +113,27 @@ public void afterUnExport() {

invokers.add(invoker);

pathResolver.add(url.getServiceKey(), invoker);
Invoker<?> previous = pathResolver.add(url.getServiceKey(), invoker);
AlbumenJ marked this conversation as resolved.
Show resolved Hide resolved
if (previous != null) {
if (url.getServiceKey().equals(url.getServiceModel().getServiceModel().getInterfaceName())) {
logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" + url.getServiceKey()
+ "], dubbo will override with invoker[" + url + "]");
} else {
throw new IllegalStateException("Already exists an invoker[" + previous.getUrl() + "] on path[" +
url.getServiceKey() + "], failed to add invoker[" + url +
"] , please use unique serviceKey.");
}
}
if (RESOLVE_FALLBACK_TO_DEFAULT) {
pathResolver.add(url.getServiceModel().getServiceModel().getInterfaceName(), invoker);
previous = pathResolver.addIfAbsent(url.getServiceModel().getServiceModel().getInterfaceName(), invoker);
AlbumenJ marked this conversation as resolved.
Show resolved Hide resolved
if (previous != null) {
logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" +
url.getServiceModel().getServiceModel().getInterfaceName() +
"], dubbo will skip override with invoker[" + url + "]");
} else {
logger.info("Add fallback triple invoker[" + url + "] to path[" +
url.getServiceModel().getServiceModel().getInterfaceName() + "] with invoker[" + url + "]");
}
}

// set service status
Expand Down