Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dbms/src/Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ add_library (clickhouse-server-lib
RootRequestHandler.cpp
Server.cpp
StatusFile.cpp
TCPHandler.cpp)
TCPHandler.cpp
ClusterManagerService.cpp)

target_link_libraries (clickhouse-server-lib clickhouse_common_io daemon clickhouse_storages_system clickhouse_functions clickhouse_aggregate_functions clickhouse_table_functions)
target_include_directories (clickhouse-server-lib PUBLIC ${ClickHouse_SOURCE_DIR}/libs/libdaemon/include)
Expand Down
49 changes: 49 additions & 0 deletions dbms/src/Server/ClusterManagerService.cpp
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;
Copy link
Contributor

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

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);
Copy link
Contributor

@solotzg solotzg Nov 28, 2019

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest format of args is: /pinary-path --config config_path


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
27 changes: 27 additions & 0 deletions dbms/src/Server/ClusterManagerService.h
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
2 changes: 2 additions & 0 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "MetricsTransmitter.h"
#include "StatusFile.h"
#include "TCPHandlerFactory.h"
#include "ClusterManagerService.h"

#if Poco_NetSSL_FOUND
#include <Poco/Net/Context.h>
Expand Down Expand Up @@ -783,6 +784,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
}

SessionCleaner session_cleaner(*global_context);
ClusterManagerService clusterMgrSvc(*global_context, config_path);

waitForTerminationRequest();
}
Expand Down