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

Purging of local datasets #1103

Merged
merged 9 commits into from
Feb 11, 2025
Merged

Purging of local datasets #1103

merged 9 commits into from
Feb 11, 2025

Conversation

gmega
Copy link
Member

@gmega gmega commented Feb 6, 2025

This PR adds an endpoint for deleting local datasets by their CID. Consistently with download API, passing a block CID will cause a block to be deleted, whereas passing a manifest CID will cause all the blocks under the dataset represented by that manifest to be deleted.

gmega added 2 commits February 6, 2025 09:39

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega
@gmega gmega requested review from 2-towns and dryajov February 6, 2025 14:49
@gmega gmega self-assigned this Feb 6, 2025
@gmega gmega added Client See https://miro.com/app/board/uXjVNZ03E-c=/ for details API labels Feb 6, 2025
## from the local node. Does nothing and returns 200
## if the dataset is not locally available.
##
var headers = buildCorsHeaders("DELETE", allowedOrigin)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to take care of the CORS here. This is the purpose of the endpoint that you created before with MethodOptions. When a preflight request is sent, it will hit the method 'OPTIONS', and you allowed 'GET' and 'DELETE' methods. So the preflight request will be successful, and the 'DELETE' request will be executed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah OK. I thought you always had to check the CORS origin, even if you have a preflight, cause callers can still not use the preflight, or otherwise screw things up.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, so I removed some of the CORS handling, but left that line cause other endpoints include it. This does smell fishy though: if we are to follow the fetch standard, it seems we're sending quite a few headers we don't need to in a bunch of places?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could remove this line as well actually. The other endpoints include it because if there is an error, you still need to pass the CORS headers, yes. But in your case, your created a specific endpoint to handle this so you don't need to pass the headers even if there is an error.

If think the only header we don't need is X-Requested-With. But Access-Control-Allow-Origin and Access-Control-Allow-Methods are definitely needed. Access-Control-Max-Age is for caching the previous header.

Copy link
Member Author

@gmega gmega Feb 7, 2025

Choose a reason for hiding this comment

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

OK so if we're to follow the standard, my understanding is that I should always send Access-Control-Allow-Origin, even in this endpoint.

Then, for the preflight endpoint, I should send:

  • Access-Control-Allow-Origin;
  • Access-Control-Allow-Methods;
  • Access-Control-Max-Age;
  • Access-Control-Headers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we need Access-Control-Allow-Origin in the endpoint itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

But yes you are right we need it

gmega added 2 commits February 6, 2025 18:31

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega
@gmega gmega requested a review from 2-towns February 6, 2025 21:34
@gmega
Copy link
Member Author

gmega commented Feb 6, 2025

I think I've addressed your comments @2-towns, either by fixing them or by continuing the discussion.

without manifest =? Manifest.decode(manifestBlock), err:
return failure(err)

for i in 0 ..< manifest.blocksCount:
Copy link
Contributor

Choose a reason for hiding this comment

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

This will very likely lockup the node for the duration of the delete, unless we yield some time back to the main thread. I think there is an IdleAsync method in chronos, that will schedule this after all the IO related work is done, otherwise, we can always do an async sleep after some number of blocks have been processed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good catch - I forget that those are actually blocking all the way. I'll add one of those.

Copy link
Member Author

@gmega gmega Feb 7, 2025

Choose a reason for hiding this comment

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

OK I've added a fix for this, I ended up going with a time-based quota as I think that's a lot more predictable than counting iterations. It also ended up being simple to implement.

gmega added 3 commits February 7, 2025 13:27

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega
…s, fix API status code

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega
… CORS headers
@gmega gmega requested a review from dryajov February 7, 2025 17:34
@gmega gmega mentioned this pull request Feb 7, 2025

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega
Copy link
Contributor

@2-towns 2-towns left a comment

Choose a reason for hiding this comment

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

I am approving it since you resolved my comments and you will address the CORS issues in another PR.

Thanks @gmega for your work.

Verified

This commit was signed with the committer’s verified signature.
gmega Giuliano Mega
@@ -4,7 +4,6 @@ import std/os except commandLineParams

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like I've ran nph on build.nims as part of some commit, for some reason, in this branch. Rolling this back would be more trouble than just leaving it here, so I'll "bundle" it with this PR.

@gmega gmega added this pull request to the merge queue Feb 11, 2025
Merged via the queue into master with commit bbe1f09 Feb 11, 2025
19 checks passed
@gmega gmega deleted the feat/dataset-deletion branch February 11, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Client See https://miro.com/app/board/uXjVNZ03E-c=/ for details
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants