Skip to content

Commit

Permalink
support delay before history joins membership
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred-landrum committed Jul 6, 2023
1 parent 6d175c2 commit 5dc16b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions common/dynamicconfig/constants.go
Expand Up @@ -478,6 +478,9 @@ const (
HistoryCacheMaxSize = "history.cacheMaxSize"
// HistoryCacheTTL is TTL of history cache
HistoryCacheTTL = "history.cacheTTL"
// HistoryStartupMembershipJoinDelay is the duration a history instance waits
// before joining membership after starting.
HistoryStartupMembershipJoinDelay = "history.startupMembershipJoinDelay"
// HistoryShutdownDrainDuration is the duration of traffic drain during shutdown
HistoryShutdownDrainDuration = "history.shutdownDrainDuration"
// EventsCacheInitialSize is initial size of events cache
Expand Down
12 changes: 7 additions & 5 deletions service/history/configs/config.go
Expand Up @@ -57,11 +57,12 @@ type Config struct {
VisibilityDisableOrderByClause dynamicconfig.BoolPropertyFnWithNamespaceFilter
VisibilityEnableManualPagination dynamicconfig.BoolPropertyFnWithNamespaceFilter

EmitShardLagLog dynamicconfig.BoolPropertyFn
MaxAutoResetPoints dynamicconfig.IntPropertyFnWithNamespaceFilter
ThrottledLogRPS dynamicconfig.IntPropertyFn
EnableStickyQuery dynamicconfig.BoolPropertyFnWithNamespaceFilter
ShutdownDrainDuration dynamicconfig.DurationPropertyFn
EmitShardLagLog dynamicconfig.BoolPropertyFn
MaxAutoResetPoints dynamicconfig.IntPropertyFnWithNamespaceFilter
ThrottledLogRPS dynamicconfig.IntPropertyFn
EnableStickyQuery dynamicconfig.BoolPropertyFnWithNamespaceFilter
ShutdownDrainDuration dynamicconfig.DurationPropertyFn
StartupMembershipJoinDelay dynamicconfig.DurationPropertyFn

// HistoryCache settings
// Change of these configs require shard restart
Expand Down Expand Up @@ -334,6 +335,7 @@ func NewConfig(
EnablePersistencePriorityRateLimiting: dc.GetBoolProperty(dynamicconfig.HistoryEnablePersistencePriorityRateLimiting, true),
PersistenceDynamicRateLimitingParams: dc.GetMapProperty(dynamicconfig.HistoryPersistenceDynamicRateLimitingParams, dynamicconfig.DefaultDynamicRateLimitingParams),
ShutdownDrainDuration: dc.GetDurationProperty(dynamicconfig.HistoryShutdownDrainDuration, 0*time.Second),
StartupMembershipJoinDelay: dc.GetDurationProperty(dynamicconfig.HistoryStartupMembershipJoinDelay, 0*time.Second),
MaxAutoResetPoints: dc.GetIntPropertyFilteredByNamespace(dynamicconfig.HistoryMaxAutoResetPoints, DefaultHistoryMaxAutoResetPoints),
DefaultWorkflowTaskTimeout: dc.GetDurationPropertyFilteredByNamespace(dynamicconfig.DefaultWorkflowTaskTimeout, common.DefaultWorkflowTaskTimeout),
ContinueAsNewMinInterval: dc.GetDurationPropertyFilteredByNamespace(dynamicconfig.ContinueAsNewMinInterval, time.Second),
Expand Down
12 changes: 11 additions & 1 deletion service/history/service.go
Expand Up @@ -113,7 +113,17 @@ func (s *Service) Start() {
// that we own. Ideally, then, we would start the GRPC server, and only then
// join membership. That's not possible with the GRPC interface, though, hence
// we start membership in a goroutine.
go s.membershipMonitor.Start()
go func() {
if delay := s.config.StartupMembershipJoinDelay(); delay > 0 {
// In some situations, like rolling upgrades of the history service,
// pausing before joining membership can help separate the shard movement
// caused by another history instance terminating with this instance starting.
logger.Info("history start: delaying before membership start",
tag.NewDurationTag("startupMembershipJoinDelay", delay))
time.Sleep(delay)
}
s.membershipMonitor.Start()
}()

logger.Info("Starting to serve on history listener")
if err := s.server.Serve(s.grpcListener); err != nil {
Expand Down

0 comments on commit 5dc16b7

Please sign in to comment.