Skip to content

Comments

feat(core): implement if_modified_since and if_unmodified_since for read_with and reader_with#5500

Merged
meteorgan merged 4 commits intoapache:mainfrom
meteorgan:conditional_reader
Jan 4, 2025
Merged

feat(core): implement if_modified_since and if_unmodified_since for read_with and reader_with#5500
meteorgan merged 4 commits intoapache:mainfrom
meteorgan:conditional_reader

Conversation

@meteorgan
Copy link
Contributor

Which issue does this PR close?

Part of #5486.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

We'll add two methods if_modified_since and if_unmodified_since for read_with and reader_with API

@github-actions github-actions bot added the releases-note/feat The PR implements a new feature or has a title that begins with "feat" label Jan 2, 2025
@meteorgan
Copy link
Contributor Author

Tests failed in Minio, I'm not sure if it supports these two options. I'll look into it.

@Xuanwo
Copy link
Member

Xuanwo commented Jan 2, 2025

minio should support those headers: minio/minio#1098

@meteorgan
Copy link
Contributor Author

meteorgan commented Jan 3, 2025

minio should support those headers: minio/minio#1098

Minio requires the time format to follow RFC1123(like: Fri, 01 Mar 2019 15:00:00 GMT) 😢

@meteorgan meteorgan marked this pull request as ready for review January 3, 2025 11:37
@meteorgan meteorgan requested a review from Xuanwo as a code owner January 3, 2025 11:37
@Xuanwo
Copy link
Member

Xuanwo commented Jan 3, 2025

Minio requires the time format to follow RFC1123(like: Fri, 01 Mar 2019 15:00:00 GMT) 😢

Ooops, it does have the requirement for If-Modified-Since and If-Unmodified-Since: https://httpwg.org/specs/rfc9110.html#field.if-modified-since

let bs = reader.read(..).await?.to_bytes();
assert_eq!(bs, content);

sleep(Duration::from_secs(3)).await;
Copy link
Member

Choose a reason for hiding this comment

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

It's better to remove this sleep.


sleep(Duration::from_secs(3)).await;

let one_second_ago_check = chrono::Utc::now() - chrono::Duration::seconds(1);
Copy link
Member

Choose a reason for hiding this comment

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

How about using chrono::Utc::now() + chrono::Duration::seconds(10)? Also, the name one_second_ago_check is incorrect. I recommend avoiding lengthy names; a simple since should suffice.

Copy link
Contributor Author

@meteorgan meteorgan Jan 3, 2025

Choose a reason for hiding this comment

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

It doesn't work for S3. It might be considered an invalid time by S3 . (but I haven't found any official resources about this yet)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe We can just use chrono::Utc::now() here. but I'm not sure if this test will remain stable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, Using a future time works for both Minio and Ceph.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't make sense for the server to reject a future time. I believe AWS S3 is likely to support it, so we can give it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested it in my local environment, and the result is the same as using the AWS CLI. When using a future time in if-modified-since, S3 always return a 200 status.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Ok, let's test in this way:

  • Create a file.
  • Retrieve its last modified time.
  • Read it using last_modified - 1s (this should work).
  • Wait for 1 second.
  • Attempt to read it using last_modified + 1s (this should result in an error).

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, At least, this approach can help reduce the waiting time.

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Most changes look to me now, the only thing left here is the tests.

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you @meteorgan for working on this!

@meteorgan meteorgan merged commit 6ca3eab into apache:main Jan 4, 2025
241 checks passed
@meteorgan meteorgan deleted the conditional_reader branch January 4, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/feat The PR implements a new feature or has a title that begins with "feat"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants