diff options
author | ermolovd <ermolovd@yandex-team.com> | 2025-02-07 11:41:21 +0300 |
---|---|---|
committer | ermolovd <ermolovd@yandex-team.com> | 2025-02-07 11:58:46 +0300 |
commit | 2dc0b90341ba0adaa79f54a751f4e9fb8c1f2636 (patch) | |
tree | 307ae7fcd0b189d13f537b8b07331076931ef824 /yt/cpp/mapreduce/interface/temp.h | |
parent | f5d9f371e4e2b705be312223ebd0f6dfdbebb82c (diff) | |
download | ydb-2dc0b90341ba0adaa79f54a751f4e9fb8c1f2636.tar.gz |
YT-21081: improve temp directory structure, create subdirectory with username
commit_hash:004bb333221acac91378ce9fcc12ce091f38ee87
Diffstat (limited to 'yt/cpp/mapreduce/interface/temp.h')
-rw-r--r-- | yt/cpp/mapreduce/interface/temp.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/interface/temp.h b/yt/cpp/mapreduce/interface/temp.h new file mode 100644 index 0000000000..08a87eeafb --- /dev/null +++ b/yt/cpp/mapreduce/interface/temp.h @@ -0,0 +1,76 @@ +#pragma once + +#include <yt/cpp/mapreduce/interface/client.h> + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +/// +/// @brief RAII class for working with temporary tables. Constructor of this class creates temporary table and destructor removes it. +/// +/// CAVEAT: when using with transactions destructor of TTempTable should be called before commiting transaction. +class TTempTable +{ +public: + /// + /// @brief Constructor creates temporary table + /// + /// @param client -- YT client or transaction object. + /// @param prefix -- table name prefix + /// @param directory -- path to directory where temporary table will be created. + /// @param options -- options to be passed for table creation (might be useful if we want to set table attributes) + explicit TTempTable( + IClientBasePtr client, + const TString& prefix = {}, + const TYPath& directory = {}, + const TCreateOptions& options = {}); + + TTempTable(const TTempTable&) = delete; + TTempTable& operator=(const TTempTable&) = delete; + + TTempTable(TTempTable&&); + TTempTable& operator=(TTempTable&&); + + ~TTempTable(); + + /// + /// @brief Create table with given path that will be autoremoved in RAII manner. + /// + /// In contrast to TTempTable constructor this function uses provided path to table and don't modify it in any manner. + /// It's user responsibility to provide unique path. + static TTempTable CreateAutoremovingTable(IClientBasePtr client, TYPath path, const TCreateOptions& options); + + /// Return full path to the table. + TString Name() const &; + TString Name() && = delete; + + /// Release table and return its path. Table will not be deleted by TTempTable destructor after this call. + TString Release(); + +private: + struct TPrivateConstuctorTag + { }; + TTempTable(TPrivateConstuctorTag, IClientBasePtr client, TYPath path, const TCreateOptions& options); + +private: + IClientBasePtr Client_; + TYPath Name_; + bool Owns_ = true; + +private: + void RemoveTable(); +}; + +/// +/// @brief Create empty table with unique name in given directory and return its path. +/// +/// @param client -- YT client or transaction object. +/// @param prefix -- table name prefix +/// @param directory -- path to directory where temporary table will be created. +/// @param options -- options to be passed for table creation (might be useful if we want to set table attributes) +TYPath CreateTempTable(const IClientBasePtr& client, const TString& prefix, const TYPath& directory, const TCreateOptions& options); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT |