mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 01:12:12 +00:00
d40dbdee62
Previously during RESTORE you may get the following warning in logs: <Warning> TemporaryFileOnDisk: Temporary path 'tmp/21672kaaaaa' does not exist in './disks/s3_common_disk/' The reason is that it uses not disks/s3_common_disk/tmp but instead disks/s3_common_disk/disks/s3_common_disk/tmp path. Fix this by adding TemporaryFileOnDisk::getRelativePath() and use it when appropriate. And now - `find disks`, does not shows any more temporary leftovers. v2: rename getPath to getAbsolutePath Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <Core/Types.h>
|
|
#include <memory>
|
|
#include <Disks/IDisk.h>
|
|
#include <Common/CurrentMetrics.h>
|
|
|
|
namespace DB
|
|
{
|
|
using DiskPtr = std::shared_ptr<IDisk>;
|
|
|
|
/// This class helps with the handling of temporary files or directories.
|
|
/// A unique name for the temporary file or directory is automatically chosen based on a specified prefix.
|
|
/// Create a directory in the constructor.
|
|
/// The destructor always removes the temporary file or directory with all contained files.
|
|
class TemporaryFileOnDisk
|
|
{
|
|
public:
|
|
explicit TemporaryFileOnDisk(const DiskPtr & disk_, CurrentMetrics::Metric metric_scope);
|
|
explicit TemporaryFileOnDisk(const DiskPtr & disk_, const String & prefix = "tmp");
|
|
|
|
~TemporaryFileOnDisk();
|
|
|
|
DiskPtr getDisk() const { return disk; }
|
|
/// Return absolute path (disk + relative_path)
|
|
String getAbsolutePath() const;
|
|
/// Return relative path (without disk)
|
|
const String & getRelativePath() const { return relative_path; }
|
|
|
|
private:
|
|
DiskPtr disk;
|
|
|
|
/// Relative path in disk to the temporary file or directory
|
|
String relative_path;
|
|
|
|
CurrentMetrics::Increment metric_increment;
|
|
|
|
/// Specified if we know what for file is used (sort/aggregate/join).
|
|
std::optional<CurrentMetrics::Increment> sub_metric_increment = {};
|
|
};
|
|
|
|
using TemporaryFileOnDiskHolder = std::unique_ptr<TemporaryFileOnDisk>;
|
|
|
|
}
|