Skip to content
Open
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
5 changes: 5 additions & 0 deletions common/dynamicconfig/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,11 @@ This can help reduce effects of shard movement.`,
false,
`EnableHostLevelEventsCache controls if the events cache is host level`,
)
EventsCacheBackgroundEvict = NewGlobalTypedSetting(
"history.eventsCacheBackgroundEvict",
DefaultHistoryCacheBackgroundEvictSettings,
`EventsCacheBackgroundEvict configures background processing to purge expired entries from the events cache.`,
)
AcquireShardInterval = NewGlobalDurationSetting(
"history.acquireShardInterval",
time.Minute,
Expand Down
2 changes: 2 additions & 0 deletions service/history/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Config struct {
// Change of these configs require shard restart
EventsShardLevelCacheMaxSizeBytes dynamicconfig.IntPropertyFn
EventsCacheTTL dynamicconfig.DurationPropertyFn
EventsCacheBackgroundEvict dynamicconfig.TypedPropertyFn[dynamicconfig.CacheBackgroundEvictSettings]
// Change of these configs require service restart
EnableHostLevelEventsCache dynamicconfig.BoolPropertyFn
EventsHostLevelCacheMaxSizeBytes dynamicconfig.IntPropertyFn
Expand Down Expand Up @@ -429,6 +430,7 @@ func NewConfig(
EventsHostLevelCacheMaxSizeBytes: dynamicconfig.EventsHostLevelCacheMaxSizeBytes.Get(dc), // 256MB
EventsCacheTTL: dynamicconfig.EventsCacheTTL.Get(dc),
EnableHostLevelEventsCache: dynamicconfig.EnableHostLevelEventsCache.Get(dc),
EventsCacheBackgroundEvict: dynamicconfig.EventsCacheBackgroundEvict.Get(dc),

RangeSizeBits: 20, // 20 bits for sequencer, 2^20 sequence number for any range

Expand Down
18 changes: 15 additions & 3 deletions service/history/events/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common"
"go.temporal.io/server/common/cache"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/metrics"
Expand Down Expand Up @@ -60,7 +61,11 @@ func NewHostLevelEventsCache(
logger log.Logger,
disabled bool,
) Cache {
return newEventsCache(executionManager, handler, logger, config.EventsHostLevelCacheMaxSizeBytes(), config.EventsCacheTTL(), disabled)
return newEventsCache(executionManager, handler, logger,
config.EventsHostLevelCacheMaxSizeBytes(),
config.EventsCacheTTL(),
config.EventsCacheBackgroundEvict,
disabled)
}

func NewShardLevelEventsCache(
Expand All @@ -70,7 +75,11 @@ func NewShardLevelEventsCache(
logger log.Logger,
disabled bool,
) Cache {
return newEventsCache(executionManager, handler, logger, config.EventsShardLevelCacheMaxSizeBytes(), config.EventsCacheTTL(), disabled)
return newEventsCache(executionManager, handler, logger,
config.EventsShardLevelCacheMaxSizeBytes(),
config.EventsCacheTTL(),
config.EventsCacheBackgroundEvict,
disabled)
}

func newEventsCache(
Expand All @@ -79,9 +88,12 @@ func newEventsCache(
logger log.Logger,
maxSize int,
ttl time.Duration,
backgroundEvict func() dynamicconfig.CacheBackgroundEvictSettings,
disabled bool,
) *CacheImpl {
opts := &cache.Options{}
opts := &cache.Options{
BackgroundEvict: backgroundEvict,
}
opts.TTL = ttl

taggedMetricHandler := metricsHandler.WithTags(metrics.CacheTypeTag(metrics.EventsCacheTypeTagValue))
Expand Down
4 changes: 4 additions & 0 deletions service/history/events/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
enumspb "go.temporal.io/api/enums/v1"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/server/common"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/metrics"
"go.temporal.io/server/common/namespace"
Expand Down Expand Up @@ -66,6 +67,9 @@ func (s *eventsCacheSuite) newTestEventsCache() *CacheImpl {
s.logger,
32,
time.Minute,
func() dynamicconfig.CacheBackgroundEvictSettings {
return dynamicconfig.DefaultHistoryCacheBackgroundEvictSettings
},
false)
}

Expand Down
Loading