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

optimize: fall back to any of available cluster address when query cluster address is empty #6797

Merged
merged 10 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
do some optimize
  • Loading branch information
yuanxiao01 committed Aug 29, 2024
commit d8934e385f7fd41f2c4df3cf56f8a522c2b9c654
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ default List<InetSocketAddress> aliveLookup(String transactionServiceGroup) {
}

// fall back to addresses of any cluster
return clusterAddressMap.values().stream().findAny().orElse(Collections.emptyList());
return clusterAddressMap.values().stream().filter(CollectionUtils::isNotEmpty)
.findAny().orElse(Collections.emptyList());
}

default List<InetSocketAddress> refreshAliveLookup(String transactionServiceGroup,
Expand Down Expand Up @@ -165,7 +166,10 @@ default void removeOfflineAddressesIfNecessary(String transactionGroupService, S
.stream().filter(newAddressed::contains).collect(
Collectors.toList());

clusterAddressMap.put(clusterName, inetSocketAddresses);
// prevent empty update
if (CollectionUtils.isNotEmpty(inetSocketAddresses)) {
clusterAddressMap.put(clusterName, inetSocketAddresses);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.HashMap;
import java.util.Objects;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -50,6 +51,7 @@
import org.apache.seata.common.metadata.namingserver.Instance;
import org.apache.seata.common.metadata.namingserver.MetaResponse;
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.common.util.HttpClientUtil;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.common.util.StringUtils;
Expand Down Expand Up @@ -401,6 +403,31 @@ public String getNamespace() {
return namespace;
}

@Override
public List<InetSocketAddress> aliveLookup(String transactionServiceGroup) {
Map<String, List<InetSocketAddress>> clusterAddressMap = CURRENT_ADDRESS_MAP.computeIfAbsent(transactionServiceGroup,
k -> new ConcurrentHashMap<>());

List<InetSocketAddress> inetSocketAddresses = clusterAddressMap.get(transactionServiceGroup);
if (CollectionUtils.isNotEmpty(inetSocketAddresses)) {
return inetSocketAddresses;
}

// fall back to addresses of any cluster
return clusterAddressMap.values().stream().filter(CollectionUtils::isNotEmpty)
.findAny().orElse(Collections.emptyList());
}

@Override
public List<InetSocketAddress> refreshAliveLookup(String transactionServiceGroup,
List<InetSocketAddress> aliveAddress) {
Map<String, List<InetSocketAddress>> clusterAddressMap = CURRENT_ADDRESS_MAP.computeIfAbsent(transactionServiceGroup,
key -> new ConcurrentHashMap<>());


return clusterAddressMap.put(transactionServiceGroup, aliveAddress);
}


/**
* get one namingserver url
Expand Down
Loading