-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Bound CHASM scheduler request IDs #11240
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
Changes from 5 commits
4999eb8
28f28bc
ed5e509
42be25f
dc1a58f
60f03c6
42f414b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package schedules | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
@@ -7,9 +7,13 @@ import ( | |
| "github.com/google/uuid" | ||
| ) | ||
|
|
||
| const lowestKnownSchemaRequestIDColumnLimit = 255 | ||
|
|
||
| // GenerateRequestID 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. | ||
| // Its total length must not exceed SQLite's request ID VARCHAR size, the | ||
| // smallest known persistence limit. | ||
| // | ||
| // backfillID should be left blank for actions that are being started | ||
| // automatically, based on the schedule spec. It must be set for backfills, | ||
|
|
@@ -26,11 +30,14 @@ func GenerateRequestID( | |
| if backfillID == "" { | ||
| backfillID = "auto" | ||
| } | ||
|
|
||
| // Keep request IDs bounded and deterministic even when schedule IDs are long. | ||
| scheduleIDUUID := uuid.NewSHA1(uuid.Nil, []byte(scheduleID)) | ||
|
Contributor
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. Not super sure I understand, wouldn't hashing the entire thing be the goal? What it if the NS is really long? I am not sure if we need the requestID to be human-readable, but if we don't, then what about:
Contributor
Author
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. I think the only places we'd see this is in tdbg execution dumps of the chasms schedule or workflows started by a schedule. I'd also like to keep auto vs backfiller id since the boolean marking a buffered start as manual is not displayed in tdbg output when false. Having the backfiller is also help with identifying which backfiller a buffered start came from. |
||
| return fmt.Sprintf( | ||
| "sched-%s-%s-%s-%d-%d-%d", | ||
| backfillID, | ||
|
Contributor
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. if you want to be completionist, it might be worth capping the backfill ID as well at a max length so that user-defined inputs can't exceed the field size. |
||
| namespaceID, | ||
| scheduleID, | ||
| scheduleIDUUID, | ||
| conflictToken, | ||
| nominal.UnixMilli(), | ||
| actual.UnixMilli(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGenerateWorkflowID(t *testing.T) { | ||
| baseWorkflowID := "my-workflow" | ||
| nominalTime := time.Date(2024, 6, 15, 10, 30, 45, 123456789, time.UTC) | ||
|
|
||
| actual := GenerateWorkflowID(baseWorkflowID, nominalTime) | ||
| require.Equal(t, "my-workflow-2024-06-15T10:30:45Z", actual) | ||
| } | ||
|
|
||
| func TestGenerateRequestID(t *testing.T) { | ||
| nominalTime := time.Now() | ||
| actualTime := time.Now() | ||
| scheduleID := "mysched" | ||
| scheduleIDUUID := uuid.NewSHA1(uuid.Nil, []byte(scheduleID)) | ||
|
|
||
| actual := GenerateRequestID("nsid", scheduleID, 10, "", nominalTime, actualTime) | ||
| expected := fmt.Sprintf( | ||
| "sched-auto-nsid-%s-10-%d-%d", | ||
| scheduleIDUUID, | ||
| nominalTime.UnixMilli(), | ||
| actualTime.UnixMilli(), | ||
| ) | ||
| require.Equal(t, expected, actual) | ||
|
|
||
| actual = GenerateRequestID("nsid", scheduleID, 10, "backfillid", nominalTime, actualTime) | ||
| expected = fmt.Sprintf( | ||
| "sched-backfillid-nsid-%s-10-%d-%d", | ||
| scheduleIDUUID, | ||
| nominalTime.UnixMilli(), | ||
| actualTime.UnixMilli(), | ||
| ) | ||
| require.Equal(t, expected, actual) | ||
| } | ||
|
|
||
| func TestGenerateRequestIDUsesUUIDv5ForScheduleID(t *testing.T) { | ||
| nominalTime := time.UnixMilli(1_700_000_000_000) | ||
| actualTime := time.UnixMilli(1_700_000_000_001) | ||
| scheduleID := strings.Repeat("a", 1000) | ||
| scheduleIDUUID := uuid.NewSHA1(uuid.Nil, []byte(scheduleID)) | ||
| require.Equal(t, uuid.Version(5), scheduleIDUUID.Version()) | ||
|
|
||
| for _, tc := range []struct { | ||
| name string | ||
| backfillID string | ||
| prefix string | ||
| }{ | ||
| {name: "automatic", prefix: "auto"}, | ||
| {name: "backfill", backfillID: "backfill-id", prefix: "backfill-id"}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| requestID := GenerateRequestID("nsid", scheduleID, 1, tc.backfillID, nominalTime, actualTime) | ||
| require.Contains(t, requestID, fmt.Sprintf("sched-%s-nsid-%s-1-", tc.prefix, scheduleIDUUID)) | ||
| require.NotContains(t, requestID, scheduleID) | ||
| require.LessOrEqual(t, len(requestID), lowestKnownSchemaRequestIDColumnLimit) | ||
|
|
||
| otherRequestID := GenerateRequestID("nsid", scheduleID+"b", 1, tc.backfillID, nominalTime, actualTime) | ||
| require.NotEqual(t, requestID, otherRequestID) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateRequestIDFitsSQLColumn(t *testing.T) { | ||
| requestID := GenerateRequestID( | ||
| strings.Repeat("a", 36), | ||
| "schedule-id", | ||
| math.MinInt64, | ||
| strings.Repeat("b", 36), | ||
| time.UnixMilli(math.MinInt64), | ||
| time.UnixMilli(math.MaxInt64), | ||
| ) | ||
|
|
||
| require.LessOrEqual(t, len(requestID), lowestKnownSchemaRequestIDColumnLimit) | ||
| } |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.