mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Review comments
This commit is contained in:
parent
7b8216775a
commit
ebf5e4e62a
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RoomServerNIDsCache contains the subset of functions needed for
|
// RoomServerEventsCache contains the subset of functions needed for
|
||||||
// a roomserver NID cache.
|
// a roomserver event cache.
|
||||||
type RoomServerEventsCache interface {
|
type RoomServerEventsCache interface {
|
||||||
GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.Event, bool)
|
GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.Event, bool)
|
||||||
StoreRoomServerEvent(eventNID types.EventNID, event *gomatrixserverlib.Event)
|
StoreRoomServerEvent(eventNID types.EventNID, event *gomatrixserverlib.Event)
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,16 @@ import (
|
||||||
// different implementations as long as they satisfy the Cache
|
// different implementations as long as they satisfy the Cache
|
||||||
// interface.
|
// interface.
|
||||||
type Caches struct {
|
type Caches struct {
|
||||||
RoomVersions Cache[string, gomatrixserverlib.RoomVersion]
|
RoomVersions Cache[string, gomatrixserverlib.RoomVersion] // room ID -> room version
|
||||||
ServerKeys Cache[string, gomatrixserverlib.PublicKeyLookupResult]
|
ServerKeys Cache[string, gomatrixserverlib.PublicKeyLookupResult] // server name -> server keys
|
||||||
RoomServerRoomNIDs Cache[string, types.RoomNID]
|
RoomServerRoomNIDs Cache[string, types.RoomNID] // room ID -> room NID
|
||||||
RoomServerRoomIDs Cache[int64, string]
|
RoomServerRoomIDs Cache[int64, string] // room NID -> room ID
|
||||||
RoomServerEvents Cache[int64, *gomatrixserverlib.Event]
|
RoomServerEvents Cache[int64, *gomatrixserverlib.Event] // event NID -> event
|
||||||
RoomInfos Cache[string, types.RoomInfo]
|
RoomInfos Cache[string, types.RoomInfo] // room ID -> room info
|
||||||
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent]
|
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU
|
||||||
FederationEDUs Cache[int64, *gomatrixserverlib.EDU]
|
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
|
||||||
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse]
|
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse] // room ID -> space response
|
||||||
LazyLoading Cache[lazyLoadingCacheKey, string]
|
LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache is the interface that an implementation must satisfy.
|
// Cache is the interface that an implementation must satisfy.
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import (
|
||||||
const (
|
const (
|
||||||
roomVersionsCache byte = iota + 1
|
roomVersionsCache byte = iota + 1
|
||||||
serverKeysCache
|
serverKeysCache
|
||||||
|
roomNIDsCache
|
||||||
roomIDsCache
|
roomIDsCache
|
||||||
roomEventsCache
|
roomEventsCache
|
||||||
roomInfosCache
|
roomInfosCache
|
||||||
|
|
@ -43,9 +44,9 @@ const (
|
||||||
|
|
||||||
func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) *Caches {
|
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, // 10x number of expected cache items, affects bloom filter size, gives us room for 10,000 currently
|
||||||
|
BufferItems: 64, // recommended by the ristretto godocs as a sane buffer size value
|
||||||
MaxCost: int64(maxCost),
|
MaxCost: int64(maxCost),
|
||||||
BufferItems: 64,
|
|
||||||
Metrics: true,
|
Metrics: true,
|
||||||
KeyToHash: func(key interface{}) (uint64, uint64) {
|
KeyToHash: func(key interface{}) (uint64, uint64) {
|
||||||
return z.KeyToHash(key)
|
return z.KeyToHash(key)
|
||||||
|
|
@ -71,36 +72,41 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &Caches{
|
return &Caches{
|
||||||
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{ // room ID -> room version
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomVersionsCache,
|
Prefix: roomVersionsCache,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
ServerKeys: &RistrettoCachePartition[string, gomatrixserverlib.PublicKeyLookupResult]{
|
ServerKeys: &RistrettoCachePartition[string, gomatrixserverlib.PublicKeyLookupResult]{ // server name -> server keys
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: serverKeysCache,
|
Prefix: serverKeysCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
RoomServerRoomIDs: &RistrettoCachePartition[int64, string]{
|
RoomServerRoomNIDs: &RistrettoCachePartition[string, types.RoomNID]{ // room ID -> room NID
|
||||||
|
cache: cache,
|
||||||
|
Prefix: roomNIDsCache,
|
||||||
|
MaxAge: maxAge,
|
||||||
|
},
|
||||||
|
RoomServerRoomIDs: &RistrettoCachePartition[int64, string]{ // room NID -> room ID
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomIDsCache,
|
Prefix: roomIDsCache,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
RoomServerEvents: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.Event]{
|
RoomServerEvents: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.Event]{ // event NID -> event
|
||||||
&RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
&RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomEventsCache,
|
Prefix: roomEventsCache,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{
|
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{ // room ID -> room info
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomInfosCache,
|
Prefix: roomInfosCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
FederationPDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
FederationPDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{ // queue NID -> PDU
|
||||||
&RistrettoCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
&RistrettoCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: federationPDUsCache,
|
Prefix: federationPDUsCache,
|
||||||
|
|
@ -108,7 +114,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
||||||
MaxAge: lesserOf(time.Hour/2, maxAge),
|
MaxAge: lesserOf(time.Hour/2, maxAge),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
FederationEDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.EDU]{
|
FederationEDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.EDU]{ // queue NID -> EDU
|
||||||
&RistrettoCachePartition[int64, *gomatrixserverlib.EDU]{
|
&RistrettoCachePartition[int64, *gomatrixserverlib.EDU]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: federationEDUsCache,
|
Prefix: federationEDUsCache,
|
||||||
|
|
@ -116,13 +122,13 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
||||||
MaxAge: lesserOf(time.Hour/2, maxAge),
|
MaxAge: lesserOf(time.Hour/2, maxAge),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
SpaceSummaryRooms: &RistrettoCachePartition[string, gomatrixserverlib.MSC2946SpacesResponse]{
|
SpaceSummaryRooms: &RistrettoCachePartition[string, gomatrixserverlib.MSC2946SpacesResponse]{ // room ID -> space response
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: spaceSummaryRoomsCache,
|
Prefix: spaceSummaryRoomsCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
LazyLoading: &RistrettoCachePartition[lazyLoadingCacheKey, string]{
|
LazyLoading: &RistrettoCachePartition[lazyLoadingCacheKey, string]{ // composite key -> event ID
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: lazyLoadingCache,
|
Prefix: lazyLoadingCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue