We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
场景: 1、fastdfs部署的双节点集群 2、正常功能压测通过,连接正常 3、非功能压测时,当停止一个节点服务后,会偶发出现两个节点 无法获取资源连接问题 ,但手动执行正常 4、非功能测试必现问题
问题: 1、查看源码,在获取资源连接时,轮询圈CircularList存在并发性问题,导致获取资源连接时会获取多次异常连接,导致报无法获取资源连接问题
/** * 获取Tracker服务器地址 * * @return trackerAddress */ public InetSocketAddress getTrackerAddress() { TrackerAddressHolder holder; // 遍历连接地址,抓取当前有效的地址 for (int i = 0; i < trackerAddressCircular.size(); i++) { holder = trackerAddressCircular.next(); if (holder.canTryToConnect(retryAfterSecond)) { return holder.getAddress(); } } throw new FdfsUnavailableException("找不到可用的tracker " + getTrackerAddressConfigString()); }
解决: 重写资源连接随机获取算法 ` /** * 获取Tracker服务器地址 * * @return trackerAddress */ public InetSocketAddress getTrackerAddress() { TrackerAddressHolder holder; CircularList localTrackerAddressCircular = new CircularList<>(); localTrackerAddressCircular.addAll(trackerAddressCircular);
// 遍历连接地址,抓取当前有效的地址 int size = localTrackerAddressCircular.size(); for (int i = 0; i < size; i++) { holder = randomIndex(localTrackerAddressCircular); log.info("tracker server --> {}", holder.getAddress().getHostName()); if (holder.canTryToConnect(retryAfterSecond)) { return holder.getAddress(); } } throw new FdfsUnavailableException("找不到可用的tracker " + getTrackerAddressConfigString()); }
/** * 数组随机下标,获取后剔除 * cnzz 20220307 * * @param list 数组 * @return T */ public static TrackerAddressHolder randomIndex(List list) { Integer index = (int) (Math.random() * list.size()); TrackerAddressHolder holder = list.get(index); list.remove(holder); return holder; } `
The text was updated successfully, but these errors were encountered:
这里确实是有问题,因为这个list被共享了,导致第一次取到是一个错误的,然后被其他线程修改了index后,会导致持续多次都拿到那个错误的tracker。
Sorry, something went wrong.
No branches or pull requests
场景:
1、fastdfs部署的双节点集群
2、正常功能压测通过,连接正常
3、非功能压测时,当停止一个节点服务后,会偶发出现两个节点 无法获取资源连接问题 ,但手动执行正常
4、非功能测试必现问题
问题:
1、查看源码,在获取资源连接时,轮询圈CircularList存在并发性问题,导致获取资源连接时会获取多次异常连接,导致报无法获取资源连接问题
/** * 获取Tracker服务器地址 * * @return trackerAddress */ public InetSocketAddress getTrackerAddress() { TrackerAddressHolder holder; // 遍历连接地址,抓取当前有效的地址 for (int i = 0; i < trackerAddressCircular.size(); i++) { holder = trackerAddressCircular.next(); if (holder.canTryToConnect(retryAfterSecond)) { return holder.getAddress(); } } throw new FdfsUnavailableException("找不到可用的tracker " + getTrackerAddressConfigString()); }
解决:
重写资源连接随机获取算法
`
/**
* 获取Tracker服务器地址
*
* @return trackerAddress
*/
public InetSocketAddress getTrackerAddress() {
TrackerAddressHolder holder;
CircularList localTrackerAddressCircular = new CircularList<>();
localTrackerAddressCircular.addAll(trackerAddressCircular);
/**
* 数组随机下标,获取后剔除
* cnzz 20220307
*
* @param list 数组
* @return T
*/
public static TrackerAddressHolder randomIndex(List list) {
Integer index = (int) (Math.random() * list.size());
TrackerAddressHolder holder = list.get(index);
list.remove(holder);
return holder;
}
`
The text was updated successfully, but these errors were encountered: