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

Unshared blockstore #150

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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 @@ -168,6 +167,7 @@ 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: 4 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ func makeGatewayHandler(bs bstore.Blockstore, kuboRPC []string, port int, blockC

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

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 := withHTTPMetrics(newKuboRPCHandler(kuboRPC), "legacyKuboRpc")
legacyKuboRpcHandler := newKuboRPCHandler(kuboRPC)
mux.Handle("/api/v0/", legacyKuboRpcHandler)

// Construct the HTTP handler for the gateway.
Expand Down
43 changes: 19 additions & 24 deletions lib/blockstore_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,31 @@ 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
}

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

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