Skip to content

Commit 7a125d9

Browse files
yycpttdnr
authored andcommitted
Allow configurating history cache non-user context lock timeout (#4645)
1 parent f97b681 commit 7a125d9

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

common/dynamicconfig/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ const (
475475
HistoryCacheMaxSize = "history.cacheMaxSize"
476476
// HistoryCacheTTL is TTL of history cache
477477
HistoryCacheTTL = "history.cacheTTL"
478+
// HistoryCacheNonUserContextLockTimeout controls how long non-user call (callerType != API or Operator)
479+
// will wait on workflow lock acquisition. Requires service restart to take effect.
480+
HistoryCacheNonUserContextLockTimeout = "history.cacheNonUserContextLockTimeout"
481+
// HistoryStartupMembershipJoinDelay is the duration a history instance waits
482+
// before joining membership after starting.
483+
HistoryStartupMembershipJoinDelay = "history.startupMembershipJoinDelay"
478484
// HistoryShutdownDrainDuration is the duration of traffic drain during shutdown
479485
HistoryShutdownDrainDuration = "history.shutdownDrainDuration"
480486
// EventsCacheInitialSize is initial size of events cache

service/history/configs/config.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ type Config struct {
6565

6666
// HistoryCache settings
6767
// Change of these configs require shard restart
68-
HistoryCacheInitialSize dynamicconfig.IntPropertyFn
69-
HistoryCacheMaxSize dynamicconfig.IntPropertyFn
70-
HistoryCacheTTL dynamicconfig.DurationPropertyFn
68+
HistoryCacheInitialSize dynamicconfig.IntPropertyFn
69+
HistoryCacheMaxSize dynamicconfig.IntPropertyFn
70+
HistoryCacheTTL dynamicconfig.DurationPropertyFn
71+
HistoryCacheNonUserContextLockTimeout dynamicconfig.DurationPropertyFn
7172

7273
// EventsCache settings
7374
// Change of these configs require shard restart
@@ -345,13 +346,16 @@ func NewConfig(
345346
VisibilityDisableOrderByClause: dc.GetBoolPropertyFnWithNamespaceFilter(dynamicconfig.VisibilityDisableOrderByClause, true),
346347
VisibilityEnableManualPagination: dc.GetBoolPropertyFnWithNamespaceFilter(dynamicconfig.VisibilityEnableManualPagination, true),
347348

348-
EmitShardLagLog: dc.GetBoolProperty(dynamicconfig.EmitShardLagLog, false),
349-
HistoryCacheInitialSize: dc.GetIntProperty(dynamicconfig.HistoryCacheInitialSize, 128),
350-
HistoryCacheMaxSize: dc.GetIntProperty(dynamicconfig.HistoryCacheMaxSize, 512),
351-
HistoryCacheTTL: dc.GetDurationProperty(dynamicconfig.HistoryCacheTTL, time.Hour),
352-
EventsCacheInitialSize: dc.GetIntProperty(dynamicconfig.EventsCacheInitialSize, 128*1024), // 128KB
353-
EventsCacheMaxSize: dc.GetIntProperty(dynamicconfig.EventsCacheMaxSize, 512*1024), // 512KB
354-
EventsCacheTTL: dc.GetDurationProperty(dynamicconfig.EventsCacheTTL, time.Hour),
349+
EmitShardLagLog: dc.GetBoolProperty(dynamicconfig.EmitShardLagLog, false),
350+
HistoryCacheInitialSize: dc.GetIntProperty(dynamicconfig.HistoryCacheInitialSize, 128),
351+
HistoryCacheMaxSize: dc.GetIntProperty(dynamicconfig.HistoryCacheMaxSize, 512),
352+
HistoryCacheTTL: dc.GetDurationProperty(dynamicconfig.HistoryCacheTTL, time.Hour),
353+
HistoryCacheNonUserContextLockTimeout: dc.GetDurationProperty(dynamicconfig.HistoryCacheNonUserContextLockTimeout, 500*time.Millisecond),
354+
355+
EventsCacheInitialSize: dc.GetIntProperty(dynamicconfig.EventsCacheInitialSize, 128*1024), // 128KB
356+
EventsCacheMaxSize: dc.GetIntProperty(dynamicconfig.EventsCacheMaxSize, 512*1024), // 512KB
357+
EventsCacheTTL: dc.GetDurationProperty(dynamicconfig.EventsCacheTTL, time.Hour),
358+
355359
RangeSizeBits: 20, // 20 bits for sequencer, 2^20 sequence number for any range
356360
AcquireShardInterval: dc.GetDurationProperty(dynamicconfig.AcquireShardInterval, time.Minute),
357361
AcquireShardConcurrency: dc.GetIntProperty(dynamicconfig.AcquireShardConcurrency, 10),

service/history/workflow/cache/cache.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
"go.temporal.io/server/common/metrics"
4545
"go.temporal.io/server/common/namespace"
4646
"go.temporal.io/server/common/persistence"
47-
"go.temporal.io/server/service/history/configs"
4847
"go.temporal.io/server/service/history/consts"
4948
"go.temporal.io/server/service/history/shard"
5049
"go.temporal.io/server/service/history/workflow"
@@ -78,7 +77,8 @@ type (
7877
shard shard.Context
7978
logger log.Logger
8079
metricsHandler metrics.Handler
81-
config *configs.Config
80+
81+
nonUserContextLockTimeout time.Duration
8282
}
8383

8484
NewCacheFn func(shard shard.Context) Cache
@@ -87,10 +87,12 @@ type (
8787
var NoopReleaseFn ReleaseCacheFunc = func(err error) {}
8888

8989
const (
90-
cacheNotReleased int32 = 0
91-
cacheReleased int32 = 1
92-
workflowLockTimeoutTailTime = 500 * time.Millisecond
93-
nonApiContextLockTimeout = 500 * time.Millisecond
90+
cacheNotReleased int32 = 0
91+
cacheReleased int32 = 1
92+
)
93+
94+
const (
95+
workflowLockTimeoutTailTime = 500 * time.Millisecond
9496
)
9597

9698
func NewCache(shard shard.Context) Cache {
@@ -101,11 +103,11 @@ func NewCache(shard shard.Context) Cache {
101103
opts.Pin = true
102104

103105
return &CacheImpl{
104-
Cache: cache.New(config.HistoryCacheMaxSize(), opts),
105-
shard: shard,
106-
logger: log.With(shard.GetLogger(), tag.ComponentHistoryCache),
107-
metricsHandler: shard.GetMetricsHandler().WithTags(metrics.CacheTypeTag(metrics.MutableStateCacheTypeTagValue)),
108-
config: config,
106+
Cache: cache.New(config.HistoryCacheMaxSize(), opts),
107+
shard: shard,
108+
logger: log.With(shard.GetLogger(), tag.ComponentHistoryCache),
109+
metricsHandler: shard.GetMetricsHandler().WithTags(metrics.CacheTypeTag(metrics.MutableStateCacheTypeTagValue)),
110+
nonUserContextLockTimeout: config.HistoryCacheNonUserContextLockTimeout(),
109111
}
110112
}
111113

@@ -220,7 +222,7 @@ func (c *CacheImpl) lockWorkflowExecution(ctx context.Context,
220222
if deadline, ok := ctx.Deadline(); ok {
221223
var cancel context.CancelFunc
222224
if headers.GetCallerInfo(ctx).CallerType != headers.CallerTypeAPI {
223-
newDeadline := time.Now().Add(nonApiContextLockTimeout)
225+
newDeadline := time.Now().Add(c.nonUserContextLockTimeout)
224226
if newDeadline.Before(deadline) {
225227
ctx, cancel = context.WithDeadline(ctx, newDeadline)
226228
defer cancel()

0 commit comments

Comments
 (0)