-
Notifications
You must be signed in to change notification settings - Fork 412
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
[FLASH-739] Add cluster manager service by poco timer #332
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "ClusterManagerService.h" | ||
|
||
|
||
#include <Common/FunctionTimerTask.h> | ||
#include <Common/ShellCommand.h> | ||
#include <Interpreters/Context.h> | ||
#include <Poco/File.h> | ||
#include <Poco/Path.h> | ||
#include <Storages/Transaction/TMTContext.h> | ||
#include <common/logger_useful.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
const std::string CLUSTER_MANAGER_PATH_KEY = "flash.flash_cluster.cluster_manager_path"; | ||
const std::string BIN_NAME = "flash_cluster_manager"; | ||
const std::string TASK_INTERVAL_KEY = "flash.flash_cluster.update_rule_interval"; | ||
|
||
constexpr long SECOND = 1000; | ||
constexpr long INIT_DELAY = SECOND * 5; | ||
|
||
void ClusterManagerService::run(const std::string & bin_path, const std::vector<std::string> & args) | ||
{ | ||
auto proc = ShellCommand::executeDirect(bin_path, args); | ||
proc->wait(); | ||
} | ||
|
||
ClusterManagerService::ClusterManagerService(DB::Context & context_, const std::string config_path) | ||
: context(context_), timer(), log(&Logger::get("ClusterManagerService")) | ||
{ | ||
const auto & conf = context.getConfigRef(); | ||
|
||
auto bin_path = conf.getString(CLUSTER_MANAGER_PATH_KEY, ".") + Poco::Path::separator() + BIN_NAME; | ||
auto task_interval = conf.getInt(TASK_INTERVAL_KEY, 10) * SECOND; | ||
|
||
if (!Poco::File(bin_path).exists()) | ||
throw Exception("Cluster manager binary file does not exist: " + bin_path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add error log here, application will exit without any info if is running as daemon. use ErrorCodes::LOGICAL_ERROR |
||
|
||
std::vector<std::string> args; | ||
args.push_back(config_path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. latest format of args is: / |
||
|
||
LOG_INFO(log, "Registered timed cluster manager task at rate " << task_interval / SECOND << " seconds"); | ||
|
||
timer.scheduleAtFixedRate(FunctionTimerTask::create(std::bind(&ClusterManagerService::run, bin_path, args)), INIT_DELAY, task_interval); | ||
} | ||
|
||
ClusterManagerService::~ClusterManagerService() { timer.cancel(true); } | ||
|
||
} // namespace DB |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <Poco/Util/Timer.h> | ||
#include <Storages/MergeTree/BackgroundProcessingPool.h> | ||
#include <common/logger_useful.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
class Context; | ||
class BackgroundProcessingPool; | ||
|
||
class ClusterManagerService : private boost::noncopyable | ||
{ | ||
public: | ||
ClusterManagerService(Context & context_, const std::string config_path); | ||
~ClusterManagerService(); | ||
|
||
private: | ||
static void run(const std::string & command, const std::vector<std::string> & args); | ||
Context & context; | ||
Poco::Util::Timer timer; | ||
Logger * log; | ||
}; | ||
|
||
|
||
} // namespace DB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our mock test,
flash_cluster_manager
can not be found definitely, make it optional