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

Commit

Permalink
Revert "Unshared blockstore (#150)"
Browse files Browse the repository at this point in the history
This reverts commit edb5cd4.
  • Loading branch information
willscott authored Jul 18, 2023
1 parent 8fa9649 commit be84787
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 75 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.9.0
go.uber.org/zap v1.24.0
)

Expand Down Expand Up @@ -166,7 +167,6 @@ require (
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/dig v1.15.0 // indirect
go.uber.org/fx v1.18.2 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb // indirect
golang.org/x/mod v0.7.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,14 @@ func makeGatewayHandler(bs bstore.Blockstore, kuboRPC []string, port int, blockC

gwHandler := gateway.NewHandler(gwConf, gwAPI)
ipfsHandler := withHTTPMetrics(gwHandler, "ipfs")
//ipnsHandler := withHTTPMetrics(gwHandler, "ipns")
ipnsHandler := gwHandler
ipnsHandler := withHTTPMetrics(gwHandler, "ipns")

Check warning on line 152 in handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers.go#L152

Added line #L152 was not covered by tests

mux := http.NewServeMux()
mux.Handle("/ipfs/", ipfsHandler)
mux.Handle("/ipns/", ipnsHandler)
// TODO: below is legacy which we want to remove, measuring this separately
// allows us to decide when is the time to do it.
//legacyKuboRpcHandler := withHTTPMetrics(newKuboRPCHandler(kuboRPC), "legacyKuboRpc")
legacyKuboRpcHandler := newKuboRPCHandler(kuboRPC)
legacyKuboRpcHandler := withHTTPMetrics(newKuboRPCHandler(kuboRPC), "legacyKuboRpc")

Check warning on line 159 in handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers.go#L159

Added line #L159 was not covered by tests
mux.Handle("/api/v0/", legacyKuboRpcHandler)

// Construct the HTTP handler for the gateway.
Expand Down
43 changes: 24 additions & 19 deletions lib/blockstore_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,36 @@ const DefaultCacheBlockStoreSize = 1024

var cacheLog = golog.Logger("cache/block")

var cacheHitsMetric = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "blockstore_cache_hit",
Help: "The number of global block cache hits.",
})

var cacheRequestsMetric = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "blockstore_cache_requests",
Help: "The number of global block cache requests.",
})

func init() {
prometheus.Register(cacheHitsMetric)
prometheus.Register(cacheRequestsMetric)
}

func NewCacheBlockStore(size int) (blockstore.Blockstore, error) {
c, err := lru.New2Q[string, []byte](size)
if err != nil {
return nil, err
}

cacheHitsMetric := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "blockstore_cache_hit",
Help: "The number of global block cache hits.",
})

cacheRequestsMetric := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "blockstore_cache_requests",
Help: "The number of global block cache requests.",
})

err = prometheus.Register(cacheHitsMetric)
if err != nil {
return nil, err
}

Check warning on line 47 in lib/blockstore_cache.go

View check run for this annotation

Codecov / codecov/patch

lib/blockstore_cache.go#L30-L47

Added lines #L30 - L47 were not covered by tests

err = prometheus.Register(cacheRequestsMetric)
if err != nil {
return nil, err
}

Check warning on line 52 in lib/blockstore_cache.go

View check run for this annotation

Codecov / codecov/patch

lib/blockstore_cache.go#L49-L52

Added lines #L49 - L52 were not covered by tests

return &cacheBlockStore{
cache: c,
rehash: uatomic.NewBool(false),
Expand Down
Loading

0 comments on commit be84787

Please sign in to comment.