mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
fix build
This commit is contained in:
parent
9e9fa043ca
commit
4d71f65082
@ -44,7 +44,6 @@
|
||||
#include <IO/WriteBufferFromFile.h>
|
||||
#include <IO/WriteBufferFromFileDescriptorDiscardOnFailure.h>
|
||||
#include <IO/ReadBufferFromFileDescriptor.h>
|
||||
#include <IO/ReadBufferFromFile.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <Common/Exception.h>
|
||||
@ -1060,49 +1059,3 @@ String BaseDaemon::getStoredBinaryHash() const
|
||||
{
|
||||
return stored_binary_hash;
|
||||
}
|
||||
|
||||
void BaseDaemon::loadServerUUID(const fs::path & server_uuid_file, Poco::Logger * log)
|
||||
{
|
||||
/// Write a uuid file containing a unique uuid if the file doesn't already exist during server start.
|
||||
|
||||
if (fs::exists(server_uuid_file))
|
||||
{
|
||||
try
|
||||
{
|
||||
DB::UUID uuid;
|
||||
DB::ReadBufferFromFile in(server_uuid_file);
|
||||
DB::readUUIDText(uuid, in);
|
||||
DB::assertEOF(in);
|
||||
server_uuid = uuid;
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
/// As for now it's ok to just overwrite it, because persistency in not essential.
|
||||
LOG_ERROR(log, "Cannot read server UUID from file {}: {}. Will overwrite it",
|
||||
server_uuid_file.string(), DB::getCurrentExceptionMessage(true));
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DB::UUID new_uuid = DB::UUIDHelpers::generateV4();
|
||||
auto uuid_str = DB::toString(new_uuid);
|
||||
DB::WriteBufferFromFile out(server_uuid_file);
|
||||
out.write(uuid_str.data(), uuid_str.size());
|
||||
out.sync();
|
||||
out.finalize();
|
||||
server_uuid = new_uuid;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw Poco::Exception(
|
||||
"Caught Exception " + DB::getCurrentExceptionMessage(true) + " while writing the Server UUID file "
|
||||
+ server_uuid_file.string());
|
||||
}
|
||||
}
|
||||
|
||||
DB::UUID BaseDaemon::getServerUUID() const
|
||||
{
|
||||
return server_uuid;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
@ -25,7 +24,6 @@
|
||||
#include <Common/StatusFile.h>
|
||||
#include <loggers/Loggers.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
/// \brief Base class for applications that can run as daemons.
|
||||
///
|
||||
@ -126,9 +124,6 @@ public:
|
||||
/// Hash of the binary for integrity checks.
|
||||
String getStoredBinaryHash() const;
|
||||
|
||||
void loadServerUUID(const fs::path & server_uuid_file, Poco::Logger * log);
|
||||
DB::UUID getServerUUID() const;
|
||||
|
||||
protected:
|
||||
virtual void logRevision() const;
|
||||
|
||||
@ -184,8 +179,6 @@ protected:
|
||||
|
||||
bool should_setup_watchdog = false;
|
||||
char * argv0 = nullptr;
|
||||
|
||||
DB::UUID server_uuid = DB::UUIDHelpers::Nil;
|
||||
};
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <Common/SymbolIndex.h>
|
||||
#include <Common/StackTrace.h>
|
||||
#include <Common/getNumberOfPhysicalCPUCores.h>
|
||||
#include <Common/getServerUUID.h>
|
||||
#include <Common/ServerUUID.h>
|
||||
|
||||
#if !defined(ARCADIA_BUILD)
|
||||
# include "Common/config_version.h"
|
||||
@ -39,7 +39,7 @@ void setExtras()
|
||||
if (!anonymize)
|
||||
sentry_set_extra("server_name", sentry_value_new_string(getFQDNOrHostName().c_str()));
|
||||
|
||||
DB::UUID server_uuid = getServerUUID();
|
||||
DB::UUID server_uuid = DB::ServerUUID::get();
|
||||
if (server_uuid != DB::UUIDHelpers::Nil)
|
||||
{
|
||||
std::string server_uuid_str = DB::toString(server_uuid);
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <Poco/Version.h>
|
||||
#include <Poco/Environment.h>
|
||||
#include <Common/getMultipleKeysFromConfig.h>
|
||||
#include <Common/ServerUUID.h>
|
||||
#include <filesystem>
|
||||
#include <IO/UseSSL.h>
|
||||
|
||||
@ -326,7 +327,7 @@ int Keeper::main(const std::vector<std::string> & /*args*/)
|
||||
}
|
||||
}
|
||||
|
||||
loadServerUUID(path + "/uuid", log);
|
||||
DB::ServerUUID::load(path + "/uuid", log);
|
||||
|
||||
const Settings & settings = global_context->getSettingsRef();
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <Common/getMappedArea.h>
|
||||
#include <Common/remapExecutable.h>
|
||||
#include <Common/TLDListsHolder.h>
|
||||
#include <Common/ServerUUID.h>
|
||||
#include <IO/HTTPCommon.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
#include <IO/UseSSL.h>
|
||||
@ -695,7 +696,7 @@ if (ThreadFuzzer::instance().isEffective())
|
||||
|
||||
StatusFile status{path / "status", StatusFile::write_full_info};
|
||||
|
||||
loadServerUUID(path / "uuid", log);
|
||||
DB::ServerUUID::load(path / "uuid", log);
|
||||
|
||||
/// Try to increase limit on number of open files.
|
||||
{
|
||||
|
56
src/Common/ServerUUID.cpp
Normal file
56
src/Common/ServerUUID.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <Common/ServerUUID.h>
|
||||
#include <IO/ReadBufferFromFile.h>
|
||||
#include <IO/WriteBufferFromFile.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int CANNOT_CREATE_FILE;
|
||||
}
|
||||
|
||||
void ServerUUID::load(const fs::path & server_uuid_file, Poco::Logger * log)
|
||||
{
|
||||
/// Write a uuid file containing a unique uuid if the file doesn't already exist during server start.
|
||||
|
||||
if (fs::exists(server_uuid_file))
|
||||
{
|
||||
try
|
||||
{
|
||||
UUID uuid;
|
||||
ReadBufferFromFile in(server_uuid_file);
|
||||
readUUIDText(uuid, in);
|
||||
assertEOF(in);
|
||||
server_uuid = uuid;
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
/// As for now it's ok to just overwrite it, because persistency in not essential.
|
||||
LOG_ERROR(log, "Cannot read server UUID from file {}: {}. Will overwrite it",
|
||||
server_uuid_file.string(), getCurrentExceptionMessage(true));
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
UUID new_uuid = UUIDHelpers::generateV4();
|
||||
auto uuid_str = toString(new_uuid);
|
||||
WriteBufferFromFile out(server_uuid_file);
|
||||
out.write(uuid_str.data(), uuid_str.size());
|
||||
out.sync();
|
||||
out.finalize();
|
||||
server_uuid = new_uuid;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw Exception(ErrorCodes::CANNOT_CREATE_FILE, "Caught Exception {} while writing the Server UUID file {}",
|
||||
getCurrentExceptionMessage(false), server_uuid_file.string());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
26
src/Common/ServerUUID.h
Normal file
26
src/Common/ServerUUID.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <Core/UUID.h>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
namespace Poco
|
||||
{
|
||||
class Logger;
|
||||
}
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class ServerUUID
|
||||
{
|
||||
inline static UUID server_uuid = UUIDHelpers::Nil;
|
||||
|
||||
public:
|
||||
/// Returns persistent UUID of current clickhouse-server or clickhouse-keeper instance.
|
||||
static UUID get() { return server_uuid; }
|
||||
|
||||
/// Loads server UUID from file or creates new one. Should be called on daemon startup.
|
||||
static void load(const fs::path & server_uuid_file, Poco::Logger * log);
|
||||
};
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#include <Common/getServerUUID.h>
|
||||
#include <daemon/BaseDaemon.h>
|
||||
#include <Poco/Util/Application.h>
|
||||
|
||||
DB::UUID getServerUUID()
|
||||
{
|
||||
const auto * daemon = dynamic_cast<const BaseDaemon *>(&Poco::Util::Application::instance());
|
||||
if (daemon)
|
||||
return daemon->getServerUUID();
|
||||
else
|
||||
return DB::UUIDHelpers::Nil;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
#include <Core/Types.h>
|
||||
|
||||
/// Returns persistent UUID of current clickhouse-server or clickhouse-keeper instance.
|
||||
DB::UUID getServerUUID();
|
@ -1,4 +1,4 @@
|
||||
#include <Common/getServerUUID.h>
|
||||
#include <Common/ServerUUID.h>
|
||||
#include <DataTypes/DataTypeUUID.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Interpreters/Context.h>
|
||||
@ -17,7 +17,7 @@ class FunctionServerUUID : public IFunction
|
||||
|
||||
static FunctionPtr create(ContextPtr context)
|
||||
{
|
||||
return std::make_shared<FunctionServerUUID>(context->isDistributed(), getServerUUID());
|
||||
return std::make_shared<FunctionServerUUID>(context->isDistributed(), ServerUUID::get());
|
||||
}
|
||||
|
||||
explicit FunctionServerUUID(bool is_distributed_, UUID server_uuid_)
|
||||
|
Loading…
Reference in New Issue
Block a user