-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add last BuildID to workflow info #1335
Changes from all commits
2885d7a
4d73ea3
fb4f811
ea4c083
cec9ee9
dff44a4
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 |
---|---|---|
|
@@ -1005,6 +1005,10 @@ type WorkflowInfo struct { | |
// build-id based versioning, is the explicitly set worker build id. If this is the first worker to operate on the | ||
// workflow, it is this worker's current value. | ||
BinaryChecksum string | ||
// currentTaskBuildID, if nonempty, contains the Build ID of the worker that processed the task | ||
// which is currently or about to be executing. If no longer replaying will be set to the ID of | ||
// this worker | ||
currentTaskBuildID string | ||
|
||
continueAsNewSuggested bool | ||
currentHistorySize int | ||
|
@@ -1016,14 +1020,24 @@ type UpdateInfo struct { | |
ID string | ||
} | ||
|
||
// GetBinaryChecksum return binary checksum. | ||
// GetBinaryChecksum returns the binary checksum of the last worker to complete a task for this | ||
// workflow, or if this is the first task, this worker's checksum. | ||
func (wInfo *WorkflowInfo) GetBinaryChecksum() string { | ||
if wInfo.BinaryChecksum == "" { | ||
return getBinaryChecksum() | ||
} | ||
return wInfo.BinaryChecksum | ||
} | ||
|
||
// GetCurrentBuildID returns the Build ID of the worker that processed this task, which may be | ||
// empty. During replay this id may not equal the id of the replaying worker. If not replaying and | ||
// this worker has a defined Build ID, it will equal that ID. It is safe to use for branching. | ||
// When used inside a query, the ID of the worker that processed the task which last affected | ||
// the workflow will be returned. | ||
func (wInfo *WorkflowInfo) GetCurrentBuildID() string { | ||
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. May want to add a note for queries. Since they are not replaying, but also not using the current workers build ID. |
||
return wInfo.currentTaskBuildID | ||
} | ||
|
||
// GetCurrentHistoryLength returns the current length of history when called. | ||
// This value may change throughout the life of the workflow. | ||
func (wInfo *WorkflowInfo) GetCurrentHistoryLength() int { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"go.temporal.io/api/common/v1" | ||
"go.temporal.io/api/workflowservice/v1" | ||
|
||
"github.com/pborman/uuid" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
|
@@ -38,7 +41,8 @@ type WorkerVersioningTestSuite struct { | |
*require.Assertions | ||
suite.Suite | ||
ConfigAndClientSuiteBase | ||
workflows *Workflows | ||
workflows *Workflows | ||
activities *Activities | ||
} | ||
|
||
func TestWorkerVersioningTestSuite(t *testing.T) { | ||
|
@@ -48,6 +52,7 @@ func TestWorkerVersioningTestSuite(t *testing.T) { | |
func (ts *WorkerVersioningTestSuite) SetupSuite() { | ||
ts.Assertions = require.New(ts.T()) | ||
ts.workflows = &Workflows{} | ||
ts.activities = &Activities{} | ||
ts.NoError(ts.InitConfigAndNamespace()) | ||
ts.NoError(ts.InitClient()) | ||
} | ||
|
@@ -149,8 +154,6 @@ func (ts *WorkerVersioningTestSuite) TestTwoWorkersGetDifferentTasks() { | |
ts.NoError(handle12.Get(ctx, nil)) | ||
ts.NoError(handle21.Get(ctx, nil)) | ||
ts.NoError(handle22.Get(ctx, nil)) | ||
|
||
// TODO: Actually assert they ran on the appropriate workers, once David's changes are ready | ||
} | ||
|
||
func (ts *WorkerVersioningTestSuite) TestReachabilityUnreachable() { | ||
|
@@ -273,3 +276,80 @@ func (ts *WorkerVersioningTestSuite) TestReachabilityVersions() { | |
ts.Equal(1, len(taskQueueReachability.TaskQueueReachability)) | ||
ts.Equal([]client.TaskReachability{client.TaskReachabilityNewWorkflows}, taskQueueReachability.TaskQueueReachability) | ||
} | ||
|
||
func (ts *WorkerVersioningTestSuite) TestBuildIDChangesOverWorkflowLifetime() { | ||
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout) | ||
defer cancel() | ||
|
||
err := ts.client.UpdateWorkerBuildIdCompatibility(ctx, &client.UpdateWorkerBuildIdCompatibilityOptions{ | ||
TaskQueue: ts.taskQueueName, | ||
Operation: &client.BuildIDOpAddNewIDInNewDefaultSet{ | ||
BuildID: "1.0", | ||
}, | ||
}) | ||
ts.NoError(err) | ||
|
||
worker1 := worker.New(ts.client, ts.taskQueueName, worker.Options{BuildID: "1.0", UseBuildIDForVersioning: true}) | ||
ts.workflows.register(worker1) | ||
ts.activities.register(worker1) | ||
ts.NoError(worker1.Start()) | ||
|
||
// Start workflow | ||
wfHandle, err := ts.client.ExecuteWorkflow(ctx, ts.startWorkflowOptions("evolving-wf"), ts.workflows.BuildIDWorkflow) | ||
// Query to see that the build ID is 1.0 | ||
var lastBuildID string | ||
res, err := ts.client.QueryWorkflow(ctx, wfHandle.GetID(), wfHandle.GetRunID(), "get-last-build-id", nil) | ||
ts.NoError(err) | ||
ts.NoError(res.Get(&lastBuildID)) | ||
ts.Equal("1.0", lastBuildID) | ||
|
||
// Make sure we've got to the activity | ||
ts.Eventually(func() bool { | ||
var didRun bool | ||
res, err := ts.client.QueryWorkflow(ctx, wfHandle.GetID(), wfHandle.GetRunID(), "activity-ran", nil) | ||
ts.NoError(err) | ||
ts.NoError(res.Get(&didRun)) | ||
return didRun | ||
}, time.Second*10, time.Millisecond*100) | ||
worker1.Stop() | ||
|
||
// Add new compat ver | ||
err = ts.client.UpdateWorkerBuildIdCompatibility(ctx, &client.UpdateWorkerBuildIdCompatibilityOptions{ | ||
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. nit: this doesn't require versioning to test, you can use build ID with unversioned workers. 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. Could make sense to test with and without versioning just to be safe. 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. The bit you reviewed is subtly wrong in terms of querying on a cached worker after the worker has completed a task with its' ID. New test also makes sure the first task doesn't have an ID, which covers this path. (will need another update to fix the problem I mention) |
||
TaskQueue: ts.taskQueueName, | ||
Operation: &client.BuildIDOpAddNewCompatibleVersion{ | ||
BuildID: "1.1", | ||
ExistingCompatibleBuildID: "1.0", | ||
}, | ||
}) | ||
ts.NoError(err) | ||
|
||
worker11 := worker.New(ts.client, ts.taskQueueName, worker.Options{BuildID: "1.1", UseBuildIDForVersioning: true}) | ||
ts.workflows.register(worker11) | ||
ts.activities.register(worker11) | ||
ts.NoError(worker11.Start()) | ||
defer worker11.Stop() | ||
|
||
_, err = ts.client.WorkflowService().ResetStickyTaskQueue(ctx, &workflowservice.ResetStickyTaskQueueRequest{ | ||
Namespace: ts.config.Namespace, | ||
Execution: &common.WorkflowExecution{ | ||
WorkflowId: wfHandle.GetID(), | ||
}, | ||
}) | ||
ts.NoError(err) | ||
|
||
// The current task, with the new worker, should still be 1.0 since no new tasks have happened | ||
enval, err := ts.client.QueryWorkflow(ctx, wfHandle.GetID(), wfHandle.GetRunID(), "get-last-build-id", nil) | ||
ts.NoError(err) | ||
ts.NoError(enval.Get(&lastBuildID)) | ||
ts.Equal("1.0", lastBuildID) | ||
|
||
// finish the workflow under 1.1 | ||
ts.NoError(ts.client.SignalWorkflow(ctx, wfHandle.GetID(), wfHandle.GetRunID(), "finish", "")) | ||
ts.NoError(wfHandle.Get(ctx, nil)) | ||
|
||
// Post completion it should have the value of the last task | ||
enval, err = ts.client.QueryWorkflow(ctx, wfHandle.GetID(), wfHandle.GetRunID(), "get-last-build-id", nil) | ||
ts.NoError(err) | ||
ts.NoError(enval.Get(&lastBuildID)) | ||
ts.Equal("1.1", lastBuildID) | ||
} |
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.
can we add a comment here explaining why a query only task is treated special.