2022-02-24 12:23:26 +00:00
|
|
|
#include <Storages/MergeTree/TemporaryParts.h>
|
2022-08-09 16:44:51 +00:00
|
|
|
#include <Common/Exception.h>
|
2022-02-24 12:23:26 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-08-09 16:44:51 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2022-02-24 12:23:26 +00:00
|
|
|
bool TemporaryParts::contains(const std::string & basename) const
|
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
|
|
|
return parts.contains(basename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TemporaryParts::add(std::string basename)
|
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
2022-08-09 16:44:51 +00:00
|
|
|
bool inserted = parts.emplace(std::move(basename)).second;
|
|
|
|
if (!inserted)
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Temporary part {} already added", basename);
|
2022-02-24 12:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TemporaryParts::remove(const std::string & basename)
|
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
2022-08-09 16:44:51 +00:00
|
|
|
bool removed = parts.erase(basename);
|
|
|
|
if (!removed)
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Temporary part {} does not exist", basename);
|
2022-02-24 12:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|