Skip to content
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

Gateway: Add Cache-Control/max-age and ETag to IPNS requests #1921

Closed
wants to merge 6 commits into from

Conversation

ion1
Copy link

@ion1 ion1 commented Oct 31, 2015

Based on #1887 “cache ipns entries to speed things up a little”.

Addresses https://github.com/ipfs/go-ipfs/issues/1818.

This is my first time learning Go, I hope I’m doing things somewhat correctly.

@jbenet jbenet added the backlog label Oct 31, 2015
@ion1 ion1 force-pushed the feat/ipns-cache-resolve branch 8 times, most recently from 6e96a45 to 85b8962 Compare November 1, 2015 22:12
@ion1 ion1 mentioned this pull request Nov 2, 2015
47 tasks
@ion1 ion1 force-pushed the feat/ipns-cache-resolve branch 4 times, most recently from 338a8ac to 763370f Compare November 2, 2015 23:14
// and only if it's /ipfs!
// TODO: break this out when we split /ipfs /ipns routes.
w.Header().Set("ETag", etag)
w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", int(res.TTL.Seconds())))
Copy link
Member

Choose a reason for hiding this comment

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

nope, errors still happen below. this is trickty! -- maybe the error functions should clear this header to be sure.

Copy link
Member

Choose a reason for hiding this comment

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

ensure it's /ipfs/ route. code evolves!

@ion1
Copy link
Author

ion1 commented Nov 3, 2015

  • Added code to unset Cache-Control and ETag in the webError functions.
  • Checked that all error responses in getOrHeadHandler go through those functions.
  • Added a comment reminding to unset the headers in error responses if not using the functions.

@jbenet
Copy link
Member

jbenet commented Nov 3, 2015

Ok, this LGTM to me. @ion1 last thing is we should test some of this using sharness tests, so that the api tests are carried to other impls eventually.

@ion1
Copy link
Author

ion1 commented Nov 4, 2015

  • Added sharness tests.
  • Noticed that we weren’t following the RFC for ETags. Quote marks around the tag are mandatory. Fixed.

The sharness tests involving IPNS were test_expect_failure because ipfs name publish fails with Error: failed to find any peer in table.

All the new IPNS tests in the PR are test_expect_successes at the moment, and I verified them to succeed in a modified environment where they have access to the swarm.

Should I leave them as they are (which leaves the test suite failing until the publish problem is fixed) or change them all to test_expect_failures?

@ion1
Copy link
Author

ion1 commented Nov 4, 2015

I created #1941, changed them to test_expect_failures and added a comment with a link to the issue.

@ion1 ion1 force-pushed the feat/ipns-cache-resolve branch 6 times, most recently from c0b09e0 to b020415 Compare November 5, 2015 00:50
@jbenet
Copy link
Member

jbenet commented Nov 8, 2015

@ion1 Looking much better! some comments above.

@ion1
Copy link
Author

ion1 commented Nov 8, 2015

@jbenet, thanks for your input.

Done:

@ion1
Copy link
Author

ion1 commented Nov 8, 2015

The Travis failure does not seem to have anything to do with my changes.

// Remember to unset the Cache-Control/ETag headers before error
// responses! The webError functions unset them automatically.
// TODO: Consider letting clients cache 404s. Are there cases where
// that would hurt?
Copy link
Member

Choose a reason for hiding this comment

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

yes let's not cache 404s anytime soon.

Copy link
Author

Choose a reason for hiding this comment

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

It’s unclear to me where it would hurt, though. Given a successfully resolved /ipfs/QmFoo, the knowledge that “/ipfs/QmFoo/fileA exists” should be as cacheable as “/ipfs/QmFoo/fileB does not exist” for example. QmFoo is immutable after all.

The same applies to /ipns/QmBar. The record’s TTL dictates that the knowledge that “/ipns/QmBar/fileA exists” can be cached for just as long as that “/ipns/QmBar/fileB does not exist”.

Copy link
Member

Choose a reason for hiding this comment

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

i think @ion1 has a point here, but its going to be difficult to do it right. A 404 should only be cached if its for a link under a valid resolved hash. A 'could not find this hash on the network' 404 should never be cached.

Copy link
Author

Choose a reason for hiding this comment

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

The code should already return a TTL of 0 for all network failures.

@jbenet
Copy link
Member

jbenet commented Nov 10, 2015

@ion1 thanks -- more CR. and rebase to keep abreast of recent merges.

Closes ipfs#1934.

License: MIT
Signed-off-by: Johan Kiviniemi <[email protected]>
License: MIT
Signed-off-by: Johan Kiviniemi <[email protected]>
License: MIT
Signed-off-by: Johan Kiviniemi <[email protected]>
License: MIT
Signed-off-by: Johan Kiviniemi <[email protected]>
Closes ipfs/go-ipfs#1818.

License: MIT
Signed-off-by: Johan Kiviniemi <[email protected]>
@ion1
Copy link
Author

ion1 commented Nov 13, 2015

@jbenet, thanks for your input.

Done:

  • Rebase.
  • Add util/infduration with the constructors InfiniteDuration() and FiniteDuration(d), use it in the TTL code.

I’m looking forward to your response to my comment about test_expect_success_1941. I’d like to emphasize that pending a fix for #1941, the tests running ipfs name publish while the daemon is running with zero peers will fail unconditionally.

@@ -10,12 +10,14 @@ test_description="Test ipfs repo operations"

test_init_ipfs

for TTL_PARAMS in "" "--ttl=0s" "--ttl=1h"; do
Copy link
Member

Choose a reason for hiding this comment

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

wow the rest of the file is in a for loop without indentation. didnt even catch this the first time. please dont do that.

do this instead:

somefunc() {
  TTL=$1
  all the tests here
}

for TTL in "" "--ttl=0s" "--ttl=1h"; do
  somefunc $TTL
done

This was referenced Nov 16, 2015
@whyrusleeping
Copy link
Member

@ion1 since this PR touches a lot of files, I'd prefer if we put this on 0.4.0. Give rebasing it a shot, let me know how it goes.

@whyrusleeping
Copy link
Member

also, the infinite duration stuff (which i'm still not convinced is better than just using -1 as a special value) should go in thirdparty, i'm working on shrinking the util package.

@ghost ghost added the topic/gateway Topic gateway label Dec 22, 2015
@daviddias daviddias removed the backlog label Jan 2, 2016
@whyrusleeping
Copy link
Member

@ion1 update here?

@ion1
Copy link
Author

ion1 commented Jan 29, 2016

@whyrusleeping: I have been waiting for a fix for #1941 which prevents the tests in this PR from working. I will rebase this and address the other remaining comments at that point.

@whyrusleeping
Copy link
Member

Has been idle for about a year. Closing for now. Please do feel free to reopen this as necessary. Closing old PRs just helps us more easily see what needs immediate attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/gateway Topic gateway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants