Adding system.warnings

This commit is contained in:
Artur 2021-07-09 09:27:51 +00:00
parent e231f6ce5c
commit 146a45a8b3
5 changed files with 63 additions and 0 deletions

View File

@ -1,3 +1,4 @@
#include <cmath>
#include <map>
#include <set>
#include <optional>
@ -6,6 +7,7 @@
#include <Poco/UUID.h>
#include <Poco/Net/IPAddress.h>
#include <Poco/Util/Application.h>
#include "common/types.h"
#include <Common/Macros.h>
#include <Common/escapeForFileName.h>
#include <Common/setThreadName.h>
@ -77,6 +79,7 @@
#include <Storages/MergeTree/BackgroundJobsExecutor.h>
#include <Storages/MergeTree/MergeTreeDataPartUUID.h>
#include <filesystem>
#include <vector>
namespace fs = std::filesystem;
@ -386,6 +389,7 @@ struct ContextSharedPart
ActionLocksManagerPtr action_locks_manager; /// Set of storages' action lockers
std::unique_ptr<SystemLogs> system_logs; /// Used to log queries and operations on parts
std::optional<StorageS3Settings> storage_s3_settings; /// Settings of S3 storage
std::vector<String> warnings_logs; /// Store warning messages
RemoteHostFilter remote_host_filter; /// Allowed URL from config.xml
@ -514,6 +518,12 @@ struct ContextSharedPart
trace_collector.emplace(std::move(trace_log));
}
void addWarningMessage(const String& message)
{
log->warning(message);
warnings_logs.push_back(message);
}
};
@ -635,6 +645,12 @@ String Context::getDictionariesLibPath() const
return shared->dictionaries_lib_path;
}
std::vector<String> Context::getWarnings() const
{
auto lock = getLock();
return shared->warnings_logs;
}
VolumePtr Context::getTemporaryVolume() const
{
auto lock = getLock();

View File

@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include <Access/RowPolicy.h>
#include <Core/Block.h>
#include <Core/NamesAndTypes.h>
@ -318,6 +319,7 @@ public:
String getFlagsPath() const;
String getUserFilesPath() const;
String getDictionariesLibPath() const;
std::vector<String> getWarnings() const;
VolumePtr getTemporaryVolume() const;

View File

@ -0,0 +1,22 @@
#include <memory>
#include <Storages/System/StorageSystemWarnings.h>
#include <Interpreters/Context.h>
namespace DB
{
NamesAndTypesList StorageSystemWarnings::getNamesAndTypes()
{
return {
{"description", std::make_shared<DataTypeString>()},
};
}
void StorageSystemWarnings::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
{
for (auto& warning : context->getWarnings()) {
res_columns[0]->insert(warning);
}
}
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <Storages/System/IStorageSystemOneBlock.h>
namespace DB {
class Context;
class StorageSystemWarnings final : public shared_ptr_helper<StorageSystemWarnings>, public IStorageSystemOneBlock<StorageSystemWarnings> {
public:
std::string getName() const override { return "SystemWarnings"; }
static NamesAndTypesList getNamesAndTypes();
protected:
friend struct shared_ptr_helper<StorageSystemWarnings>;
using IStorageSystemOneBlock::IStorageSystemOneBlock;
void fillData(MutableColumns & res_columns, ContextPtr, const SelectQueryInfo &) const override;
};
}

View File

@ -43,6 +43,7 @@
#include <Storages/System/StorageSystemZooKeeper.h>
#include <Storages/System/StorageSystemContributors.h>
#include <Storages/System/StorageSystemErrors.h>
#include <Storages/System/StorageSystemWarnings.h>
#include <Storages/System/StorageSystemDDLWorkerQueue.h>
#if !defined(ARCADIA_BUILD)
@ -116,6 +117,7 @@ void attachSystemTablesLocal(IDatabase & system_database)
attach<StorageSystemUserDirectories>(system_database, "user_directories");
attach<StorageSystemPrivileges>(system_database, "privileges");
attach<StorageSystemErrors>(system_database, "errors");
attach<StorageSystemWarnings>(system_database, "warnings");
attach<StorageSystemDataSkippingIndices>(system_database, "data_skipping_indices");
#if !defined(ARCADIA_BUILD)
attach<StorageSystemLicenses>(system_database, "licenses");