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

refactor: Use inmemory Kubo API if the local node is used. #1615

Merged
merged 2 commits into from
Jan 26, 2023
Merged

Conversation

philwinder
Copy link
Contributor

This does 2 main things:
First, change the connection to the local IPFS node to directly wire the local CoreAPI object. This will make stack traces more usefull and skip an extra HTTP step, helping to debug.

Secondly, more correct type enforcement around the ipfs.Client object, there were many places with code like this:

result, err := doStuffFunc(params, client.APIAddress())

// ...
func doStuffFunc(params paramsT, api string) (result, error) {
  cl, err := ipfs.NewClient(api)
  if err != nil {
    return nil, err
  }

  // ...
}

All of thoses has been rewriten to:

result, err := doStuffFunc(params, client)

// ...
func doStuffFunc(params paramsT, cl ipfs.Client) (result, error) {
  // ...
}

Passing typed clients object is much more expressfull than strings.

Fixes #1523

@Jorropo
Copy link
Contributor

Jorropo commented Jan 9, 2023

@philwinder just so you know, this is an improvement but I don't think this is solving the exact case we intended to solve (meaningfull stack traces when debugging) because AFAIT the internal node is not used when doing bacalhau serve:

I think a second PR that add support for inprocess kubo node will be needed.
Currently this will be only used for devstack:

@philwinder
Copy link
Contributor Author

Hi @Jorropo no I think this PR is what we want by default: serve uses HTTP, because providers have external IPFS clusters. Everything else uses internal.

Also, the specific problem I was having was with the get functionality, i.e. communicating with an embedded ipfs node to download results.

I've just finished my load tests with this version and the gets work 1000/1000 times. Previously it would fail about 1 in 10.

So, fingers crossed, I think this fixes that issue.

However, some of the tests are broken, so I need to fix them before merging.

But you're right, in the future, there could be an option of using a direct client with the serve command.

@philwinder philwinder self-assigned this Jan 10, 2023
@Jorropo
Copy link
Contributor

Jorropo commented Jan 10, 2023

I've just finished my load tests with this version and the gets work 1000/1000 times. Previously it would fail about 1 in 10.

Honnestly that very surprising, there are possibilities that Kubo's http api client or server is at fault but except than this, this should be the same codepaths.
Anyway ot gonna complain if we get some fixes for free.

@philwinder
Copy link
Contributor Author

Some issues with respect to how Bacalhau currently uses timeouts. Working through them.

Thread: https://filecoinproject.slack.com/archives/CRLC5H4J0/p1673347336829899
Issue: ipfs/kubo#9532

@wdbaruni wdbaruni changed the base branch from dev to main January 19, 2023 18:21
@philwinder philwinder changed the title refactor: Use inmemory Kubo API if the local node is used. [blocked] refactor: Use inmemory Kubo API if the local node is used. Jan 23, 2023
@Jorropo
Copy link
Contributor

Jorropo commented Jan 25, 2023

@philwinder this happen because your tests is using the same node to add and get the files and flatfs does not use context (see ipfs/kubo#9532 (comment)).

I think your easiest path here is to use two different IPFS nodes and have them bitswap each other content (which is the real thing we care about).

This does 2 main things:
First, change the connection to the local IPFS node to directly wire the local CoreAPI object. This will make stack traces more usefull and skip an extra HTTP step, helping to debug.

Secondly, more correct type enforcement around the ipfs.Client object, there were many places with code like this:
```go
result, err := doStuffFunc(params, client.APIAddress())

// ...
func doStuffFunc(params paramsT, api string) (result, error) {
  cl, err := ipfs.NewClient(api)
  if err != nil {
    return nil, err
  }

  // ...
}
```
All of thoses has been rewriten to:
```go
result, err := doStuffFunc(params, client)

// ...
func doStuffFunc(params paramsT, cl ipfs.Client) (result, error) {
  // ...
}
```

Passing typed clients object is much more expressfull than strings.

Fixes #1523
timeouts aren't respected when getting cached files
@philwinder philwinder changed the title [blocked] refactor: Use inmemory Kubo API if the local node is used. refactor: Use inmemory Kubo API if the local node is used. Jan 26, 2023
@philwinder philwinder merged commit dc67616 into main Jan 26, 2023
@philwinder philwinder deleted the ipfs-local branch January 26, 2023 12:42
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.

[Refactor] Investigate the use of the "direct" IPFS API for get and devstack commands
2 participants