Merge pull request #41 from alpc62/master

fix LRUCache and Upstream bugs
This commit is contained in:
xiehan
2020-09-10 18:51:41 +08:00
committed by GitHub
2 changed files with 17 additions and 19 deletions
+7 -4
View File
@@ -496,11 +496,13 @@ static inline bool __is_alive_or_group_alive(const UpstreamAddress *ua)
const UpstreamAddress *Upstream::weighted_random_try_another() const
{
if (available_weight_ == 0)
int temp_weight = available_weight_;
if (temp_weight == 0)
return NULL;
const UpstreamAddress *ua = NULL;
int x = rand() % available_weight_;
int x = rand() % temp_weight;
int s = 0;
for (const auto *master : masters_)
@@ -633,9 +635,10 @@ const UpstreamAddress *Upstream::get(const ParsedURI& uri)
{
int x = 0;
int s = 0;
int temp_weight = total_weight_;
if (total_weight_ > 0)
x = rand() % total_weight_;
if (temp_weight > 0)
x = rand() % temp_weight;
for (idx = 0; idx < n; idx++)
{
+10 -15
View File
@@ -185,23 +185,18 @@ public:
e->ref = 1;
std::lock_guard<std::mutex> lock(mutex_);
if (max_size_ == 0 || size_ < max_size_)
size_++;
e->in_cache = true;
e->ref++;
list_append(&in_use_, e);
MapIterator it = cache_map_.find(key);
if (it != cache_map_.end())
{
size_++;
e->in_cache = true;
e->ref++;
list_append(&in_use_, e);
MapIterator it = cache_map_.find(key);
if (it != cache_map_.end())
{
erase_node(it->second);
it->second = e;
}
else
cache_map_[key] = e;
erase_node(it->second);
it->second = e;
}
else//do not cache
e->next = NULL;
else
cache_map_[key] = e;
if (max_size_ > 0)
{