mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Don't return errors when creating caches (it is better just to crash since otherwise we'll nil-pointer exception everywhere)
This commit is contained in:
parent
0c63a8e0d3
commit
7b8216775a
|
|
@ -54,12 +54,10 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("Fetching", len(snapshotNIDs), "snapshot NIDs")
|
fmt.Println("Fetching", len(snapshotNIDs), "snapshot NIDs")
|
||||||
|
|
||||||
cache, err := caching.NewRistrettoCache(128*1024*1024, time.Hour, true)
|
roomserverDB, err := storage.Open(
|
||||||
if err != nil {
|
base, &cfg.RoomServer.Database,
|
||||||
panic(err)
|
caching.NewRistrettoCache(128*1024*1024, time.Hour, true),
|
||||||
}
|
)
|
||||||
|
|
||||||
roomserverDB, err := storage.Open(base, &cfg.RoomServer.Database, cache)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new cache but don't enable prometheus!
|
// Create a new cache but don't enable prometheus!
|
||||||
s.cache, err = caching.NewRistrettoCache(8*1024*1024, time.Hour, false)
|
s.cache = caching.NewRistrettoCache(8*1024*1024, time.Hour, false)
|
||||||
if err != nil {
|
|
||||||
panic("can't create cache: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a temporary directory for JetStream.
|
// Create a temporary directory for JetStream.
|
||||||
d, err := ioutil.TempDir("./", "jetstream*")
|
d, err := ioutil.TempDir("./", "jetstream*")
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,19 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustCreateCache(maxCost config.DataUnit, enablePrometheus bool) *ristretto.Cache {
|
const (
|
||||||
|
roomVersionsCache byte = iota + 1
|
||||||
|
serverKeysCache
|
||||||
|
roomIDsCache
|
||||||
|
roomEventsCache
|
||||||
|
roomInfosCache
|
||||||
|
federationPDUsCache
|
||||||
|
federationEDUsCache
|
||||||
|
spaceSummaryRoomsCache
|
||||||
|
lazyLoadingCache
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) *Caches {
|
||||||
cache, err := ristretto.NewCache(&ristretto.Config{
|
cache, err := ristretto.NewCache(&ristretto.Config{
|
||||||
NumCounters: 1e5,
|
NumCounters: 1e5,
|
||||||
MaxCost: int64(maxCost),
|
MaxCost: int64(maxCost),
|
||||||
|
|
@ -58,23 +70,6 @@ func mustCreateCache(maxCost config.DataUnit, enablePrometheus bool) *ristretto.
|
||||||
return float64(cache.Metrics.CostAdded() - cache.Metrics.CostEvicted())
|
return float64(cache.Metrics.CostAdded() - cache.Metrics.CostEvicted())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return cache
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
roomVersionsCache byte = iota + 1
|
|
||||||
serverKeysCache
|
|
||||||
roomIDsCache
|
|
||||||
roomEventsCache
|
|
||||||
roomInfosCache
|
|
||||||
federationPDUsCache
|
|
||||||
federationEDUsCache
|
|
||||||
spaceSummaryRoomsCache
|
|
||||||
lazyLoadingCache
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) (*Caches, error) {
|
|
||||||
cache := mustCreateCache(maxCost, enablePrometheus)
|
|
||||||
return &Caches{
|
return &Caches{
|
||||||
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
|
|
@ -133,7 +128,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RistrettoCostedCachePartition[k keyable, v costable] struct {
|
type RistrettoCostedCachePartition[k keyable, v costable] struct {
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,6 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
||||||
Kind: api.KindOutlier, // don't panic if we generate an output event
|
Kind: api.KindOutlier, // don't panic if we generate an output event
|
||||||
Event: event.Headered(gomatrixserverlib.RoomVersionV6),
|
Event: event.Headered(gomatrixserverlib.RoomVersionV6),
|
||||||
}
|
}
|
||||||
cache, err := caching.NewRistrettoCache(8*1024*1024, time.Hour, false)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
db, err := storage.Open(
|
db, err := storage.Open(
|
||||||
nil,
|
nil,
|
||||||
&config.DatabaseOptions{
|
&config.DatabaseOptions{
|
||||||
|
|
@ -59,7 +55,7 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
||||||
MaxOpenConnections: 1,
|
MaxOpenConnections: 1,
|
||||||
MaxIdleConnections: 1,
|
MaxIdleConnections: 1,
|
||||||
},
|
},
|
||||||
cache,
|
caching.NewRistrettoCache(8*1024*1024, time.Hour, false),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("PostgreSQL not available (%s), skipping", err)
|
t.Logf("PostgreSQL not available (%s), skipping", err)
|
||||||
|
|
|
||||||
|
|
@ -161,11 +161,6 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, err := caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, enableMetrics)
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(err).Fatalf("Failed to create cache")
|
|
||||||
}
|
|
||||||
|
|
||||||
var dnsCache *gomatrixserverlib.DNSCache
|
var dnsCache *gomatrixserverlib.DNSCache
|
||||||
if cfg.Global.DNSCache.Enabled {
|
if cfg.Global.DNSCache.Enabled {
|
||||||
dnsCache = gomatrixserverlib.NewDNSCache(
|
dnsCache = gomatrixserverlib.NewDNSCache(
|
||||||
|
|
@ -233,7 +228,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
|
||||||
UseHTTPAPIs: useHTTPAPIs,
|
UseHTTPAPIs: useHTTPAPIs,
|
||||||
tracerCloser: closer,
|
tracerCloser: closer,
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Caches: cache,
|
Caches: caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, enableMetrics),
|
||||||
DNSCache: dnsCache,
|
DNSCache: dnsCache,
|
||||||
PublicClientAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicClientPathPrefix).Subrouter().UseEncodedPath(),
|
PublicClientAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicClientPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
PublicFederationAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicFederationPathPrefix).Subrouter().UseEncodedPath(),
|
PublicFederationAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicFederationPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue