ClickHouse/src/Disks/TemporaryFileOnDisk.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.2 KiB
C++
Raw Normal View History

2021-08-18 22:19:14 +00:00
#pragma once
#include <Core/Types.h>
#include <memory>
#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.
/// 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.
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);
~TemporaryFileOnDisk();
2021-08-18 22:19:14 +00:00
DiskPtr getDisk() const { return disk; }
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 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
};
using TemporaryFileOnDiskHolder = std::unique_ptr<TemporaryFileOnDisk>;
2021-08-18 22:19:14 +00:00
}