-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Fixing extra download for filesystem's localization #254
base: main
Are you sure you want to change the base?
Changes from 7 commits
e5a40b7
8474fa0
8511943
af94ad7
2bd9a25
6903e1c
c5ded7e
d35a794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,14 +86,17 @@ class ASFileSystem : public FileSystem { | |
const std::string& path, std::set<std::string>* files) override; | ||
Status ReadTextFile(const std::string& path, std::string* contents) override; | ||
Status LocalizePath( | ||
const std::string& path, | ||
const std::string& path, const bool recursive, | ||
const std::string& mount_dir, | ||
std::shared_ptr<LocalizedPath>* localized) override; | ||
Status WriteTextFile( | ||
const std::string& path, const std::string& contents) override; | ||
Status WriteBinaryFile( | ||
const std::string& path, const char* contents, | ||
const size_t content_len) override; | ||
Status MakeDirectory(const std::string& dir, const bool recursive) override; | ||
Status MakeDirectory( | ||
const std::string& dir, const bool recursive, | ||
const bool allow_dir_exist) override; | ||
Status MakeTemporaryDirectory(std::string* temp_dir) override; | ||
Status DeletePath(const std::string& path) override; | ||
|
||
|
@@ -113,7 +116,8 @@ class ASFileSystem : public FileSystem { | |
|
||
Status DownloadFolder( | ||
const std::string& container, const std::string& path, | ||
const std::string& dest); | ||
const std::string& dest, const bool recursive, | ||
const bool allow_dir_exist); | ||
|
||
std::shared_ptr<asb::BlobServiceClient> client_; | ||
re2::RE2 as_regex_; | ||
|
@@ -389,7 +393,7 @@ ASFileSystem::FileExists(const std::string& path, bool* exists) | |
Status | ||
ASFileSystem::DownloadFolder( | ||
const std::string& container, const std::string& path, | ||
const std::string& dest) | ||
const std::string& dest, const bool recursive, const bool allow_dir_exist) | ||
{ | ||
auto container_client = client_->GetBlobContainerClient(container); | ||
auto func = [&](const std::vector<asb::Models::BlobItem>& blobs, | ||
|
@@ -405,17 +409,21 @@ ASFileSystem::DownloadFolder( | |
"Failed to download file at " + blob_item.Name + ":" + ex.what()); | ||
} | ||
} | ||
for (const auto& directory_item : blob_prefixes) { | ||
const auto& local_path = JoinPath({dest, BaseName(directory_item)}); | ||
int status = mkdir( | ||
const_cast<char*>(local_path.c_str()), S_IRUSR | S_IWUSR | S_IXUSR); | ||
if (status == -1) { | ||
return Status( | ||
Status::Code::INTERNAL, | ||
"Failed to create local folder: " + local_path + | ||
", errno:" + strerror(errno)); | ||
if (recursive) { | ||
for (const auto& directory_item : blob_prefixes) { | ||
const auto& local_path = JoinPath({dest, BaseName(directory_item)}); | ||
int status = mkdir( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, for Windows. good catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
const_cast<char*>(local_path.c_str()), S_IRUSR | S_IWUSR | S_IXUSR); | ||
if (status == -1 && !(allow_dir_exist && errno == EEXIST)) { | ||
return Status( | ||
Status::Code::INTERNAL, | ||
"Failed to create local folder: " + local_path + | ||
", errno:" + strerror(errno)); | ||
} | ||
RETURN_IF_ERROR(DownloadFolder( | ||
container, directory_item, local_path, recursive, | ||
true /*allow_dir_exist*/)); | ||
} | ||
RETURN_IF_ERROR(DownloadFolder(container, directory_item, local_path)); | ||
} | ||
return Status::Success; | ||
}; | ||
|
@@ -424,7 +432,8 @@ ASFileSystem::DownloadFolder( | |
|
||
Status | ||
ASFileSystem::LocalizePath( | ||
const std::string& path, std::shared_ptr<LocalizedPath>* localized) | ||
const std::string& path, const bool recursive, const std::string& mount_dir, | ||
std::shared_ptr<LocalizedPath>* localized) | ||
{ | ||
bool exists; | ||
RETURN_IF_ERROR(FileExists(path, &exists)); | ||
|
@@ -441,21 +450,31 @@ ASFileSystem::LocalizePath( | |
"AS file localization not yet implemented " + path); | ||
} | ||
|
||
std::string folder_template = "/tmp/folderXXXXXX"; | ||
char* tmp_folder = mkdtemp(const_cast<char*>(folder_template.c_str())); | ||
if (tmp_folder == nullptr) { | ||
return Status( | ||
Status::Code::INTERNAL, | ||
"Failed to create local temp folder: " + folder_template + | ||
", errno:" + strerror(errno)); | ||
// Create a local directory for s3 model store. | ||
// If `mount_dir` or ENV variable are not set, | ||
// creates a temporary directory under `/tmp` with the format: "folderXXXXXX". | ||
// Otherwise, will create a folder under specified directory with the name | ||
// indicated in path (i.e. everything after the last encounter of `/`). | ||
const char* env_mount_dir = std::getenv("TRITON_AZURE_MOUNT_DIRECTORY"); | ||
std::string tmp_folder; | ||
if (mount_dir.empty() && env_mount_dir == nullptr) { | ||
Comment on lines
+451
to
+453
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's already a follow-up ticket, I'd like to see use of some helper function like this one that safely checks if the env var is set or is nullptr, and just returns a Currently this if/else is OK, but if the conditions were to be tweaked in the future, there is some risk for |
||
RETURN_IF_ERROR(triton::core::MakeTemporaryDirectory( | ||
FileSystemType::LOCAL, &tmp_folder)); | ||
} else { | ||
tmp_folder = mount_dir.empty() ? std::string(env_mount_dir) : mount_dir; | ||
tmp_folder = | ||
JoinPath({tmp_folder, path.substr(path.find_last_of('/') + 1)}); | ||
RETURN_IF_ERROR(triton::core::MakeDirectory( | ||
tmp_folder, true /*recursive*/, true /*allow_dir_exist*/)); | ||
Comment on lines
+457
to
+461
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oandreeva-nv just checking my understanding, I see your comment saying:
But in the code I'm seeing calls to So to clarify, is the mount directory required to exist before server startup? Or will Triton create it on demand, similar to tmp folder workflow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will clarify this in a follow-up commit. This PR would need more de-bugging and testing |
||
} | ||
localized->reset(new LocalizedPath(path, tmp_folder)); | ||
|
||
std::string dest(folder_template); | ||
localized->reset(new LocalizedPath(path, tmp_folder)); | ||
|
||
std::string dest(tmp_folder); | ||
std::string container, blob; | ||
RETURN_IF_ERROR(ParsePath(path, &container, &blob)); | ||
return DownloadFolder(container, blob, dest); | ||
return DownloadFolder( | ||
container, blob, dest, recursive, true /*allow_dir_exist*/); | ||
} | ||
|
||
Status | ||
|
@@ -487,7 +506,8 @@ ASFileSystem::WriteBinaryFile( | |
} | ||
|
||
Status | ||
ASFileSystem::MakeDirectory(const std::string& dir, const bool recursive) | ||
ASFileSystem::MakeDirectory( | ||
const std::string& dir, const bool recursive, const bool allow_dir_exist) | ||
{ | ||
return Status( | ||
Status::Code::UNSUPPORTED, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,14 +75,17 @@ class GCSFileSystem : public FileSystem { | |
const std::string& path, std::set<std::string>* files) override; | ||
Status ReadTextFile(const std::string& path, std::string* contents) override; | ||
Status LocalizePath( | ||
const std::string& path, | ||
const std::string& path, const bool recursive, | ||
const std::string& mount_dir, | ||
std::shared_ptr<LocalizedPath>* localized) override; | ||
Status WriteTextFile( | ||
const std::string& path, const std::string& contents) override; | ||
Status WriteBinaryFile( | ||
const std::string& path, const char* contents, | ||
const size_t content_len) override; | ||
Status MakeDirectory(const std::string& dir, const bool recursive) override; | ||
Status MakeDirectory( | ||
const std::string& dir, const bool recursive, | ||
const bool allow_dir_exist) override; | ||
Status MakeTemporaryDirectory(std::string* temp_dir) override; | ||
Status DeletePath(const std::string& path) override; | ||
|
||
|
@@ -363,7 +366,8 @@ GCSFileSystem::ReadTextFile(const std::string& path, std::string* contents) | |
|
||
Status | ||
GCSFileSystem::LocalizePath( | ||
const std::string& path, std::shared_ptr<LocalizedPath>* localized) | ||
const std::string& path, const bool recursive, const std::string& mount_dir, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you going to implement the new API in other cloud file system in this PR as well? If not, should return error if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I wanted to first get an agreement on the implementation for s3. I'll populate it to GCS and AS in the next commit for easier review |
||
std::shared_ptr<LocalizedPath>* localized) | ||
{ | ||
bool exists; | ||
RETURN_IF_ERROR(FileExists(path, &exists)); | ||
|
@@ -380,9 +384,23 @@ GCSFileSystem::LocalizePath( | |
"GCS file localization not yet implemented " + path); | ||
} | ||
|
||
// Create a local directory for s3 model store. | ||
// If `mount_dir` or ENV variable are not set, | ||
// creates a temporary directory under `/tmp` with the format: "folderXXXXXX". | ||
// Otherwise, will create a folder under specified directory with the name | ||
// indicated in path (i.e. everything after the last encounter of `/`). | ||
const char* env_mount_dir = std::getenv("TRITON_GCS_MOUNT_DIRECTORY"); | ||
std::string tmp_folder; | ||
RETURN_IF_ERROR( | ||
triton::core::MakeTemporaryDirectory(FileSystemType::LOCAL, &tmp_folder)); | ||
if (mount_dir.empty() && env_mount_dir == nullptr) { | ||
RETURN_IF_ERROR(triton::core::MakeTemporaryDirectory( | ||
FileSystemType::LOCAL, &tmp_folder)); | ||
} else { | ||
tmp_folder = mount_dir.empty() ? std::string(env_mount_dir) : mount_dir; | ||
tmp_folder = | ||
JoinPath({tmp_folder, path.substr(path.find_last_of('/') + 1)}); | ||
RETURN_IF_ERROR(triton::core::MakeDirectory( | ||
tmp_folder, true /*recursive*/, true /*allow_dir_exist*/)); | ||
} | ||
|
||
localized->reset(new LocalizedPath(path, tmp_folder)); | ||
|
||
|
@@ -402,7 +420,7 @@ GCSFileSystem::LocalizePath( | |
std::string local_fpath = | ||
JoinPath({(*localized)->Path(), gcs_removed_path}); | ||
RETURN_IF_ERROR(IsDirectory(gcs_fpath, &is_subdir)); | ||
if (is_subdir) { | ||
if (recursive && is_subdir) { | ||
// Create local mirror of sub-directories | ||
#ifdef _WIN32 | ||
int status = mkdir(const_cast<char*>(local_fpath.c_str())); | ||
|
@@ -425,7 +443,7 @@ GCSFileSystem::LocalizePath( | |
++itr) { | ||
contents.insert(JoinPath({gcs_fpath, *itr})); | ||
} | ||
} else { | ||
} else if (!is_subdir) { | ||
// Create local copy of file | ||
std::string file_bucket, file_object; | ||
RETURN_IF_ERROR(ParsePath(gcs_fpath, &file_bucket, &file_object)); | ||
|
@@ -472,7 +490,8 @@ GCSFileSystem::WriteBinaryFile( | |
} | ||
|
||
Status | ||
GCSFileSystem::MakeDirectory(const std::string& dir, const bool recursive) | ||
GCSFileSystem::MakeDirectory( | ||
const std::string& dir, const bool recursive, const bool allow_dir_exist) | ||
{ | ||
return Status( | ||
Status::Code::UNSUPPORTED, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this (L565-L567) can potentially be shortened to