Skip to content

Commit

Permalink
Remove some global macros and rename an interface. (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim authored Dec 1, 2024
1 parent e4203a1 commit e928e85
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/nameservice/UpstreamPolicies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash,
return this->check_and_get(it->second, false, tracing);
}

#define VIRTUAL_GROUP_SIZE 16

void UPSGroupPolicy::hash_map_add_addr(EndpointAddress *addr)
{
UPSAddrParams *params = static_cast<UPSAddrParams *>(addr->params);
Expand Down
21 changes: 20 additions & 1 deletion src/nameservice/WFServiceGovernance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
#include <vector>
#include <chrono>
#include "URIParser.h"
Expand All @@ -35,6 +36,24 @@
#define DNS_CACHE_LEVEL_1 1
#define DNS_CACHE_LEVEL_2 2

#define MTTR_SECONDS_DEFAULT 30

WFServiceGovernance::WFServiceGovernance() :
breaker_lock(PTHREAD_MUTEX_INITIALIZER),
rwlock(PTHREAD_RWLOCK_INITIALIZER)
{
this->nalives = 0;
this->try_another = false;
this->mttr_seconds = MTTR_SECONDS_DEFAULT;
INIT_LIST_HEAD(&this->breaker_list);
}

WFServiceGovernance::~WFServiceGovernance()
{
for (EndpointAddress *addr : this->servers)
delete addr;
}

PolicyAddrParams::PolicyAddrParams()
{
const struct AddressParams *params = &ADDRESS_PARAMS_DEFAULT;
Expand Down Expand Up @@ -226,7 +245,7 @@ void WFServiceGovernance::fuse_server_to_breaker(EndpointAddress *addr)
pthread_mutex_lock(&this->breaker_lock);
if (!addr->entry.list.next)
{
addr->broken_timeout = GET_CURRENT_SECOND + this->mttr_second;
addr->broken_timeout = GET_CURRENT_SECOND + this->mttr_seconds;
list_add_tail(&addr->entry.list, &this->breaker_list);
this->fuse_one_server(addr);
}
Expand Down
32 changes: 10 additions & 22 deletions src/nameservice/WFServiceGovernance.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#include "EndpointParams.h"
#include "WFNameService.h"

#define MTTR_SECOND_DEFAULT 30
#define VIRTUAL_GROUP_SIZE 16

struct AddressParams
{
struct EndpointParams endpoint_params; ///< Connection config
Expand Down Expand Up @@ -119,7 +116,11 @@ class WFServiceGovernance : public WFNSPolicy
void disable_server(const std::string& address);
virtual void get_current_address(std::vector<std::string>& addr_list);

void set_mttr_second(unsigned int second) { this->mttr_second = second; }
void set_mttr_seconds(unsigned int seconds)
{
this->mttr_seconds = seconds;
}

static bool in_select_history(WFNSTracing *tracing, EndpointAddress *addr);

public:
Expand All @@ -130,23 +131,6 @@ class WFServiceGovernance : public WFNSPolicy
pre_select_ = std::move(pre_select);
}

public:
WFServiceGovernance() :
breaker_lock(PTHREAD_MUTEX_INITIALIZER),
rwlock(PTHREAD_RWLOCK_INITIALIZER)
{
this->nalives = 0;
this->try_another = false;
this->mttr_second = MTTR_SECOND_DEFAULT;
INIT_LIST_HEAD(&this->breaker_list);
}

virtual ~WFServiceGovernance()
{
for (EndpointAddress *addr : this->servers)
delete addr;
}

private:
virtual bool select(const ParsedURI& uri, WFNSTracing *tracing,
EndpointAddress **addr);
Expand All @@ -171,7 +155,7 @@ class WFServiceGovernance : public WFNSPolicy
private:
struct list_head breaker_list;
pthread_mutex_t breaker_lock;
unsigned int mttr_second;
unsigned int mttr_seconds;
pre_select_t pre_select_;

protected:
Expand All @@ -197,6 +181,10 @@ class WFServiceGovernance : public WFNSPolicy
pthread_rwlock_t rwlock;
std::atomic<int> nalives;
bool try_another;

public:
WFServiceGovernance();
virtual ~WFServiceGovernance();
friend class WFSGResolverTask;
};

Expand Down
2 changes: 1 addition & 1 deletion test/upstream_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ TEST(upstream_unittest, FuseAndRecover)
int timeout = (MTTR + 1) * 1000000;

UPSWeightedRandomPolicy test_policy(false);
test_policy.set_mttr_second(MTTR);
test_policy.set_mttr_seconds(MTTR);
AddressParams address_params = ADDRESS_PARAMS_DEFAULT;

address_params.weight = 1000;
Expand Down

0 comments on commit e928e85

Please sign in to comment.