Skip to content

[Feature] Loading XML from remote locations - #7297

Closed
jpfeuffer wants to merge 1 commit into
OpenMS:developfrom
jpfeuffer:feature/remoteXML
Closed

jpfeuffer wants to merge 1 commit into
OpenMS:developfrom
jpfeuffer:feature/remoteXML

Conversation

@jpfeuffer

@jpfeuffer jpfeuffer commented Jan 14, 2024 •

Copy link
Copy Markdown
Contributor

S3: AWS SDK if present
FTP/HTTP(S): Xerces NetAccessor, i.e. if built with libcurl support (apt, brew = default, but not in contrib)

TODO:

  • Safer CMake and conditional compilation
  • Support Indexed MzML

Description

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

@cbielow cbielow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting feature.

Some code beween S3InputSource and S3ChunkedInputSource seems repetitive and might benefit from refactor?!

Comment on lines +13 to +15
#include <aws/s3/model/GetObjectRequest.h>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this will choke without S3's headers?

make conditional?

Comment thread CMakeLists.txt
option(WITH_GUI "Build GUI parts of OpenMS (TOPPView&Co). This requires QtGui." ON)
option(NO_WEBENGINE_WIDGETS "Do not use QtWebengineWidgets. Disables Javascript views in TOPPView." OFF)
option(WITH_HDF5 "Build HDF5 parts of OpenMS." OFF)
option(WITH_S3 "Build with S3 loading support" OFF)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
option(WITH_S3 "Build with S3 loading support" OFF)
option(WITH_S3 "Build with Amazon-S3 loading support" OFF)

#include <xercesc/util/BinInputStream.hpp>
#include <aws/s3/model/GetObjectResult.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <aws/core/Aws.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should (!) be Apache2 licensed, and compatible to our stuff. Nice.

Aws::S3::Model::GetObjectRequest getObjectRequest;
getObjectRequest.WithBucket(m_bucketName).WithKey(m_objectKey);

auto getObjectOutcome = new Aws::S3::Model::GetObjectOutcome(s3Client.GetObject(getObjectRequest));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a potential memleak.
Use uniquePtr

m_bzStream.next_in = NULL;

if (BZ2_bzDecompressInit(&m_bzStream, 0, 0) != BZ_OK) {
throw new std::runtime_error("Error occurred during bzip decompression");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

now need to dynamically allocate a new object. Just throw the thing!

(more occurrences below)

Aws::S3::Model::GetObjectRequest getObjectRequest;
getObjectRequest.WithBucket(m_bucketName).WithKey(m_objectKey);

auto getObjectOutcome = new Aws::S3::Model::GetObjectOutcome(s3Client.GetObject(getObjectRequest));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same mem-leak here.

FileTypes::Type ft_name = FileHandler::getTypeByFileName(file_);
FileTypes::Type ft_content = FileHandler::getTypeByContent(file_);
if (ft_name != ft_content)
if (!file_.hasPrefix("http://") && !file_.hasPrefix("https://") && !file_.hasPrefix("ftp://") && !file_.hasPrefix("s3://"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this kind of query looks useful in a more general scope.
Since its used repetitively here, can this the externalized to something like:

  /// check if filename starts with http, https, ftp or s3 followed by `://`
  bool File::isRemoteFile(const std::string& filename);

@jpfeuffer

jpfeuffer commented Jan 15, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks a lot! Yes, I was thinking about re-using a bit more. I will check what's doable. I am also not sure if and how I should offer the two types of "reading". Should probably go in some configuration of the XMLHandler or decide based on file size. I just figured out late, that by default it loads the whole file into memory first.

Better safeguarding against missing SDK is also on the list.

@cbielow

cbielow commented Jan 15, 2024

Copy link
Copy Markdown
Contributor

I am also not sure if and how I should offer the two types of "reading". Should probably go in some configuration of the XMLHandler or decide based on file size. I just figured out late, that by default it loads the whole file into memory first.

Good point. Given the large files these days, probably chunked is enough and more memory efficient? Maybe a quick benchmark can tell if chunked is even noticeably slower and depending on the outcome, just keeping chunked?!

@jpfeuffer

Copy link
Copy Markdown
Contributor Author

@timosachsenberg We should revisit this, now that parquet has the AWS dependency anyway.

@jpfeuffer

Copy link
Copy Markdown
Contributor Author

@timosachsenberg this would also be really cool to finish. Now that we have AWS for arrow anyway. And will need curl if we get rid of qtnetwork, we would get this for freee

@jpfeuffer

Copy link
Copy Markdown
Contributor Author

It was basically finished but badly tested. Now there are some conflicts of course

@timosachsenberg

Copy link
Copy Markdown
Contributor

Ok I can bring it up to current state I think

@timosachsenberg

Copy link
Copy Markdown
Contributor

Code Review & Fixes

I've reviewed this PR and made several fixes in commit f59ba4f. Here's a summary:

Critical Fixes (would break build or cause crashes)

Issue Fix
S3 sources compiled unconditionally Added if(WITH_S3) guards in sources.cmake files
Headers include AWS SDK without guards Added #ifdef WITH_S3 guards to S3InputSource.h and S3ChunkedInputSource.h
throw new instead of throw Fixed 8 occurrences - was causing memory corruption
Memory leaks in makeStream() Changed to std::make_shared<> for proper RAII
AWS SDK initialized multiple times Created shared AwsSdkHelper::initializeAwsSdk() with thread-safe static init

Medium Priority Fixes

Issue Fix
Silent failure in parseS3Uri_() Now throws std::runtime_error with descriptive message
Inconsistent logging Changed all std::cerr to OPENMS_LOG_ERROR in S3InputSource.cpp
Redundant object fetch Removed extra GetObject call in S3ChunkedInputSource::makeStream() (HeadObject already verified access)

Minor Fixes

  • Fixed comment typos: "GZIP" → "bzip2", "zlib buffer" → "bzip2 buffer", "Bzib2" → "Bzip2"
  • Updated copyright to "2002-present"
  • Guarded S3 tests with #ifdef WITH_S3

Remaining TODOs from PR description

  • Support Indexed MzML (commented out code exists in IndexedMzMLDecoder.cpp)

The PR should now compile correctly with WITH_S3=OFF (default) and be memory-safe when WITH_S3=ON.

@timosachsenberg

Copy link
Copy Markdown
Contributor

Closing in favor of #8671 - Claude Code couldn't push to this branch due to GitHub OAuth workflow permissions, so opened a new PR with the rebased and fixed code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants