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 copyset creation #1211

Merged
merged 1 commit into from
Apr 6, 2022
Merged

Conversation

cw123
Copy link
Contributor

@cw123 cw123 commented Mar 25, 2022

What problem does this PR solve?

Issue Number: #1196

Problem Summary: Initially created copies data is not balanced

What is changed and how it works?

What's Changed: optimize copyset creation

1、优化了copyset的创建算法,copyset的创建分为两个场景:
场景一:集群第一次创建copyset,为每个copyset随机选择metaserver;
场景二:集群已有copyset,继续创建copyset的场景,根据metaserver的资源使用率,选择使用率低的metaserver创建copyset。
2、优化了partition选择copyset的算法,为每个partition都选择一次copyset。

@cw123 cw123 modified the milestone: Curve-2.1.0-beta Mar 25, 2022
@cw123 cw123 force-pushed the optimize_copyset_creation branch 3 times, most recently from 23f28da to 137bb4e Compare March 28, 2022 07:47
int randomValue = GetOneRandomNumber(0, copysetList.size() - 1);
auto iter = copysetList.begin();
std::advance(iter, randomValue);
auto it = copySetMap_.find(*iter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto it = copySetMap_.find(*iter) is needn't ?
if (iter != copySetMap_.end()) {


}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iter is copysetKey, it is copysetInfo.

it select key first, then use the key find the info


// 5. generate result
if (candidateMap.size() == 0) {
LOG(WARNING) << "can not find available for copyset.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"can not find available metaservers for creating copyset." ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return TopoStatusCode::TOPO_OK;
}

TopoStatusCode ret = TopoStatusCode::TOPO_OK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add some notes here to explain the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

TopoStatusCode CreateEnoughCopyset();
TopoStatusCode CreateCopysetRandom(int createNum);
TopoStatusCode CreateCopysetByResourceUsage(int createNum);
TopoStatusCode CreateNewCopyset(const CopysetCreateInfo& copyset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateNewCopyset -> CreateCopyset ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@cw123 cw123 force-pushed the optimize_copyset_creation branch from 137bb4e to 25925c2 Compare March 31, 2022 02:59
@@ -1257,8 +1281,152 @@ TopoStatusCode TopologyImpl::ChooseNewMetaServerForCopyset(
return TopoStatusCode::TOPO_OK;
}

TopoStatusCode TopologyImpl::ChooseAvailableMetaServers(
std::set<MetaServerIdType> *metaServers, PoolIdType *poolId) {
TopoStatusCode TopologyImpl::GenCopysetAddrRandomBatch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is too long, and it does different things, you can consider splitting it.It's also easier to test

std::vector<const MetaServer *> vec;
for (const auto &it : metaServerMap_) {
if (it.second.GetOnlineState() == OnlineState::ONLINE
&& it.second.GetMetaServerSpace().IsMetaserverResourceAvailable()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to considering memory and disk utilization, the number of copies also needs to be considered.
If there are too many replication groups, no matter how the number of balanced leaders on this metaserver is large, it should become a bottleneck.

@cw123 cw123 force-pushed the optimize_copyset_creation branch from 25925c2 to cd2c8c9 Compare April 2, 2022 10:15
@cw123 cw123 merged commit 4e11952 into opencurve:master Apr 6, 2022
@cw123 cw123 deleted the optimize_copyset_creation branch April 6, 2022 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants