-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Scheduled Actions V2] WIP Common/util Package #6903
Draft
lina-temporal
wants to merge
1
commit into
sched2_proto
Choose a base branch
from
sched2_common
base: sched2_proto
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package common | ||
|
||
import ( | ||
"time" | ||
|
||
"go.temporal.io/server/common/dynamicconfig" | ||
) | ||
|
||
type ( | ||
Tweakables struct { | ||
DefaultCatchupWindow time.Duration // Default for catchup window | ||
MinCatchupWindow time.Duration // Minimum for catchup window | ||
MaxBufferSize int // MaxBufferSize limits the number of buffered actions pending execution in total | ||
BackfillsPerIteration int // How many backfilled actions to buffer per iteration (implies rate limit since min sleep is 1s) | ||
CanceledTerminatedCountAsFailures bool // Whether cancelled+terminated count for pause-on-failure | ||
|
||
// TODO - incomplete tweakables list | ||
} | ||
|
||
// V2 Scheduler dynamic config, shared among all substate machines. | ||
Config struct { | ||
Tweakables dynamicconfig.TypedPropertyFnWithNamespaceFilter[Tweakables] | ||
ExecutionTimeout dynamicconfig.DurationPropertyFnWithNamespaceFilter | ||
} | ||
) | ||
|
||
var ( | ||
CurrentTweakables = dynamicconfig.NewNamespaceTypedSetting( | ||
"component.scheduler.tweakables", | ||
DefaultTweakables, | ||
"A set of tweakable parameters for the V2 scheduler") | ||
|
||
ExecutionTimeout = dynamicconfig.NewNamespaceDurationSetting( | ||
"component.scheduler.executionTimeout", | ||
time.Second*10, | ||
`ExecutionTimeout is the timeout for executing a single scheduler task.`, | ||
) | ||
|
||
DefaultTweakables = Tweakables{ | ||
DefaultCatchupWindow: 365 * 24 * time.Hour, | ||
MinCatchupWindow: 10 * time.Second, | ||
MaxBufferSize: 1000, | ||
BackfillsPerIteration: 10, | ||
CanceledTerminatedCountAsFailures: false, | ||
} | ||
) | ||
|
||
func ConfigProvider(dc *dynamicconfig.Collection) *Config { | ||
return &Config{ | ||
Tweakables: CurrentTweakables.Get(dc), | ||
ExecutionTimeout: ExecutionTimeout.Get(dc), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,77 @@ | ||||||
package common | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
"fmt" | ||||||
"time" | ||||||
|
||||||
servercommon "go.temporal.io/server/common" | ||||||
"go.temporal.io/server/components/scheduler2/core" | ||||||
"go.temporal.io/server/service/history/consts" | ||||||
"go.temporal.io/server/service/history/hsm" | ||||||
) | ||||||
|
||||||
func ValidateTask[ | ||||||
S comparable, | ||||||
SM hsm.StateMachine[S], | ||||||
E any](node *hsm.Node, transition hsm.Transition[S, SM, E]) error { | ||||||
if err := node.CheckRunning(); err != nil { | ||||||
return err | ||||||
} | ||||||
sm, err := hsm.MachineData[SM](node) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
if !transition.Possible(sm) { | ||||||
return fmt.Errorf( | ||||||
"%w: %w: cannot transition from state %v to %v", | ||||||
consts.ErrStaleReference, | ||||||
hsm.ErrInvalidTransition, | ||||||
sm.State(), | ||||||
transition.Destination, | ||||||
) | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
// Intended to be called with a substate machine's node. Returns a cloned copy | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Go conventions for docstrings please.
Suggested change
|
||||||
// of the top-level Scheduler from its persisted state. | ||||||
func LoadSchedulerFromParent( | ||||||
ctx context.Context, | ||||||
env hsm.Environment, | ||||||
ref hsm.Ref) (scheduler core.Scheduler, err error) { | ||||||
err = env.Access(ctx, ref, hsm.AccessRead, func(node *hsm.Node) error { | ||||||
prevScheduler, err := hsm.MachineData[core.Scheduler](node.Parent) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
scheduler = core.Scheduler{ | ||||||
HsmSchedulerV2State: servercommon.CloneProto(prevScheduler.HsmSchedulerV2State), | ||||||
} | ||||||
return nil | ||||||
}) | ||||||
return | ||||||
} | ||||||
|
||||||
// Generates a deterministic request ID for a buffered action's time. The request | ||||||
// ID is deterministic because the jittered actual time (as well as the spec's | ||||||
// nominal time) is, in turn, also deterministic. | ||||||
// | ||||||
// backfillID should be left blank for actions that are being started | ||||||
// automatically, based on the schedule spec. It must be set for backfills, | ||||||
// as backfills may generate buffered actions that overlap with both | ||||||
// automatically-buffered actions, as well as other requested backfills. | ||||||
func GenerateRequestID(scheduler core.Scheduler, backfillID string, nominal, actual time.Time) string { | ||||||
if backfillID == "" { | ||||||
backfillID = "auto" | ||||||
} | ||||||
return fmt.Sprintf( | ||||||
"sched-%s-%s-%s-%d-%d-%d", | ||||||
backfillID, | ||||||
scheduler.NamespaceId, | ||||||
scheduler.ScheduleId, | ||||||
scheduler.ConflictToken, | ||||||
nominal.UnixMilli(), | ||||||
actual.UnixMilli(), | ||||||
) | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other PR, I'd put everything in the same package.