dubbo
dubbo copied to clipboard
Nacos做dubbo注册中心,NacosRegistry#getAllServiceNames()只能获取第一页的服务
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.7.12
- Operating System version: win10
- Java version: 8
Steps to reproduce this issue
- dubbo-registry-nacos模块的NacosRegistry类下getAllServiceNames()方法,会按照nacos.service.names.pagination.size(默认100)大小进行分页查询nacos的/v1/ns/service/list ,并按照返回的count判断是否继续翻页。可看过nacos源码,count是小于等于一页行数的,也就是说getAllServiceNames()永远不会翻页,只会返回前100个服务。
Pls. provide [GitHub address] to reproduce this issue.
Expected Behavior
getAllServiceNames()能自动翻页
Actual Behavior
dubbo:
private Set<String> getAllServiceNames() {
final Set<String> serviceNames = new LinkedHashSet<>();
execute(namingService -> {
int pageIndex = 1;
ListView<String> listView = namingService.getServicesOfServer(pageIndex, PAGINATION_SIZE,
getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
// First page data
List<String> firstPageData = listView.getData();
// Append first page into list
serviceNames.addAll(firstPageData);
// the total count
int count = listView.getCount();
// the number of pages
int pageNumbers = count / PAGINATION_SIZE;
int remainder = count % PAGINATION_SIZE;
// remain
if (remainder > 0) {
pageNumbers += 1;
}
// If more than 1 page
while (pageIndex < pageNumbers) {
listView = namingService.getServicesOfServer(++pageIndex, PAGINATION_SIZE,
getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
serviceNames.addAll(listView.getData());
}
});
return serviceNames;
}
nacos:
@GetMapping("/service/list")
@Secured(action = ActionTypes.READ)
public ObjectNode listService(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {
final int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
final int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String groupName = WebUtils.optional(request, CommonParams.GROUP_NAME, Constants.DEFAULT_GROUP);
String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
Collection<String> serviceNameList = getServiceOperator(ver)
.listService(namespaceId, groupName, selectorString);
result.put("count", serviceNameList.size());
result.replace("doms",
JacksonUtils.transferToJsonNode(ServiceUtil.pageServiceName(pageNo, pageSize, serviceNameList)));
return result;
}
这里应该是 Nacos 的问题吧,Dubbo 只能依赖 Nacos 返回的 count 来判断总数
nacos去年有人提过了,https://github.com/alibaba/nacos/issues/7502,但目前没人管
Nacos 版本是多少
Nacos 版本是多少
2.0.3
看起来是 2.0.4 修复的,你升级下版本呢