Skip to content

Conversation

@the-david-oy
Copy link
Contributor

This PR upgrades the version of ListObjectsRequest and ListObjectsResult, as per AWS recommendations here to switch to V2. It also enables Triton to load all files in an S3 bucket, beyond the page limit of 1000.

" due to exception: " +
list_objects_outcome.GetError().GetExceptionName() +
", error message: " +
list_objects_outcome.GetError().GetMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this before the success handling, so the failure handle is a bit more obvious:

if (not_success) {
  return error;
}
// Check content..

Copy link
Contributor Author

@the-david-oy the-david-oy Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Done.

Copy link
Contributor

@kthui kthui Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @GuanLuo means this?

while (!done_listing) {
  auto list_objects_outcome = client_->ListObjectsV2(objects_request);

  if (!list_objects_outcome.IsSuccess()) {
    return Status(
        Status::Code::INTERNAL,
        "Could not list contents of directory at " + true_path +
            " due to exception: " +
            list_objects_outcome.GetError().GetExceptionName() +
            ", error message: " +
            list_objects_outcome.GetError().GetMessage());
  }

  const auto& list_objects_result = list_objects_outcome.GetResult();
  for (const auto& s3_object : list_objects_result.GetContents()) {
    // In the case of empty directories, the directory itself will appear here
    if (s3_object.GetKey().c_str() == full_dir) {
      continue;
    }
  
    // We have to make sure that subdirectory contents do not appear here
    std::string name(s3_object.GetKey().c_str());
    int item_start = name.find(full_dir) + full_dir.size();
    // S3 response prepends parent directory name
    int item_end = name.find("/", item_start);
  
    // Let set take care of subdirectory contents
    std::string item = name.substr(item_start, item_end - item_start);
    contents->insert(item);
  
    // Fail-safe check to ensure the item name is not empty
    if (item.empty()) {
      return Status(
          Status::Code::INTERNAL,
          "Cannot handle item with empty name at " + true_path);
    }
  }
  // If there are more pages to retrieve, set the marker to the next page.
  if (list_objects_result.GetIsTruncated()) {
    objects_request.SetContinuationToken(
        list_objects_result.GetNextContinuationToken());
  } else {
    done_listing = true;
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this have one less nesting for the success case

Copy link
Contributor Author

@the-david-oy the-david-oy Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, that makes sense! Thanks for clarifying, @kthui and @GuanLuo. Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still passes CI after removing the nesting. Please review when you get a chance!

@the-david-oy the-david-oy requested a review from GuanLuo June 26, 2023 15:55
@the-david-oy the-david-oy merged commit f458805 into main Jun 29, 2023
@the-david-oy the-david-oy deleted the dyas-s3-files branch June 29, 2023 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants