-
Notifications
You must be signed in to change notification settings - Fork 111
[WIP] Fixing extra download for filesystem's localization #254
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
base: main
Are you sure you want to change the base?
Changes from 4 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 |
---|---|---|
|
@@ -94,7 +94,9 @@ class ASFileSystem : public FileSystem { | |
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; | ||
|
||
|
@@ -114,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_; | ||
|
@@ -390,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, | ||
|
@@ -406,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( | ||
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; | ||
}; | ||
|
@@ -443,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 | ||
|
@@ -489,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, | ||
|
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.
Shouldn't the
FileSystem
wrapped API be used here as well?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.
right, for Windows. good catch
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.
changed