Skip to content

Commit

Permalink
[INLONG-10799][SDK] Support fork child process for DataProxy CPP SDK (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
doleyzi authored Aug 16, 2024
1 parent 109e9ca commit 29612cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#include "../utils/utils.h"

namespace inlong {
SdkConfig *SdkConfig::instance_ = new SdkConfig();
SdkConfig *SdkConfig::getInstance() { return SdkConfig::instance_; }
SdkConfig *SdkConfig::getInstance() {
static SdkConfig instance;
return &instance;
}

bool SdkConfig::ParseConfig(const std::string &config_path) {
// Ensure the data consistency of each sdk instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
namespace inlong {
class SdkConfig {
private:
static SdkConfig *instance_;
std::string config_path_;
std::mutex mutex_;
void InitThreadParam(const rapidjson::Value &doc);
Expand All @@ -41,6 +40,7 @@ class SdkConfig {
void InitAuthParm(const rapidjson::Value &doc);
void OthersParam(const rapidjson::Value &doc);
bool GetLocalIPV4Address(std::string& err_info, std::string& localhost);
SdkConfig() { defaultInit(); };

public:
// cache parameter
Expand Down Expand Up @@ -116,8 +116,6 @@ class SdkConfig {
void defaultInit();
static SdkConfig *getInstance();

SdkConfig() { defaultInit(); }

bool ParseConfig(const std::string &config_path);
void ShowClientConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@

namespace inlong {
const uint64_t MINUTE = 60000;
ProxyManager *ProxyManager::instance_ = new ProxyManager();
ProxyManager::~ProxyManager() {
if (update_conf_thread_.joinable()) {
update_conf_thread_.join();
}

LOG_INFO("~ProxyManager");
exit_flag_ = true;
std::unique_lock<std::mutex> con_lck(cond_mutex_);
update_flag_ = true;
con_lck.unlock();
cond_.notify_one();

if (update_conf_thread_.joinable()) {
update_conf_thread_.join();
}
}
void ProxyManager::Init() {
timeout_ = SdkConfig::getInstance()->manager_url_timeout_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
namespace inlong {
class ProxyManager {
private:
static ProxyManager *instance_;
uint32_t timeout_;
read_write_mutex groupid_2_cluster_id_rwmutex_;
read_write_mutex groupid_2_proxy_map_rwmutex_;
Expand Down Expand Up @@ -59,7 +58,10 @@ class ProxyManager {
public:
ProxyManager(){};
~ProxyManager();
static ProxyManager *GetInstance() { return instance_; }
static ProxyManager *GetInstance() {
static ProxyManager instance;
return &instance;
}
int32_t CheckBidConf(const std::string &inlong_group_id, bool is_inited);
void Update();
void DoUpdate();
Expand Down

0 comments on commit 29612cd

Please sign in to comment.