Merge pull request #944 from wzl12356/master

fix UPSVNSWRRPolicy
This commit is contained in:
xiehan
2022-06-16 16:34:02 +08:00
committed by GitHub
2 changed files with 6 additions and 7 deletions

View File

@@ -603,18 +603,17 @@ void UPSWeightedRandomPolicy::fuse_one_server(const EndpointAddress *addr)
EndpointAddress *UPSVNSWRRPolicy::first_strategy(const ParsedURI& uri,
WFNSTracing *tracing)
{
int idx = this->cur_idx;
for (int i = 0; i < this->total_weight; i++)
int idx = this->cur_idx.fetch_add(1);
int pos = 0;
for (int i = 0; i < this->total_weight; i++, idx++)
{
idx = (this->cur_idx + i) % this->pre_generated_vec.size();
int pos = this->pre_generated_vec[idx];
pos = this->pre_generated_vec[idx % this->pre_generated_vec.size()];
if (WFServiceGovernance::in_select_history(tracing, this->servers[pos]))
continue;
break;
}
this->cur_idx = idx + 1;
return this->servers[idx];
return this->servers[pos];
}
void UPSVNSWRRPolicy::init_virtual_nodes()

View File

@@ -160,7 +160,7 @@ private:
void init_virtual_nodes();
std::vector<size_t> pre_generated_vec;
std::vector<int> current_weight_vec;
size_t cur_idx;
std::atomic<size_t> cur_idx;
};
class UPSConsistentHashPolicy : public UPSGroupPolicy