Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fix: car request timeout and friends
Browse files Browse the repository at this point in the history
19s was way too low:
filecoin-saturn/caboose@aaf9ff9
  • Loading branch information
lidel committed Mar 29, 2023
1 parent f06dc97 commit ba35d74
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
13 changes: 7 additions & 6 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package main
import (
"errors"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"sync"

"github.com/ipfs/bifrost-gateway/lib"
"github.com/ipfs/boxo/bitswap/client"
"github.com/ipfs/boxo/bitswap/network"
Expand All @@ -15,14 +21,9 @@ import (
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/routing"
"github.com/spf13/cobra"
"log"
"net/http"
"os"
"os/signal"
"sync"
)

var goLog = golog.Logger("bifrost-gateway-backend")
var goLog = golog.Logger("test-backend")

func main() {
if err := rootCmd.Execute(); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions blockstore_caboose.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS)
}

saturnOrchestratorClient := &http.Client{
Timeout: caboose.DefaultSaturnRequestTimeout,
Timeout: caboose.DefaultSaturnOrchestratorRequestTimeout,
Transport: &customTransport{
RoundTripper: &http.Transport{
DialContext: cdns.dialWithCachedDNS,
Expand All @@ -50,7 +50,7 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS)
}

saturnLoggerClient := &http.Client{
Timeout: caboose.DefaultSaturnRequestTimeout,
Timeout: caboose.DefaultSaturnLoggerRequestTimeout,
Transport: &customTransport{
AuthorizationBearerToken: os.Getenv(EnvSaturnLoggerSecret),
RoundTripper: &http.Transport{
Expand All @@ -60,7 +60,7 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS)
}

saturnRetrievalClient := &http.Client{
Timeout: caboose.DefaultSaturnRequestTimeout,
Timeout: caboose.DefaultSaturnCarRequestTimeout,
Transport: &customTransport{
RoundTripper: &http.Transport{
// Increasing concurrency defaults from http.DefaultTransport
Expand Down Expand Up @@ -93,10 +93,10 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS)

LoggingEndpoint: *loggURL,
LoggingClient: saturnLoggerClient,
LoggingInterval: 5 * time.Second,
LoggingInterval: caboose.DefaultLoggingInterval,

DoValidation: true,
PoolRefresh: 5 * time.Minute,
PoolRefresh: caboose.DefaultPoolRefreshInterval,
SaturnClient: saturnRetrievalClient,
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/cskr/pubsub v1.0.2
github.com/filecoin-saturn/caboose v0.0.0-20230329141039-b4cc70873ccd
github.com/filecoin-saturn/caboose v0.0.0-20230329185035-5b37545e2a41
github.com/gogo/protobuf v1.3.2
github.com/hashicorp/golang-lru/v2 v2.0.1
github.com/ipfs/boxo v0.8.0-rc2.0.20230329082438-360b031ed895
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/filecoin-saturn/caboose v0.0.0-20230329141039-b4cc70873ccd h1:+Je9eB4IlUAG/NP8seXFC5vD+hPM6mYMN4dOEQESSZI=
github.com/filecoin-saturn/caboose v0.0.0-20230329141039-b4cc70873ccd/go.mod h1:u8END6RLUG9ZWudtVHAOOg7ptGiAgKjf/QnNOUOC160=
github.com/filecoin-saturn/caboose v0.0.0-20230329185035-5b37545e2a41 h1:CRERrZrpsrSwWYyBzlQJZUeh9gy8LaOukw7E6dMgd3E=
github.com/filecoin-saturn/caboose v0.0.0-20230329185035-5b37545e2a41/go.mod h1:u8END6RLUG9ZWudtVHAOOg7ptGiAgKjf/QnNOUOC160=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
Expand Down
12 changes: 6 additions & 6 deletions lib/blockstore_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
format "github.com/ipfs/go-ipld-format"

blockstore "github.com/ipfs/boxo/blockstore"
"github.com/ipfs/go-block-format"
blocks "github.com/ipfs/go-block-format"
golog "github.com/ipfs/go-log/v2"

lru "github.com/hashicorp/golang-lru/v2"
Expand All @@ -19,7 +19,7 @@ import (

const DefaultCacheBlockStoreSize = 1024

var goLog = golog.Logger("cache-blockstore")
var cacheLog = golog.Logger("bifrost-gateway:cache-blockstore")

func NewCacheBlockStore(size int) (blockstore.Blockstore, error) {
c, err := lru.New2Q[string, []byte](size)
Expand Down Expand Up @@ -80,16 +80,16 @@ func (l *cacheBlockStore) Get(ctx context.Context, c cid.Cid) (blocks.Block, err

blkData, found := l.cache.Get(string(c.Hash()))
if !found {
if goLog.Level().Enabled(zapcore.DebugLevel) {
goLog.Debugw("block not found in cache", "cid", c.String())
if cacheLog.Level().Enabled(zapcore.DebugLevel) {
cacheLog.Debugw("block not found in cache", "cid", c.String())
}
return nil, format.ErrNotFound{Cid: c}
}

// It's a HIT!
l.cacheHitsMetric.Add(1)
if goLog.Level().Enabled(zapcore.DebugLevel) {
goLog.Debugw("block found in cache", "cid", c.String())
if cacheLog.Level().Enabled(zapcore.DebugLevel) {
cacheLog.Debugw("block found in cache", "cid", c.String())
}

if l.rehash.Load() {
Expand Down
26 changes: 15 additions & 11 deletions lib/graph_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"runtime"
"sync"

"github.com/filecoin-saturn/caboose"
"github.com/ipfs/boxo/blockservice"
blockstore "github.com/ipfs/boxo/blockstore"
Expand All @@ -16,21 +21,20 @@ import (
"github.com/ipfs/boxo/namesys"
"github.com/ipfs/boxo/namesys/resolve"
ipfspath "github.com/ipfs/boxo/path"
"github.com/ipfs/go-block-format"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
golog "github.com/ipfs/go-log/v2"
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/routing"
"github.com/multiformats/go-multicodec"
"github.com/multiformats/go-multihash"
"go.uber.org/multierr"
"io"
"net/http"
"runtime"
"sync"
)

var graphLog = golog.Logger("bifrost-gateway:graph-backend")

// type DataCallback = func(resource string, reader io.Reader) error
// TODO: Don't use a caboose type, perhaps ask them to use a type alias instead of a type
type DataCallback = caboose.DataCallback
Expand Down Expand Up @@ -187,10 +191,10 @@ func (api *GraphGateway) loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx con
}
})
if err != nil {
goLog.Error(err)
graphLog.Error(err)
}
if err := carFetchingExch.Close(); err != nil {
goLog.Error(err)
graphLog.Error(err)
}
doneWithFetcher <- struct{}{}
close(doneWithFetcher)
Expand All @@ -214,7 +218,7 @@ func (api *GraphGateway) notifyAllOngoingRequests(ctx context.Context, blks ...b
for n := range api.notifiers {
err := n.NotifyNewBlocks(ctx, blks...)
if err != nil {
goLog.Error(fmt.Errorf("notifyAllOngoingRequests failed: %w", err))
graphLog.Error(fmt.Errorf("notifyAllOngoingRequests failed: %w", err))
}
}
api.lk.RUnlock()
Expand Down Expand Up @@ -489,7 +493,7 @@ func (f *handoffExchange) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block

select {
case <-f.handoffCh:
goLog.Infof("needed to use use a backup fetcher for cid %s", c)
graphLog.Infof("needed to use use a backup fetcher for cid %s", c)
return f.followupExchange.GetBlock(ctx, c)
case <-ctx.Done():
return nil, ctx.Err()
Expand Down Expand Up @@ -529,10 +533,10 @@ func (f *handoffExchange) GetBlocks(ctx context.Context, cids []cid.Cid) (<-chan
newCidArr = append(newCidArr, c)
}
}
goLog.Infof("needed to use use a backup fetcher for cids %v", newCidArr)
graphLog.Infof("needed to use use a backup fetcher for cids %v", newCidArr)
fch, err := f.followupExchange.GetBlocks(ctx, newCidArr)
if err != nil {
goLog.Error(fmt.Errorf("error getting blocks from followup exchange %w", err))
graphLog.Error(fmt.Errorf("error getting blocks from followup exchange %w", err))
return
}
for cs.Len() < len(cids) {
Expand Down

0 comments on commit ba35d74

Please sign in to comment.