2021-08-18 22:19:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <memory>
|
2022-08-23 10:52:38 +00:00
|
|
|
#include <Disks/IDisk.h>
|
2022-08-15 18:04:25 +00:00
|
|
|
#include <Common/CurrentMetrics.h>
|
|
|
|
|
2021-08-18 22:19:14 +00:00
|
|
|
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.
|
2022-08-23 10:52:38 +00:00
|
|
|
/// Create a directory in the constructor.
|
2021-08-18 22:19:14 +00:00
|
|
|
/// The destructor always removes the temporary file or directory with all contained files.
|
2022-12-02 13:50:56 +00:00
|
|
|
class TemporaryFileOnDisk
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-08-23 11:19:34 +00:00
|
|
|
explicit TemporaryFileOnDisk(const DiskPtr & disk_);
|
|
|
|
explicit TemporaryFileOnDisk(const DiskPtr & disk_, CurrentMetrics::Value metric_scope);
|
2022-10-05 16:35:10 +00:00
|
|
|
explicit TemporaryFileOnDisk(const DiskPtr & disk_, const String & prefix);
|
2022-08-23 10:52:38 +00:00
|
|
|
|
2022-12-02 13:50:56 +00:00
|
|
|
~TemporaryFileOnDisk();
|
2021-08-18 22:19:14 +00:00
|
|
|
|
|
|
|
DiskPtr getDisk() const { return disk; }
|
2022-12-02 13:50:56 +00:00
|
|
|
String getPath() const;
|
2021-08-18 22:19:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DiskPtr disk;
|
2022-08-17 15:07:39 +00:00
|
|
|
|
2022-10-05 16:35:10 +00:00
|
|
|
/// Relative path in disk to the temporary file or directory
|
|
|
|
String relative_path;
|
|
|
|
|
|
|
|
CurrentMetrics::Increment metric_increment;
|
2022-08-15 16:42:50 +00:00
|
|
|
|
2022-08-15 18:04:25 +00:00
|
|
|
/// Specified if we know what for file is used (sort/aggregate/join).
|
2022-08-23 11:19:34 +00:00
|
|
|
std::optional<CurrentMetrics::Increment> sub_metric_increment = {};
|
2021-08-18 22:19:14 +00:00
|
|
|
};
|
|
|
|
|
2022-08-23 10:52:38 +00:00
|
|
|
using TemporaryFileOnDiskHolder = std::unique_ptr<TemporaryFileOnDisk>;
|
|
|
|
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|