diff --git a/api/adminservice/v1/request_response.pb.go b/api/adminservice/v1/request_response.pb.go index d9eb926cc53..9a2e0de3221 100644 --- a/api/adminservice/v1/request_response.pb.go +++ b/api/adminservice/v1/request_response.pb.go @@ -252,6 +252,7 @@ type DescribeMutableStateRequest struct { Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Execution *v1.WorkflowExecution `protobuf:"bytes,2,opt,name=execution,proto3" json:"execution,omitempty"` SkipForceReload bool `protobuf:"varint,3,opt,name=skip_force_reload,json=skipForceReload,proto3" json:"skip_force_reload,omitempty"` + Archetype string `protobuf:"bytes,4,opt,name=archetype,proto3" json:"archetype,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -307,6 +308,13 @@ func (x *DescribeMutableStateRequest) GetSkipForceReload() bool { return false } +func (x *DescribeMutableStateRequest) GetArchetype() string { + if x != nil { + return x.Archetype + } + return "" +} + type DescribeMutableStateResponse struct { state protoimpl.MessageState `protogen:"open.v1"` ShardId string `protobuf:"bytes,1,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"` @@ -3080,6 +3088,7 @@ type RefreshWorkflowTasksRequest struct { state protoimpl.MessageState `protogen:"open.v1"` NamespaceId string `protobuf:"bytes,3,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` Execution *v1.WorkflowExecution `protobuf:"bytes,2,opt,name=execution,proto3" json:"execution,omitempty"` + Archetype string `protobuf:"bytes,4,opt,name=archetype,proto3" json:"archetype,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -3128,6 +3137,13 @@ func (x *RefreshWorkflowTasksRequest) GetExecution() *v1.WorkflowExecution { return nil } +func (x *RefreshWorkflowTasksRequest) GetArchetype() string { + if x != nil { + return x.Archetype + } + return "" +} + type RefreshWorkflowTasksResponse struct { state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields @@ -3464,6 +3480,7 @@ type DeleteWorkflowExecutionRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Execution *v1.WorkflowExecution `protobuf:"bytes,2,opt,name=execution,proto3" json:"execution,omitempty"` + Archetype string `protobuf:"bytes,3,opt,name=archetype,proto3" json:"archetype,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -3512,6 +3529,13 @@ func (x *DeleteWorkflowExecutionRequest) GetExecution() *v1.WorkflowExecution { return nil } +func (x *DeleteWorkflowExecutionRequest) GetArchetype() string { + if x != nil { + return x.Archetype + } + return "" +} + type DeleteWorkflowExecutionResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Warnings []string `protobuf:"bytes,1,rep,name=warnings,proto3" json:"warnings,omitempty"` @@ -4779,8 +4803,10 @@ type SyncWorkflowStateRequest struct { VersionedTransition *v12.VersionedTransition `protobuf:"bytes,3,opt,name=versioned_transition,json=versionedTransition,proto3" json:"versioned_transition,omitempty"` VersionHistories *v11.VersionHistories `protobuf:"bytes,4,opt,name=version_histories,json=versionHistories,proto3" json:"version_histories,omitempty"` TargetClusterId int32 `protobuf:"varint,5,opt,name=target_cluster_id,json=targetClusterId,proto3" json:"target_cluster_id,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,6,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *SyncWorkflowStateRequest) Reset() { @@ -4848,6 +4874,13 @@ func (x *SyncWorkflowStateRequest) GetTargetClusterId() int32 { return 0 } +func (x *SyncWorkflowStateRequest) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type SyncWorkflowStateResponse struct { state protoimpl.MessageState `protogen:"open.v1"` VersionedTransitionArtifact *v15.VersionedTransitionArtifact `protobuf:"bytes,5,opt,name=versioned_transition_artifact,json=versionedTransitionArtifact,proto3" json:"versioned_transition_artifact,omitempty"` @@ -4897,6 +4930,7 @@ type GenerateLastHistoryReplicationTasksRequest struct { Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Execution *v1.WorkflowExecution `protobuf:"bytes,2,opt,name=execution,proto3" json:"execution,omitempty"` TargetClusters []string `protobuf:"bytes,3,rep,name=target_clusters,json=targetClusters,proto3" json:"target_clusters,omitempty"` + Archetype string `protobuf:"bytes,4,opt,name=archetype,proto3" json:"archetype,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -4952,6 +4986,13 @@ func (x *GenerateLastHistoryReplicationTasksRequest) GetTargetClusters() []strin return nil } +func (x *GenerateLastHistoryReplicationTasksRequest) GetArchetype() string { + if x != nil { + return x.Archetype + } + return "" +} + type GenerateLastHistoryReplicationTasksResponse struct { state protoimpl.MessageState `protogen:"open.v1"` StateTransitionCount int64 `protobuf:"varint,1,opt,name=state_transition_count,json=stateTransitionCount,proto3" json:"state_transition_count,omitempty"` @@ -5334,11 +5375,12 @@ const file_temporal_server_api_adminservice_v1_request_response_proto_rawDesc = "\x0fversion_history\x18\x04 \x01(\v2..temporal.server.api.history.v1.VersionHistoryR\x0eversionHistory\x12\x14\n" + "\x05token\x18\x05 \x01(\fR\x05token\"7\n" + "\x1fImportWorkflowExecutionResponse\x12\x14\n" + - "\x05token\x18\x01 \x01(\fR\x05token\"\xb0\x01\n" + + "\x05token\x18\x01 \x01(\fR\x05token\"\xce\x01\n" + "\x1bDescribeMutableStateRequest\x12\x1c\n" + "\tnamespace\x18\x01 \x01(\tR\tnamespace\x12G\n" + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12*\n" + - "\x11skip_force_reload\x18\x03 \x01(\bR\x0fskipForceReload\"\xb6\x02\n" + + "\x11skip_force_reload\x18\x03 \x01(\bR\x0fskipForceReload\x12\x1c\n" + + "\tarchetype\x18\x04 \x01(\tR\tarchetype\"\xb6\x02\n" + "\x1cDescribeMutableStateResponse\x12\x19\n" + "\bshard_id\x18\x01 \x01(\tR\ashardId\x12!\n" + "\fhistory_addr\x18\x02 \x01(\tR\vhistoryAddr\x12h\n" + @@ -5554,10 +5596,11 @@ const file_temporal_server_api_adminservice_v1_request_response_proto_rawDesc = "\x11maximum_page_size\x18\x05 \x01(\x05R\x0fmaximumPageSize\x12&\n" + "\x0fnext_page_token\x18\x06 \x01(\fR\rnextPageToken\"B\n" + "\x18MergeDLQMessagesResponse\x12&\n" + - "\x0fnext_page_token\x18\x01 \x01(\fR\rnextPageToken\"\x8f\x01\n" + + "\x0fnext_page_token\x18\x01 \x01(\fR\rnextPageToken\"\xad\x01\n" + "\x1bRefreshWorkflowTasksRequest\x12!\n" + "\fnamespace_id\x18\x03 \x01(\tR\vnamespaceId\x12G\n" + - "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecutionJ\x04\b\x01\x10\x02\"\x1e\n" + + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12\x1c\n" + + "\tarchetype\x18\x04 \x01(\tR\tarchetypeJ\x04\b\x01\x10\x02\"\x1e\n" + "\x1cRefreshWorkflowTasksResponse\"\xaf\x02\n" + "\x1dResendReplicationTasksRequest\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12\x1f\n" + @@ -5586,10 +5629,11 @@ const file_temporal_server_api_adminservice_v1_request_response_proto_rawDesc = "\bsubqueue\x18\b \x01(\x05R\bsubqueue\"\x90\x01\n" + "\x19GetTaskQueueTasksResponse\x12K\n" + "\x05tasks\x18\x01 \x03(\v25.temporal.server.api.persistence.v1.AllocatedTaskInfoR\x05tasks\x12&\n" + - "\x0fnext_page_token\x18\x02 \x01(\fR\rnextPageToken\"\x87\x01\n" + + "\x0fnext_page_token\x18\x02 \x01(\fR\rnextPageToken\"\xa5\x01\n" + "\x1eDeleteWorkflowExecutionRequest\x12\x1c\n" + "\tnamespace\x18\x01 \x01(\tR\tnamespace\x12G\n" + - "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\"=\n" + + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12\x1c\n" + + "\tarchetype\x18\x03 \x01(\tR\tarchetype\"=\n" + "\x1fDeleteWorkflowExecutionResponse\x12\x1a\n" + "\bwarnings\x18\x01 \x03(\tR\bwarnings\"\xaa\x01\n" + "(StreamWorkflowReplicationMessagesRequest\x12p\n" + @@ -5676,19 +5720,21 @@ const file_temporal_server_api_adminservice_v1_request_response_proto_rawDesc = "\x0flast_message_id\x18\x03 \x01(\x03R\rlastMessageId\"\x18\n" + "\x16DeepHealthCheckRequest\"Z\n" + "\x17DeepHealthCheckResponse\x12?\n" + - "\x05state\x18\x01 \x01(\x0e2).temporal.server.api.enums.v1.HealthStateR\x05state\"\xfd\x02\n" + + "\x05state\x18\x01 \x01(\x0e2).temporal.server.api.enums.v1.HealthStateR\x05state\"\xa0\x03\n" + "\x18SyncWorkflowStateRequest\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12G\n" + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12j\n" + "\x14versioned_transition\x18\x03 \x01(\v27.temporal.server.api.persistence.v1.VersionedTransitionR\x13versionedTransition\x12]\n" + "\x11version_histories\x18\x04 \x01(\v20.temporal.server.api.history.v1.VersionHistoriesR\x10versionHistories\x12*\n" + - "\x11target_cluster_id\x18\x05 \x01(\x05R\x0ftargetClusterId\"\xb9\x01\n" + + "\x11target_cluster_id\x18\x05 \x01(\x05R\x0ftargetClusterId\x12!\n" + + "\farchetype_id\x18\x06 \x01(\rR\varchetypeId\"\xb9\x01\n" + "\x19SyncWorkflowStateResponse\x12\x83\x01\n" + - "\x1dversioned_transition_artifact\x18\x05 \x01(\v2?.temporal.server.api.replication.v1.VersionedTransitionArtifactR\x1bversionedTransitionArtifactJ\x04\b\x01\x10\x02J\x04\b\x02\x10\x03J\x04\b\x03\x10\x04J\x04\b\x04\x10\x05\"\xbc\x01\n" + + "\x1dversioned_transition_artifact\x18\x05 \x01(\v2?.temporal.server.api.replication.v1.VersionedTransitionArtifactR\x1bversionedTransitionArtifactJ\x04\b\x01\x10\x02J\x04\b\x02\x10\x03J\x04\b\x03\x10\x04J\x04\b\x04\x10\x05\"\xda\x01\n" + "*GenerateLastHistoryReplicationTasksRequest\x12\x1c\n" + "\tnamespace\x18\x01 \x01(\tR\tnamespace\x12G\n" + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12'\n" + - "\x0ftarget_clusters\x18\x03 \x03(\tR\x0etargetClusters\"\x8a\x01\n" + + "\x0ftarget_clusters\x18\x03 \x03(\tR\x0etargetClusters\x12\x1c\n" + + "\tarchetype\x18\x04 \x01(\tR\tarchetype\"\x8a\x01\n" + "+GenerateLastHistoryReplicationTasksResponse\x124\n" + "\x16state_transition_count\x18\x01 \x01(\x03R\x14stateTransitionCount\x12%\n" + "\x0ehistory_length\x18\x02 \x01(\x03R\rhistoryLength\"\xfc\x01\n" + diff --git a/api/errordetails/v1/message.pb.go b/api/errordetails/v1/message.pb.go index ece9658709b..0200cd36111 100644 --- a/api/errordetails/v1/message.pb.go +++ b/api/errordetails/v1/message.pb.go @@ -281,8 +281,10 @@ type SyncStateFailure struct { RunId string `protobuf:"bytes,3,opt,name=run_id,json=runId,proto3" json:"run_id,omitempty"` VersionedTransition *v1.VersionedTransition `protobuf:"bytes,4,opt,name=versioned_transition,json=versionedTransition,proto3" json:"versioned_transition,omitempty"` VersionHistories *v11.VersionHistories `protobuf:"bytes,5,opt,name=version_histories,json=versionHistories,proto3" json:"version_histories,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,6,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *SyncStateFailure) Reset() { @@ -350,6 +352,13 @@ func (x *SyncStateFailure) GetVersionHistories() *v11.VersionHistories { return nil } +func (x *SyncStateFailure) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type StickyWorkerUnavailableFailure struct { state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields @@ -522,14 +531,15 @@ const file_temporal_server_api_errordetails_v1_message_proto_rawDesc = "" + "\x13start_event_version\x18\x05 \x01(\x03R\x11startEventVersion\x12 \n" + "\fend_event_id\x18\x06 \x01(\x03R\n" + "endEventId\x12*\n" + - "\x11end_event_version\x18\a \x01(\x03R\x0fendEventVersion\"\xb8\x02\n" + + "\x11end_event_version\x18\a \x01(\x03R\x0fendEventVersion\"\xdb\x02\n" + "\x10SyncStateFailure\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12\x1f\n" + "\vworkflow_id\x18\x02 \x01(\tR\n" + "workflowId\x12\x15\n" + "\x06run_id\x18\x03 \x01(\tR\x05runId\x12j\n" + "\x14versioned_transition\x18\x04 \x01(\v27.temporal.server.api.persistence.v1.VersionedTransitionR\x13versionedTransition\x12]\n" + - "\x11version_histories\x18\x05 \x01(\v20.temporal.server.api.history.v1.VersionHistoriesR\x10versionHistories\" \n" + + "\x11version_histories\x18\x05 \x01(\v20.temporal.server.api.history.v1.VersionHistoriesR\x10versionHistories\x12!\n" + + "\farchetype_id\x18\x06 \x01(\rR\varchetypeId\" \n" + "\x1eStickyWorkerUnavailableFailure\" \n" + "\x1eObsoleteDispatchBuildIdFailure\"\x1d\n" + "\x1bObsoleteMatchingTaskFailure\"&\n" + diff --git a/api/historyservice/v1/request_response.pb.go b/api/historyservice/v1/request_response.pb.go index f0b89ea6a3c..ff7a1f83f10 100644 --- a/api/historyservice/v1/request_response.pb.go +++ b/api/historyservice/v1/request_response.pb.go @@ -4982,8 +4982,10 @@ type DescribeMutableStateRequest struct { NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` Execution *v14.WorkflowExecution `protobuf:"bytes,2,opt,name=execution,proto3" json:"execution,omitempty"` SkipForceReload bool `protobuf:"varint,3,opt,name=skip_force_reload,json=skipForceReload,proto3" json:"skip_force_reload,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,4,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *DescribeMutableStateRequest) Reset() { @@ -5037,6 +5039,13 @@ func (x *DescribeMutableStateRequest) GetSkipForceReload() bool { return false } +func (x *DescribeMutableStateRequest) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type DescribeMutableStateResponse struct { state protoimpl.MessageState `protogen:"open.v1"` // CacheMutableState is only available when mutable state is in cache. @@ -6256,8 +6265,10 @@ func (x *MergeDLQMessagesResponse) GetNextPageToken() []byte { } type RefreshWorkflowTasksRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,3,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` Request *v118.RefreshWorkflowTasksRequest `protobuf:"bytes,2,opt,name=request,proto3" json:"request,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -6300,6 +6311,13 @@ func (x *RefreshWorkflowTasksRequest) GetNamespaceId() string { return "" } +func (x *RefreshWorkflowTasksRequest) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + func (x *RefreshWorkflowTasksRequest) GetRequest() *v118.RefreshWorkflowTasksRequest { if x != nil { return x.Request @@ -6348,8 +6366,10 @@ type GenerateLastHistoryReplicationTasksRequest struct { NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` Execution *v14.WorkflowExecution `protobuf:"bytes,2,opt,name=execution,proto3" json:"execution,omitempty"` TargetClusters []string `protobuf:"bytes,3,rep,name=target_clusters,json=targetClusters,proto3" json:"target_clusters,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,4,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *GenerateLastHistoryReplicationTasksRequest) Reset() { @@ -6403,6 +6423,13 @@ func (x *GenerateLastHistoryReplicationTasksRequest) GetTargetClusters() []strin return nil } +func (x *GenerateLastHistoryReplicationTasksRequest) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type GenerateLastHistoryReplicationTasksResponse struct { state protoimpl.MessageState `protogen:"open.v1"` StateTransitionCount int64 `protobuf:"varint,1,opt,name=state_transition_count,json=stateTransitionCount,proto3" json:"state_transition_count,omitempty"` @@ -7827,8 +7854,10 @@ func (x *GetWorkflowExecutionRawHistoryResponse) GetResponse() *v118.GetWorkflow } type ForceDeleteWorkflowExecutionRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,3,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` Request *v118.DeleteWorkflowExecutionRequest `protobuf:"bytes,2,opt,name=request,proto3" json:"request,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -7871,6 +7900,13 @@ func (x *ForceDeleteWorkflowExecutionRequest) GetNamespaceId() string { return "" } +func (x *ForceDeleteWorkflowExecutionRequest) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + func (x *ForceDeleteWorkflowExecutionRequest) GetRequest() *v118.DeleteWorkflowExecutionRequest { if x != nil { return x.Request @@ -8965,8 +9001,10 @@ type SyncWorkflowStateRequest struct { VersionedTransition *v19.VersionedTransition `protobuf:"bytes,3,opt,name=versioned_transition,json=versionedTransition,proto3" json:"versioned_transition,omitempty"` VersionHistories *v18.VersionHistories `protobuf:"bytes,4,opt,name=version_histories,json=versionHistories,proto3" json:"version_histories,omitempty"` TargetClusterId int32 `protobuf:"varint,5,opt,name=target_cluster_id,json=targetClusterId,proto3" json:"target_cluster_id,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,6,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *SyncWorkflowStateRequest) Reset() { @@ -9034,6 +9072,13 @@ func (x *SyncWorkflowStateRequest) GetTargetClusterId() int32 { return 0 } +func (x *SyncWorkflowStateRequest) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type SyncWorkflowStateResponse struct { state protoimpl.MessageState `protogen:"open.v1"` VersionedTransitionArtifact *v117.VersionedTransitionArtifact `protobuf:"bytes,5,opt,name=versioned_transition_artifact,json=versionedTransitionArtifact,proto3" json:"versioned_transition_artifact,omitempty"` @@ -10451,11 +10496,12 @@ const file_temporal_server_api_historyservice_v1_request_response_proto_rawDesc "\x16retry_maximum_attempts\x18\x18 \x01(\x05R\x14retryMaximumAttempts\x12:\n" + "\x19retry_backoff_coefficient\x18\x19 \x01(\x01R\x17retryBackoffCoefficient\x12#\n" + "\rstart_version\x18\x1a \x01(\x03R\fstartVersion\"\x16\n" + - "\x14SyncActivityResponse\"\xd2\x01\n" + + "\x14SyncActivityResponse\"\xf5\x01\n" + "\x1bDescribeMutableStateRequest\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12G\n" + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12*\n" + - "\x11skip_force_reload\x18\x03 \x01(\bR\x0fskipForceReload:\x1b\x92\xc4\x03\x17*\x15execution.workflow_id\"\xf8\x01\n" + + "\x11skip_force_reload\x18\x03 \x01(\bR\x0fskipForceReload\x12!\n" + + "\farchetype_id\x18\x04 \x01(\rR\varchetypeId:\x1b\x92\xc4\x03\x17*\x15execution.workflow_id\"\xf8\x01\n" + "\x1cDescribeMutableStateResponse\x12h\n" + "\x13cache_mutable_state\x18\x01 \x01(\v28.temporal.server.api.persistence.v1.WorkflowMutableStateR\x11cacheMutableState\x12n\n" + "\x16database_mutable_state\x18\x02 \x01(\v28.temporal.server.api.persistence.v1.WorkflowMutableStateR\x14databaseMutableState\"\xdf\x01\n" + @@ -10538,15 +10584,17 @@ const file_temporal_server_api_historyservice_v1_request_response_proto_rawDesc "\x0fnext_page_token\x18\x06 \x01(\fR\rnextPageToken:\x0e\x92\xc4\x03\n" + "\x1a\bshard_id\"B\n" + "\x18MergeDLQMessagesResponse\x12&\n" + - "\x0fnext_page_token\x18\x01 \x01(\fR\rnextPageToken\"\xc1\x01\n" + + "\x0fnext_page_token\x18\x01 \x01(\fR\rnextPageToken\"\xe4\x01\n" + "\x1bRefreshWorkflowTasksRequest\x12!\n" + - "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12Z\n" + + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12!\n" + + "\farchetype_id\x18\x03 \x01(\rR\varchetypeId\x12Z\n" + "\arequest\x18\x02 \x01(\v2@.temporal.server.api.adminservice.v1.RefreshWorkflowTasksRequestR\arequest:#\x92\xc4\x03\x1f*\x1drequest.execution.workflow_id\"\x1e\n" + - "\x1cRefreshWorkflowTasksResponse\"\xde\x01\n" + + "\x1cRefreshWorkflowTasksResponse\"\x81\x02\n" + "*GenerateLastHistoryReplicationTasksRequest\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12G\n" + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12'\n" + - "\x0ftarget_clusters\x18\x03 \x03(\tR\x0etargetClusters:\x1b\x92\xc4\x03\x17*\x15execution.workflow_id\"\x8a\x01\n" + + "\x0ftarget_clusters\x18\x03 \x03(\tR\x0etargetClusters\x12!\n" + + "\farchetype_id\x18\x04 \x01(\rR\varchetypeId:\x1b\x92\xc4\x03\x17*\x15execution.workflow_id\"\x8a\x01\n" + "+GenerateLastHistoryReplicationTasksResponse\x124\n" + "\x16state_transition_count\x18\x01 \x01(\x03R\x14stateTransitionCount\x12%\n" + "\x0ehistory_length\x18\x02 \x01(\x03R\rhistoryLength\"N\n" + @@ -10632,9 +10680,10 @@ const file_temporal_server_api_historyservice_v1_request_response_proto_rawDesc "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12d\n" + "\arequest\x18\x02 \x01(\v2J.temporal.server.api.adminservice.v1.GetWorkflowExecutionRawHistoryRequestR\arequest:#\x92\xc4\x03\x1f*\x1drequest.execution.workflow_id\"\x91\x01\n" + "&GetWorkflowExecutionRawHistoryResponse\x12g\n" + - "\bresponse\x18\x01 \x01(\v2K.temporal.server.api.adminservice.v1.GetWorkflowExecutionRawHistoryResponseR\bresponse\"\xcc\x01\n" + + "\bresponse\x18\x01 \x01(\v2K.temporal.server.api.adminservice.v1.GetWorkflowExecutionRawHistoryResponseR\bresponse\"\xef\x01\n" + "#ForceDeleteWorkflowExecutionRequest\x12!\n" + - "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12]\n" + + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12!\n" + + "\farchetype_id\x18\x03 \x01(\rR\varchetypeId\x12]\n" + "\arequest\x18\x02 \x01(\v2C.temporal.server.api.adminservice.v1.DeleteWorkflowExecutionRequestR\arequest:#\x92\xc4\x03\x1f*\x1drequest.execution.workflow_id\"\x88\x01\n" + "$ForceDeleteWorkflowExecutionResponse\x12`\n" + "\bresponse\x18\x01 \x01(\v2D.temporal.server.api.adminservice.v1.DeleteWorkflowExecutionResponseR\bresponse\"\xa8\x01\n" + @@ -10713,13 +10762,14 @@ const file_temporal_server_api_historyservice_v1_request_response_proto_rawDesc "\x16DeepHealthCheckRequest\x12!\n" + "\fhost_address\x18\x01 \x01(\tR\vhostAddress:\x06\x92\xc4\x03\x02\b\x01\"Z\n" + "\x17DeepHealthCheckResponse\x12?\n" + - "\x05state\x18\x01 \x01(\x0e2).temporal.server.api.enums.v1.HealthStateR\x05state\"\x9a\x03\n" + + "\x05state\x18\x01 \x01(\x0e2).temporal.server.api.enums.v1.HealthStateR\x05state\"\xbd\x03\n" + "\x18SyncWorkflowStateRequest\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12G\n" + "\texecution\x18\x02 \x01(\v2).temporal.api.common.v1.WorkflowExecutionR\texecution\x12j\n" + "\x14versioned_transition\x18\x03 \x01(\v27.temporal.server.api.persistence.v1.VersionedTransitionR\x13versionedTransition\x12]\n" + "\x11version_histories\x18\x04 \x01(\v20.temporal.server.api.history.v1.VersionHistoriesR\x10versionHistories\x12*\n" + - "\x11target_cluster_id\x18\x05 \x01(\x05R\x0ftargetClusterId:\x1b\x92\xc4\x03\x17*\x15execution.workflow_id\"\xb9\x01\n" + + "\x11target_cluster_id\x18\x05 \x01(\x05R\x0ftargetClusterId\x12!\n" + + "\farchetype_id\x18\x06 \x01(\rR\varchetypeId:\x1b\x92\xc4\x03\x17*\x15execution.workflow_id\"\xb9\x01\n" + "\x19SyncWorkflowStateResponse\x12\x83\x01\n" + "\x1dversioned_transition_artifact\x18\x05 \x01(\v2?.temporal.server.api.replication.v1.VersionedTransitionArtifactR\x1bversionedTransitionArtifactJ\x04\b\x01\x10\x02J\x04\b\x02\x10\x03J\x04\b\x03\x10\x04J\x04\b\x04\x10\x05\"\xd3\x01\n" + "\x1cUpdateActivityOptionsRequest\x12!\n" + diff --git a/api/persistence/v1/chasm.pb.go b/api/persistence/v1/chasm.pb.go index 2dbdf24c8b5..b73f00387c8 100644 --- a/api/persistence/v1/chasm.pb.go +++ b/api/persistence/v1/chasm.pb.go @@ -408,7 +408,10 @@ type ChasmTaskInfo struct { TypeId uint32 `protobuf:"varint,4,opt,name=type_id,json=typeId,proto3" json:"type_id,omitempty"` // Opaque attached task data. May be nil. Usable by components, not the CHASM // framework itself. - Data *v1.DataBlob `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"` + Data *v1.DataBlob `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"` + // ArchetypeID of the execution that generated this task. + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,6,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -478,6 +481,13 @@ func (x *ChasmTaskInfo) GetData() *v1.DataBlob { return nil } +func (x *ChasmTaskInfo) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + // ChasmComponentRef references a specific chasm component. type ChasmComponentRef struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -811,13 +821,14 @@ const file_temporal_server_api_persistence_v1_chasm_proto_rawDesc = "" + "\x13ChasmDataAttributes\"\x1b\n" + "\x19ChasmCollectionAttributes\"5\n" + "\x16ChasmPointerAttributes\x12\x1b\n" + - "\tnode_path\x18\x01 \x03(\tR\bnodePath\"\x97\x03\n" + + "\tnode_path\x18\x01 \x03(\tR\bnodePath\"\xba\x03\n" + "\rChasmTaskInfo\x12\x8c\x01\n" + "&component_initial_versioned_transition\x18\x01 \x01(\v27.temporal.server.api.persistence.v1.VersionedTransitionR#componentInitialVersionedTransition\x12\x93\x01\n" + "*component_last_update_versioned_transition\x18\x02 \x01(\v27.temporal.server.api.persistence.v1.VersionedTransitionR&componentLastUpdateVersionedTransition\x12\x12\n" + "\x04path\x18\x03 \x03(\tR\x04path\x12\x17\n" + "\atype_id\x18\x04 \x01(\rR\x06typeId\x124\n" + - "\x04data\x18\x05 \x01(\v2 .temporal.api.common.v1.DataBlobR\x04data\"\xc6\x03\n" + + "\x04data\x18\x05 \x01(\v2 .temporal.api.common.v1.DataBlobR\x04data\x12!\n" + + "\farchetype_id\x18\x06 \x01(\rR\varchetypeId\"\xc6\x03\n" + "\x11ChasmComponentRef\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12\x1f\n" + "\vbusiness_id\x18\x02 \x01(\tR\n" + diff --git a/api/persistence/v1/executions.pb.go b/api/persistence/v1/executions.pb.go index fa980263350..4c79139121f 100644 --- a/api/persistence/v1/executions.pb.go +++ b/api/persistence/v1/executions.pb.go @@ -1529,8 +1529,10 @@ type ReplicationTaskInfo struct { IsFirstTask bool `protobuf:"varint,22,opt,name=is_first_task,json=isFirstTask,proto3" json:"is_first_task,omitempty"` TargetClusters []string `protobuf:"bytes,23,rep,name=target_clusters,json=targetClusters,proto3" json:"target_clusters,omitempty"` IsForceReplication bool `protobuf:"varint,24,opt,name=is_force_replication,json=isForceReplication,proto3" json:"is_force_replication,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,25,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *ReplicationTaskInfo) Reset() { @@ -1703,6 +1705,13 @@ func (x *ReplicationTaskInfo) GetIsForceReplication() bool { return false } +func (x *ReplicationTaskInfo) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + // visibility_task_data column type VisibilityTaskInfo struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -4654,7 +4663,7 @@ const file_temporal_server_api_persistence_v1_executions_proto_rawDesc = "" + "\x05stamp\x18\x11 \x01(\x05R\x05stamp\x1a\\\n" + "\x19CloseExecutionTaskDetails\x12?\n" + "\x1ccan_skip_visibility_archival\x18\x01 \x01(\bR\x19canSkipVisibilityArchivalB\x0e\n" + - "\ftask_detailsJ\x04\b\x0e\x10\x0f\"\xb5\b\n" + + "\ftask_detailsJ\x04\b\x0e\x10\x0f\"\xd8\b\n" + "\x13ReplicationTaskInfo\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12\x1f\n" + "\vworkflow_id\x18\x02 \x01(\tR\n" + @@ -4677,7 +4686,8 @@ const file_temporal_server_api_persistence_v1_executions_proto_rawDesc = "" + "\x19last_version_history_item\x18\x15 \x01(\v22.temporal.server.api.history.v1.VersionHistoryItemR\x16lastVersionHistoryItem\x12\"\n" + "\ris_first_task\x18\x16 \x01(\bR\visFirstTask\x12'\n" + "\x0ftarget_clusters\x18\x17 \x03(\tR\x0etargetClusters\x120\n" + - "\x14is_force_replication\x18\x18 \x01(\bR\x12isForceReplicationJ\x04\b\t\x10\n" + + "\x14is_force_replication\x18\x18 \x01(\bR\x12isForceReplication\x12!\n" + + "\farchetype_id\x18\x19 \x01(\rR\varchetypeIdJ\x04\b\t\x10\n" + "J\x04\b\n" + "\x10\vJ\x04\b\f\x10\rJ\x04\b\x0e\x10\x0f\"\x99\x04\n" + "\x12VisibilityTaskInfo\x12!\n" + diff --git a/api/replication/v1/message.go-helpers.pb.go b/api/replication/v1/message.go-helpers.pb.go index 464e562f730..a4b44907168 100644 --- a/api/replication/v1/message.go-helpers.pb.go +++ b/api/replication/v1/message.go-helpers.pb.go @@ -818,3 +818,40 @@ func (this *VersionedTransitionArtifact) Equal(that interface{}) bool { return proto.Equal(this, that1) } + +// Marshal an object of type MigrationExecutionInfo to the protobuf v3 wire format +func (val *MigrationExecutionInfo) Marshal() ([]byte, error) { + return proto.Marshal(val) +} + +// Unmarshal an object of type MigrationExecutionInfo from the protobuf v3 wire format +func (val *MigrationExecutionInfo) Unmarshal(buf []byte) error { + return proto.Unmarshal(buf, val) +} + +// Size returns the size of the object, in bytes, once serialized +func (val *MigrationExecutionInfo) Size() int { + return proto.Size(val) +} + +// Equal returns whether two MigrationExecutionInfo values are equivalent by recursively +// comparing the message's fields. +// For more information see the documentation for +// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal +func (this *MigrationExecutionInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + var that1 *MigrationExecutionInfo + switch t := that.(type) { + case *MigrationExecutionInfo: + that1 = t + case MigrationExecutionInfo: + that1 = &t + default: + return false + } + + return proto.Equal(this, that1) +} diff --git a/api/replication/v1/message.pb.go b/api/replication/v1/message.pb.go index ba2135c334f..b8b029520ec 100644 --- a/api/replication/v1/message.pb.go +++ b/api/replication/v1/message.pb.go @@ -1760,8 +1760,10 @@ type VerifyVersionedTransitionTaskAttributes struct { NextEventId int64 `protobuf:"varint,4,opt,name=next_event_id,json=nextEventId,proto3" json:"next_event_id,omitempty"` EventVersionHistory []*v16.VersionHistoryItem `protobuf:"bytes,5,rep,name=event_version_history,json=eventVersionHistory,proto3" json:"event_version_history,omitempty"` NewRunId string `protobuf:"bytes,6,opt,name=new_run_id,json=newRunId,proto3" json:"new_run_id,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,7,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *VerifyVersionedTransitionTaskAttributes) Reset() { @@ -1836,14 +1838,23 @@ func (x *VerifyVersionedTransitionTaskAttributes) GetNewRunId() string { return "" } +func (x *VerifyVersionedTransitionTaskAttributes) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type SyncVersionedTransitionTaskAttributes struct { state protoimpl.MessageState `protogen:"open.v1"` VersionedTransitionArtifact *VersionedTransitionArtifact `protobuf:"bytes,5,opt,name=versioned_transition_artifact,json=versionedTransitionArtifact,proto3" json:"versioned_transition_artifact,omitempty"` NamespaceId string `protobuf:"bytes,6,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` WorkflowId string `protobuf:"bytes,7,opt,name=workflow_id,json=workflowId,proto3" json:"workflow_id,omitempty"` RunId string `protobuf:"bytes,8,opt,name=run_id,json=runId,proto3" json:"run_id,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,9,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *SyncVersionedTransitionTaskAttributes) Reset() { @@ -1904,6 +1915,13 @@ func (x *SyncVersionedTransitionTaskAttributes) GetRunId() string { return "" } +func (x *SyncVersionedTransitionTaskAttributes) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + type VersionedTransitionArtifact struct { state protoimpl.MessageState `protogen:"open.v1"` // Types that are valid to be assigned to StateAttributes: @@ -2028,6 +2046,69 @@ func (*VersionedTransitionArtifact_SyncWorkflowStateMutationAttributes) isVersio func (*VersionedTransitionArtifact_SyncWorkflowStateSnapshotAttributes) isVersionedTransitionArtifact_StateAttributes() { } +type MigrationExecutionInfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Should be called business_id, but to maintain backward compatibility + // with old type definition used in migration workflows. + BusinessId string `protobuf:"bytes,1,opt,name=business_id,json=workflowId,proto3" json:"business_id,omitempty"` + RunId string `protobuf:"bytes,2,opt,name=run_id,json=runId,proto3" json:"run_id,omitempty"` + // (-- api-linter: core::0141::forbidden-types=disabled --) + ArchetypeId uint32 `protobuf:"varint,3,opt,name=archetype_id,json=archetypeId,proto3" json:"archetype_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MigrationExecutionInfo) Reset() { + *x = MigrationExecutionInfo{} + mi := &file_temporal_server_api_replication_v1_message_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MigrationExecutionInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MigrationExecutionInfo) ProtoMessage() {} + +func (x *MigrationExecutionInfo) ProtoReflect() protoreflect.Message { + mi := &file_temporal_server_api_replication_v1_message_proto_msgTypes[22] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MigrationExecutionInfo.ProtoReflect.Descriptor instead. +func (*MigrationExecutionInfo) Descriptor() ([]byte, []int) { + return file_temporal_server_api_replication_v1_message_proto_rawDescGZIP(), []int{22} +} + +func (x *MigrationExecutionInfo) GetBusinessId() string { + if x != nil { + return x.BusinessId + } + return "" +} + +func (x *MigrationExecutionInfo) GetRunId() string { + if x != nil { + return x.RunId + } + return "" +} + +func (x *MigrationExecutionInfo) GetArchetypeId() uint32 { + if x != nil { + return x.ArchetypeId + } + return 0 +} + var File_temporal_server_api_replication_v1_message_proto protoreflect.FileDescriptor const file_temporal_server_api_replication_v1_message_proto_rawDesc = "" + @@ -2183,7 +2264,7 @@ const file_temporal_server_api_replication_v1_message_proto_rawDesc = "" + "$exclusive_start_versioned_transition\x18\x01 \x01(\v27.temporal.server.api.persistence.v1.VersionedTransitionR!exclusiveStartVersionedTransition\x12g\n" + "\x0estate_mutation\x18\x02 \x01(\v2@.temporal.server.api.persistence.v1.WorkflowMutableStateMutationR\rstateMutation\"u\n" + "#SyncWorkflowStateSnapshotAttributes\x12N\n" + - "\x05state\x18\x01 \x01(\v28.temporal.server.api.persistence.v1.WorkflowMutableStateR\x05state\"\xae\x02\n" + + "\x05state\x18\x01 \x01(\v28.temporal.server.api.persistence.v1.WorkflowMutableStateR\x05state\"\xd1\x02\n" + "'VerifyVersionedTransitionTaskAttributes\x12!\n" + "\fnamespace_id\x18\x01 \x01(\tR\vnamespaceId\x12\x1f\n" + "\vworkflow_id\x18\x02 \x01(\tR\n" + @@ -2192,13 +2273,15 @@ const file_temporal_server_api_replication_v1_message_proto_rawDesc = "" + "\rnext_event_id\x18\x04 \x01(\x03R\vnextEventId\x12f\n" + "\x15event_version_history\x18\x05 \x03(\v22.temporal.server.api.history.v1.VersionHistoryItemR\x13eventVersionHistory\x12\x1c\n" + "\n" + - "new_run_id\x18\x06 \x01(\tR\bnewRunId\"\xa0\x02\n" + + "new_run_id\x18\x06 \x01(\tR\bnewRunId\x12!\n" + + "\farchetype_id\x18\a \x01(\rR\varchetypeId\"\xc3\x02\n" + "%SyncVersionedTransitionTaskAttributes\x12\x83\x01\n" + "\x1dversioned_transition_artifact\x18\x05 \x01(\v2?.temporal.server.api.replication.v1.VersionedTransitionArtifactR\x1bversionedTransitionArtifact\x12!\n" + "\fnamespace_id\x18\x06 \x01(\tR\vnamespaceId\x12\x1f\n" + "\vworkflow_id\x18\a \x01(\tR\n" + "workflowId\x12\x15\n" + - "\x06run_id\x18\b \x01(\tR\x05runIdJ\x04\b\x01\x10\x02J\x04\b\x02\x10\x03J\x04\b\x03\x10\x04J\x04\b\x04\x10\x05\"\xa4\x05\n" + + "\x06run_id\x18\b \x01(\tR\x05runId\x12!\n" + + "\farchetype_id\x18\t \x01(\rR\varchetypeIdJ\x04\b\x01\x10\x02J\x04\b\x02\x10\x03J\x04\b\x03\x10\x04J\x04\b\x04\x10\x05\"\xa4\x05\n" + "\x1bVersionedTransitionArtifact\x12\x9f\x01\n" + "'sync_workflow_state_mutation_attributes\x18\x01 \x01(\v2G.temporal.server.api.replication.v1.SyncWorkflowStateMutationAttributesH\x00R#syncWorkflowStateMutationAttributes\x12\x9f\x01\n" + "'sync_workflow_state_snapshot_attributes\x18\x02 \x01(\v2G.temporal.server.api.replication.v1.SyncWorkflowStateSnapshotAttributesH\x00R#syncWorkflowStateSnapshotAttributes\x12E\n" + @@ -2208,7 +2291,12 @@ const file_temporal_server_api_replication_v1_message_proto_rawDesc = "" + "\ris_first_sync\x18\x05 \x01(\bR\visFirstSync\x12>\n" + "\x1cis_close_transfer_task_acked\x18\x06 \x01(\bR\x18isCloseTransferTaskAcked\x120\n" + "\x14is_force_replication\x18\a \x01(\bR\x12isForceReplicationB\x12\n" + - "\x10state_attributesB5Z3go.temporal.io/server/api/replication/v1;repicationb\x06proto3" + "\x10state_attributes\"s\n" + + "\x16MigrationExecutionInfo\x12\x1f\n" + + "\vbusiness_id\x18\x01 \x01(\tR\n" + + "workflowId\x12\x15\n" + + "\x06run_id\x18\x02 \x01(\tR\x05runId\x12!\n" + + "\farchetype_id\x18\x03 \x01(\rR\varchetypeIdB5Z3go.temporal.io/server/api/replication/v1;repicationb\x06proto3" var ( file_temporal_server_api_replication_v1_message_proto_rawDescOnce sync.Once @@ -2222,7 +2310,7 @@ func file_temporal_server_api_replication_v1_message_proto_rawDescGZIP() []byte return file_temporal_server_api_replication_v1_message_proto_rawDescData } -var file_temporal_server_api_replication_v1_message_proto_msgTypes = make([]protoimpl.MessageInfo, 22) +var file_temporal_server_api_replication_v1_message_proto_msgTypes = make([]protoimpl.MessageInfo, 23) var file_temporal_server_api_replication_v1_message_proto_goTypes = []any{ (*ReplicationTask)(nil), // 0: temporal.server.api.replication.v1.ReplicationTask (*ReplicationToken)(nil), // 1: temporal.server.api.replication.v1.ReplicationToken @@ -2246,32 +2334,33 @@ var file_temporal_server_api_replication_v1_message_proto_goTypes = []any{ (*VerifyVersionedTransitionTaskAttributes)(nil), // 19: temporal.server.api.replication.v1.VerifyVersionedTransitionTaskAttributes (*SyncVersionedTransitionTaskAttributes)(nil), // 20: temporal.server.api.replication.v1.SyncVersionedTransitionTaskAttributes (*VersionedTransitionArtifact)(nil), // 21: temporal.server.api.replication.v1.VersionedTransitionArtifact - (v1.ReplicationTaskType)(0), // 22: temporal.server.api.enums.v1.ReplicationTaskType - (*v11.DataBlob)(nil), // 23: temporal.api.common.v1.DataBlob - (*timestamppb.Timestamp)(nil), // 24: google.protobuf.Timestamp - (v1.TaskPriority)(0), // 25: temporal.server.api.enums.v1.TaskPriority - (*v12.VersionedTransition)(nil), // 26: temporal.server.api.persistence.v1.VersionedTransition - (*v12.ReplicationTaskInfo)(nil), // 27: temporal.server.api.persistence.v1.ReplicationTaskInfo - (v1.ReplicationFlowControlCommand)(0), // 28: temporal.server.api.enums.v1.ReplicationFlowControlCommand - (v1.TaskType)(0), // 29: temporal.server.api.enums.v1.TaskType - (v1.NamespaceOperation)(0), // 30: temporal.server.api.enums.v1.NamespaceOperation - (*v13.NamespaceInfo)(nil), // 31: temporal.api.namespace.v1.NamespaceInfo - (*v13.NamespaceConfig)(nil), // 32: temporal.api.namespace.v1.NamespaceConfig - (*v14.NamespaceReplicationConfig)(nil), // 33: temporal.api.replication.v1.NamespaceReplicationConfig - (*v14.FailoverStatus)(nil), // 34: temporal.api.replication.v1.FailoverStatus - (*v11.Payloads)(nil), // 35: temporal.api.common.v1.Payloads - (*v15.Failure)(nil), // 36: temporal.api.failure.v1.Failure - (*v16.VersionHistory)(nil), // 37: temporal.server.api.history.v1.VersionHistory - (*v17.BaseExecutionInfo)(nil), // 38: temporal.server.api.workflow.v1.BaseExecutionInfo - (*durationpb.Duration)(nil), // 39: google.protobuf.Duration - (*v16.VersionHistoryItem)(nil), // 40: temporal.server.api.history.v1.VersionHistoryItem - (*v12.WorkflowMutableState)(nil), // 41: temporal.server.api.persistence.v1.WorkflowMutableState - (*v12.TaskQueueUserData)(nil), // 42: temporal.server.api.persistence.v1.TaskQueueUserData - (*v12.StateMachineNode)(nil), // 43: temporal.server.api.persistence.v1.StateMachineNode - (*v12.WorkflowMutableStateMutation)(nil), // 44: temporal.server.api.persistence.v1.WorkflowMutableStateMutation + (*MigrationExecutionInfo)(nil), // 22: temporal.server.api.replication.v1.MigrationExecutionInfo + (v1.ReplicationTaskType)(0), // 23: temporal.server.api.enums.v1.ReplicationTaskType + (*v11.DataBlob)(nil), // 24: temporal.api.common.v1.DataBlob + (*timestamppb.Timestamp)(nil), // 25: google.protobuf.Timestamp + (v1.TaskPriority)(0), // 26: temporal.server.api.enums.v1.TaskPriority + (*v12.VersionedTransition)(nil), // 27: temporal.server.api.persistence.v1.VersionedTransition + (*v12.ReplicationTaskInfo)(nil), // 28: temporal.server.api.persistence.v1.ReplicationTaskInfo + (v1.ReplicationFlowControlCommand)(0), // 29: temporal.server.api.enums.v1.ReplicationFlowControlCommand + (v1.TaskType)(0), // 30: temporal.server.api.enums.v1.TaskType + (v1.NamespaceOperation)(0), // 31: temporal.server.api.enums.v1.NamespaceOperation + (*v13.NamespaceInfo)(nil), // 32: temporal.api.namespace.v1.NamespaceInfo + (*v13.NamespaceConfig)(nil), // 33: temporal.api.namespace.v1.NamespaceConfig + (*v14.NamespaceReplicationConfig)(nil), // 34: temporal.api.replication.v1.NamespaceReplicationConfig + (*v14.FailoverStatus)(nil), // 35: temporal.api.replication.v1.FailoverStatus + (*v11.Payloads)(nil), // 36: temporal.api.common.v1.Payloads + (*v15.Failure)(nil), // 37: temporal.api.failure.v1.Failure + (*v16.VersionHistory)(nil), // 38: temporal.server.api.history.v1.VersionHistory + (*v17.BaseExecutionInfo)(nil), // 39: temporal.server.api.workflow.v1.BaseExecutionInfo + (*durationpb.Duration)(nil), // 40: google.protobuf.Duration + (*v16.VersionHistoryItem)(nil), // 41: temporal.server.api.history.v1.VersionHistoryItem + (*v12.WorkflowMutableState)(nil), // 42: temporal.server.api.persistence.v1.WorkflowMutableState + (*v12.TaskQueueUserData)(nil), // 43: temporal.server.api.persistence.v1.TaskQueueUserData + (*v12.StateMachineNode)(nil), // 44: temporal.server.api.persistence.v1.StateMachineNode + (*v12.WorkflowMutableStateMutation)(nil), // 45: temporal.server.api.persistence.v1.WorkflowMutableStateMutation } var file_temporal_server_api_replication_v1_message_proto_depIdxs = []int32{ - 22, // 0: temporal.server.api.replication.v1.ReplicationTask.task_type:type_name -> temporal.server.api.enums.v1.ReplicationTaskType + 23, // 0: temporal.server.api.replication.v1.ReplicationTask.task_type:type_name -> temporal.server.api.enums.v1.ReplicationTaskType 8, // 1: temporal.server.api.replication.v1.ReplicationTask.namespace_task_attributes:type_name -> temporal.server.api.replication.v1.NamespaceTaskAttributes 9, // 2: temporal.server.api.replication.v1.ReplicationTask.sync_shard_status_task_attributes:type_name -> temporal.server.api.replication.v1.SyncShardStatusTaskAttributes 10, // 3: temporal.server.api.replication.v1.ReplicationTask.sync_activity_task_attributes:type_name -> temporal.server.api.replication.v1.SyncActivityTaskAttributes @@ -2282,63 +2371,63 @@ var file_temporal_server_api_replication_v1_message_proto_depIdxs = []int32{ 15, // 8: temporal.server.api.replication.v1.ReplicationTask.backfill_history_task_attributes:type_name -> temporal.server.api.replication.v1.BackfillHistoryTaskAttributes 19, // 9: temporal.server.api.replication.v1.ReplicationTask.verify_versioned_transition_task_attributes:type_name -> temporal.server.api.replication.v1.VerifyVersionedTransitionTaskAttributes 20, // 10: temporal.server.api.replication.v1.ReplicationTask.sync_versioned_transition_task_attributes:type_name -> temporal.server.api.replication.v1.SyncVersionedTransitionTaskAttributes - 23, // 11: temporal.server.api.replication.v1.ReplicationTask.data:type_name -> temporal.api.common.v1.DataBlob - 24, // 12: temporal.server.api.replication.v1.ReplicationTask.visibility_time:type_name -> google.protobuf.Timestamp - 25, // 13: temporal.server.api.replication.v1.ReplicationTask.priority:type_name -> temporal.server.api.enums.v1.TaskPriority - 26, // 14: temporal.server.api.replication.v1.ReplicationTask.versioned_transition:type_name -> temporal.server.api.persistence.v1.VersionedTransition - 27, // 15: temporal.server.api.replication.v1.ReplicationTask.raw_task_info:type_name -> temporal.server.api.persistence.v1.ReplicationTaskInfo - 24, // 16: temporal.server.api.replication.v1.ReplicationToken.last_processed_visibility_time:type_name -> google.protobuf.Timestamp - 24, // 17: temporal.server.api.replication.v1.SyncShardStatus.status_time:type_name -> google.protobuf.Timestamp - 24, // 18: temporal.server.api.replication.v1.SyncReplicationState.inclusive_low_watermark_time:type_name -> google.protobuf.Timestamp + 24, // 11: temporal.server.api.replication.v1.ReplicationTask.data:type_name -> temporal.api.common.v1.DataBlob + 25, // 12: temporal.server.api.replication.v1.ReplicationTask.visibility_time:type_name -> google.protobuf.Timestamp + 26, // 13: temporal.server.api.replication.v1.ReplicationTask.priority:type_name -> temporal.server.api.enums.v1.TaskPriority + 27, // 14: temporal.server.api.replication.v1.ReplicationTask.versioned_transition:type_name -> temporal.server.api.persistence.v1.VersionedTransition + 28, // 15: temporal.server.api.replication.v1.ReplicationTask.raw_task_info:type_name -> temporal.server.api.persistence.v1.ReplicationTaskInfo + 25, // 16: temporal.server.api.replication.v1.ReplicationToken.last_processed_visibility_time:type_name -> google.protobuf.Timestamp + 25, // 17: temporal.server.api.replication.v1.SyncShardStatus.status_time:type_name -> google.protobuf.Timestamp + 25, // 18: temporal.server.api.replication.v1.SyncReplicationState.inclusive_low_watermark_time:type_name -> google.protobuf.Timestamp 4, // 19: temporal.server.api.replication.v1.SyncReplicationState.high_priority_state:type_name -> temporal.server.api.replication.v1.ReplicationState 4, // 20: temporal.server.api.replication.v1.SyncReplicationState.low_priority_state:type_name -> temporal.server.api.replication.v1.ReplicationState - 24, // 21: temporal.server.api.replication.v1.ReplicationState.inclusive_low_watermark_time:type_name -> google.protobuf.Timestamp - 28, // 22: temporal.server.api.replication.v1.ReplicationState.flow_control_command:type_name -> temporal.server.api.enums.v1.ReplicationFlowControlCommand + 25, // 21: temporal.server.api.replication.v1.ReplicationState.inclusive_low_watermark_time:type_name -> google.protobuf.Timestamp + 29, // 22: temporal.server.api.replication.v1.ReplicationState.flow_control_command:type_name -> temporal.server.api.enums.v1.ReplicationFlowControlCommand 0, // 23: temporal.server.api.replication.v1.ReplicationMessages.replication_tasks:type_name -> temporal.server.api.replication.v1.ReplicationTask 2, // 24: temporal.server.api.replication.v1.ReplicationMessages.sync_shard_status:type_name -> temporal.server.api.replication.v1.SyncShardStatus 0, // 25: temporal.server.api.replication.v1.WorkflowReplicationMessages.replication_tasks:type_name -> temporal.server.api.replication.v1.ReplicationTask - 24, // 26: temporal.server.api.replication.v1.WorkflowReplicationMessages.exclusive_high_watermark_time:type_name -> google.protobuf.Timestamp - 25, // 27: temporal.server.api.replication.v1.WorkflowReplicationMessages.priority:type_name -> temporal.server.api.enums.v1.TaskPriority - 29, // 28: temporal.server.api.replication.v1.ReplicationTaskInfo.task_type:type_name -> temporal.server.api.enums.v1.TaskType - 25, // 29: temporal.server.api.replication.v1.ReplicationTaskInfo.priority:type_name -> temporal.server.api.enums.v1.TaskPriority - 30, // 30: temporal.server.api.replication.v1.NamespaceTaskAttributes.namespace_operation:type_name -> temporal.server.api.enums.v1.NamespaceOperation - 31, // 31: temporal.server.api.replication.v1.NamespaceTaskAttributes.info:type_name -> temporal.api.namespace.v1.NamespaceInfo - 32, // 32: temporal.server.api.replication.v1.NamespaceTaskAttributes.config:type_name -> temporal.api.namespace.v1.NamespaceConfig - 33, // 33: temporal.server.api.replication.v1.NamespaceTaskAttributes.replication_config:type_name -> temporal.api.replication.v1.NamespaceReplicationConfig - 34, // 34: temporal.server.api.replication.v1.NamespaceTaskAttributes.failover_history:type_name -> temporal.api.replication.v1.FailoverStatus - 24, // 35: temporal.server.api.replication.v1.SyncShardStatusTaskAttributes.status_time:type_name -> google.protobuf.Timestamp - 24, // 36: temporal.server.api.replication.v1.SyncActivityTaskAttributes.scheduled_time:type_name -> google.protobuf.Timestamp - 24, // 37: temporal.server.api.replication.v1.SyncActivityTaskAttributes.started_time:type_name -> google.protobuf.Timestamp - 24, // 38: temporal.server.api.replication.v1.SyncActivityTaskAttributes.last_heartbeat_time:type_name -> google.protobuf.Timestamp - 35, // 39: temporal.server.api.replication.v1.SyncActivityTaskAttributes.details:type_name -> temporal.api.common.v1.Payloads - 36, // 40: temporal.server.api.replication.v1.SyncActivityTaskAttributes.last_failure:type_name -> temporal.api.failure.v1.Failure - 37, // 41: temporal.server.api.replication.v1.SyncActivityTaskAttributes.version_history:type_name -> temporal.server.api.history.v1.VersionHistory - 38, // 42: temporal.server.api.replication.v1.SyncActivityTaskAttributes.base_execution_info:type_name -> temporal.server.api.workflow.v1.BaseExecutionInfo - 24, // 43: temporal.server.api.replication.v1.SyncActivityTaskAttributes.first_scheduled_time:type_name -> google.protobuf.Timestamp - 24, // 44: temporal.server.api.replication.v1.SyncActivityTaskAttributes.last_attempt_complete_time:type_name -> google.protobuf.Timestamp - 39, // 45: temporal.server.api.replication.v1.SyncActivityTaskAttributes.retry_initial_interval:type_name -> google.protobuf.Duration - 39, // 46: temporal.server.api.replication.v1.SyncActivityTaskAttributes.retry_maximum_interval:type_name -> google.protobuf.Duration - 40, // 47: temporal.server.api.replication.v1.HistoryTaskAttributes.version_history_items:type_name -> temporal.server.api.history.v1.VersionHistoryItem - 23, // 48: temporal.server.api.replication.v1.HistoryTaskAttributes.events:type_name -> temporal.api.common.v1.DataBlob - 23, // 49: temporal.server.api.replication.v1.HistoryTaskAttributes.new_run_events:type_name -> temporal.api.common.v1.DataBlob - 38, // 50: temporal.server.api.replication.v1.HistoryTaskAttributes.base_execution_info:type_name -> temporal.server.api.workflow.v1.BaseExecutionInfo - 23, // 51: temporal.server.api.replication.v1.HistoryTaskAttributes.events_batches:type_name -> temporal.api.common.v1.DataBlob - 41, // 52: temporal.server.api.replication.v1.SyncWorkflowStateTaskAttributes.workflow_state:type_name -> temporal.server.api.persistence.v1.WorkflowMutableState - 42, // 53: temporal.server.api.replication.v1.TaskQueueUserDataAttributes.user_data:type_name -> temporal.server.api.persistence.v1.TaskQueueUserData - 37, // 54: temporal.server.api.replication.v1.SyncHSMAttributes.version_history:type_name -> temporal.server.api.history.v1.VersionHistory - 43, // 55: temporal.server.api.replication.v1.SyncHSMAttributes.state_machine_node:type_name -> temporal.server.api.persistence.v1.StateMachineNode - 40, // 56: temporal.server.api.replication.v1.BackfillHistoryTaskAttributes.event_version_history:type_name -> temporal.server.api.history.v1.VersionHistoryItem - 23, // 57: temporal.server.api.replication.v1.BackfillHistoryTaskAttributes.event_batches:type_name -> temporal.api.common.v1.DataBlob + 25, // 26: temporal.server.api.replication.v1.WorkflowReplicationMessages.exclusive_high_watermark_time:type_name -> google.protobuf.Timestamp + 26, // 27: temporal.server.api.replication.v1.WorkflowReplicationMessages.priority:type_name -> temporal.server.api.enums.v1.TaskPriority + 30, // 28: temporal.server.api.replication.v1.ReplicationTaskInfo.task_type:type_name -> temporal.server.api.enums.v1.TaskType + 26, // 29: temporal.server.api.replication.v1.ReplicationTaskInfo.priority:type_name -> temporal.server.api.enums.v1.TaskPriority + 31, // 30: temporal.server.api.replication.v1.NamespaceTaskAttributes.namespace_operation:type_name -> temporal.server.api.enums.v1.NamespaceOperation + 32, // 31: temporal.server.api.replication.v1.NamespaceTaskAttributes.info:type_name -> temporal.api.namespace.v1.NamespaceInfo + 33, // 32: temporal.server.api.replication.v1.NamespaceTaskAttributes.config:type_name -> temporal.api.namespace.v1.NamespaceConfig + 34, // 33: temporal.server.api.replication.v1.NamespaceTaskAttributes.replication_config:type_name -> temporal.api.replication.v1.NamespaceReplicationConfig + 35, // 34: temporal.server.api.replication.v1.NamespaceTaskAttributes.failover_history:type_name -> temporal.api.replication.v1.FailoverStatus + 25, // 35: temporal.server.api.replication.v1.SyncShardStatusTaskAttributes.status_time:type_name -> google.protobuf.Timestamp + 25, // 36: temporal.server.api.replication.v1.SyncActivityTaskAttributes.scheduled_time:type_name -> google.protobuf.Timestamp + 25, // 37: temporal.server.api.replication.v1.SyncActivityTaskAttributes.started_time:type_name -> google.protobuf.Timestamp + 25, // 38: temporal.server.api.replication.v1.SyncActivityTaskAttributes.last_heartbeat_time:type_name -> google.protobuf.Timestamp + 36, // 39: temporal.server.api.replication.v1.SyncActivityTaskAttributes.details:type_name -> temporal.api.common.v1.Payloads + 37, // 40: temporal.server.api.replication.v1.SyncActivityTaskAttributes.last_failure:type_name -> temporal.api.failure.v1.Failure + 38, // 41: temporal.server.api.replication.v1.SyncActivityTaskAttributes.version_history:type_name -> temporal.server.api.history.v1.VersionHistory + 39, // 42: temporal.server.api.replication.v1.SyncActivityTaskAttributes.base_execution_info:type_name -> temporal.server.api.workflow.v1.BaseExecutionInfo + 25, // 43: temporal.server.api.replication.v1.SyncActivityTaskAttributes.first_scheduled_time:type_name -> google.protobuf.Timestamp + 25, // 44: temporal.server.api.replication.v1.SyncActivityTaskAttributes.last_attempt_complete_time:type_name -> google.protobuf.Timestamp + 40, // 45: temporal.server.api.replication.v1.SyncActivityTaskAttributes.retry_initial_interval:type_name -> google.protobuf.Duration + 40, // 46: temporal.server.api.replication.v1.SyncActivityTaskAttributes.retry_maximum_interval:type_name -> google.protobuf.Duration + 41, // 47: temporal.server.api.replication.v1.HistoryTaskAttributes.version_history_items:type_name -> temporal.server.api.history.v1.VersionHistoryItem + 24, // 48: temporal.server.api.replication.v1.HistoryTaskAttributes.events:type_name -> temporal.api.common.v1.DataBlob + 24, // 49: temporal.server.api.replication.v1.HistoryTaskAttributes.new_run_events:type_name -> temporal.api.common.v1.DataBlob + 39, // 50: temporal.server.api.replication.v1.HistoryTaskAttributes.base_execution_info:type_name -> temporal.server.api.workflow.v1.BaseExecutionInfo + 24, // 51: temporal.server.api.replication.v1.HistoryTaskAttributes.events_batches:type_name -> temporal.api.common.v1.DataBlob + 42, // 52: temporal.server.api.replication.v1.SyncWorkflowStateTaskAttributes.workflow_state:type_name -> temporal.server.api.persistence.v1.WorkflowMutableState + 43, // 53: temporal.server.api.replication.v1.TaskQueueUserDataAttributes.user_data:type_name -> temporal.server.api.persistence.v1.TaskQueueUserData + 38, // 54: temporal.server.api.replication.v1.SyncHSMAttributes.version_history:type_name -> temporal.server.api.history.v1.VersionHistory + 44, // 55: temporal.server.api.replication.v1.SyncHSMAttributes.state_machine_node:type_name -> temporal.server.api.persistence.v1.StateMachineNode + 41, // 56: temporal.server.api.replication.v1.BackfillHistoryTaskAttributes.event_version_history:type_name -> temporal.server.api.history.v1.VersionHistoryItem + 24, // 57: temporal.server.api.replication.v1.BackfillHistoryTaskAttributes.event_batches:type_name -> temporal.api.common.v1.DataBlob 16, // 58: temporal.server.api.replication.v1.BackfillHistoryTaskAttributes.new_run_info:type_name -> temporal.server.api.replication.v1.NewRunInfo - 23, // 59: temporal.server.api.replication.v1.NewRunInfo.event_batch:type_name -> temporal.api.common.v1.DataBlob - 26, // 60: temporal.server.api.replication.v1.SyncWorkflowStateMutationAttributes.exclusive_start_versioned_transition:type_name -> temporal.server.api.persistence.v1.VersionedTransition - 44, // 61: temporal.server.api.replication.v1.SyncWorkflowStateMutationAttributes.state_mutation:type_name -> temporal.server.api.persistence.v1.WorkflowMutableStateMutation - 41, // 62: temporal.server.api.replication.v1.SyncWorkflowStateSnapshotAttributes.state:type_name -> temporal.server.api.persistence.v1.WorkflowMutableState - 40, // 63: temporal.server.api.replication.v1.VerifyVersionedTransitionTaskAttributes.event_version_history:type_name -> temporal.server.api.history.v1.VersionHistoryItem + 24, // 59: temporal.server.api.replication.v1.NewRunInfo.event_batch:type_name -> temporal.api.common.v1.DataBlob + 27, // 60: temporal.server.api.replication.v1.SyncWorkflowStateMutationAttributes.exclusive_start_versioned_transition:type_name -> temporal.server.api.persistence.v1.VersionedTransition + 45, // 61: temporal.server.api.replication.v1.SyncWorkflowStateMutationAttributes.state_mutation:type_name -> temporal.server.api.persistence.v1.WorkflowMutableStateMutation + 42, // 62: temporal.server.api.replication.v1.SyncWorkflowStateSnapshotAttributes.state:type_name -> temporal.server.api.persistence.v1.WorkflowMutableState + 41, // 63: temporal.server.api.replication.v1.VerifyVersionedTransitionTaskAttributes.event_version_history:type_name -> temporal.server.api.history.v1.VersionHistoryItem 21, // 64: temporal.server.api.replication.v1.SyncVersionedTransitionTaskAttributes.versioned_transition_artifact:type_name -> temporal.server.api.replication.v1.VersionedTransitionArtifact 17, // 65: temporal.server.api.replication.v1.VersionedTransitionArtifact.sync_workflow_state_mutation_attributes:type_name -> temporal.server.api.replication.v1.SyncWorkflowStateMutationAttributes 18, // 66: temporal.server.api.replication.v1.VersionedTransitionArtifact.sync_workflow_state_snapshot_attributes:type_name -> temporal.server.api.replication.v1.SyncWorkflowStateSnapshotAttributes - 23, // 67: temporal.server.api.replication.v1.VersionedTransitionArtifact.event_batches:type_name -> temporal.api.common.v1.DataBlob + 24, // 67: temporal.server.api.replication.v1.VersionedTransitionArtifact.event_batches:type_name -> temporal.api.common.v1.DataBlob 16, // 68: temporal.server.api.replication.v1.VersionedTransitionArtifact.new_run_info:type_name -> temporal.server.api.replication.v1.NewRunInfo 69, // [69:69] is the sub-list for method output_type 69, // [69:69] is the sub-list for method input_type @@ -2374,7 +2463,7 @@ func file_temporal_server_api_replication_v1_message_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_temporal_server_api_replication_v1_message_proto_rawDesc), len(file_temporal_server_api_replication_v1_message_proto_rawDesc)), NumEnums: 0, - NumMessages: 22, + NumMessages: 23, NumExtensions: 0, NumServices: 0, }, diff --git a/chasm/archetype.go b/chasm/archetype.go index 49c19842e39..c1dbfdbc5db 100644 --- a/chasm/archetype.go +++ b/chasm/archetype.go @@ -7,10 +7,6 @@ type Archetype = string type ArchetypeID = uint32 const ( - // ArchetypeAny is a special value that matches any archetype. - // TODO: deprecate this constant and always specify the actual archetypeID of the execution. - ArchetypeAny Archetype = "__any__" - // UnspecifiedArchetypeID is a reserved special ArchetypeID value indicating that the // ArchetypeID is not specified. // This typically happens when: diff --git a/chasm/lib/scheduler/library.go b/chasm/lib/scheduler/library.go index 4b7b4f23e68..56b7a2996a3 100644 --- a/chasm/lib/scheduler/library.go +++ b/chasm/lib/scheduler/library.go @@ -39,12 +39,12 @@ func NewLibrary( } func (l *Library) Name() string { - return "scheduler" + return chasm.SchedulerLibraryName } func (l *Library) Components() []*chasm.RegistrableComponent { return []*chasm.RegistrableComponent{ - chasm.NewRegistrableComponent[*Scheduler]("scheduler"), + chasm.NewRegistrableComponent[*Scheduler](chasm.SchedulerComponentName), chasm.NewRegistrableComponent[*Generator]("generator"), chasm.NewRegistrableComponent[*Invoker]("invoker"), chasm.NewRegistrableComponent[*Backfiller]("backfiller"), diff --git a/chasm/library.go b/chasm/library.go index 3f52aa13bf9..bdaa2a1e80b 100644 --- a/chasm/library.go +++ b/chasm/library.go @@ -2,7 +2,9 @@ package chasm -import "google.golang.org/grpc" +import ( + "google.golang.org/grpc" +) type ( Library interface { diff --git a/chasm/registry.go b/chasm/registry.go index f819958916c..268d762c953 100644 --- a/chasm/registry.go +++ b/chasm/registry.go @@ -81,6 +81,17 @@ func (r *Registry) ComponentFqnByID(id uint32) (string, bool) { return fqn, ok } +// ComponentIDByFqn converts fully qualified component type name to component type ID. +// This method should only be used by CHASM framework internal code, +// NOT CHASM library developers. +func (r *Registry) ComponentIDByFqn(fqn string) (uint32, bool) { + rc, ok := r.componentByType[fqn] + if !ok { + return 0, false + } + return rc.componentID, true +} + // ComponentIDFor converts registered component instance to component type ID. // This method should only be used by CHASM framework internal code, // NOT CHASM library developers. diff --git a/chasm/scheduler.go b/chasm/scheduler.go new file mode 100644 index 00000000000..4283e989c66 --- /dev/null +++ b/chasm/scheduler.go @@ -0,0 +1,14 @@ +package chasm + +// This file defines constants for Scheduler which is special to the CHASM framework +// because it shares the same ID space with Workflow for backwards compatibility reasons. + +const ( + SchedulerLibraryName = "scheduler" + SchedulerComponentName = "scheduler" +) + +var ( + SchedulerArchetype = Archetype(fullyQualifiedName(SchedulerLibraryName, SchedulerComponentName)) + SchedulerArchetypeID = ArchetypeID(generateTypeID(SchedulerArchetype)) +) diff --git a/chasm/tree.go b/chasm/tree.go index 084541767d0..88530e22c1a 100644 --- a/chasm/tree.go +++ b/chasm/tree.go @@ -261,6 +261,8 @@ func NewEmptyTree( // If serializedNodes is empty, it means that this new tree. // Initialize empty serializedNode. root.initSerializedNode(fieldTypeComponent) + // Default to Workflow archetype as empty tree is created for workflow as well. + root.serializedNode.Metadata.GetComponentAttributes().TypeId = WorkflowArchetypeID // Although both value and serializedNode.Data are nil, they are considered NOT synced // because value has no type and serializedNode does. // deserialize method should set value when called. @@ -1600,6 +1602,8 @@ func (n *Node) closeTransactionUpdateComponentTasks( taskOffset := int64(1) validateContext := NewContext(context.Background(), n) + archetypeID := n.ArchetypeID() + var firstPureTask *persistencespb.ChasmComponentAttributes_Task var firstPureTaskNode *Node @@ -1645,6 +1649,7 @@ func (n *Node) closeTransactionUpdateComponentTasks( node.closeTransactionGeneratePhysicalSideEffectTask( sideEffectTask, nodePath, + archetypeID, ) } @@ -1671,6 +1676,7 @@ func (n *Node) closeTransactionUpdateComponentTasks( return n.closeTransactionGeneratePhysicalPureTask( firstPureTask, firstPureTaskNode, + archetypeID, ) } @@ -1840,6 +1846,7 @@ func (n *Node) closeTransactionHandleNewTasks( func (n *Node) closeTransactionGeneratePhysicalSideEffectTask( sideEffectTask *persistencespb.ChasmComponentAttributes_Task, nodePath []string, + archetypeID ArchetypeID, ) { n.backend.AddTasks(&tasks.ChasmTask{ WorkflowKey: n.backend.GetWorkflowKey(), @@ -1852,6 +1859,7 @@ func (n *Node) closeTransactionGeneratePhysicalSideEffectTask( Path: nodePath, TypeId: sideEffectTask.TypeId, Data: sideEffectTask.Data, + ArchetypeId: archetypeID, }, }) sideEffectTask.PhysicalTaskStatus = physicalTaskStatusCreated @@ -1860,6 +1868,7 @@ func (n *Node) closeTransactionGeneratePhysicalSideEffectTask( func (n *Node) closeTransactionGeneratePhysicalPureTask( firstPureTask *persistencespb.ChasmComponentAttributes_Task, firstTaskNode *Node, + archetypeID ArchetypeID, ) error { if firstPureTask == nil { n.backend.DeleteCHASMPureTasks(tasks.MaximumKey.FireTime) @@ -1876,7 +1885,7 @@ func (n *Node) closeTransactionGeneratePhysicalPureTask( n.backend.AddTasks(&tasks.ChasmTaskPure{ WorkflowKey: n.backend.GetWorkflowKey(), VisibilityTimestamp: firstPureTaskScheduledTime, - Category: tasks.CategoryTimer, + ArchetypeID: archetypeID, }) // We need to persist the task status change as well, so add the node diff --git a/chasm/tree_test.go b/chasm/tree_test.go index 310be49a019..dffc8597b2a 100644 --- a/chasm/tree_test.go +++ b/chasm/tree_test.go @@ -2219,6 +2219,7 @@ func (s *nodeSuite) TestCloseTransaction_NewComponentTasks() { Path: rootPath, TypeId: testSideEffectTaskTypeID, Data: chasmTask.Info.GetData(), // This is tested by TestSerializeTask() + ArchetypeId: testComponentTypeID, }, chasmTask.Info) s.Len(rootAttr.PureTasks, 1) // Only one valid side effect task. @@ -2233,7 +2234,7 @@ func (s *nodeSuite) TestCloseTransaction_NewComponentTasks() { }, newPureTask) s.Len(s.nodeBackend.TasksByCategory[tasks.CategoryTimer], 1) chasmPureTask := s.nodeBackend.TasksByCategory[tasks.CategoryTimer][0].(*tasks.ChasmTaskPure) - s.Equal(tasks.CategoryTimer, chasmPureTask.Category) + s.Equal(tasks.CategoryTimer, chasmPureTask.GetCategory()) s.True(chasmPureTask.VisibilityTimestamp.Equal(s.timeSource.Now())) subComponent2Attr := mutation.UpdatedNodes["SubComponent2"].GetMetadata().GetComponentAttributes() @@ -2255,6 +2256,7 @@ func (s *nodeSuite) TestCloseTransaction_NewComponentTasks() { Path: []string{"SubComponent2"}, TypeId: testOutboundSideEffectTaskTypeID, Data: chasmTask.Info.GetData(), // This is tested by TestSerializeTask() + ArchetypeId: testComponentTypeID, }, chasmTask.Info) } diff --git a/common/log/tag/tags.go b/common/log/tag/tags.go index ed6f29e33d5..f8d1067dc98 100644 --- a/common/log/tag/tags.go +++ b/common/log/tag/tags.go @@ -85,6 +85,11 @@ func Archetype(archetype string) ZapTag { return NewStringTag("archetype", archetype) } +// ArchetypeID returns tag for Archetype +func ArchetypeID(archetype uint32) ZapTag { + return NewUInt32("archetype-id", archetype) +} + // WorkflowTimeoutType returns tag for WorkflowTimeoutType func WorkflowTimeoutType(timeoutType enumspb.TimeoutType) ZapTag { return NewStringerTag("wf-timeout-type", timeoutType) diff --git a/common/log/tag/zap_tag.go b/common/log/tag/zap_tag.go index 8a49bc89327..f54260f7e6e 100644 --- a/common/log/tag/zap_tag.go +++ b/common/log/tag/zap_tag.go @@ -99,6 +99,12 @@ func NewInt32(key string, value int32) ZapTag { } } +func NewUInt32(key string, value uint32) ZapTag { + return ZapTag{ + field: zap.Uint32(key, value), + } +} + func NewFloat64(key string, value float64) ZapTag { return ZapTag{ field: zap.Float64(key, value), diff --git a/common/persistence/client/persistence_rate_limited_clients_test.go b/common/persistence/client/persistence_rate_limited_clients_test.go index dfa2783d93b..a8c46be2db1 100644 --- a/common/persistence/client/persistence_rate_limited_clients_test.go +++ b/common/persistence/client/persistence_rate_limited_clients_test.go @@ -10,7 +10,10 @@ import ( "github.com/stretchr/testify/assert" enumspb "go.temporal.io/api/enums/v1" "go.temporal.io/api/serviceerror" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/config" + "go.temporal.io/server/common/log" + "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/client" "go.temporal.io/server/common/persistence/mock" @@ -164,8 +167,8 @@ func TestRateLimitedPersistenceClients(t *testing.T) { serialization.NewSerializer(), nil, "", - nil, - nil, + metrics.NoopMetricsHandler, + log.NewTestLogger(), nil, func() bool { return false }, func() bool { return false }, @@ -191,7 +194,9 @@ func TestRateLimitedPersistenceClients(t *testing.T) { { name: "DeleteWorkflowExecution", call: func() error { - return executionManager.DeleteWorkflowExecution(context.Background(), &persistence.DeleteWorkflowExecutionRequest{}) + return executionManager.DeleteWorkflowExecution(context.Background(), &persistence.DeleteWorkflowExecutionRequest{ + ArchetypeID: chasm.WorkflowArchetypeID, + }) }, }, { diff --git a/common/persistence/data_interfaces.go b/common/persistence/data_interfaces.go index c9137af2ee5..0055ec281a5 100644 --- a/common/persistence/data_interfaces.go +++ b/common/persistence/data_interfaces.go @@ -190,6 +190,7 @@ type ( NamespaceID string WorkflowID string + ArchetypeID chasm.ArchetypeID Tasks map[tasks.Category][]tasks.Task } @@ -204,6 +205,8 @@ type ( PreviousRunID string PreviousLastWriteVersion int64 + ArchetypeID chasm.ArchetypeID + NewWorkflowSnapshot WorkflowSnapshot NewWorkflowEvents []*WorkflowEvents } @@ -220,6 +223,8 @@ type ( Mode UpdateWorkflowMode + ArchetypeID chasm.ArchetypeID + UpdateWorkflowMutation WorkflowMutation UpdateWorkflowEvents []*WorkflowEvents NewWorkflowSnapshot *WorkflowSnapshot @@ -239,6 +244,8 @@ type ( Mode ConflictResolveWorkflowMode + ArchetypeID chasm.ArchetypeID + // workflow to be resetted ResetWorkflowSnapshot WorkflowSnapshot ResetWorkflowEvents []*WorkflowEvents @@ -263,6 +270,7 @@ type ( ShardID int32 NamespaceID string WorkflowID string + ArchetypeID chasm.ArchetypeID } // GetCurrentExecutionResponse is the response to GetCurrentExecution @@ -279,6 +287,7 @@ type ( NamespaceID string WorkflowID string RunID string + ArchetypeID chasm.ArchetypeID } // GetWorkflowExecutionResponse is the response to GetWorkflowExecutionRequest @@ -293,6 +302,8 @@ type ( ShardID int32 RangeID int64 + ArchetypeID chasm.ArchetypeID + SetWorkflowSnapshot WorkflowSnapshot } @@ -386,6 +397,7 @@ type ( NamespaceID string WorkflowID string RunID string + ArchetypeID chasm.ArchetypeID } // DeleteCurrentWorkflowExecutionRequest is used to delete the current workflow execution @@ -394,6 +406,7 @@ type ( NamespaceID string WorkflowID string RunID string + ArchetypeID chasm.ArchetypeID } // GetHistoryTasksRequest is used to get a range of history tasks diff --git a/common/persistence/execution_manager.go b/common/persistence/execution_manager.go index dc5c1792320..bfb42bc988d 100644 --- a/common/persistence/execution_manager.go +++ b/common/persistence/execution_manager.go @@ -3,6 +3,7 @@ package persistence import ( "context" "errors" + "runtime/debug" "strings" commonpb "go.temporal.io/api/common/v1" @@ -11,6 +12,7 @@ import ( workflowpb "go.temporal.io/api/workflow/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" @@ -19,6 +21,7 @@ import ( "go.temporal.io/server/common/persistence/serialization" "go.temporal.io/server/common/persistence/transitionhistory" "go.temporal.io/server/common/persistence/versionhistory" + "go.temporal.io/server/common/softassert" "go.temporal.io/server/service/history/tasks" ) @@ -103,12 +106,14 @@ func (m *executionManagerImpl) CreateWorkflowExecution( return nil, err } + archetypeID, _ := m.assertAndConvertArchetypeID(request.ArchetypeID, "CreateWorkflowExecution") newRequest := &InternalCreateWorkflowExecutionRequest{ ShardID: request.ShardID, RangeID: request.RangeID, Mode: request.Mode, PreviousRunID: request.PreviousRunID, PreviousLastWriteVersion: request.PreviousLastWriteVersion, + ArchetypeID: archetypeID, NewWorkflowSnapshot: *serializedNewWorkflowSnapshot, NewWorkflowNewEvents: newWorkflowNewEvents, } @@ -186,12 +191,15 @@ func (m *executionManagerImpl) UpdateWorkflowExecution( } } + archetypeID, _ := m.assertAndConvertArchetypeID(request.ArchetypeID, "UpdateWorkflowExecution") newRequest := &InternalUpdateWorkflowExecutionRequest{ ShardID: request.ShardID, RangeID: request.RangeID, Mode: request.Mode, + ArchetypeID: archetypeID, + UpdateWorkflowMutation: *serializedWorkflowMutation, UpdateWorkflowNewEvents: updateWorkflowNewEvents, NewWorkflowSnapshot: serializedNewWorkflowSnapshot, @@ -223,6 +231,7 @@ func (m *executionManagerImpl) UpdateWorkflowExecution( updateMutation.ExecutionInfo.NamespaceId, updateMutation.ExecutionInfo.WorkflowId, updateMutation.ExecutionState.RunId, + archetypeID, ) return nil, err default: @@ -342,12 +351,15 @@ func (m *executionManagerImpl) ConflictResolveWorkflowExecution( } } + archetypeID, _ := m.assertAndConvertArchetypeID(request.ArchetypeID, "ConflictResolveWorkflowExecution") newRequest := &InternalConflictResolveWorkflowExecutionRequest{ ShardID: request.ShardID, RangeID: request.RangeID, Mode: request.Mode, + ArchetypeID: archetypeID, + ResetWorkflowSnapshot: *serializedResetWorkflowSnapshot, ResetWorkflowEventsNewEvents: resetWorkflowEvents, @@ -387,6 +399,7 @@ func (m *executionManagerImpl) ConflictResolveWorkflowExecution( resetSnapshot.ExecutionInfo.NamespaceId, resetSnapshot.ExecutionInfo.WorkflowId, resetSnapshot.ExecutionState.RunId, + archetypeID, ) if currentMutation != nil { m.trimHistoryNode( @@ -395,6 +408,7 @@ func (m *executionManagerImpl) ConflictResolveWorkflowExecution( currentMutation.ExecutionInfo.NamespaceId, currentMutation.ExecutionInfo.WorkflowId, currentMutation.ExecutionState.RunId, + archetypeID, ) } return nil, err @@ -407,6 +421,15 @@ func (m *executionManagerImpl) GetWorkflowExecution( ctx context.Context, request *GetWorkflowExecutionRequest, ) (*GetWorkflowExecutionResponse, error) { + if archetypeID, converted := m.assertAndConvertArchetypeID(request.ArchetypeID, "GetWorkflowExecution"); converted { + request = &GetWorkflowExecutionRequest{ + ShardID: request.ShardID, + NamespaceID: request.NamespaceID, + WorkflowID: request.WorkflowID, + RunID: request.RunID, + ArchetypeID: archetypeID, + } + } response, respErr := m.persistence.GetWorkflowExecution(ctx, request) var notFound *serviceerror.NotFound @@ -446,10 +469,13 @@ func (m *executionManagerImpl) SetWorkflowExecution( return nil, err } + archetypeID, _ := m.assertAndConvertArchetypeID(request.ArchetypeID, "SetWorkflowExecution") newRequest := &InternalSetWorkflowExecutionRequest{ ShardID: request.ShardID, RangeID: request.RangeID, + ArchetypeID: archetypeID, + SetWorkflowSnapshot: *serializedWorkflowSnapshot, } @@ -461,7 +487,7 @@ func (m *executionManagerImpl) SetWorkflowExecution( } func (m *executionManagerImpl) serializeWorkflowEventBatches( - ctx context.Context, + _ context.Context, shardID int32, executionInfo *persistencespb.WorkflowExecutionInfo, eventBatches []*WorkflowEvents, @@ -783,6 +809,16 @@ func (m *executionManagerImpl) DeleteWorkflowExecution( ctx context.Context, request *DeleteWorkflowExecutionRequest, ) error { + if archetypeID, converted := m.assertAndConvertArchetypeID(request.ArchetypeID, "DeleteWorkflowExecution"); converted { + request = &DeleteWorkflowExecutionRequest{ + ShardID: request.ShardID, + NamespaceID: request.NamespaceID, + WorkflowID: request.WorkflowID, + RunID: request.RunID, + ArchetypeID: archetypeID, + } + } + return m.persistence.DeleteWorkflowExecution(ctx, request) } @@ -790,6 +826,16 @@ func (m *executionManagerImpl) DeleteCurrentWorkflowExecution( ctx context.Context, request *DeleteCurrentWorkflowExecutionRequest, ) error { + if archetypeID, converted := m.assertAndConvertArchetypeID(request.ArchetypeID, "DeleteCurrentWorkflowExecution"); converted { + request = &DeleteCurrentWorkflowExecutionRequest{ + ShardID: request.ShardID, + NamespaceID: request.NamespaceID, + WorkflowID: request.WorkflowID, + RunID: request.RunID, + ArchetypeID: archetypeID, + } + } + return m.persistence.DeleteCurrentWorkflowExecution(ctx, request) } @@ -797,6 +843,15 @@ func (m *executionManagerImpl) GetCurrentExecution( ctx context.Context, request *GetCurrentExecutionRequest, ) (*GetCurrentExecutionResponse, error) { + if archetypeID, converted := m.assertAndConvertArchetypeID(request.ArchetypeID, "GetCurrentExecution"); converted { + request = &GetCurrentExecutionRequest{ + ShardID: request.ShardID, + NamespaceID: request.NamespaceID, + WorkflowID: request.WorkflowID, + ArchetypeID: archetypeID, + } + } + response, respErr := m.persistence.GetCurrentExecution(ctx, request) var notFound *serviceerror.NotFound @@ -848,12 +903,14 @@ func (m *executionManagerImpl) AddHistoryTasks( return err } + archetypeID, _ := m.assertAndConvertArchetypeID(input.ArchetypeID, "AddHistoryTasks") return m.persistence.AddHistoryTasks(ctx, &InternalAddHistoryTasksRequest{ ShardID: input.ShardID, RangeID: input.RangeID, NamespaceID: input.NamespaceID, WorkflowID: input.WorkflowID, + ArchetypeID: archetypeID, Tasks: tasks, }) @@ -989,12 +1046,14 @@ func (m *executionManagerImpl) trimHistoryNode( namespaceID string, workflowID string, runID string, + archetypeID chasm.ArchetypeID, ) { response, err := m.GetWorkflowExecution(ctx, &GetWorkflowExecutionRequest{ ShardID: shardID, NamespaceID: namespaceID, WorkflowID: workflowID, RunID: runID, + ArchetypeID: archetypeID, }) if err != nil { m.logger.Error("ExecutionManager unable to get mutable state for trimming history branch", @@ -1119,6 +1178,28 @@ func (m *executionManagerImpl) toWorkflowMutableState(internState *InternalWorkf return state, nil } +func (m *executionManagerImpl) assertAndConvertArchetypeID( + archetypeID chasm.ArchetypeID, + methodName string, +) (chasm.ArchetypeID, bool) { + if !softassert.That( + m.logger, + archetypeID != chasm.UnspecifiedArchetypeID, + "ArchetypeID not specified, defaulting to Workflow.", + tag.Operation(methodName), + tag.SysStackTrace(string(debug.Stack())), + ) { + return chasm.WorkflowArchetypeID, true + } + + // This is a temporary exception to allow Schedules run in the same ID space as workflows. + if archetypeID == chasm.SchedulerArchetypeID { + return chasm.WorkflowArchetypeID, true + } + + return archetypeID, false +} + func getCurrentBranchToken( versionHistories *historyspb.VersionHistories, ) ([]byte, error) { diff --git a/common/persistence/execution_manager_test.go b/common/persistence/execution_manager_test.go index 5989eef93a5..b6918af9274 100644 --- a/common/persistence/execution_manager_test.go +++ b/common/persistence/execution_manager_test.go @@ -9,6 +9,7 @@ import ( "go.temporal.io/api/serviceerror" enumsspb "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" p "go.temporal.io/server/common/persistence" @@ -23,9 +24,10 @@ func newTestUpdateRequest(keys []tasks.Key) *p.UpdateWorkflowExecutionRequest { tasks.CategoryTimer: keys, } return &p.UpdateWorkflowExecutionRequest{ - ShardID: 1, - RangeID: 1, - Mode: p.UpdateWorkflowModeUpdateCurrent, + ShardID: 1, + RangeID: 1, + Mode: p.UpdateWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, UpdateWorkflowMutation: p.WorkflowMutation{ ExecutionInfo: &persistencespb.WorkflowExecutionInfo{NamespaceId: "ns", WorkflowId: "wid", ExecutionStats: &persistencespb.ExecutionStats{}}, ExecutionState: &persistencespb.WorkflowExecutionState{RunId: "rid", State: enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, Status: enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING}, diff --git a/common/persistence/history_branch_util.go b/common/persistence/history_branch_util.go index 48814988067..a30907455e0 100644 --- a/common/persistence/history_branch_util.go +++ b/common/persistence/history_branch_util.go @@ -8,6 +8,7 @@ import ( commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/persistence/serialization" "go.temporal.io/server/common/primitives" ) @@ -18,6 +19,7 @@ type ( namespaceID string, workflowID string, runID string, + archetypeID chasm.ArchetypeID, treeID string, branchID *string, ancestors []*persistencespb.HistoryBranchRange, @@ -45,6 +47,7 @@ func (u *HistoryBranchUtilImpl) NewHistoryBranch( _ string, // namespaceID _ string, // workflowID _ string, // runID + _ chasm.ArchetypeID, treeID string, branchID *string, ancestors []*persistencespb.HistoryBranchRange, diff --git a/common/persistence/history_branch_util_mock.go b/common/persistence/history_branch_util_mock.go index fb4572acdb1..4298c927a06 100644 --- a/common/persistence/history_branch_util_mock.go +++ b/common/persistence/history_branch_util_mock.go @@ -14,6 +14,7 @@ import ( time "time" persistence "go.temporal.io/server/api/persistence/v1" + chasm "go.temporal.io/server/chasm" gomock "go.uber.org/mock/gomock" ) @@ -42,18 +43,18 @@ func (m *MockHistoryBranchUtil) EXPECT() *MockHistoryBranchUtilMockRecorder { } // NewHistoryBranch mocks base method. -func (m *MockHistoryBranchUtil) NewHistoryBranch(namespaceID, workflowID, runID, treeID string, branchID *string, ancestors []*persistence.HistoryBranchRange, runTimeout, executionTimeout, retentionDuration time.Duration) ([]byte, error) { +func (m *MockHistoryBranchUtil) NewHistoryBranch(namespaceID, workflowID, runID string, archetypeID chasm.ArchetypeID, treeID string, branchID *string, ancestors []*persistence.HistoryBranchRange, runTimeout, executionTimeout, retentionDuration time.Duration) ([]byte, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewHistoryBranch", namespaceID, workflowID, runID, treeID, branchID, ancestors, runTimeout, executionTimeout, retentionDuration) + ret := m.ctrl.Call(m, "NewHistoryBranch", namespaceID, workflowID, runID, archetypeID, treeID, branchID, ancestors, runTimeout, executionTimeout, retentionDuration) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } // NewHistoryBranch indicates an expected call of NewHistoryBranch. -func (mr *MockHistoryBranchUtilMockRecorder) NewHistoryBranch(namespaceID, workflowID, runID, treeID, branchID, ancestors, runTimeout, executionTimeout, retentionDuration any) *gomock.Call { +func (mr *MockHistoryBranchUtilMockRecorder) NewHistoryBranch(namespaceID, workflowID, runID, archetypeID, treeID, branchID, ancestors, runTimeout, executionTimeout, retentionDuration any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewHistoryBranch", reflect.TypeOf((*MockHistoryBranchUtil)(nil).NewHistoryBranch), namespaceID, workflowID, runID, treeID, branchID, ancestors, runTimeout, executionTimeout, retentionDuration) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewHistoryBranch", reflect.TypeOf((*MockHistoryBranchUtil)(nil).NewHistoryBranch), namespaceID, workflowID, runID, archetypeID, treeID, branchID, ancestors, runTimeout, executionTimeout, retentionDuration) } // ParseHistoryBranchInfo mocks base method. diff --git a/common/persistence/history_branch_util_test.go b/common/persistence/history_branch_util_test.go index 23f2701b043..4f74635e4ee 100644 --- a/common/persistence/history_branch_util_test.go +++ b/common/persistence/history_branch_util_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/primitives" ) @@ -44,6 +45,7 @@ func (s *historyBranchUtilSuite) TestHistoryBranchUtil() { primitives.NewUUID().String(), primitives.NewUUID().String(), primitives.NewUUID().String(), + chasm.WorkflowArchetypeID, treeID0, &branchID0, ancestors, diff --git a/common/persistence/persistence-tests/history_v2_persistence.go b/common/persistence/persistence-tests/history_v2_persistence.go index 52168801851..a1160f349a4 100644 --- a/common/persistence/persistence-tests/history_v2_persistence.go +++ b/common/persistence/persistence-tests/history_v2_persistence.go @@ -12,6 +12,7 @@ import ( historypb "go.temporal.io/api/history/v1" "go.temporal.io/api/serviceerror" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/debug" p "go.temporal.io/server/common/persistence" @@ -684,6 +685,7 @@ func (s *HistoryV2PersistenceSuite) newHistoryBranch(treeID string) ([]byte, err uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, nil, []*persistencespb.HistoryBranchRange{}, diff --git a/common/persistence/persistence_interface.go b/common/persistence/persistence_interface.go index af109b7b41a..256395d9c51 100644 --- a/common/persistence/persistence_interface.go +++ b/common/persistence/persistence_interface.go @@ -10,6 +10,7 @@ import ( commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/service/history/tasks" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -341,6 +342,8 @@ type ( PreviousRunID string PreviousLastWriteVersion int64 + ArchetypeID chasm.ArchetypeID + NewWorkflowSnapshot InternalWorkflowSnapshot NewWorkflowNewEvents []*InternalAppendHistoryNodesRequest `json:",omitempty"` } @@ -356,6 +359,8 @@ type ( Mode UpdateWorkflowMode + ArchetypeID chasm.ArchetypeID + UpdateWorkflowMutation InternalWorkflowMutation UpdateWorkflowNewEvents []*InternalAppendHistoryNodesRequest `json:",omitempty"` NewWorkflowSnapshot *InternalWorkflowSnapshot @@ -369,6 +374,8 @@ type ( Mode ConflictResolveWorkflowMode + ArchetypeID chasm.ArchetypeID + // workflow to be resetted ResetWorkflowSnapshot InternalWorkflowSnapshot ResetWorkflowEventsNewEvents []*InternalAppendHistoryNodesRequest `json:",omitempty"` @@ -384,6 +391,8 @@ type ( ShardID int32 RangeID int64 + ArchetypeID chasm.ArchetypeID + SetWorkflowSnapshot InternalWorkflowSnapshot } @@ -416,6 +425,7 @@ type ( NamespaceID string WorkflowID string + ArchetypeID chasm.ArchetypeID Tasks map[tasks.Category][]InternalHistoryTask `json:",omitempty"` } diff --git a/common/persistence/serialization/task_serializer.go b/common/persistence/serialization/task_serializer.go index f197bc55dd1..47aed423040 100644 --- a/common/persistence/serialization/task_serializer.go +++ b/common/persistence/serialization/task_serializer.go @@ -200,6 +200,11 @@ func (s *TaskSerializer) timerChasmPureTaskToProto(task *tasks.ChasmTaskPure) *p TaskId: task.TaskID, VisibilityTime: timestamppb.New(task.VisibilityTimestamp), TaskType: task.GetType(), + TaskDetails: &persistencespb.TimerTaskInfo_ChasmTaskInfo{ + ChasmTaskInfo: &persistencespb.ChasmTaskInfo{ + ArchetypeId: task.ArchetypeID, + }, + }, } } @@ -278,7 +283,7 @@ func (s *TaskSerializer) timerChasmPureTaskFromProto(info *persistencespb.TimerT ), VisibilityTimestamp: info.VisibilityTime.AsTime(), TaskID: info.TaskId, - Category: tasks.CategoryTimer, + ArchetypeID: info.GetChasmTaskInfo().GetArchetypeId(), } } @@ -704,6 +709,11 @@ func (s *TaskSerializer) transferDeleteExecutionTaskToProto( TaskType: enumsspb.TASK_TYPE_TRANSFER_DELETE_EXECUTION, TaskId: deleteExecutionTask.TaskID, VisibilityTime: timestamppb.New(deleteExecutionTask.VisibilityTimestamp), + TaskDetails: &persistencespb.TransferTaskInfo_ChasmTaskInfo{ + ChasmTaskInfo: &persistencespb.ChasmTaskInfo{ + ArchetypeId: deleteExecutionTask.ArchetypeID, + }, + }, } } @@ -718,6 +728,7 @@ func (s *TaskSerializer) transferDeleteExecutionTaskFromProto( ), VisibilityTimestamp: deleteExecutionTask.VisibilityTime.AsTime(), TaskID: deleteExecutionTask.TaskId, + ArchetypeID: deleteExecutionTask.GetChasmTaskInfo().GetArchetypeId(), // Delete workflow task process stage is not persisted. It is only for in memory retries. ProcessStage: tasks.DeleteWorkflowExecutionStageNone, } @@ -983,6 +994,11 @@ func (s *TaskSerializer) timerWorkflowCleanupTaskToProto( // We set this to true even though it's no longer checked in case someone downgrades to a version that still // checks this field. AlreadyArchived: true, + TaskDetails: &persistencespb.TimerTaskInfo_ChasmTaskInfo{ + ChasmTaskInfo: &persistencespb.ChasmTaskInfo{ + ArchetypeId: workflowCleanupTimer.ArchetypeID, + }, + }, } } @@ -1011,6 +1027,7 @@ func (s *TaskSerializer) timerWorkflowCleanupTaskFromProto( TaskID: workflowCleanupTimer.TaskId, Version: workflowCleanupTimer.Version, BranchToken: workflowCleanupTimer.BranchToken, + ArchetypeID: workflowCleanupTimer.GetChasmTaskInfo().GetArchetypeId(), // Delete workflow task process stage is not persisted. It is only for in memory retries. ProcessStage: tasks.DeleteWorkflowExecutionStageNone, } @@ -1126,6 +1143,11 @@ func (s *TaskSerializer) visibilityDeleteTaskToProto( VisibilityTime: timestamppb.New(deleteVisibilityTask.VisibilityTimestamp), CloseVisibilityTaskId: deleteVisibilityTask.CloseExecutionVisibilityTaskID, CloseTime: timestamppb.New(deleteVisibilityTask.CloseTime), + TaskDetails: &persistencespb.VisibilityTaskInfo_ChasmTaskInfo{ + ChasmTaskInfo: &persistencespb.ChasmTaskInfo{ + ArchetypeId: deleteVisibilityTask.ArchetypeID, + }, + }, } } @@ -1140,6 +1162,7 @@ func (s *TaskSerializer) visibilityDeleteTaskFromProto( ), VisibilityTimestamp: deleteVisibilityTask.VisibilityTime.AsTime(), TaskID: deleteVisibilityTask.TaskId, + ArchetypeID: deleteVisibilityTask.GetChasmTaskInfo().GetArchetypeId(), CloseExecutionVisibilityTaskID: deleteVisibilityTask.CloseVisibilityTaskId, CloseTime: deleteVisibilityTask.CloseTime.AsTime(), } @@ -1384,6 +1407,7 @@ func (s *TaskSerializer) replicationSyncVersionedTransitionTaskToProto( TaskType: enumsspb.TASK_TYPE_REPLICATION_SYNC_VERSIONED_TRANSITION, TaskId: syncVersionedTransitionTask.TaskID, VisibilityTime: timestamppb.New(syncVersionedTransitionTask.VisibilityTimestamp), + ArchetypeId: syncVersionedTransitionTask.ArchetypeID, VersionedTransition: syncVersionedTransitionTask.VersionedTransition, FirstEventId: syncVersionedTransitionTask.FirstEventID, Version: syncVersionedTransitionTask.FirstEventVersion, @@ -1422,6 +1446,7 @@ func (s *TaskSerializer) replicationSyncVersionedTransitionTaskFromProto( ), VisibilityTimestamp: visibilityTimestamp, TaskID: syncVersionedTransitionTask.TaskId, + ArchetypeID: syncVersionedTransitionTask.ArchetypeId, FirstEventID: syncVersionedTransitionTask.FirstEventId, FirstEventVersion: syncVersionedTransitionTask.Version, NextEventID: syncVersionedTransitionTask.NextEventId, diff --git a/common/persistence/serialization/task_serializer_test.go b/common/persistence/serialization/task_serializer_test.go index 6b5bd2c96b1..799749a0da8 100644 --- a/common/persistence/serialization/task_serializer_test.go +++ b/common/persistence/serialization/task_serializer_test.go @@ -141,6 +141,7 @@ func (s *taskSerializerSuite) TestTransferChasmTask() { Data: &commonpb.DataBlob{ Data: []byte("some-data"), }, + ArchetypeId: rand.Uint32(), }, } @@ -261,6 +262,7 @@ func (s *taskSerializerSuite) TestTimerWorkflowCleanupTask() { TaskID: rand.Int63(), Version: rand.Int63(), BranchToken: []byte{123}, + ArchetypeID: rand.Uint32(), } s.assertEqualTasks(workflowCleanupTimer) } @@ -297,15 +299,17 @@ func (s *taskSerializerSuite) TestVisibilityCloseTask() { s.assertEqualTasks(visibilityClose) } -func (s *taskSerializerSuite) TestVisibilityDeleteTask() { - visibilityDelete := &tasks.CloseExecutionVisibilityTask{ - WorkflowKey: s.workflowKey, - VisibilityTimestamp: time.Unix(0, rand.Int63()).UTC(), - TaskID: rand.Int63(), - Version: rand.Int63(), +func (s *taskSerializerSuite) TestDeleteExecutionVisibilityTask() { + deleteExecutionVisibilityTask := &tasks.DeleteExecutionVisibilityTask{ + WorkflowKey: s.workflowKey, + VisibilityTimestamp: time.Unix(0, 0).UTC(), // go == compare for location as well which is striped during marshaling/unmarshaling + TaskID: rand.Int63(), + ArchetypeID: rand.Uint32(), + CloseExecutionVisibilityTaskID: rand.Int63(), + CloseTime: time.Unix(0, 0).UTC(), } - s.assertEqualTasks(visibilityDelete) + s.assertEqualTasks(deleteExecutionVisibilityTask) } func (s *taskSerializerSuite) TestVisibilityChasmTask() { @@ -318,6 +322,7 @@ func (s *taskSerializerSuite) TestVisibilityChasmTask() { Data: &commonpb.DataBlob{ Data: []byte("some-data"), }, + ArchetypeId: rand.Uint32(), }, } @@ -366,6 +371,7 @@ func (s *taskSerializerSuite) TestSyncVersionedTransitionTask() { WorkflowKey: s.workflowKey, VisibilityTimestamp: time.Unix(0, 0).UTC(), // go == compare for location as well which is striped during marshaling/unmarshaling TaskID: rand.Int63(), + ArchetypeID: rand.Uint32(), FirstEventID: rand.Int63(), NextEventID: rand.Int63(), NewRunID: uuid.New().String(), @@ -405,23 +411,12 @@ func (s *taskSerializerSuite) TestSyncWorkflowStateTask() { s.assertEqualTasks(syncWorkflowStateTask) } -func (s *taskSerializerSuite) TestDeleteExecutionVisibilityTask() { - deleteExecutionVisibilityTask := &tasks.DeleteExecutionVisibilityTask{ - WorkflowKey: s.workflowKey, - VisibilityTimestamp: time.Unix(0, 0).UTC(), // go == compare for location as well which is striped during marshaling/unmarshaling - TaskID: rand.Int63(), - CloseExecutionVisibilityTaskID: rand.Int63(), - CloseTime: time.Unix(0, 0).UTC(), - } - - s.assertEqualTasks(deleteExecutionVisibilityTask) -} - func (s *taskSerializerSuite) TestDeleteExecutionTask() { deleteExecutionTask := &tasks.DeleteExecutionTask{ WorkflowKey: s.workflowKey, VisibilityTimestamp: time.Unix(0, 0).UTC(), // go == compare for location as well which is striped during marshaling/unmarshaling TaskID: rand.Int63(), + ArchetypeID: rand.Uint32(), } s.assertEqualTasks(deleteExecutionTask) @@ -450,6 +445,7 @@ func (s *taskSerializerSuite) TestOutboundChasmTask() { Data: &commonpb.DataBlob{ Data: []byte("some-data"), }, + ArchetypeId: rand.Uint32(), }, Destination: "somewhere", } @@ -517,6 +513,7 @@ func (s *taskSerializerSuite) TestTimerChasmTask() { Data: &commonpb.DataBlob{ Data: []byte("some-data"), }, + ArchetypeId: rand.Uint32(), }, } @@ -528,7 +525,7 @@ func (s *taskSerializerSuite) TestTimerChasmPureTask() { WorkflowKey: s.workflowKey, VisibilityTimestamp: time.Unix(0, rand.Int63()).UTC(), TaskID: rand.Int63(), - Category: tasks.CategoryTimer, + ArchetypeID: rand.Uint32(), } s.assertEqualTasks(task) diff --git a/common/persistence/tests/execution_mutable_state.go b/common/persistence/tests/execution_mutable_state.go index 316ae7766a3..14938aa805c 100644 --- a/common/persistence/tests/execution_mutable_state.go +++ b/common/persistence/tests/execution_mutable_state.go @@ -17,6 +17,7 @@ import ( "go.temporal.io/api/serviceerror" enumsspb "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/convert" "go.temporal.io/server/common/debug" @@ -124,20 +125,22 @@ func (s *ExecutionMutableStateSuite) TestCreate_BrandNew() { rand.Int63(), ) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, newEvents) } func (s *ExecutionMutableStateSuite) TestCreate_BrandNew_CHASM() { // CHASM snapshot has no events and empty current version history. + archetypeID := rand.Uint32() newSnapshot := s.CreateCHASMSnapshot( rand.Int63(), enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING, rand.Int63(), + archetypeID, ) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(archetypeID, newSnapshot) } func (s *ExecutionMutableStateSuite) TestCreate_BrandNew_CurrentConflict() { @@ -161,6 +164,8 @@ func (s *ExecutionMutableStateSuite) TestCreate_BrandNew_CurrentConflict() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) @@ -179,7 +184,7 @@ func (s *ExecutionMutableStateSuite) TestCreate_BrandNew_CurrentConflict() { // Restore origin execution stats so GetWorkflowExecution matches with the pre-failed snapshot stats above newSnapshot.ExecutionInfo.ExecutionStats = executionStats - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, newEvents) } @@ -215,23 +220,27 @@ func (s *ExecutionMutableStateSuite) TestCreate_Reuse() { PreviousRunID: prevSnapshot.ExecutionState.RunId, PreviousLastWriteVersion: prevLastWriteVersion, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(newBranchToken, newEvents) } func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CHASM() { // CHASM snapshot has no events and empty current version history. prevLastWriteVersion := rand.Int63() + archetypeID := rand.Uint32() prevSnapshot := s.CreateCHASMSnapshot( prevLastWriteVersion, enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED, rand.Int63(), + archetypeID, ) newRunID := uuid.New().String() @@ -257,12 +266,14 @@ func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CHASM() { PreviousRunID: prevSnapshot.ExecutionState.RunId, PreviousLastWriteVersion: prevLastWriteVersion, + ArchetypeID: archetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(archetypeID, newSnapshot) } func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CurrentConflict() { @@ -286,6 +297,8 @@ func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CurrentConflict() { PreviousRunID: uuid.New().String(), PreviousLastWriteVersion: rand.Int63(), + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *prevSnapshot, NewWorkflowEvents: prevEvents, }) @@ -304,7 +317,7 @@ func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CurrentConflict() { // Restore origin execution stats so GetWorkflowExecution matches with the pre-failed snapshot stats above prevSnapshot.ExecutionInfo.ExecutionStats = executionStats - s.AssertMSEqualWithDB(prevSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, prevSnapshot) s.AssertHEEqualWithDB(branchToken, prevEvents) } @@ -340,12 +353,14 @@ func (s *ExecutionMutableStateSuite) TestCreate_Zombie() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(newBranchToken, newEvents) } @@ -366,6 +381,8 @@ func (s *ExecutionMutableStateSuite) TestCreate_Conflict() { PreviousRunID: newSnapshot.ExecutionState.RunId, PreviousLastWriteVersion: lastWriteVersion, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) @@ -380,7 +397,7 @@ func (s *ExecutionMutableStateSuite) TestCreate_ClosedWorkflow_BrandNew() { rand.Int63(), ) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, newEvents) } @@ -416,12 +433,14 @@ func (s *ExecutionMutableStateSuite) TestCreate_ClosedWorkflow_Bypass() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(newBranchToken, newEvents) } @@ -457,12 +476,14 @@ func (s *ExecutionMutableStateSuite) TestCreate_ClosedWorkflow_UpdateCurrent() { PreviousRunID: prevSnapshot.ExecutionState.RunId, PreviousLastWriteVersion: prevLastWriteVersion, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(newBranchToken, newEvents) } @@ -491,6 +512,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *currentMutation, UpdateWorkflowEvents: currentEvents, @@ -499,16 +522,18 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie() { }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot, currentMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot, currentMutation) s.AssertHEEqualWithDB(branchToken, newEvents, currentEvents) } func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_CHASM() { + archetypeID := rand.Uint32() newSnapshot := s.CreateCHASMSnapshot( rand.Int63(), enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING, rand.Int63(), + archetypeID, ) currentMutation, currentEvents := RandomMutation( @@ -528,6 +553,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_CHASM() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeUpdateCurrent, + ArchetypeID: archetypeID, + UpdateWorkflowMutation: *currentMutation, UpdateWorkflowEvents: currentEvents, @@ -536,7 +563,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_CHASM() { }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot, currentMutation) + s.AssertMSEqualWithDB(archetypeID, newSnapshot, currentMutation) } func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_CurrentConflict() { @@ -568,6 +595,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_CurrentConflict() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *currentMutation, UpdateWorkflowEvents: currentEvents, @@ -580,6 +609,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_CurrentConflict() { currentMutation.ExecutionInfo.NamespaceId, currentMutation.ExecutionInfo.WorkflowId, currentMutation.ExecutionState.RunId, + chasm.WorkflowArchetypeID, ) } @@ -608,6 +638,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_Conflict() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *currentMutation, UpdateWorkflowEvents: currentEvents, @@ -616,7 +648,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_Conflict() { }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEPrefixWithDB(branchToken, newEvents) } @@ -659,6 +691,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_WithNew() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *updateMutation, UpdateWorkflowEvents: updateEvents, @@ -667,8 +701,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_NotZombie_WithNew() { }) s.NoError(err) - s.AssertMSEqualWithDB(currentSnapshot, updateMutation) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot, updateMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, currentEvents, updateEvents) s.AssertHEEqualWithDB(newBranchToken, newEvents) } @@ -703,6 +737,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *zombieSnapshot, NewWorkflowEvents: zombieEvents1, }) @@ -725,6 +761,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *zombieMutation, UpdateWorkflowEvents: zombieEvents2, @@ -733,7 +771,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie() { }) s.NoError(err) - s.AssertMSEqualWithDB(zombieSnapshot, zombieMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, zombieSnapshot, zombieMutation) s.AssertHEEqualWithDB(zombieBranchToken, zombieEvents1, zombieEvents2) } @@ -762,6 +800,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_CurrentConflict() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *currentMutation, UpdateWorkflowEvents: currentEvents, @@ -770,7 +810,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_CurrentConflict() { }) s.IsType(&p.CurrentWorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEPrefixWithDB(branchToken, newEvents) } @@ -804,6 +844,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_Conflict() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *zombieSnapshot, NewWorkflowEvents: zombieEvents1, }) @@ -826,6 +868,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_Conflict() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *zombieMutation, UpdateWorkflowEvents: zombieEvents2, @@ -834,7 +878,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_Conflict() { }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(zombieSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, zombieSnapshot) s.AssertHEPrefixWithDB(zombieBranchToken, zombieEvents1) } @@ -867,6 +911,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_WithNew() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *zombieSnapshot, NewWorkflowEvents: zombieEvents1, }) @@ -903,6 +949,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_WithNew() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *zombieMutation, UpdateWorkflowEvents: zombieEvents2, @@ -911,8 +959,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_Zombie_WithNew() { }) s.NoError(err) - s.AssertMSEqualWithDB(zombieSnapshot, zombieMutation) - s.AssertMSEqualWithDB(newZombieSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, zombieSnapshot, zombieMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newZombieSnapshot) s.AssertHEEqualWithDB(zombieBranchToken, zombieEvents1, zombieEvents2) s.AssertHEEqualWithDB(newBranchToken, newEvents3) } @@ -943,6 +991,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_ClosedWorkflow_IsCurrent() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeIgnoreCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *currentMutation, UpdateWorkflowEvents: nil, @@ -951,7 +1001,7 @@ func (s *ExecutionMutableStateSuite) TestUpdate_ClosedWorkflow_IsCurrent() { }) s.NoError(err) - s.AssertMSEqualWithDB(newSnapshot, currentMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot, currentMutation) s.AssertHEEqualWithDB(branchToken, newEvents) } @@ -987,6 +1037,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_ClosedWorkflow_IsNonCurrent() { PreviousRunID: nonCurrentSnapshot.ExecutionState.RunId, PreviousLastWriteVersion: nonCurrentLastWriteVersion, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *currentSnapshot, NewWorkflowEvents: currentEvents, }) @@ -1011,6 +1063,8 @@ func (s *ExecutionMutableStateSuite) TestUpdate_ClosedWorkflow_IsNonCurrent() { RangeID: s.RangeID, Mode: p.UpdateWorkflowModeIgnoreCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + UpdateWorkflowMutation: *nonCurrentMutation, UpdateWorkflowEvents: nil, @@ -1019,9 +1073,9 @@ func (s *ExecutionMutableStateSuite) TestUpdate_ClosedWorkflow_IsNonCurrent() { }) s.NoError(err) - s.AssertMSEqualWithDB(nonCurrentSnapshot, nonCurrentMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, nonCurrentSnapshot, nonCurrentMutation) s.AssertHEEqualWithDB(nonCurrentBranchToken, nonCurrentEvents) - s.AssertMSEqualWithDB(currentSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot) s.AssertHEEqualWithDB(currentBranchToken, currentEvents) } @@ -1055,6 +1109,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1089,6 +1145,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent() { RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1100,8 +1158,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent() { }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) - s.AssertMSEqualWithDB(currentSnapshot, currentMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, resetSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot, currentMutation) s.AssertHEEqualWithDB(baseBranchToken, baseEvents, resetEvents) s.AssertHEEqualWithDB(branchToken, currentEvents1, currentEvents2) } @@ -1136,6 +1194,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Current PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1172,6 +1232,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Current RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1183,8 +1245,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Current }) s.IsType(&p.CurrentWorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) - s.AssertMSEqualWithDB(currentSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot) s.AssertHEPrefixWithDB(baseBranchToken, baseEvents) } @@ -1218,6 +1280,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Conflic PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1252,6 +1316,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Conflic RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1263,8 +1329,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Conflic }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) - s.AssertMSEqualWithDB(currentSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot) s.AssertHEPrefixWithDB(baseBranchToken, baseEvents) } @@ -1298,6 +1364,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Conflic PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1332,6 +1400,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Conflic RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1343,8 +1413,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_Conflic }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) - s.AssertMSEqualWithDB(currentSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot) s.AssertHEPrefixWithDB(baseBranchToken, baseEvents) } @@ -1378,6 +1448,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1426,6 +1498,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1437,20 +1511,22 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) - s.AssertMSEqualWithDB(newSnapshot) - s.AssertMSEqualWithDB(currentSnapshot, currentMutation) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, resetSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, currentSnapshot, currentMutation) s.AssertHEEqualWithDB(baseBranchToken, baseEvents, resetEvents) s.AssertHEEqualWithDB(newBranchToken, newEvents) s.AssertHEEqualWithDB(branchToken, currentEvents1, currentEvents2) } func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew_CHASM() { + archetypeID := rand.Uint32() currentSnapshot := s.CreateCHASMSnapshot( rand.Int63(), enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING, rand.Int63(), + archetypeID, ) baseRunID := uuid.New().String() @@ -1475,6 +1551,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: archetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1528,6 +1606,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: archetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1539,9 +1619,9 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) - s.AssertMSEqualWithDB(newSnapshot) - s.AssertMSEqualWithDB(currentSnapshot, currentMutation) + s.AssertMSEqualWithDB(archetypeID, resetSnapshot) + s.AssertMSEqualWithDB(archetypeID, newSnapshot) + s.AssertMSEqualWithDB(archetypeID, currentSnapshot, currentMutation) } func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent() { @@ -1569,6 +1649,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent() { RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1580,7 +1662,7 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent() { }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, resetSnapshot) s.AssertHEEqualWithDB(branchToken, baseEvents, resetEvents) } @@ -1613,6 +1695,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_CurrentCon PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1635,6 +1719,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_CurrentCon RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1646,7 +1732,7 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_CurrentCon }) s.IsType(&p.CurrentWorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) s.AssertHEPrefixWithDB(baseBranchToken, baseEvents) } @@ -1675,6 +1761,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_Conflict() RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1686,7 +1774,7 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_Conflict() }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) s.AssertHEPrefixWithDB(branchToken, baseEvents) } @@ -1729,6 +1817,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_WithNew() RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeUpdateCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1740,8 +1830,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent_WithNew() }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, resetSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, baseEvents, resetEvents) s.AssertHEEqualWithDB(newBranchToken, newEvents) } @@ -1775,6 +1865,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1797,6 +1889,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie() { RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1808,7 +1902,7 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie() { }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, resetSnapshot) s.AssertHEEqualWithDB(baseBranchToken, baseEvents, resetEvents) } @@ -1837,6 +1931,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_CurrentConflict( RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1848,7 +1944,7 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_CurrentConflict( }) s.IsType(&p.CurrentWorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) s.AssertHEPrefixWithDB(branchToken, baseEvents) } @@ -1881,6 +1977,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_Conflict() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1903,6 +2001,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_Conflict() { RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1914,7 +2014,7 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_Conflict() { }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(baseSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, baseSnapshot) s.AssertHEPrefixWithDB(baseBranchToken, baseEvents) } @@ -1947,6 +2047,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_WithNew() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *baseSnapshot, NewWorkflowEvents: baseEvents, }) @@ -1983,6 +2085,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_WithNew() { RangeID: s.RangeID, Mode: p.ConflictResolveWorkflowModeBypassCurrent, + ArchetypeID: chasm.WorkflowArchetypeID, + ResetWorkflowSnapshot: *resetSnapshot, ResetWorkflowEvents: resetEvents, @@ -1994,8 +2098,8 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_Zombie_WithNew() { }) s.NoError(err) - s.AssertMSEqualWithDB(resetSnapshot) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, resetSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(baseBranchToken, baseEvents, resetEvents) s.AssertHEEqualWithDB(newBranchToken, newEvents) } @@ -2018,11 +2122,13 @@ func (s *ExecutionMutableStateSuite) TestSet_NotExists() { ShardID: s.ShardID, RangeID: s.RangeID, + ArchetypeID: chasm.WorkflowArchetypeID, + SetWorkflowSnapshot: *setSnapshot, }) s.IsType(&p.ConditionFailedError{}, err) - s.AssertMissingFromDB(s.NamespaceID, s.WorkflowID, s.RunID) + s.AssertMissingFromDB(s.NamespaceID, s.WorkflowID, s.RunID, chasm.WorkflowArchetypeID) } func (s *ExecutionMutableStateSuite) TestSet_Conflict() { @@ -2049,11 +2155,13 @@ func (s *ExecutionMutableStateSuite) TestSet_Conflict() { ShardID: s.ShardID, RangeID: s.RangeID, + ArchetypeID: chasm.WorkflowArchetypeID, + SetWorkflowSnapshot: *setSnapshot, }) s.IsType(&p.WorkflowConditionFailedError{}, err) - s.AssertMSEqualWithDB(snapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, snapshot) s.AssertHEEqualWithDB(branchToken, events) } @@ -2081,20 +2189,24 @@ func (s *ExecutionMutableStateSuite) TestSet() { ShardID: s.ShardID, RangeID: s.RangeID, + ArchetypeID: chasm.WorkflowArchetypeID, + SetWorkflowSnapshot: *setSnapshot, }) s.NoError(err) - s.AssertMSEqualWithDB(setSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, setSnapshot) s.AssertHEEqualWithDB(branchToken, events) } func (s *ExecutionMutableStateSuite) TestSet_CHASM() { + archetypeID := rand.Uint32() snapshot := s.CreateCHASMSnapshot( rand.Int63(), enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING, rand.Int63(), + archetypeID, ) setSnapshot, _ := RandomSnapshot( @@ -2113,11 +2225,13 @@ func (s *ExecutionMutableStateSuite) TestSet_CHASM() { ShardID: s.ShardID, RangeID: s.RangeID, + ArchetypeID: archetypeID, + SetWorkflowSnapshot: *setSnapshot, }) s.NoError(err) - s.AssertMSEqualWithDB(setSnapshot) + s.AssertMSEqualWithDB(archetypeID, setSnapshot) } func (s *ExecutionMutableStateSuite) TestDeleteCurrent_IsCurrent() { @@ -2133,6 +2247,7 @@ func (s *ExecutionMutableStateSuite) TestDeleteCurrent_IsCurrent() { NamespaceID: s.NamespaceID, WorkflowID: s.WorkflowID, RunID: s.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }) s.NoError(err) @@ -2140,11 +2255,12 @@ func (s *ExecutionMutableStateSuite) TestDeleteCurrent_IsCurrent() { ShardID: s.ShardID, NamespaceID: s.NamespaceID, WorkflowID: s.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }) s.IsType(&serviceerror.NotFound{}, err) s.EqualError(err, "workflow not found for ID: "+s.WorkflowID) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, newEvents) } @@ -2171,6 +2287,8 @@ func (s *ExecutionMutableStateSuite) TestDeleteCurrent_NotCurrent() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) @@ -2181,6 +2299,7 @@ func (s *ExecutionMutableStateSuite) TestDeleteCurrent_NotCurrent() { NamespaceID: s.NamespaceID, WorkflowID: s.WorkflowID, RunID: s.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }) s.NoError(err) @@ -2188,11 +2307,12 @@ func (s *ExecutionMutableStateSuite) TestDeleteCurrent_NotCurrent() { ShardID: s.ShardID, NamespaceID: s.NamespaceID, WorkflowID: s.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }) s.IsType(&serviceerror.NotFound{}, err) s.EqualError(err, "workflow not found for ID: "+s.WorkflowID) - s.AssertMSEqualWithDB(newSnapshot) + s.AssertMSEqualWithDB(chasm.WorkflowArchetypeID, newSnapshot) s.AssertHEEqualWithDB(branchToken, newEvents) } @@ -2219,6 +2339,8 @@ func (s *ExecutionMutableStateSuite) TestDelete_Exists() { PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *newSnapshot, NewWorkflowEvents: newEvents, }) @@ -2229,10 +2351,11 @@ func (s *ExecutionMutableStateSuite) TestDelete_Exists() { NamespaceID: s.NamespaceID, WorkflowID: s.WorkflowID, RunID: s.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }) s.NoError(err) - s.AssertMissingFromDB(s.NamespaceID, s.WorkflowID, s.RunID) + s.AssertMissingFromDB(s.NamespaceID, s.WorkflowID, s.RunID, chasm.WorkflowArchetypeID) } func (s *ExecutionMutableStateSuite) TestDelete_NotExists() { @@ -2241,10 +2364,11 @@ func (s *ExecutionMutableStateSuite) TestDelete_NotExists() { NamespaceID: s.NamespaceID, WorkflowID: s.WorkflowID, RunID: s.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }) s.NoError(err) - s.AssertMissingFromDB(s.NamespaceID, s.WorkflowID, s.RunID) + s.AssertMissingFromDB(s.NamespaceID, s.WorkflowID, s.RunID, chasm.WorkflowArchetypeID) } func (s *ExecutionMutableStateSuite) CreateWorkflow( @@ -2274,6 +2398,8 @@ func (s *ExecutionMutableStateSuite) CreateWorkflow( PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: chasm.WorkflowArchetypeID, + NewWorkflowSnapshot: *snapshot, NewWorkflowEvents: events, }) @@ -2286,6 +2412,7 @@ func (s *ExecutionMutableStateSuite) CreateCHASMSnapshot( state enumsspb.WorkflowExecutionState, status enumspb.WorkflowExecutionStatus, dbRecordVersion int64, + archetypeID chasm.ArchetypeID, ) *p.WorkflowSnapshot { snapshot, events := RandomSnapshot( s.T(), @@ -2307,6 +2434,8 @@ func (s *ExecutionMutableStateSuite) CreateCHASMSnapshot( PreviousRunID: "", PreviousLastWriteVersion: 0, + ArchetypeID: archetypeID, + NewWorkflowSnapshot: *snapshot, NewWorkflowEvents: events, }) @@ -2318,12 +2447,14 @@ func (s *ExecutionMutableStateSuite) AssertMissingFromDB( namespaceID string, workflowID string, runID string, + archetypeID chasm.ArchetypeID, ) { _, err := s.ExecutionManager.GetWorkflowExecution(s.Ctx, &p.GetWorkflowExecutionRequest{ ShardID: s.ShardID, NamespaceID: namespaceID, WorkflowID: workflowID, RunID: runID, + ArchetypeID: archetypeID, }) s.IsType(&serviceerror.NotFound{}, err) s.EqualError(err, fmt.Sprintf("workflow execution not found for workflow ID %q and run ID %q", workflowID, runID)) @@ -2371,6 +2502,7 @@ func (s *ExecutionMutableStateSuite) assertHEWithDB( } func (s *ExecutionMutableStateSuite) AssertMSEqualWithDB( + archetypeID chasm.ArchetypeID, snapshot *p.WorkflowSnapshot, mutations ...*p.WorkflowMutation, ) { @@ -2379,6 +2511,7 @@ func (s *ExecutionMutableStateSuite) AssertMSEqualWithDB( NamespaceID: snapshot.ExecutionInfo.NamespaceId, WorkflowID: snapshot.ExecutionInfo.WorkflowId, RunID: snapshot.ExecutionState.RunId, + ArchetypeID: archetypeID, }) s.NoError(err) diff --git a/common/persistence/tests/execution_mutable_state_task.go b/common/persistence/tests/execution_mutable_state_task.go index 926b0684919..d8ebefad930 100644 --- a/common/persistence/tests/execution_mutable_state_task.go +++ b/common/persistence/tests/execution_mutable_state_task.go @@ -13,6 +13,7 @@ import ( commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/debug" "go.temporal.io/server/common/definition" @@ -464,6 +465,7 @@ func (s *ExecutionMutableStateTaskSuite) TestGetTimerTasksOrdered() { RangeID: s.RangeID, NamespaceID: s.WorkflowKey.NamespaceID, WorkflowID: s.WorkflowKey.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, Tasks: map[tasks.Category][]tasks.Task{ tasks.CategoryTimer: timerTasks, }, @@ -505,6 +507,7 @@ func (s *ExecutionMutableStateTaskSuite) TestGetScheduledTasksOrdered() { RangeID: s.RangeID, NamespaceID: s.WorkflowKey.NamespaceID, WorkflowID: s.WorkflowKey.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, Tasks: map[tasks.Category][]tasks.Task{ fakeScheduledTaskCategory: scheduledTasks, }, @@ -562,6 +565,7 @@ func (s *ExecutionMutableStateTaskSuite) AddRandomTasks( RangeID: s.RangeID, NamespaceID: s.WorkflowKey.NamespaceID, WorkflowID: s.WorkflowKey.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, Tasks: map[tasks.Category][]tasks.Task{ category: randomTasks, }, diff --git a/common/persistence/tests/history_store.go b/common/persistence/tests/history_store.go index d7527342be1..6a6b9adff88 100644 --- a/common/persistence/tests/history_store.go +++ b/common/persistence/tests/history_store.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/suite" historypb "go.temporal.io/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/debug" "go.temporal.io/server/common/dynamicconfig" @@ -99,6 +100,7 @@ func (s *HistoryEventsSuite) TestAppendSelect_First() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -126,6 +128,7 @@ func (s *HistoryEventsSuite) TestAppendSelect_NonShadowing() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -164,6 +167,7 @@ func (s *HistoryEventsSuite) TestAppendSelect_Shadowing() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -214,6 +218,7 @@ func (s *HistoryEventsSuite) TestAppendForkSelect_NoShadowing() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -266,6 +271,7 @@ func (s *HistoryEventsSuite) TestAppendForkSelect_Shadowing_NonLastBranch() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -335,6 +341,7 @@ func (s *HistoryEventsSuite) TestAppendForkSelect_Shadowing_LastBranch() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -394,6 +401,7 @@ func (s *HistoryEventsSuite) TestAppendSelectTrim() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -438,6 +446,7 @@ func (s *HistoryEventsSuite) TestAppendForkSelectTrim_NonLastBranch() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -507,6 +516,7 @@ func (s *HistoryEventsSuite) TestAppendForkSelectTrim_LastBranch() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -558,6 +568,7 @@ func (s *HistoryEventsSuite) TestAppendBatches() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -599,6 +610,7 @@ func (s *HistoryEventsSuite) TestForkDeleteBranch_DeleteBaseBranchFirst() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, @@ -667,6 +679,7 @@ func (s *HistoryEventsSuite) TestForkDeleteBranch_DeleteForkedBranchFirst() { uuid.New(), uuid.New(), uuid.New(), + chasm.WorkflowArchetypeID, treeID, &branchID, []*persistencespb.HistoryBranchRange{}, diff --git a/common/persistence/tests/util.go b/common/persistence/tests/util.go index 2f67bf30716..55e73e0e61b 100644 --- a/common/persistence/tests/util.go +++ b/common/persistence/tests/util.go @@ -13,6 +13,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" p "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/serialization" @@ -353,6 +354,7 @@ func RandomBranchToken( namespaceID, workflowID, runID, + chasm.WorkflowArchetypeID, uuid.NewString(), nil, nil, diff --git a/common/serviceerror/sync_state.go b/common/serviceerror/sync_state.go index d85a8a50252..1dd526d137d 100644 --- a/common/serviceerror/sync_state.go +++ b/common/serviceerror/sync_state.go @@ -11,11 +11,13 @@ import ( type ( // SyncState represents sync state error. + // nolint:staticcheck SyncState struct { Message string NamespaceId string WorkflowId string RunId string + ArchetypeId uint32 VersionedTransition *persistencespb.VersionedTransition VersionHistories *historyspb.VersionHistories st *status.Status @@ -23,11 +25,13 @@ type ( ) // NewSyncState returns new SyncState error. +// nolint:staticcheck func NewSyncState( message string, namespaceId string, workflowId string, runId string, + archetypeId uint32, versionedTransition *persistencespb.VersionedTransition, versionHistories *historyspb.VersionHistories, ) error { @@ -36,6 +40,7 @@ func NewSyncState( NamespaceId: namespaceId, WorkflowId: workflowId, RunId: runId, + ArchetypeId: archetypeId, VersionedTransition: versionedTransition, VersionHistories: versionHistories, } @@ -57,6 +62,7 @@ func (e *SyncState) Status() *status.Status { NamespaceId: e.NamespaceId, WorkflowId: e.WorkflowId, RunId: e.RunId, + ArchetypeId: e.ArchetypeId, VersionedTransition: e.VersionedTransition, VersionHistories: e.VersionHistories, }, @@ -68,6 +74,7 @@ func (e *SyncState) Equal(err *SyncState) bool { return e.NamespaceId == err.NamespaceId && e.WorkflowId == err.WorkflowId && e.RunId == err.RunId && + e.ArchetypeId == err.ArchetypeId && proto.Equal(e.VersionedTransition, err.VersionedTransition) && proto.Equal(e.VersionHistories, err.VersionHistories) } @@ -81,6 +88,7 @@ func newSyncState( NamespaceId: errDetails.GetNamespaceId(), WorkflowId: errDetails.GetWorkflowId(), RunId: errDetails.GetRunId(), + ArchetypeId: errDetails.GetArchetypeId(), VersionedTransition: errDetails.GetVersionedTransition(), VersionHistories: errDetails.GetVersionHistories(), st: st, diff --git a/proto/internal/temporal/server/api/adminservice/v1/request_response.proto b/proto/internal/temporal/server/api/adminservice/v1/request_response.proto index 71d2e06a0f5..8dc1c95c324 100644 --- a/proto/internal/temporal/server/api/adminservice/v1/request_response.proto +++ b/proto/internal/temporal/server/api/adminservice/v1/request_response.proto @@ -55,6 +55,7 @@ message DescribeMutableStateRequest { string namespace = 1; temporal.api.common.v1.WorkflowExecution execution = 2; bool skip_force_reload = 3; + string archetype = 4; } message DescribeMutableStateResponse { @@ -360,6 +361,7 @@ message RefreshWorkflowTasksRequest { reserved 1; string namespace_id = 3; temporal.api.common.v1.WorkflowExecution execution = 2; + string archetype = 4; } message RefreshWorkflowTasksResponse { @@ -399,6 +401,7 @@ message GetTaskQueueTasksResponse { message DeleteWorkflowExecutionRequest { string namespace = 1; temporal.api.common.v1.WorkflowExecution execution = 2; + string archetype = 3; } message DeleteWorkflowExecutionResponse { @@ -557,6 +560,8 @@ message SyncWorkflowStateRequest { temporal.server.api.persistence.v1.VersionedTransition versioned_transition = 3; temporal.server.api.history.v1.VersionHistories version_histories = 4; int32 target_cluster_id = 5; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 6; } message SyncWorkflowStateResponse { @@ -571,6 +576,7 @@ message GenerateLastHistoryReplicationTasksRequest { string namespace = 1; temporal.api.common.v1.WorkflowExecution execution = 2; repeated string target_clusters = 3; + string archetype = 4; } message GenerateLastHistoryReplicationTasksResponse { diff --git a/proto/internal/temporal/server/api/errordetails/v1/message.proto b/proto/internal/temporal/server/api/errordetails/v1/message.proto index 508d9236974..d26aca8f6c6 100644 --- a/proto/internal/temporal/server/api/errordetails/v1/message.proto +++ b/proto/internal/temporal/server/api/errordetails/v1/message.proto @@ -39,7 +39,9 @@ message SyncStateFailure { string workflow_id = 2; string run_id = 3; temporal.server.api.persistence.v1.VersionedTransition versioned_transition = 4; - temporal.server.api.history.v1.VersionHistories version_histories = 5; + temporal.server.api.history.v1.VersionHistories version_histories = 5; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 6; } message StickyWorkerUnavailableFailure { diff --git a/proto/internal/temporal/server/api/historyservice/v1/request_response.proto b/proto/internal/temporal/server/api/historyservice/v1/request_response.proto index 80c6ff17d60..e5e3bd453d3 100644 --- a/proto/internal/temporal/server/api/historyservice/v1/request_response.proto +++ b/proto/internal/temporal/server/api/historyservice/v1/request_response.proto @@ -729,6 +729,8 @@ message DescribeMutableStateRequest { string namespace_id = 1; temporal.api.common.v1.WorkflowExecution execution = 2; bool skip_force_reload = 3; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 4; } message DescribeMutableStateResponse { @@ -882,6 +884,8 @@ message RefreshWorkflowTasksRequest { option (routing).workflow_id = "request.execution.workflow_id"; string namespace_id = 1; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 3; temporal.server.api.adminservice.v1.RefreshWorkflowTasksRequest request = 2; } @@ -894,6 +898,8 @@ message GenerateLastHistoryReplicationTasksRequest { string namespace_id = 1; temporal.api.common.v1.WorkflowExecution execution = 2; repeated string target_clusters = 3; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 4; } message GenerateLastHistoryReplicationTasksResponse { @@ -1070,6 +1076,8 @@ message ForceDeleteWorkflowExecutionRequest { option (routing).workflow_id = "request.execution.workflow_id"; string namespace_id = 1; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 3; temporal.server.api.adminservice.v1.DeleteWorkflowExecutionRequest request = 2; } @@ -1248,6 +1256,8 @@ message SyncWorkflowStateRequest { temporal.server.api.persistence.v1.VersionedTransition versioned_transition = 3; temporal.server.api.history.v1.VersionHistories version_histories = 4; int32 target_cluster_id = 5; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 6; } message SyncWorkflowStateResponse { diff --git a/proto/internal/temporal/server/api/persistence/v1/chasm.proto b/proto/internal/temporal/server/api/persistence/v1/chasm.proto index 0c14caab97d..a2335a9832d 100644 --- a/proto/internal/temporal/server/api/persistence/v1/chasm.proto +++ b/proto/internal/temporal/server/api/persistence/v1/chasm.proto @@ -89,6 +89,10 @@ message ChasmTaskInfo { // Opaque attached task data. May be nil. Usable by components, not the CHASM // framework itself. temporal.api.common.v1.DataBlob data = 5; + + // ArchetypeID of the execution that generated this task. + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 6; } // ChasmComponentRef references a specific chasm component. diff --git a/proto/internal/temporal/server/api/persistence/v1/executions.proto b/proto/internal/temporal/server/api/persistence/v1/executions.proto index 545226adf00..444599d5cdb 100644 --- a/proto/internal/temporal/server/api/persistence/v1/executions.proto +++ b/proto/internal/temporal/server/api/persistence/v1/executions.proto @@ -376,8 +376,10 @@ message ReplicationTaskInfo { repeated ReplicationTaskInfo task_equivalents = 20; history.v1.VersionHistoryItem last_version_history_item = 21; bool is_first_task = 22; - repeated string target_clusters= 23; + repeated string target_clusters = 23; bool is_force_replication = 24; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 25; } // visibility_task_data column diff --git a/proto/internal/temporal/server/api/replication/v1/message.proto b/proto/internal/temporal/server/api/replication/v1/message.proto index 27b8b8729ae..ad9edc1715c 100644 --- a/proto/internal/temporal/server/api/replication/v1/message.proto +++ b/proto/internal/temporal/server/api/replication/v1/message.proto @@ -228,6 +228,8 @@ message VerifyVersionedTransitionTaskAttributes { int64 next_event_id = 4; repeated temporal.server.api.history.v1.VersionHistoryItem event_version_history = 5; string new_run_id = 6; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 7; } message SyncVersionedTransitionTaskAttributes { @@ -239,6 +241,8 @@ message SyncVersionedTransitionTaskAttributes { string namespace_id = 6; string workflow_id = 7; string run_id = 8; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 9; } message VersionedTransitionArtifact { @@ -252,3 +256,12 @@ message VersionedTransitionArtifact { bool is_close_transfer_task_acked = 6; bool is_force_replication = 7; } + +message MigrationExecutionInfo { + // Should be called business_id, but to maintain backward compatibility + // with old type definition used in migration workflows. + string business_id = 1 [json_name = "workflowId"]; + string run_id = 2; + // (-- api-linter: core::0141::forbidden-types=disabled --) + uint32 archetype_id = 3; +} \ No newline at end of file diff --git a/service/frontend/admin_handler.go b/service/frontend/admin_handler.go index 8a7f495d2ea..58d609d3404 100644 --- a/service/frontend/admin_handler.go +++ b/service/frontend/admin_handler.go @@ -29,6 +29,7 @@ import ( "go.temporal.io/server/api/matchingservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" serverClient "go.temporal.io/server/client" "go.temporal.io/server/client/admin" "go.temporal.io/server/client/frontend" @@ -105,6 +106,7 @@ type ( clusterMetadata cluster.Metadata healthServer *health.Server historyHealthChecker HealthChecker + chasmRegistry *chasm.Registry // DEPRECATED: only history service on server side is supposed to // use the following components. @@ -139,6 +141,7 @@ type ( HealthServer *health.Server EventSerializer serialization.Serializer TimeSource clock.TimeSource + ChasmRegistry *chasm.Registry // DEPRECATED: only history service on server side is supposed to // use the following components. @@ -149,8 +152,6 @@ type ( var ( _ adminservice.AdminServiceServer = (*AdminHandler)(nil) - - resendStartEventID = int64(0) ) // NewAdminHandler creates a gRPC handler for the adminservice @@ -225,6 +226,7 @@ func NewAdminHandler( historyHealthChecker: historyHealthChecker, taskCategoryRegistry: args.CategoryRegistry, matchingClient: args.matchingClient, + chasmRegistry: args.ChasmRegistry, } } @@ -773,6 +775,11 @@ func (adh *AdminHandler) DescribeMutableState(ctx context.Context, request *admi return nil, err } + archetypeID, err := adh.archetypeNameToID(request.GetArchetype()) + if err != nil { + return nil, err + } + shardID := common.WorkflowIDToHistoryShard(namespaceID.String(), request.Execution.WorkflowId, adh.numberOfHistoryShards) shardIDStr := convert.Int32ToString(shardID) @@ -786,10 +793,12 @@ func (adh *AdminHandler) DescribeMutableState(ctx context.Context, request *admi } historyAddr := historyHost.GetAddress() + historyResponse, err := adh.historyClient.DescribeMutableState(ctx, &historyservice.DescribeMutableStateRequest{ NamespaceId: namespaceID.String(), Execution: request.Execution, SkipForceReload: request.GetSkipForceReload(), + ArchetypeId: archetypeID, }) if err != nil { @@ -1531,8 +1540,14 @@ func (adh *AdminHandler) RefreshWorkflowTasks( return nil, err } + archetypeID, err := adh.archetypeNameToID(request.GetArchetype()) + if err != nil { + return nil, err + } + _, err = adh.historyClient.RefreshWorkflowTasks(ctx, &historyservice.RefreshWorkflowTasksRequest{ NamespaceId: namespaceEntry.ID().String(), + ArchetypeId: archetypeID, Request: request, }) if err != nil { @@ -1689,9 +1704,15 @@ func (adh *AdminHandler) DeleteWorkflowExecution( return nil, err } + archetypeID, err := adh.archetypeNameToID(request.GetArchetype()) + if err != nil { + return nil, err + } + response, err := adh.historyClient.ForceDeleteWorkflowExecution(ctx, &historyservice.ForceDeleteWorkflowExecutionRequest{ NamespaceId: namespaceID.String(), + ArchetypeId: archetypeID, Request: request, }) if err != nil { @@ -2119,6 +2140,7 @@ func (adh *AdminHandler) SyncWorkflowState(ctx context.Context, request *adminse VersionHistories: request.VersionHistories, VersionedTransition: request.VersionedTransition, TargetClusterId: request.TargetClusterId, + ArchetypeId: request.ArchetypeId, }) if err != nil { return nil, err @@ -2147,12 +2169,18 @@ func (adh *AdminHandler) GenerateLastHistoryReplicationTasks( return nil, err } + archetypeID, err := adh.archetypeNameToID(request.GetArchetype()) + if err != nil { + return nil, err + } + resp, err := adh.historyClient.GenerateLastHistoryReplicationTasks( ctx, &historyservice.GenerateLastHistoryReplicationTasksRequest{ NamespaceId: namespaceEntry.ID().String(), Execution: request.Execution, TargetClusters: request.TargetClusters, + ArchetypeId: archetypeID, }, ) if err != nil { @@ -2177,6 +2205,19 @@ func (adh *AdminHandler) getDLQWorkflowID( ) } +func (adh *AdminHandler) archetypeNameToID(archetype chasm.Archetype) (chasm.ArchetypeID, error) { + if len(archetype) == 0 { + // For backwards compatibility, default to Workflow + return chasm.WorkflowArchetypeID, nil + } + + archetypeID, ok := adh.chasmRegistry.ComponentIDByFqn(archetype) + if !ok { + return chasm.UnspecifiedArchetypeID, serviceerror.NewInvalidArgumentf("unknown archetype: %s", archetype) + } + return archetypeID, nil +} + func validateHistoryDLQKey( key *commonspb.HistoryDLQKey, ) error { diff --git a/service/frontend/admin_handler_test.go b/service/frontend/admin_handler_test.go index f1754c4d7c2..cd4d7f0316a 100644 --- a/service/frontend/admin_handler_test.go +++ b/service/frontend/admin_handler_test.go @@ -31,6 +31,8 @@ import ( "go.temporal.io/server/api/matchingservicemock/v1" persistencespb "go.temporal.io/server/api/persistence/v1" taskqueuespb "go.temporal.io/server/api/taskqueue/v1" + "go.temporal.io/server/chasm" + chasmworkflow "go.temporal.io/server/chasm/lib/workflow" clientmocks "go.temporal.io/server/client" historyclient "go.temporal.io/server/client/history" "go.temporal.io/server/common/clock" @@ -145,6 +147,11 @@ func (s *adminHandlerSuite) SetupTest() { VisibilityAllowList: dynamicconfig.GetBoolPropertyFnFilteredByNamespace(false), SuppressErrorSetSystemSearchAttribute: dynamicconfig.GetBoolPropertyFnFilteredByNamespace(false), } + + chasmRegistry := chasm.NewRegistry(s.mockResource.GetLogger()) + err := chasmRegistry.Register(chasmworkflow.NewLibrary()) + s.NoError(err) + args := NewAdminHandlerArgs{ persistenceConfig, cfg, @@ -172,6 +179,7 @@ func (s *adminHandlerSuite) SetupTest() { health.NewServer(), serialization.NewSerializer(), clock.NewRealTimeSource(), + chasmRegistry, tasks.NewDefaultTaskCategoryRegistry(), s.mockResource.GetMatchingClient(), } diff --git a/service/frontend/fx.go b/service/frontend/fx.go index 0dbfdff5eb5..7bc3a826e60 100644 --- a/service/frontend/fx.go +++ b/service/frontend/fx.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "go.temporal.io/server/api/adminservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/archiver" @@ -654,6 +655,7 @@ func AdminHandlerProvider( timeSource clock.TimeSource, taskCategoryRegistry tasks.TaskCategoryRegistry, matchingClient resource.MatchingClient, + chasmRegistry *chasm.Registry, ) *AdminHandler { args := NewAdminHandlerArgs{ persistenceConfig, @@ -682,6 +684,7 @@ func AdminHandlerProvider( healthServer, eventSerializer, timeSource, + chasmRegistry, taskCategoryRegistry, matchingClient, } diff --git a/service/history/api/activity_util.go b/service/history/api/activity_util.go index 1b7002245ae..c569dc46ed6 100644 --- a/service/history/api/activity_util.go +++ b/service/history/api/activity_util.go @@ -27,7 +27,7 @@ func SetActivityTaskRunID( return nil } - runID, err := workflowConsistencyChecker.GetCurrentRunID( + runID, err := workflowConsistencyChecker.GetCurrentWorkflowRunID( ctx, token.NamespaceId, token.WorkflowId, diff --git a/service/history/api/addtasks/api.go b/service/history/api/addtasks/api.go index f117e62c9bf..9dc97d3edc8 100644 --- a/service/history/api/addtasks/api.go +++ b/service/history/api/addtasks/api.go @@ -6,7 +6,7 @@ import ( commonpb "go.temporal.io/api/common/v1" "go.temporal.io/api/serviceerror" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/persistence" "go.temporal.io/server/service/history/api" historyi "go.temporal.io/server/service/history/interfaces" @@ -19,6 +19,12 @@ type ( TaskDeserializer interface { DeserializeTask(category tasks.Category, blob *commonpb.DataBlob) (tasks.Task, error) } + + taskGroupKey struct { + namespaceID string + businessID string + archetypeID chasm.ArchetypeID + } ) const ( @@ -52,7 +58,7 @@ func Invoke( return nil, serviceerror.NewInvalidArgument("No tasks in request") } - taskBatches := make(map[definition.WorkflowKey]map[tasks.Category][]tasks.Task) + taskGroups := make(map[taskGroupKey]map[tasks.Category][]tasks.Task) for i, task := range req.Tasks { if task == nil { @@ -84,26 +90,35 @@ func Invoke( ) } - // group by namespaceID + workflowID - workflowKey := definition.NewWorkflowKey( - deserializedTask.GetNamespaceID(), - deserializedTask.GetWorkflowID(), - "", - ) - if _, ok := taskBatches[workflowKey]; !ok { - taskBatches[workflowKey] = make(map[tasks.Category][]tasks.Task, 1) + // group by namespaceID + execution businessID + archetypeID + archetypeID := chasm.WorkflowArchetypeID + if hasArchetypeID, ok := deserializedTask.(tasks.HasArchetypeID); ok { + archetypeID = hasArchetypeID.GetArchetypeID() + } + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + groupKey := taskGroupKey{ + namespaceID: deserializedTask.GetNamespaceID(), + businessID: deserializedTask.GetWorkflowID(), + archetypeID: archetypeID, + } + + if _, ok := taskGroups[groupKey]; !ok { + taskGroups[groupKey] = make(map[tasks.Category][]tasks.Task, 1) } - taskBatches[workflowKey][category] = append(taskBatches[workflowKey][category], deserializedTask) + taskGroups[groupKey][category] = append(taskGroups[groupKey][category], deserializedTask) } - for workflowKey, taskBatch := range taskBatches { + for groupKey, taskGroup := range taskGroups { err := shardContext.AddTasks(ctx, &persistence.AddHistoryTasksRequest{ ShardID: shardContext.GetShardID(), RangeID: shardContext.GetRangeID(), - NamespaceID: workflowKey.NamespaceID, - WorkflowID: workflowKey.WorkflowID, - Tasks: taskBatch, + NamespaceID: groupKey.namespaceID, + WorkflowID: groupKey.businessID, + ArchetypeID: groupKey.archetypeID, + Tasks: taskGroup, }) if err != nil { return nil, err diff --git a/service/history/api/consistency_checker.go b/service/history/api/consistency_checker.go index 763dfb6eb23..d52dcb4595a 100644 --- a/service/history/api/consistency_checker.go +++ b/service/history/api/consistency_checker.go @@ -19,12 +19,15 @@ import ( wcache "go.temporal.io/server/service/history/workflow/cache" ) +// TODO: rename to ExecutionConsistencyChecker +var _ WorkflowConsistencyChecker = (*WorkflowConsistencyCheckerImpl)(nil) + type ( MutableStateConsistencyPredicate func(mutableState historyi.MutableState) bool WorkflowConsistencyChecker interface { GetWorkflowCache() wcache.Cache - GetCurrentRunID( + GetCurrentWorkflowRunID( ctx context.Context, namespaceID string, workflowID string, @@ -45,11 +48,19 @@ type ( lockPriority locks.Priority, ) (WorkflowLease, error) + GetCurrentChasmRunID( + ctx context.Context, + namespaceID string, + workflowID string, + archetypeID chasm.ArchetypeID, + lockPriority locks.Priority, + ) (string, error) + GetChasmLease( ctx context.Context, reqClock *clockspb.VectorClock, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) @@ -58,7 +69,7 @@ type ( reqClock *clockspb.VectorClock, consistencyPredicate MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) } @@ -83,7 +94,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowCache() wcache.Cache { return c.workflowCache } -func (c *WorkflowConsistencyCheckerImpl) GetCurrentRunID( +func (c *WorkflowConsistencyCheckerImpl) GetCurrentWorkflowRunID( ctx context.Context, namespaceID string, workflowID string, @@ -95,6 +106,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetCurrentRunID( c.workflowCache, namespaceID, workflowID, + chasm.WorkflowArchetypeID, lockPriority, ) } @@ -105,7 +117,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowLease( workflowKey definition.WorkflowKey, lockPriority locks.Priority, ) (WorkflowLease, error) { - return c.getWorkflowLeaseImpl(ctx, reqClock, nil, workflowKey, chasm.WorkflowArchetype, lockPriority) + return c.getWorkflowLeaseImpl(ctx, reqClock, nil, workflowKey, chasm.WorkflowArchetypeID, lockPriority) } // The code below should be used when custom workflow state validation is required. @@ -118,17 +130,35 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowLeaseWithConsistencyCheck( workflowKey definition.WorkflowKey, lockPriority locks.Priority, ) (WorkflowLease, error) { - return c.getWorkflowLeaseImpl(ctx, reqClock, consistencyPredicate, workflowKey, chasm.WorkflowArchetype, lockPriority) + return c.getWorkflowLeaseImpl(ctx, reqClock, consistencyPredicate, workflowKey, chasm.WorkflowArchetypeID, lockPriority) +} + +func (c *WorkflowConsistencyCheckerImpl) GetCurrentChasmRunID( + ctx context.Context, + namespaceID string, + workflowID string, + archetypeID chasm.ArchetypeID, + lockPriority locks.Priority, +) (runID string, retErr error) { + return wcache.GetCurrentRunID( + ctx, + c.shardContext, + c.workflowCache, + namespaceID, + workflowID, + archetypeID, + lockPriority, + ) } func (c *WorkflowConsistencyCheckerImpl) GetChasmLease( ctx context.Context, reqClock *clockspb.VectorClock, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) { - return c.getWorkflowLeaseImpl(ctx, reqClock, nil, workflowKey, archetype, lockPriority) + return c.getWorkflowLeaseImpl(ctx, reqClock, nil, workflowKey, archetypeID, lockPriority) } func (c *WorkflowConsistencyCheckerImpl) GetChasmLeaseWithConsistencyCheck( @@ -136,10 +166,10 @@ func (c *WorkflowConsistencyCheckerImpl) GetChasmLeaseWithConsistencyCheck( reqClock *clockspb.VectorClock, consistencyPredicate MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) { - return c.getWorkflowLeaseImpl(ctx, reqClock, consistencyPredicate, workflowKey, archetype, lockPriority) + return c.getWorkflowLeaseImpl(ctx, reqClock, consistencyPredicate, workflowKey, archetypeID, lockPriority) } func (c *WorkflowConsistencyCheckerImpl) getWorkflowLeaseImpl( @@ -147,7 +177,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowLeaseImpl( reqClock *clockspb.VectorClock, consistencyPredicate MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) { if err := c.clockConsistencyCheck(reqClock); err != nil { @@ -155,7 +185,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowLeaseImpl( } if len(workflowKey.RunID) != 0 { - return c.getWorkflowLease(ctx, consistencyPredicate, workflowKey, archetype, lockPriority) + return c.getWorkflowLease(ctx, consistencyPredicate, workflowKey, archetypeID, lockPriority) } return c.getCurrentWorkflowLease( @@ -163,7 +193,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowLeaseImpl( consistencyPredicate, workflowKey.NamespaceID, workflowKey.WorkflowID, - archetype, + archetypeID, lockPriority, ) } @@ -200,13 +230,14 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentWorkflowLease( consistencyPredicate MutableStateConsistencyPredicate, namespaceID string, workflowID string, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) { - runID, err := c.GetCurrentRunID( + runID, err := c.GetCurrentChasmRunID( ctx, namespaceID, workflowID, + archetypeID, lockPriority, ) if err != nil { @@ -216,7 +247,7 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentWorkflowLease( ctx, consistencyPredicate, definition.NewWorkflowKey(namespaceID, workflowID, runID), - archetype, + archetypeID, lockPriority, ) @@ -227,7 +258,7 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentWorkflowLease( return workflowLease, nil } - currentRunID, err := c.GetCurrentRunID(ctx, namespaceID, workflowID, lockPriority) + currentRunID, err := c.GetCurrentChasmRunID(ctx, namespaceID, workflowID, archetypeID, lockPriority) if err != nil { workflowLease.GetReleaseFn()(err) @@ -245,7 +276,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowLease( ctx context.Context, consistencyPredicate MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (WorkflowLease, error) { @@ -257,7 +288,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowLease( WorkflowId: workflowKey.WorkflowID, RunId: workflowKey.RunID, }, - archetype, + archetypeID, lockPriority, ) if err != nil { diff --git a/service/history/api/consistency_checker_mock.go b/service/history/api/consistency_checker_mock.go index 62b64ec8abe..10d01006a3e 100644 --- a/service/history/api/consistency_checker_mock.go +++ b/service/history/api/consistency_checker_mock.go @@ -46,48 +46,63 @@ func (m *MockWorkflowConsistencyChecker) EXPECT() *MockWorkflowConsistencyChecke } // GetChasmLease mocks base method. -func (m *MockWorkflowConsistencyChecker) GetChasmLease(ctx context.Context, reqClock *clock.VectorClock, workflowKey definition.WorkflowKey, archetype chasm.Archetype, lockPriority locks.Priority) (WorkflowLease, error) { +func (m *MockWorkflowConsistencyChecker) GetChasmLease(ctx context.Context, reqClock *clock.VectorClock, workflowKey definition.WorkflowKey, archetypeID chasm.ArchetypeID, lockPriority locks.Priority) (WorkflowLease, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetChasmLease", ctx, reqClock, workflowKey, archetype, lockPriority) + ret := m.ctrl.Call(m, "GetChasmLease", ctx, reqClock, workflowKey, archetypeID, lockPriority) ret0, _ := ret[0].(WorkflowLease) ret1, _ := ret[1].(error) return ret0, ret1 } // GetChasmLease indicates an expected call of GetChasmLease. -func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetChasmLease(ctx, reqClock, workflowKey, archetype, lockPriority any) *gomock.Call { +func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetChasmLease(ctx, reqClock, workflowKey, archetypeID, lockPriority any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChasmLease", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetChasmLease), ctx, reqClock, workflowKey, archetype, lockPriority) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChasmLease", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetChasmLease), ctx, reqClock, workflowKey, archetypeID, lockPriority) } // GetChasmLeaseWithConsistencyCheck mocks base method. -func (m *MockWorkflowConsistencyChecker) GetChasmLeaseWithConsistencyCheck(ctx context.Context, reqClock *clock.VectorClock, consistencyPredicate MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, archetype chasm.Archetype, lockPriority locks.Priority) (WorkflowLease, error) { +func (m *MockWorkflowConsistencyChecker) GetChasmLeaseWithConsistencyCheck(ctx context.Context, reqClock *clock.VectorClock, consistencyPredicate MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, archetypeID chasm.ArchetypeID, lockPriority locks.Priority) (WorkflowLease, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetChasmLeaseWithConsistencyCheck", ctx, reqClock, consistencyPredicate, workflowKey, archetype, lockPriority) + ret := m.ctrl.Call(m, "GetChasmLeaseWithConsistencyCheck", ctx, reqClock, consistencyPredicate, workflowKey, archetypeID, lockPriority) ret0, _ := ret[0].(WorkflowLease) ret1, _ := ret[1].(error) return ret0, ret1 } // GetChasmLeaseWithConsistencyCheck indicates an expected call of GetChasmLeaseWithConsistencyCheck. -func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetChasmLeaseWithConsistencyCheck(ctx, reqClock, consistencyPredicate, workflowKey, archetype, lockPriority any) *gomock.Call { +func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetChasmLeaseWithConsistencyCheck(ctx, reqClock, consistencyPredicate, workflowKey, archetypeID, lockPriority any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChasmLeaseWithConsistencyCheck", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetChasmLeaseWithConsistencyCheck), ctx, reqClock, consistencyPredicate, workflowKey, archetype, lockPriority) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChasmLeaseWithConsistencyCheck", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetChasmLeaseWithConsistencyCheck), ctx, reqClock, consistencyPredicate, workflowKey, archetypeID, lockPriority) } -// GetCurrentRunID mocks base method. -func (m *MockWorkflowConsistencyChecker) GetCurrentRunID(ctx context.Context, namespaceID, workflowID string, lockPriority locks.Priority) (string, error) { +// GetCurrentChasmRunID mocks base method. +func (m *MockWorkflowConsistencyChecker) GetCurrentChasmRunID(ctx context.Context, namespaceID, workflowID string, archetypeID chasm.ArchetypeID, lockPriority locks.Priority) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCurrentRunID", ctx, namespaceID, workflowID, lockPriority) + ret := m.ctrl.Call(m, "GetCurrentChasmRunID", ctx, namespaceID, workflowID, archetypeID, lockPriority) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetCurrentRunID indicates an expected call of GetCurrentRunID. -func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetCurrentRunID(ctx, namespaceID, workflowID, lockPriority any) *gomock.Call { +// GetCurrentChasmRunID indicates an expected call of GetCurrentChasmRunID. +func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetCurrentChasmRunID(ctx, namespaceID, workflowID, archetypeID, lockPriority any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentRunID", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetCurrentRunID), ctx, namespaceID, workflowID, lockPriority) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentChasmRunID", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetCurrentChasmRunID), ctx, namespaceID, workflowID, archetypeID, lockPriority) +} + +// GetCurrentWorkflowRunID mocks base method. +func (m *MockWorkflowConsistencyChecker) GetCurrentWorkflowRunID(ctx context.Context, namespaceID, workflowID string, lockPriority locks.Priority) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCurrentWorkflowRunID", ctx, namespaceID, workflowID, lockPriority) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCurrentWorkflowRunID indicates an expected call of GetCurrentWorkflowRunID. +func (mr *MockWorkflowConsistencyCheckerMockRecorder) GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, lockPriority any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentWorkflowRunID", reflect.TypeOf((*MockWorkflowConsistencyChecker)(nil).GetCurrentWorkflowRunID), ctx, namespaceID, workflowID, lockPriority) } // GetWorkflowCache mocks base method. diff --git a/service/history/api/consistency_checker_test.go b/service/history/api/consistency_checker_test.go index 2006a99a354..6e9a3e5b4c4 100644 --- a/service/history/api/consistency_checker_test.go +++ b/service/history/api/consistency_checker_test.go @@ -93,7 +93,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck WorkflowId: s.workflowID, RunId: s.currentRunID, }), - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(wfContext, releaseFn, nil) wfContext.EXPECT().LoadMutableState(ctx, s.shardContext).Return(mutableState, nil) @@ -113,11 +113,12 @@ func (s *workflowConsistencyCheckerSuite) TestGetCurrentRunID_Success() { released := false releaseFn := func(err error) { released = true } - s.workflowCache.EXPECT().GetOrCreateCurrentWorkflowExecution( + s.workflowCache.EXPECT().GetOrCreateCurrentExecution( ctx, s.shardContext, namespace.ID(s.namespaceID), s.workflowID, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(releaseFn, nil) s.shardContext.EXPECT().GetCurrentExecution( @@ -126,10 +127,11 @@ func (s *workflowConsistencyCheckerSuite) TestGetCurrentRunID_Success() { ShardID: s.shardContext.GetShardID(), NamespaceID: s.namespaceID, WorkflowID: s.workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }, ).Return(&persistence.GetCurrentExecutionResponse{RunID: s.currentRunID}, nil) - runID, err := s.checker.GetCurrentRunID(ctx, s.namespaceID, s.workflowID, locks.PriorityHigh) + runID, err := s.checker.GetCurrentWorkflowRunID(ctx, s.namespaceID, s.workflowID, locks.PriorityHigh) s.NoError(err) s.Equal(s.currentRunID, runID) s.True(released) @@ -141,11 +143,12 @@ func (s *workflowConsistencyCheckerSuite) TestGetCurrentRunID_Error() { released := false releaseFn := func(err error) { released = true } - s.workflowCache.EXPECT().GetOrCreateCurrentWorkflowExecution( + s.workflowCache.EXPECT().GetOrCreateCurrentExecution( ctx, s.shardContext, namespace.ID(s.namespaceID), s.workflowID, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(releaseFn, nil) s.shardContext.EXPECT().GetCurrentExecution( @@ -154,10 +157,11 @@ func (s *workflowConsistencyCheckerSuite) TestGetCurrentRunID_Error() { ShardID: s.shardContext.GetShardID(), NamespaceID: s.namespaceID, WorkflowID: s.workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }, ).Return(nil, serviceerror.NewUnavailable("")) - runID, err := s.checker.GetCurrentRunID(ctx, s.namespaceID, s.workflowID, locks.PriorityHigh) + runID, err := s.checker.GetCurrentWorkflowRunID(ctx, s.namespaceID, s.workflowID, locks.PriorityHigh) s.IsType(&serviceerror.Unavailable{}, err) s.Empty(runID) s.True(released) diff --git a/service/history/api/create_workflow_util.go b/service/history/api/create_workflow_util.go index 11d50ba65d6..800b96b16cc 100644 --- a/service/history/api/create_workflow_util.go +++ b/service/history/api/create_workflow_util.go @@ -10,6 +10,7 @@ import ( "go.temporal.io/api/workflowservice/v1" "go.temporal.io/server/api/historyservice/v1" workflowspb "go.temporal.io/server/api/workflow/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log/tag" @@ -141,6 +142,7 @@ func NewWorkflowLeaseAndContext( ms.GetExecutionInfo().WorkflowId, ms.GetExecutionState().RunId, ), + chasm.WorkflowArchetypeID, shardCtx.GetLogger(), shardCtx.GetThrottledLogger(), shardCtx.GetMetricsHandler(), diff --git a/service/history/api/describemutablestate/api.go b/service/history/api/describemutablestate/api.go index dcc2f8d57a7..5fba9adb39e 100644 --- a/service/history/api/describemutablestate/api.go +++ b/service/history/api/describemutablestate/api.go @@ -25,6 +25,11 @@ func Invoke( return nil, err } + archetypeID := req.GetArchetypeId() + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + chasmLease, err := workflowConsistencyChecker.GetChasmLease( ctx, nil, @@ -33,7 +38,7 @@ func Invoke( req.Execution.WorkflowId, req.Execution.RunId, ), - chasm.ArchetypeAny, // DescribeMutableState works for all Archetypes. + archetypeID, locks.PriorityHigh, ) if err != nil { diff --git a/service/history/api/forcedeleteworkflowexecution/api.go b/service/history/api/forcedeleteworkflowexecution/api.go index 2d37d28d69d..f49c46a27aa 100644 --- a/service/history/api/forcedeleteworkflowexecution/api.go +++ b/service/history/api/forcedeleteworkflowexecution/api.go @@ -7,6 +7,7 @@ import ( "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/api/historyservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -19,6 +20,7 @@ func Invoke( ctx context.Context, request *historyservice.ForceDeleteWorkflowExecutionRequest, shardID int32, + chasmRegistry *chasm.Registry, persistenceExecutionMgr persistence.ExecutionManager, persistenceVisibilityMgr manager.VisibilityManager, logger log.Logger, @@ -32,11 +34,17 @@ func Invoke( tag.WorkflowRunID(execution.RunId), ) + archetypeID := request.GetArchetypeId() + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + if execution.RunId == "" { resp, err := persistenceExecutionMgr.GetCurrentExecution(ctx, &persistence.GetCurrentExecutionRequest{ ShardID: shardID, NamespaceID: request.NamespaceId, WorkflowID: execution.WorkflowId, + ArchetypeID: archetypeID, }) if err != nil { return nil, err @@ -52,6 +60,7 @@ func Invoke( NamespaceID: request.NamespaceId, WorkflowID: execution.WorkflowId, RunID: execution.RunId, + ArchetypeID: archetypeID, }) if err != nil { if common.IsContextCanceledErr(err) || common.IsContextDeadlineExceededErr(err) { @@ -89,6 +98,7 @@ func Invoke( NamespaceID: request.NamespaceId, WorkflowID: execution.WorkflowId, RunID: execution.RunId, + ArchetypeID: archetypeID, }); err != nil { return nil, err } @@ -98,6 +108,7 @@ func Invoke( NamespaceID: request.NamespaceId, WorkflowID: execution.WorkflowId, RunID: execution.RunId, + ArchetypeID: archetypeID, }); err != nil { return nil, err } diff --git a/service/history/api/get_workflow_util.go b/service/history/api/get_workflow_util.go index bed582857cc..44f837170ce 100644 --- a/service/history/api/get_workflow_util.go +++ b/service/history/api/get_workflow_util.go @@ -26,7 +26,8 @@ import ( const longPollSoftTimeout = time.Second -func GetOrPollMutableState( +//nolint:revive // cognitive complexity 39 (> max enabled 25) +func GetOrPollWorkflowMutableState( ctx context.Context, shardContext historyi.ShardContext, request *historyservice.GetMutableStateRequest, @@ -42,7 +43,7 @@ func GetOrPollMutableState( } if len(request.Execution.RunId) == 0 { - request.Execution.RunId, err = workflowConsistencyChecker.GetCurrentRunID( + request.Execution.RunId, err = workflowConsistencyChecker.GetCurrentWorkflowRunID( ctx, request.NamespaceId, request.Execution.WorkflowId, diff --git a/service/history/api/getworkflowexecutionhistory/api.go b/service/history/api/getworkflowexecutionhistory/api.go index 059c71b6071..c6249fb44a0 100644 --- a/service/history/api/getworkflowexecutionhistory/api.go +++ b/service/history/api/getworkflowexecutionhistory/api.go @@ -63,7 +63,7 @@ func Invoke( versionHistoryItem *historyspb.VersionHistoryItem, versionedTransition *persistencespb.VersionedTransition, ) ([]byte, string, int64, int64, bool, *historyspb.VersionHistoryItem, *persistencespb.VersionedTransition, error) { - response, err := api.GetOrPollMutableState( + response, err := api.GetOrPollWorkflowMutableState( ctx, shardContext, &historyservice.GetMutableStateRequest{ @@ -87,7 +87,7 @@ func Invoke( tag.Error(err), ) // if we are only querying for close event, and encounter CurrentBranchChanged error, then we retry with empty branch token to get the close event - response, err = api.GetOrPollMutableState( + response, err = api.GetOrPollWorkflowMutableState( ctx, shardContext, &historyservice.GetMutableStateRequest{ diff --git a/service/history/api/getworkflowexecutionhistoryreverse/api.go b/service/history/api/getworkflowexecutionhistoryreverse/api.go index d0c08f6da83..ebf282b22cc 100644 --- a/service/history/api/getworkflowexecutionhistoryreverse/api.go +++ b/service/history/api/getworkflowexecutionhistoryreverse/api.go @@ -41,7 +41,7 @@ func Invoke( currentBranchToken []byte, versionHistoryItem *historyspb.VersionHistoryItem, ) ([]byte, string, int64, *historyspb.VersionHistoryItem, error) { - response, err := api.GetOrPollMutableState( + response, err := api.GetOrPollWorkflowMutableState( ctx, shardContext, &historyservice.GetMutableStateRequest{ diff --git a/service/history/api/getworkflowexecutionrawhistory/api.go b/service/history/api/getworkflowexecutionrawhistory/api.go index 55ee43b08c3..f41e0bf5a07 100644 --- a/service/history/api/getworkflowexecutionrawhistory/api.go +++ b/service/history/api/getworkflowexecutionrawhistory/api.go @@ -42,7 +42,7 @@ func Invoke( var pageToken *tokenspb.RawHistoryContinuation var targetVersionHistory *historyspb.VersionHistory if req.NextPageToken == nil { - response, err := api.GetOrPollMutableState( + response, err := api.GetOrPollWorkflowMutableState( ctx, shardContext, &historyservice.GetMutableStateRequest{ diff --git a/service/history/api/getworkflowexecutionrawhistoryv2/api.go b/service/history/api/getworkflowexecutionrawhistoryv2/api.go index 8f2f19316af..99ff916da65 100644 --- a/service/history/api/getworkflowexecutionrawhistoryv2/api.go +++ b/service/history/api/getworkflowexecutionrawhistoryv2/api.go @@ -38,7 +38,7 @@ func Invoke( var pageToken *tokenspb.RawHistoryContinuation var targetVersionHistory *historyspb.VersionHistory if req.NextPageToken == nil { - response, err := api.GetOrPollMutableState( + response, err := api.GetOrPollWorkflowMutableState( ctx, shardContext, &historyservice.GetMutableStateRequest{ diff --git a/service/history/api/queryworkflow/api.go b/service/history/api/queryworkflow/api.go index 42d352c9644..3f985ed94fb 100644 --- a/service/history/api/queryworkflow/api.go +++ b/service/history/api/queryworkflow/api.go @@ -50,7 +50,7 @@ func Invoke( } if len(request.Request.Execution.RunId) == 0 { - request.Request.Execution.RunId, err = workflowConsistencyChecker.GetCurrentRunID( + request.Request.Execution.RunId, err = workflowConsistencyChecker.GetCurrentWorkflowRunID( ctx, request.NamespaceId, request.Request.Execution.WorkflowId, diff --git a/service/history/api/refreshworkflow/api.go b/service/history/api/refreshworkflow/api.go index 1616cce7dd7..8784ebcc98a 100644 --- a/service/history/api/refreshworkflow/api.go +++ b/service/history/api/refreshworkflow/api.go @@ -14,6 +14,7 @@ import ( func Invoke( ctx context.Context, workflowKey definition.WorkflowKey, + archetypeID chasm.ArchetypeID, shardContext historyi.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (retError error) { @@ -22,11 +23,15 @@ func Invoke( return err } + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + chasmLease, err := workflowConsistencyChecker.GetChasmLease( ctx, nil, workflowKey, - chasm.ArchetypeAny, // RefreshWorkflow works for all Archetypes. + archetypeID, locks.PriorityLow, ) if err != nil { diff --git a/service/history/api/replication/generate_task.go b/service/history/api/replication/generate_task.go index dcae298da87..2abc32d5b2a 100644 --- a/service/history/api/replication/generate_task.go +++ b/service/history/api/replication/generate_task.go @@ -17,15 +17,20 @@ import ( func GenerateTask( ctx context.Context, request *historyservice.GenerateLastHistoryReplicationTasksRequest, - shard historyi.ShardContext, + shardContext historyi.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (_ *historyservice.GenerateLastHistoryReplicationTasksResponse, retError error) { - namespaceEntry, err := api.GetNamespace(shard, namespace.ID(request.GetNamespaceId())) + namespaceEntry, err := api.GetNamespace(shardContext, namespace.ID(request.GetNamespaceId())) if err != nil { return nil, err } namespaceID := namespaceEntry.ID() + archetypeID := request.GetArchetypeId() + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + chasmLease, err := workflowConsistencyChecker.GetChasmLease( ctx, nil, @@ -34,7 +39,7 @@ func GenerateTask( request.Execution.WorkflowId, request.Execution.RunId, ), - chasm.ArchetypeAny, // GenerateMigrationTasks works for all Archetypes. + archetypeID, locks.PriorityHigh, ) if err != nil { @@ -48,11 +53,12 @@ func GenerateTask( return nil, err } - err = shard.AddTasks(ctx, &persistence.AddHistoryTasksRequest{ - ShardID: shard.GetShardID(), + err = shardContext.AddTasks(ctx, &persistence.AddHistoryTasksRequest{ + ShardID: shardContext.GetShardID(), // RangeID is set by shard NamespaceID: string(namespaceID), WorkflowID: request.Execution.WorkflowId, + ArchetypeID: archetypeID, Tasks: map[tasks.Category][]tasks.Task{ tasks.CategoryReplication: replicationTasks, }, diff --git a/service/history/api/replication/sync_workflow_state.go b/service/history/api/replication/sync_workflow_state.go index 8fcc5ab7f38..8a06478eafe 100644 --- a/service/history/api/replication/sync_workflow_state.go +++ b/service/history/api/replication/sync_workflow_state.go @@ -4,6 +4,7 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/service/history/replication" @@ -16,7 +17,18 @@ func SyncWorkflowState( syncStateRetriever replication.SyncStateRetriever, logger log.Logger, ) (_ *historyservice.SyncWorkflowStateResponse, retError error) { - result, err := syncStateRetriever.GetSyncWorkflowStateArtifact(ctx, request.GetNamespaceId(), request.Execution, request.VersionedTransition, request.VersionHistories) + archetypeID := request.GetArchetypeId() + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + result, err := syncStateRetriever.GetSyncWorkflowStateArtifact( + ctx, + request.GetNamespaceId(), + request.Execution, + archetypeID, + request.VersionedTransition, + request.VersionHistories, + ) if err != nil { logger.Error("SyncWorkflowState failed to retrieve sync state artifact", tag.WorkflowNamespaceID(request.NamespaceId), tag.WorkflowID(request.Execution.WorkflowId), diff --git a/service/history/api/resetworkflow/api.go b/service/history/api/resetworkflow/api.go index 93faeb1c6f8..f4705905973 100644 --- a/service/history/api/resetworkflow/api.go +++ b/service/history/api/resetworkflow/api.go @@ -63,7 +63,7 @@ func Invoke( } // also load the current run of the workflow, it can be different from the base runID - currentRunID, err := workflowConsistencyChecker.GetCurrentRunID( + currentRunID, err := workflowConsistencyChecker.GetCurrentWorkflowRunID( ctx, namespaceID.String(), request.WorkflowExecution.GetWorkflowId(), diff --git a/service/history/api/respondactivitytaskfailed/api_test.go b/service/history/api/respondactivitytaskfailed/api_test.go index 7e3e8928ccc..e871b3c61a6 100644 --- a/service/history/api/respondactivitytaskfailed/api_test.go +++ b/service/history/api/respondactivitytaskfailed/api_test.go @@ -416,9 +416,9 @@ func (s *workflowSuite) setupWorkflowContext(mutableState *historyi.MockMutableS func (s *workflowSuite) setupCache() *wcache.MockCache { workflowCache := wcache.NewMockCache(s.controller) - workflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetype, locks.PriorityHigh). + workflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetypeID, locks.PriorityHigh). Return(s.workflowContext, wcache.NoopReleaseFn, nil).AnyTimes() - workflowCache.EXPECT().GetOrCreateCurrentWorkflowExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), locks.PriorityHigh).Return(wcache.NoopReleaseFn, nil).AnyTimes() + workflowCache.EXPECT().GetOrCreateCurrentExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetypeID, locks.PriorityHigh).Return(wcache.NoopReleaseFn, nil).AnyTimes() return workflowCache } diff --git a/service/history/api/respondworkflowtaskcompleted/api.go b/service/history/api/respondworkflowtaskcompleted/api.go index 1ef2e3bfe02..4b54daaaf2c 100644 --- a/service/history/api/respondworkflowtaskcompleted/api.go +++ b/service/history/api/respondworkflowtaskcompleted/api.go @@ -15,6 +15,7 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/api/matchingservice/v1" tokenspb "go.temporal.io/server/api/token/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/collection" @@ -615,6 +616,7 @@ func (handler *WorkflowTaskCompletedHandler) Invoke( newWorkflowExecutionInfo.WorkflowId, newWorkflowExecutionState.RunId, ), + chasm.WorkflowArchetypeID, handler.logger, handler.shardContext.GetThrottledLogger(), handler.shardContext.GetMetricsHandler(), diff --git a/service/history/api/signalworkflow/api_test.go b/service/history/api/signalworkflow/api_test.go index e542940e49a..9ec94a110fd 100644 --- a/service/history/api/signalworkflow/api_test.go +++ b/service/history/api/signalworkflow/api_test.go @@ -83,7 +83,7 @@ func (s *signalWorkflowSuite) SetupTest() { s.currentContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.currentMutableState, nil).AnyTimes() s.workflowCache = wcache.NewMockCache(s.controller) - s.workflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetype, locks.PriorityHigh). + s.workflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetypeID, locks.PriorityHigh). Return(s.currentContext, wcache.NoopReleaseFn, nil).AnyTimes() s.workflowConsistencyChecker = api.NewWorkflowConsistencyChecker( diff --git a/service/history/api/startworkflow/api.go b/service/history/api/startworkflow/api.go index 96db0909fe3..6b4bd314de6 100644 --- a/service/history/api/startworkflow/api.go +++ b/service/history/api/startworkflow/api.go @@ -11,6 +11,7 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/api/workflowservice/v1" "go.temporal.io/server/api/historyservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" @@ -213,11 +214,12 @@ func (s *Starter) Invoke( func (s *Starter) lockCurrentWorkflowExecution( ctx context.Context, ) (historyi.ReleaseWorkflowContextFunc, error) { - currentRelease, err := s.workflowConsistencyChecker.GetWorkflowCache().GetOrCreateCurrentWorkflowExecution( + currentRelease, err := s.workflowConsistencyChecker.GetWorkflowCache().GetOrCreateCurrentExecution( ctx, s.shardContext, s.namespace.ID(), s.request.StartRequest.WorkflowId, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ) if err != nil { diff --git a/service/history/api/trim_history_util.go b/service/history/api/trim_history_util.go index 72766d9e1bf..b829e11aac8 100644 --- a/service/history/api/trim_history_util.go +++ b/service/history/api/trim_history_util.go @@ -21,7 +21,7 @@ func TrimHistoryNode( workflowID string, runID string, ) { - response, err := GetOrPollMutableState( + response, err := GetOrPollWorkflowMutableState( ctx, shardContext, &historyservice.GetMutableStateRequest{ diff --git a/service/history/api/updateworkflowoptions/api_test.go b/service/history/api/updateworkflowoptions/api_test.go index e7cb7ad4dcc..951445c7b9e 100644 --- a/service/history/api/updateworkflowoptions/api_test.go +++ b/service/history/api/updateworkflowoptions/api_test.go @@ -178,7 +178,7 @@ func (s *updateWorkflowOptionsSuite) SetupTest() { s.currentContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.currentMutableState, nil) s.workflowCache = wcache.NewMockCache(s.controller) - s.workflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetype, locks.PriorityHigh). + s.workflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.WorkflowArchetypeID, locks.PriorityHigh). Return(s.currentContext, wcache.NoopReleaseFn, nil) s.workflowConsistencyChecker = api.NewWorkflowConsistencyChecker( diff --git a/service/history/api/verifychildworkflowcompletionrecorded/api.go b/service/history/api/verifychildworkflowcompletionrecorded/api.go index 941a7a0a027..e418a3aad64 100644 --- a/service/history/api/verifychildworkflowcompletionrecorded/api.go +++ b/service/history/api/verifychildworkflowcompletionrecorded/api.go @@ -11,6 +11,7 @@ import ( historyspb "go.temporal.io/server/api/history/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/locks" @@ -132,6 +133,7 @@ func Invoke( WorkflowId: request.ParentExecution.WorkflowId, RunId: request.ParentExecution.RunId, }, + ArchetypeId: chasm.WorkflowArchetypeID, VersionedTransition: versionedTransition, VersionHistories: versionHistories, TargetClusterId: int32(targetClusterInfo.InitialFailoverVersion), @@ -156,7 +158,7 @@ func Invoke( if err != nil { return nil, err } - err = engine.ReplicateVersionedTransition(ctx, resp.VersionedTransitionArtifact, activeClusterName) + err = engine.ReplicateVersionedTransition(ctx, chasm.WorkflowArchetypeID, resp.VersionedTransitionArtifact, activeClusterName) if err != nil { return nil, err } diff --git a/service/history/archival_queue_task_executor.go b/service/history/archival_queue_task_executor.go index f75292e03dc..602c0179a33 100644 --- a/service/history/archival_queue_task_executor.go +++ b/service/history/archival_queue_task_executor.go @@ -7,6 +7,7 @@ import ( "time" enumspb "go.temporal.io/api/enums/v1" + "go.temporal.io/server/chasm" carchiver "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -248,6 +249,7 @@ func (e *archivalQueueTaskExecutor) addDeletionTask( ShardID: e.shardContext.GetShardID(), NamespaceID: task.GetNamespaceID(), WorkflowID: task.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, // Archival is only supported for workflow now. Tasks: mutableState.PopTasks(), }) return err diff --git a/service/history/archival_queue_task_executor_test.go b/service/history/archival_queue_task_executor_test.go index 178780ff645..416b417bb07 100644 --- a/service/history/archival_queue_task_executor_test.go +++ b/service/history/archival_queue_task_executor_test.go @@ -420,6 +420,7 @@ func TestArchivalQueueTaskExecutor(t *testing.T) { StartTime: timestamppb.New(p.StartTime), } mutableState.EXPECT().GetExecutionState().Return(executionState).AnyTimes() + mutableState.EXPECT().ChasmTree().Return(workflow.NoopChasmTree).AnyTimes() if p.ExpectAddTask { mutableState.EXPECT().AddTasks(gomock.Any()).Do(func(ts ...*tasks.DeleteHistoryEventTask) { require.Len(t, ts, 1) @@ -439,6 +440,7 @@ func TestArchivalQueueTaskExecutor(t *testing.T) { ShardID: shardID, NamespaceID: tests.NamespaceID.String(), WorkflowID: task.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, Tasks: popTasks, }) }) @@ -454,7 +456,7 @@ func TestArchivalQueueTaskExecutor(t *testing.T) { gomock.Any(), gomock.Any(), gomock.Any(), - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, gomock.Any(), ).Return( workflowContext, diff --git a/service/history/chasm_engine.go b/service/history/chasm_engine.go index a182fc2dbc1..ed429268182 100644 --- a/service/history/chasm_engine.go +++ b/service/history/chasm_engine.go @@ -96,11 +96,17 @@ func (e *ChasmEngine) NewExecution( return chasm.ExecutionKey{}, nil, err } + archetypeID, err := executionRef.ArchetypeID(e.registry) + if err != nil { + return chasm.ExecutionKey{}, nil, err + } + currentExecutionReleaseFn, err := e.lockCurrentExecution( ctx, shardContext, namespace.ID(executionRef.NamespaceID), executionRef.BusinessID, + archetypeID, ) if err != nil { return chasm.ExecutionKey{}, nil, err @@ -113,6 +119,7 @@ func (e *ChasmEngine) NewExecution( ctx, shardContext, executionRef, + archetypeID, newFn, options, ) @@ -269,12 +276,14 @@ func (e *ChasmEngine) lockCurrentExecution( shardContext historyi.ShardContext, namespaceID namespace.ID, businessID string, + archetypeID chasm.ArchetypeID, ) (historyi.ReleaseWorkflowContextFunc, error) { - currentExecutionReleaseFn, err := e.executionCache.GetOrCreateCurrentWorkflowExecution( + currentExecutionReleaseFn, err := e.executionCache.GetOrCreateCurrentExecution( ctx, shardContext, namespaceID, businessID, + archetypeID, locks.PriorityHigh, ) if err != nil { @@ -288,6 +297,7 @@ func (e *ChasmEngine) createNewExecution( ctx context.Context, shardContext historyi.ShardContext, executionRef chasm.ComponentRef, + archetypeID chasm.ArchetypeID, newFn func(chasm.MutableContext) (chasm.Component, error), options chasm.TransitionOptions, ) (newExecutionParams, error) { @@ -346,6 +356,7 @@ func (e *ChasmEngine) createNewExecution( executionKey.BusinessID, executionKey.RunID, ), + archetypeID, shardContext.GetLogger(), shardContext.GetThrottledLogger(), shardContext.GetMetricsHandler(), @@ -587,13 +598,6 @@ func (e *ChasmEngine) getExecutionLease( return nil, nil, err } - // TODO: use archetypeID as well in execution cache and then we don't need - // this extra conversion. - archetype, ok := e.registry.ComponentFqnByID(archetypeID) - if !ok { - return nil, nil, serviceerror.NewInternalf("unknown archetype ID: %v", archetypeID) - } - var staleReferenceErr error executionLease, err := consistencyChecker.GetChasmLeaseWithConsistencyCheck( ctx, @@ -614,7 +618,7 @@ func (e *ChasmEngine) getExecutionLease( ref.BusinessID, ref.RunID, ), - chasm.Archetype(archetype), + archetypeID, lockPriority, ) if err == nil && staleReferenceErr != nil { diff --git a/service/history/chasm_engine_test.go b/service/history/chasm_engine_test.go index 5fc94b69f04..078cc89ef55 100644 --- a/service/history/chasm_engine_test.go +++ b/service/history/chasm_engine_test.go @@ -51,6 +51,7 @@ type chasmEngineSuite struct { executionCache wcache.Cache registry *chasm.Registry config *configs.Config + archetypeID chasm.ArchetypeID engine *ChasmEngine } @@ -107,6 +108,10 @@ func (s *chasmEngineSuite) SetupTest() { s.NoError(err) s.mockShard.SetChasmRegistry(s.registry) + var ok bool + s.archetypeID, ok = s.registry.ComponentIDFor(&testComponent{}) + s.True(ok) + s.mockShard.SetEngineForTesting(s.mockEngine) s.mockEngine.EXPECT().NotifyNewTasks(gomock.Any()).AnyTimes() s.mockEngine.EXPECT().NotifyNewHistoryEvent(gomock.Any()).AnyTimes() @@ -146,7 +151,7 @@ func (s *chasmEngineSuite) TestNewExecution_BrandNew() { _ context.Context, request *persistence.CreateWorkflowExecutionRequest, ) (*persistence.CreateWorkflowExecutionResponse, error) { - s.validateCreateRequest(request, newActivityID, "", 0) + s.validateCreateRequest(request, s.archetypeID, newActivityID, "", 0) runID = request.NewWorkflowSnapshot.ExecutionState.RunId return tests.CreateWorkflowExecutionResponse, nil }, @@ -238,7 +243,7 @@ func (s *chasmEngineSuite) TestNewExecution_ReusePolicy_AllowDuplicate() { _ context.Context, request *persistence.CreateWorkflowExecutionRequest, ) (*persistence.CreateWorkflowExecutionResponse, error) { - s.validateCreateRequest(request, newActivityID, tv.RunID(), currentRunConditionFailedErr.LastWriteVersion) + s.validateCreateRequest(request, s.archetypeID, newActivityID, tv.RunID(), currentRunConditionFailedErr.LastWriteVersion) runID = request.NewWorkflowSnapshot.ExecutionState.RunId return tests.CreateWorkflowExecutionResponse, nil }, @@ -292,7 +297,7 @@ func (s *chasmEngineSuite) TestNewExecution_ReusePolicy_FailedOnly_Success() { _ context.Context, request *persistence.CreateWorkflowExecutionRequest, ) (*persistence.CreateWorkflowExecutionResponse, error) { - s.validateCreateRequest(request, newActivityID, tv.RunID(), currentRunConditionFailedErr.LastWriteVersion) + s.validateCreateRequest(request, s.archetypeID, newActivityID, tv.RunID(), currentRunConditionFailedErr.LastWriteVersion) runID = request.NewWorkflowSnapshot.ExecutionState.RunId return tests.CreateWorkflowExecutionResponse, nil }, @@ -480,10 +485,13 @@ func (s *chasmEngineSuite) newTestExecutionFn( func (s *chasmEngineSuite) validateCreateRequest( request *persistence.CreateWorkflowExecutionRequest, + expectedArchetypeID chasm.ArchetypeID, expectedActivityID string, expectedPreviousRunID string, expectedPreviousLastWriteVersion int64, ) { + s.Equal(expectedArchetypeID, request.ArchetypeID) + if expectedPreviousRunID == "" && expectedPreviousLastWriteVersion == 0 { s.Equal(persistence.CreateWorkflowModeBrandNew, request.Mode) } else { diff --git a/service/history/deletemanager/delete_manager.go b/service/history/deletemanager/delete_manager.go index b87923e6e61..8765f606ed3 100644 --- a/service/history/deletemanager/delete_manager.go +++ b/service/history/deletemanager/delete_manager.go @@ -6,6 +6,7 @@ import ( "context" commonpb "go.temporal.io/api/common/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" @@ -97,6 +98,7 @@ func (m *DeleteManagerImpl) AddDeleteWorkflowExecutionTask( // RangeID is set by shardContext NamespaceID: nsID.String(), WorkflowID: we.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, // this method is specific to workflow executions Tasks: map[tasks.Category][]tasks.Task{ tasks.CategoryTransfer: {deleteTask}, }, @@ -150,6 +152,7 @@ func (m *DeleteManagerImpl) deleteWorkflowExecutionInternal( WorkflowID: we.GetWorkflowId(), RunID: we.GetRunId(), }, + ms.ChasmTree().ArchetypeID(), currentBranchToken, executionInfo.GetCloseVisibilityTaskId(), executionInfo.GetCloseTime().AsTime(), diff --git a/service/history/deletemanager/delete_manager_test.go b/service/history/deletemanager/delete_manager_test.go index d11c9f02dec..78cdb094f5b 100644 --- a/service/history/deletemanager/delete_manager_test.go +++ b/service/history/deletemanager/delete_manager_test.go @@ -10,6 +10,7 @@ import ( commonpb "go.temporal.io/api/common/v1" "go.temporal.io/api/serviceerror" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/definition" @@ -19,6 +20,7 @@ import ( historyi "go.temporal.io/server/service/history/interfaces" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" + "go.temporal.io/server/service/history/workflow" wcache "go.temporal.io/server/service/history/workflow/cache" "go.uber.org/mock/gomock" ) @@ -92,6 +94,7 @@ func (s *deleteManagerWorkflowSuite) TestDeleteDeletedWorkflowExecution() { mockMutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ CloseVisibilityTaskId: closeExecutionVisibilityTaskID, }) + mockMutableState.EXPECT().ChasmTree().Return(workflow.NoopChasmTree).AnyTimes() stage := tasks.DeleteWorkflowExecutionStageNone s.mockShardContext.EXPECT().DeleteWorkflowExecution( @@ -101,6 +104,7 @@ func (s *deleteManagerWorkflowSuite) TestDeleteDeletedWorkflowExecution() { WorkflowID: tests.WorkflowID, RunID: tests.RunID, }, + chasm.WorkflowArchetypeID, []byte{22, 8, 78}, closeExecutionVisibilityTaskID, time.Unix(0, 0).UTC(), @@ -132,6 +136,7 @@ func (s *deleteManagerWorkflowSuite) TestDeleteDeletedWorkflowExecution_Error() mockMutableState.EXPECT().GetExecutionInfo().MinTimes(1).Return(&persistencespb.WorkflowExecutionInfo{ CloseVisibilityTaskId: closeExecutionVisibilityTaskID, }) + mockMutableState.EXPECT().ChasmTree().Return(workflow.NoopChasmTree).AnyTimes() stage := tasks.DeleteWorkflowExecutionStageNone s.mockShardContext.EXPECT().DeleteWorkflowExecution( @@ -141,6 +146,7 @@ func (s *deleteManagerWorkflowSuite) TestDeleteDeletedWorkflowExecution_Error() WorkflowID: tests.WorkflowID, RunID: tests.RunID, }, + chasm.WorkflowArchetypeID, []byte{22, 8, 78}, closeExecutionVisibilityTaskID, time.Unix(0, 0).UTC(), @@ -171,6 +177,7 @@ func (s *deleteManagerWorkflowSuite) TestDeleteWorkflowExecution_OpenWorkflow() mockMutableState.EXPECT().GetExecutionInfo().MinTimes(1).Return(&persistencespb.WorkflowExecutionInfo{ CloseVisibilityTaskId: closeExecutionVisibilityTaskID, }) + mockMutableState.EXPECT().ChasmTree().Return(workflow.NoopChasmTree).AnyTimes() stage := tasks.DeleteWorkflowExecutionStageNone s.mockShardContext.EXPECT().DeleteWorkflowExecution( @@ -180,6 +187,7 @@ func (s *deleteManagerWorkflowSuite) TestDeleteWorkflowExecution_OpenWorkflow() WorkflowID: tests.WorkflowID, RunID: tests.RunID, }, + chasm.WorkflowArchetypeID, []byte{22, 8, 78}, closeExecutionVisibilityTaskID, time.Unix(0, 0).UTC(), diff --git a/service/history/fx.go b/service/history/fx.go index b42a7968889..46b16368d92 100644 --- a/service/history/fx.go +++ b/service/history/fx.go @@ -126,6 +126,7 @@ func HandlerProvider(args NewHandlerArgs) *Handler { taskCategoryRegistry: args.TaskCategoryRegistry, dlqMetricsEmitter: args.DLQMetricsEmitter, chasmEngine: args.ChasmEngine, + chasmRegistry: args.ChasmRegistry, replicationTaskFetcherFactory: args.ReplicationTaskFetcherFactory, replicationTaskConverterProvider: args.ReplicationTaskConverterFactory, diff --git a/service/history/handler.go b/service/history/handler.go index 7356db9fa51..30324b80aad 100644 --- a/service/history/handler.go +++ b/service/history/handler.go @@ -94,6 +94,7 @@ type ( taskCategoryRegistry tasks.TaskCategoryRegistry dlqMetricsEmitter *persistence.DLQMetricsEmitter chasmEngine chasm.Engine + chasmRegistry *chasm.Registry replicationTaskFetcherFactory replication.TaskFetcherFactory replicationTaskConverterProvider replication.SourceTaskConverterProvider @@ -129,6 +130,7 @@ type ( TaskCategoryRegistry tasks.TaskCategoryRegistry DLQMetricsEmitter *persistence.DLQMetricsEmitter ChasmEngine chasm.Engine + ChasmRegistry *chasm.Registry ReplicationTaskFetcherFactory replication.TaskFetcherFactory ReplicationTaskConverterFactory replication.SourceTaskConverterProvider @@ -1881,10 +1883,8 @@ func (h *Handler) RefreshWorkflowTasks(ctx context.Context, request *historyserv err = engine.RefreshWorkflowTasks( ctx, namespaceID, - &commonpb.WorkflowExecution{ - WorkflowId: execution.WorkflowId, - RunId: execution.RunId, - }, + execution, + request.GetArchetypeId(), ) if err != nil { @@ -2244,6 +2244,7 @@ func (h *Handler) ForceDeleteWorkflowExecution( ctx, request, shardID, + h.chasmRegistry, h.persistenceExecutionManager, h.persistenceVisibilityManager, h.logger, diff --git a/service/history/history_engine.go b/service/history/history_engine.go index d38f40b4c20..169187830e2 100644 --- a/service/history/history_engine.go +++ b/service/history/history_engine.go @@ -13,6 +13,7 @@ import ( "go.temporal.io/server/api/matchingservice/v1" replicationspb "go.temporal.io/server/api/replication/v1" workflowspb "go.temporal.io/server/api/workflow/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" @@ -419,7 +420,7 @@ func (e *historyEngineImpl) GetMutableState( ctx context.Context, request *historyservice.GetMutableStateRequest, ) (*historyservice.GetMutableStateResponse, error) { - return api.GetOrPollMutableState(ctx, e.shardContext, request, e.workflowConsistencyChecker, e.eventNotifier) + return api.GetOrPollWorkflowMutableState(ctx, e.shardContext, request, e.workflowConsistencyChecker, e.eventNotifier) } // PollMutableState retrieves the mutable state of the workflow execution with long polling @@ -428,7 +429,7 @@ func (e *historyEngineImpl) PollMutableState( request *historyservice.PollMutableStateRequest, ) (*historyservice.PollMutableStateResponse, error) { - response, err := api.GetOrPollMutableState( + response, err := api.GetOrPollWorkflowMutableState( ctx, e.shardContext, &historyservice.GetMutableStateRequest{ @@ -762,8 +763,13 @@ func (e *historyEngineImpl) ReplicateWorkflowState( return e.nDCWorkflowStateReplicator.SyncWorkflowState(ctx, request) } -func (e *historyEngineImpl) ReplicateVersionedTransition(ctx context.Context, artifact *replicationspb.VersionedTransitionArtifact, sourceClusterName string) error { - return e.nDCWorkflowStateReplicator.ReplicateVersionedTransition(ctx, artifact, sourceClusterName) +func (e *historyEngineImpl) ReplicateVersionedTransition( + ctx context.Context, + archetypeID chasm.ArchetypeID, + artifact *replicationspb.VersionedTransitionArtifact, + sourceClusterName string, +) error { + return e.nDCWorkflowStateReplicator.ReplicateVersionedTransition(ctx, archetypeID, artifact, sourceClusterName) } func (e *historyEngineImpl) ImportWorkflowExecution( @@ -964,10 +970,12 @@ func (e *historyEngineImpl) RefreshWorkflowTasks( ctx context.Context, namespaceUUID namespace.ID, execution *commonpb.WorkflowExecution, + archetypeID chasm.ArchetypeID, ) (retError error) { return refreshworkflow.Invoke( ctx, definition.NewWorkflowKey(namespaceUUID.String(), execution.WorkflowId, execution.RunId), + archetypeID, e.shardContext, e.workflowConsistencyChecker, ) diff --git a/service/history/history_engine2_test.go b/service/history/history_engine2_test.go index 760f9e0ba59..a1844263b3e 100644 --- a/service/history/history_engine2_test.go +++ b/service/history/history_engine2_test.go @@ -27,6 +27,7 @@ import ( replicationspb "go.temporal.io/server/api/replication/v1" tokenspb "go.temporal.io/server/api/token/v1" workflowspb "go.temporal.io/server/api/workflow/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" @@ -2505,6 +2506,7 @@ func (s *engine2Suite) TestVerifyChildExecutionCompletionRecorded_ResendParent() VersionedTransition: nil, VersionHistories: nil, TargetClusterId: int32(cluster.TestAlternativeClusterInitialFailoverVersion), + ArchetypeId: chasm.WorkflowArchetypeID, } resp := &adminservice.SyncWorkflowStateResponse{ VersionedTransitionArtifact: &replicationspb.VersionedTransitionArtifact{ @@ -2523,7 +2525,7 @@ func (s *engine2Suite) TestVerifyChildExecutionCompletionRecorded_ResendParent() gomock.Any(), req, ).Return(resp, nil) - s.mockWorkflowStateReplicator.EXPECT().ReplicateVersionedTransition(gomock.Any(), resp.VersionedTransitionArtifact, cluster.TestCurrentClusterName).Return(nil) + s.mockWorkflowStateReplicator.EXPECT().ReplicateVersionedTransition(gomock.Any(), chasm.WorkflowArchetypeID, resp.VersionedTransitionArtifact, cluster.TestCurrentClusterName).Return(nil) // prepare closed workflow ms := workflow.TestGlobalMutableState(s.historyEngine.shardContext, s.mockEventsCache, log.NewTestLogger(), tests.Version, tests.WorkflowID, tests.RunID) @@ -2795,7 +2797,7 @@ func (s *engine2Suite) TestRefreshWorkflowTasks() { gomock.Any(), ).Return(startEvent, nil).AnyTimes() - err = s.historyEngine.RefreshWorkflowTasks(metrics.AddMetricsContext(context.Background()), tests.NamespaceID, execution) + err = s.historyEngine.RefreshWorkflowTasks(metrics.AddMetricsContext(context.Background()), tests.NamespaceID, execution, chasm.WorkflowArchetypeID) s.NoError(err) } diff --git a/service/history/history_engine_test.go b/service/history/history_engine_test.go index d46f8d3b7a0..c82df78551e 100644 --- a/service/history/history_engine_test.go +++ b/service/history/history_engine_test.go @@ -33,6 +33,7 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" tokenspb "go.temporal.io/server/api/token/v1" workflowspb "go.temporal.io/server/api/workflow/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" @@ -5545,6 +5546,7 @@ func (s *engineSuite) TestGetWorkflowExecutionHistory() { NamespaceID: tests.NamespaceID.String(), WorkflowID: we.WorkflowId, RunID: we.RunId, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{State: mState}, nil).AnyTimes() // GetWorkflowExecutionHistory will request the last event s.mockExecutionMgr.EXPECT().ReadHistoryBranch(gomock.Any(), &persistence.ReadHistoryBranchRequest{ @@ -5662,6 +5664,7 @@ func (s *engineSuite) TestGetWorkflowExecutionHistoryWhenInternalRawHistoryIsEna NamespaceID: tests.NamespaceID.String(), WorkflowID: we.WorkflowId, RunID: we.RunId, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{State: mState}, nil).AnyTimes() // GetWorkflowExecutionHistory will request the last event history := historypb.History{ diff --git a/service/history/history_test.go b/service/history/history_test.go index 1b254bbb292..0f7e2cf7845 100644 --- a/service/history/history_test.go +++ b/service/history/history_test.go @@ -15,6 +15,8 @@ import ( historyspb "go.temporal.io/server/api/history/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" + chasmworkflow "go.temporal.io/server/chasm/lib/workflow" "go.temporal.io/server/common" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" @@ -31,10 +33,12 @@ type ( *require.Assertions controller *gomock.Controller - logger log.Logger mockExecutionMgr *persistence.MockExecutionManager mockVisibilityMgr *manager.MockVisibilityManager mockNamespaceCache *namespace.MockRegistry + + chasmRegistry *chasm.Registry + logger log.Logger } ) @@ -54,12 +58,17 @@ func (s *historyAPISuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.logger = log.NewTestLogger() s.mockExecutionMgr = persistence.NewMockExecutionManager(s.controller) s.mockVisibilityMgr = manager.NewMockVisibilityManager(s.controller) s.mockNamespaceCache = namespace.NewMockRegistry(s.controller) s.mockNamespaceCache.EXPECT().GetNamespaceByID(tests.NamespaceID).Return(tests.LocalNamespaceEntry, nil).AnyTimes() s.mockNamespaceCache.EXPECT().GetNamespace(tests.Namespace).Return(tests.LocalNamespaceEntry, nil).AnyTimes() + + s.logger = log.NewTestLogger() + + s.chasmRegistry = chasm.NewRegistry(s.logger) + err := s.chasmRegistry.Register(chasmworkflow.NewLibrary()) + s.NoError(err) } func (s *historyAPISuite) TearDownTest() { @@ -78,8 +87,10 @@ func (s *historyAPISuite) TestDeleteWorkflowExecution_DeleteCurrentExecution() { request := &historyservice.ForceDeleteWorkflowExecutionRequest{ NamespaceId: tests.NamespaceID.String(), + ArchetypeId: chasm.WorkflowArchetypeID, Request: &adminservice.DeleteWorkflowExecutionRequest{ Execution: &execution, + Archetype: chasm.WorkflowArchetype, }, } @@ -87,7 +98,15 @@ func (s *historyAPISuite) TestDeleteWorkflowExecution_DeleteCurrentExecution() { s.mockVisibilityMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), gomock.Any()).AnyTimes() s.mockExecutionMgr.EXPECT().GetCurrentExecution(gomock.Any(), gomock.Any()).Return(nil, errors.New("some random error")) - resp, err := forcedeleteworkflowexecution.Invoke(context.Background(), request, shardID, s.mockExecutionMgr, s.mockVisibilityMgr, s.logger) + resp, err := forcedeleteworkflowexecution.Invoke( + context.Background(), + request, + shardID, + s.chasmRegistry, + s.mockExecutionMgr, + s.mockVisibilityMgr, + s.logger, + ) s.Nil(resp) s.Error(err) @@ -116,22 +135,33 @@ func (s *historyAPISuite) TestDeleteWorkflowExecution_DeleteCurrentExecution() { NamespaceID: tests.NamespaceID.String(), WorkflowID: execution.WorkflowId, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{State: mutableState}, nil) s.mockExecutionMgr.EXPECT().DeleteCurrentWorkflowExecution(gomock.Any(), &persistence.DeleteCurrentWorkflowExecutionRequest{ ShardID: shardID, NamespaceID: tests.NamespaceID.String(), WorkflowID: execution.WorkflowId, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil) s.mockExecutionMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), &persistence.DeleteWorkflowExecutionRequest{ ShardID: shardID, NamespaceID: tests.NamespaceID.String(), WorkflowID: execution.WorkflowId, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil) s.mockExecutionMgr.EXPECT().DeleteHistoryBranch(gomock.Any(), gomock.Any()).Times(len(mutableState.ExecutionInfo.VersionHistories.Histories)) - _, err = forcedeleteworkflowexecution.Invoke(context.Background(), request, shardID, s.mockExecutionMgr, s.mockVisibilityMgr, s.logger) + _, err = forcedeleteworkflowexecution.Invoke( + context.Background(), + request, + shardID, + s.chasmRegistry, + s.mockExecutionMgr, + s.mockVisibilityMgr, + s.logger, + ) s.NoError(err) } @@ -149,8 +179,10 @@ func (s *historyAPISuite) TestDeleteWorkflowExecution_LoadMutableStateFailed() { request := &historyservice.ForceDeleteWorkflowExecutionRequest{ NamespaceId: tests.NamespaceID.String(), + ArchetypeId: chasm.WorkflowArchetypeID, Request: &adminservice.DeleteWorkflowExecutionRequest{ Execution: &execution, + Archetype: chasm.WorkflowArchetype, }, } @@ -161,6 +193,14 @@ func (s *historyAPISuite) TestDeleteWorkflowExecution_LoadMutableStateFailed() { s.mockExecutionMgr.EXPECT().DeleteCurrentWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil) s.mockExecutionMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil) - _, err := forcedeleteworkflowexecution.Invoke(context.Background(), request, shardID, s.mockExecutionMgr, s.mockVisibilityMgr, s.logger) + _, err := forcedeleteworkflowexecution.Invoke( + context.Background(), + request, + shardID, + s.chasmRegistry, + s.mockExecutionMgr, + s.mockVisibilityMgr, + s.logger, + ) s.NoError(err) } diff --git a/service/history/interfaces/engine.go b/service/history/interfaces/engine.go index f3d3d6f7c8c..417c0e3688f 100644 --- a/service/history/interfaces/engine.go +++ b/service/history/interfaces/engine.go @@ -13,6 +13,7 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" replicationspb "go.temporal.io/server/api/replication/v1" workflowspb "go.temporal.io/server/api/workflow/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" @@ -64,7 +65,7 @@ type ( ) error ReplicateEventsV2(ctx context.Context, request *historyservice.ReplicateEventsV2Request) error ReplicateWorkflowState(ctx context.Context, request *historyservice.ReplicateWorkflowStateRequest) error - ReplicateVersionedTransition(ctx context.Context, artifact *replicationspb.VersionedTransitionArtifact, sourceClusterName string) error + ReplicateVersionedTransition(ctx context.Context, archetypeID chasm.ArchetypeID, artifact *replicationspb.VersionedTransitionArtifact, sourceClusterName string) error SyncShardStatus(ctx context.Context, request *historyservice.SyncShardStatusRequest) error SyncActivity(ctx context.Context, request *historyservice.SyncActivityRequest) error SyncActivities(ctx context.Context, request *historyservice.SyncActivitiesRequest) error @@ -79,7 +80,7 @@ type ( MergeDLQMessages(ctx context.Context, messagesRequest *historyservice.MergeDLQMessagesRequest) (*historyservice.MergeDLQMessagesResponse, error) RebuildMutableState(ctx context.Context, namespaceUUID namespace.ID, execution *commonpb.WorkflowExecution) error ImportWorkflowExecution(ctx context.Context, request *historyservice.ImportWorkflowExecutionRequest) (*historyservice.ImportWorkflowExecutionResponse, error) - RefreshWorkflowTasks(ctx context.Context, namespaceUUID namespace.ID, execution *commonpb.WorkflowExecution) error + RefreshWorkflowTasks(ctx context.Context, namespaceUUID namespace.ID, execution *commonpb.WorkflowExecution, archetypeID chasm.ArchetypeID) error GenerateLastHistoryReplicationTasks(ctx context.Context, request *historyservice.GenerateLastHistoryReplicationTasksRequest) (*historyservice.GenerateLastHistoryReplicationTasksResponse, error) GetReplicationStatus(ctx context.Context, request *historyservice.GetReplicationStatusRequest) (*historyservice.ShardReplicationStatus, error) UpdateWorkflowExecution(ctx context.Context, request *historyservice.UpdateWorkflowExecutionRequest) (*historyservice.UpdateWorkflowExecutionResponse, error) diff --git a/service/history/interfaces/engine_mock.go b/service/history/interfaces/engine_mock.go index 99c52f6b224..04c67cc03bc 100644 --- a/service/history/interfaces/engine_mock.go +++ b/service/history/interfaces/engine_mock.go @@ -20,6 +20,7 @@ import ( historyservice "go.temporal.io/server/api/historyservice/v1" repication "go.temporal.io/server/api/replication/v1" workflow "go.temporal.io/server/api/workflow/v1" + chasm "go.temporal.io/server/chasm" collection "go.temporal.io/server/common/collection" definition "go.temporal.io/server/common/definition" metrics "go.temporal.io/server/common/metrics" @@ -616,17 +617,17 @@ func (mr *MockEngineMockRecorder) RecordWorkflowTaskStarted(ctx, request any) *g } // RefreshWorkflowTasks mocks base method. -func (m *MockEngine) RefreshWorkflowTasks(ctx context.Context, namespaceUUID namespace.ID, execution *common.WorkflowExecution) error { +func (m *MockEngine) RefreshWorkflowTasks(ctx context.Context, namespaceUUID namespace.ID, execution *common.WorkflowExecution, archetypeID chasm.ArchetypeID) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RefreshWorkflowTasks", ctx, namespaceUUID, execution) + ret := m.ctrl.Call(m, "RefreshWorkflowTasks", ctx, namespaceUUID, execution, archetypeID) ret0, _ := ret[0].(error) return ret0 } // RefreshWorkflowTasks indicates an expected call of RefreshWorkflowTasks. -func (mr *MockEngineMockRecorder) RefreshWorkflowTasks(ctx, namespaceUUID, execution any) *gomock.Call { +func (mr *MockEngineMockRecorder) RefreshWorkflowTasks(ctx, namespaceUUID, execution, archetypeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshWorkflowTasks", reflect.TypeOf((*MockEngine)(nil).RefreshWorkflowTasks), ctx, namespaceUUID, execution) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshWorkflowTasks", reflect.TypeOf((*MockEngine)(nil).RefreshWorkflowTasks), ctx, namespaceUUID, execution, archetypeID) } // RemoveSignalMutableState mocks base method. @@ -673,17 +674,17 @@ func (mr *MockEngineMockRecorder) ReplicateHistoryEvents(ctx, workflowKey, baseE } // ReplicateVersionedTransition mocks base method. -func (m *MockEngine) ReplicateVersionedTransition(ctx context.Context, artifact *repication.VersionedTransitionArtifact, sourceClusterName string) error { +func (m *MockEngine) ReplicateVersionedTransition(ctx context.Context, archetypeID chasm.ArchetypeID, artifact *repication.VersionedTransitionArtifact, sourceClusterName string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReplicateVersionedTransition", ctx, artifact, sourceClusterName) + ret := m.ctrl.Call(m, "ReplicateVersionedTransition", ctx, archetypeID, artifact, sourceClusterName) ret0, _ := ret[0].(error) return ret0 } // ReplicateVersionedTransition indicates an expected call of ReplicateVersionedTransition. -func (mr *MockEngineMockRecorder) ReplicateVersionedTransition(ctx, artifact, sourceClusterName any) *gomock.Call { +func (mr *MockEngineMockRecorder) ReplicateVersionedTransition(ctx, archetypeID, artifact, sourceClusterName any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReplicateVersionedTransition", reflect.TypeOf((*MockEngine)(nil).ReplicateVersionedTransition), ctx, artifact, sourceClusterName) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReplicateVersionedTransition", reflect.TypeOf((*MockEngine)(nil).ReplicateVersionedTransition), ctx, archetypeID, artifact, sourceClusterName) } // ReplicateWorkflowState mocks base method. diff --git a/service/history/interfaces/shard_context.go b/service/history/interfaces/shard_context.go index 89f66a3d591..96d959d4931 100644 --- a/service/history/interfaces/shard_context.go +++ b/service/history/interfaces/shard_context.go @@ -95,7 +95,7 @@ type ( GetWorkflowExecution(ctx context.Context, request *persistence.GetWorkflowExecutionRequest) (*persistence.GetWorkflowExecutionResponse, error) // DeleteWorkflowExecution add task to delete visibility, current workflow execution, and deletes workflow execution. // If branchToken != nil, then delete history also, otherwise leave history. - DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, branchToken []byte, closeExecutionVisibilityTaskID int64, workflowCloseTime time.Time, stage *tasks.DeleteWorkflowExecutionStage) error + DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, archetypeID chasm.ArchetypeID, branchToken []byte, closeExecutionVisibilityTaskID int64, workflowCloseTime time.Time, stage *tasks.DeleteWorkflowExecutionStage) error GetCachedWorkflowContext(ctx context.Context, namespaceID namespace.ID, execution *commonpb.WorkflowExecution, lockPriority locks.Priority) (WorkflowContext, ReleaseWorkflowContextFunc, error) GetCurrentCachedWorkflowContext(ctx context.Context, namespaceID namespace.ID, workflowID string, lockPriority locks.Priority) (ReleaseWorkflowContextFunc, error) diff --git a/service/history/interfaces/shard_context_mock.go b/service/history/interfaces/shard_context_mock.go index 525aad8f2da..9e537e6d95b 100644 --- a/service/history/interfaces/shard_context_mock.go +++ b/service/history/interfaces/shard_context_mock.go @@ -180,17 +180,17 @@ func (mr *MockShardContextMockRecorder) CurrentVectorClock() *gomock.Call { } // DeleteWorkflowExecution mocks base method. -func (m *MockShardContext) DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, branchToken []byte, closeExecutionVisibilityTaskID int64, workflowCloseTime time.Time, stage *tasks.DeleteWorkflowExecutionStage) error { +func (m *MockShardContext) DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, archetypeID chasm.ArchetypeID, branchToken []byte, closeExecutionVisibilityTaskID int64, workflowCloseTime time.Time, stage *tasks.DeleteWorkflowExecutionStage) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, workflowKey, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) + ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, workflowKey, archetypeID, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) ret0, _ := ret[0].(error) return ret0 } // DeleteWorkflowExecution indicates an expected call of DeleteWorkflowExecution. -func (mr *MockShardContextMockRecorder) DeleteWorkflowExecution(ctx, workflowKey, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage any) *gomock.Call { +func (mr *MockShardContextMockRecorder) DeleteWorkflowExecution(ctx, workflowKey, archetypeID, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).DeleteWorkflowExecution), ctx, workflowKey, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).DeleteWorkflowExecution), ctx, workflowKey, archetypeID, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) } // GenerateTaskID mocks base method. @@ -957,17 +957,17 @@ func (mr *MockControllableContextMockRecorder) CurrentVectorClock() *gomock.Call } // DeleteWorkflowExecution mocks base method. -func (m *MockControllableContext) DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, branchToken []byte, closeExecutionVisibilityTaskID int64, workflowCloseTime time.Time, stage *tasks.DeleteWorkflowExecutionStage) error { +func (m *MockControllableContext) DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, archetypeID chasm.ArchetypeID, branchToken []byte, closeExecutionVisibilityTaskID int64, workflowCloseTime time.Time, stage *tasks.DeleteWorkflowExecutionStage) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, workflowKey, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) + ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, workflowKey, archetypeID, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) ret0, _ := ret[0].(error) return ret0 } // DeleteWorkflowExecution indicates an expected call of DeleteWorkflowExecution. -func (mr *MockControllableContextMockRecorder) DeleteWorkflowExecution(ctx, workflowKey, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage any) *gomock.Call { +func (mr *MockControllableContextMockRecorder) DeleteWorkflowExecution(ctx, workflowKey, archetypeID, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWorkflowExecution", reflect.TypeOf((*MockControllableContext)(nil).DeleteWorkflowExecution), ctx, workflowKey, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWorkflowExecution", reflect.TypeOf((*MockControllableContext)(nil).DeleteWorkflowExecution), ctx, workflowKey, archetypeID, branchToken, closeExecutionVisibilityTaskID, workflowCloseTime, stage) } // FinishStop mocks base method. diff --git a/service/history/interfaces/workflow_context.go b/service/history/interfaces/workflow_context.go index 82ea60f22a7..0378d8469a0 100644 --- a/service/history/interfaces/workflow_context.go +++ b/service/history/interfaces/workflow_context.go @@ -6,7 +6,6 @@ import ( "context" persistencespb "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/chasm" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/locks" "go.temporal.io/server/common/persistence" @@ -23,7 +22,6 @@ type ( WorkflowContext interface { GetWorkflowKey() definition.WorkflowKey - SetArchetype(archetype chasm.Archetype) LoadMutableState(ctx context.Context, shardContext ShardContext) (MutableState, error) LoadExecutionStats(ctx context.Context, shardContext ShardContext) (*persistencespb.ExecutionStats, error) Clear() diff --git a/service/history/interfaces/workflow_context_mock.go b/service/history/interfaces/workflow_context_mock.go index bc1567d57a9..e9d886d71ed 100644 --- a/service/history/interfaces/workflow_context_mock.go +++ b/service/history/interfaces/workflow_context_mock.go @@ -14,7 +14,6 @@ import ( reflect "reflect" persistence "go.temporal.io/server/api/persistence/v1" - chasm "go.temporal.io/server/chasm" definition "go.temporal.io/server/common/definition" locks "go.temporal.io/server/common/locks" persistence0 "go.temporal.io/server/common/persistence" @@ -206,18 +205,6 @@ func (mr *MockWorkflowContextMockRecorder) RefreshTasks(ctx, shardContext any) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshTasks", reflect.TypeOf((*MockWorkflowContext)(nil).RefreshTasks), ctx, shardContext) } -// SetArchetype mocks base method. -func (m *MockWorkflowContext) SetArchetype(archetype chasm.Archetype) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetArchetype", archetype) -} - -// SetArchetype indicates an expected call of SetArchetype. -func (mr *MockWorkflowContextMockRecorder) SetArchetype(archetype any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetArchetype", reflect.TypeOf((*MockWorkflowContext)(nil).SetArchetype), archetype) -} - // SetWorkflowExecution mocks base method. func (m *MockWorkflowContext) SetWorkflowExecution(ctx context.Context, shardContext ShardContext) error { m.ctrl.T.Helper() diff --git a/service/history/ndc/activity_state_replicator_test.go b/service/history/ndc/activity_state_replicator_test.go index 317b4d0c8f1..8d49adc6094 100644 --- a/service/history/ndc/activity_state_replicator_test.go +++ b/service/history/ndc/activity_state_replicator_test.go @@ -544,6 +544,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_WorkflowNotFound() { NamespaceID: namespaceID.String(), WorkflowID: workflowID, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, serviceerror.NewNotFound("")) s.mockNamespaceCache.EXPECT().GetNamespaceByID(namespaceID).Return( namespace.NewGlobalNamespaceForTest( @@ -581,6 +582,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_WorkflowNotFound() { NamespaceID: namespaceID.String(), WorkflowID: workflowID, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, serviceerror.NewNotFound("")) s.mockNamespaceCache.EXPECT().GetNamespaceByID(namespaceID).Return( namespace.NewGlobalNamespaceForTest( @@ -634,6 +636,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_WorkflowClosed() { key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -642,7 +645,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_WorkflowClosed() { weContext.EXPECT().Clear().AnyTimes() weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) @@ -715,6 +717,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_WorkflowClosed() { key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -723,7 +726,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_WorkflowClosed() { weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() weContext.EXPECT().Clear().AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) @@ -800,6 +802,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_ActivityNotFound() { key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -808,7 +811,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_ActivityNotFound() { weContext.EXPECT().Clear().AnyTimes() weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) @@ -882,6 +884,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_ActivityNotFound() { key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -889,7 +892,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_ActivityNotFound() { weContext.EXPECT().Lock(gomock.Any(), locks.PriorityHigh).Return(nil) weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) weContext.EXPECT().Clear().AnyTimes() err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) @@ -968,6 +970,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_ActivityFound_Zombie() { key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -975,7 +978,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_ActivityFound_Zombie() { weContext.EXPECT().Lock(gomock.Any(), locks.PriorityHigh).Return(nil) weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) @@ -1071,6 +1073,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_ActivityFound_Zombie() key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -1078,7 +1081,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_ActivityFound_Zombie() weContext.EXPECT().Lock(gomock.Any(), locks.PriorityHigh).Return(nil) weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) @@ -1177,6 +1179,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_ActivityFound_NonZombie( key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -1184,7 +1187,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivity_ActivityFound_NonZombie( weContext.EXPECT().Lock(gomock.Any(), locks.PriorityHigh).Return(nil) weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) @@ -1279,6 +1281,7 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_ActivityFound_NonZombi key := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } weContext := historyi.NewMockWorkflowContext(s.controller) @@ -1286,7 +1289,6 @@ func (s *activityReplicatorStateSuite) TestSyncActivities_ActivityFound_NonZombi weContext.EXPECT().Lock(gomock.Any(), locks.PriorityHigh).Return(nil) weContext.EXPECT().Unlock() weContext.EXPECT().IsDirty().Return(false).AnyTimes() - weContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) err := wcache.PutContextIfNotExist(s.workflowCache, key, weContext) s.NoError(err) diff --git a/service/history/ndc/history_importer.go b/service/history/ndc/history_importer.go index 6eb09d5e270..e3cc7f05808 100644 --- a/service/history/ndc/history_importer.go +++ b/service/history/ndc/history_importer.go @@ -337,6 +337,7 @@ func (r *HistoryImporterImpl) commit( memMutableState.SetUpdateCondition(nextEventID, mutableStateSpec.DBRecordVersion) if err := r.transactionMgr.CreateWorkflow( ctx, + chasm.WorkflowArchetypeID, memNDCWorkflow, ); err != nil { r.logger.Error("HistoryImporter::commit encountered error", tag.Error(err)) @@ -351,7 +352,7 @@ func (r *HistoryImporterImpl) commit( namespace.ID(workflowKey.NamespaceID), workflowKey.WorkflowID, workflowKey.RunID, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, ) if err != nil { r.logger.Error("HistoryImporter::commit unable to find workflow in DB", tag.Error(err)) @@ -431,6 +432,7 @@ func (r *HistoryImporterImpl) commit( if err := r.transactionMgr.UpdateWorkflow( ctx, true, + chasm.WorkflowArchetypeID, memNDCWorkflow, nil, ); err != nil { diff --git a/service/history/ndc/history_replicator.go b/service/history/ndc/history_replicator.go index 25164aed05b..3c451f640af 100644 --- a/service/history/ndc/history_replicator.go +++ b/service/history/ndc/history_replicator.go @@ -12,6 +12,7 @@ import ( historyspb "go.temporal.io/server/api/history/v1" "go.temporal.io/server/api/historyservice/v1" workflowspb "go.temporal.io/server/api/workflow/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/definition" @@ -262,6 +263,7 @@ func (r *HistoryReplicatorImpl) doApplyBackfillEvents( task.getNamespaceID().String(), task.getWorkflowID(), task.getRunID(), + chasm.WorkflowArchetypeID, task.getVersionedTransition(), nil, ) @@ -294,6 +296,7 @@ func (r *HistoryReplicatorImpl) applyBackfillEvents( task.getNamespaceID().String(), task.getWorkflowID(), task.getRunID(), + chasm.WorkflowArchetypeID, task.getVersionedTransition(), mutableState.GetExecutionInfo().VersionHistories, ) @@ -543,6 +546,7 @@ func (r *HistoryReplicatorImpl) applyStartEvents( err = r.transactionMgr.CreateWorkflow( ctx, + chasm.WorkflowArchetypeID, NewWorkflow( r.clusterMetadata, wfContext, @@ -591,6 +595,7 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsToCurrentBranch( newExecutionInfo.WorkflowId, newExecutionState.RunId, ), + chasm.WorkflowArchetypeID, r.logger, r.shardContext.GetThrottledLogger(), r.shardContext.GetMetricsHandler(), @@ -607,6 +612,7 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsToCurrentBranch( err = r.transactionMgr.UpdateWorkflow( ctx, isRebuilt, + chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow, ) @@ -839,6 +845,7 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsResetWorkflow( err = r.transactionMgr.CreateWorkflow( ctx, + chasm.WorkflowArchetypeID, targetWorkflow, ) if err != nil { diff --git a/service/history/ndc/hsm_state_replicator_test.go b/service/history/ndc/hsm_state_replicator_test.go index be05ea4b28e..579bd75f3f7 100644 --- a/service/history/ndc/hsm_state_replicator_test.go +++ b/service/history/ndc/hsm_state_replicator_test.go @@ -12,6 +12,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/definition" @@ -131,6 +132,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_WorkflowNotFound() { NamespaceID: nonExistKey.NamespaceID, WorkflowID: nonExistKey.WorkflowID, RunID: nonExistKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, serviceerror.NewNotFound("")).Times(1) lastEventID := int64(10) @@ -162,6 +164,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_Diverge_LocalEventVersionLarger() NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -187,6 +190,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_Diverge_IncomingEventVersionLarger NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -222,6 +226,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_LocalEventVersionSuperSet() { NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -271,6 +276,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingEventVersionSuperSet() { NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -307,6 +313,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingStateStale() { NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -345,6 +352,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingLastUpdateVersionStale() { NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -384,6 +392,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingLastUpdateVersionedTransit NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -424,6 +433,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingLastUpdateVersionNewer() { NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -466,6 +476,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingLastUpdateVersionedTransit NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -508,6 +519,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingStateNewer_WorkflowOpen() NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -568,6 +580,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingStateNewer_WorkflowZombie( NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -616,6 +629,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_IncomingStateNewer_WorkflowClosed( NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, @@ -679,6 +693,7 @@ func (s *hsmStateReplicatorSuite) TestSyncHSM_StateMachineNotFound() { NamespaceID: s.workflowKey.NamespaceID, WorkflowID: s.workflowKey.WorkflowID, RunID: s.workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{ State: persistedState, DBRecordVersion: 777, diff --git a/service/history/ndc/mutable_state_initializer.go b/service/history/ndc/mutable_state_initializer.go index db134ca9765..93c91e8ea9e 100644 --- a/service/history/ndc/mutable_state_initializer.go +++ b/service/history/ndc/mutable_state_initializer.go @@ -10,6 +10,7 @@ import ( historypb "go.temporal.io/api/history/v1" "go.temporal.io/api/serviceerror" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/locks" "go.temporal.io/server/common/log" @@ -156,6 +157,7 @@ func (r *MutableStateInitializerImpl) InitializeFromToken( wfContext := workflow.NewContext( r.shardContext.GetConfig(), workflowKey, + chasm.WorkflowArchetypeID, r.logger, r.shardContext.GetThrottledLogger(), r.shardContext.GetMetricsHandler(), diff --git a/service/history/ndc/resetter.go b/service/history/ndc/resetter.go index 6650da7abbe..65dad0372de 100644 --- a/service/history/ndc/resetter.go +++ b/service/history/ndc/resetter.go @@ -150,7 +150,7 @@ func (r *resetterImpl) getBaseBranchToken( r.namespaceID, r.workflowID, r.baseRunID, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, ) switch err.(type) { case nil: diff --git a/service/history/ndc/resetter_test.go b/service/history/ndc/resetter_test.go index 6f71eaa7488..ab04d7a5514 100644 --- a/service/history/ndc/resetter_test.go +++ b/service/history/ndc/resetter_test.go @@ -90,6 +90,7 @@ func (s *resetterSuite) SetupTest() { s.workflowID, s.newRunID, ), + chasm.WorkflowArchetypeID, s.logger, s.mockShard.GetThrottledLogger(), s.mockShard.GetMetricsHandler(), @@ -143,7 +144,7 @@ func (s *resetterSuite) TestResetWorkflow_NoError() { s.namespaceID, s.workflowID, s.baseRunID, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, ).Return(mockBaseWorkflow, nil) s.mockStateBuilder.EXPECT().Rebuild( @@ -222,7 +223,7 @@ func (s *resetterSuite) TestResetWorkflow_Error() { s.namespaceID, s.workflowID, s.baseRunID, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, ).Return(mockBaseWorkflow, nil) rebuiltMutableState, err := s.workflowResetter.resetWorkflow( diff --git a/service/history/ndc/transaction_manager.go b/service/history/ndc/transaction_manager.go index 5350f313f1b..5f51d84bcb7 100644 --- a/service/history/ndc/transaction_manager.go +++ b/service/history/ndc/transaction_manager.go @@ -91,11 +91,13 @@ type ( TransactionManager interface { CreateWorkflow( ctx context.Context, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, ) error UpdateWorkflow( ctx context.Context, isWorkflowRebuilt bool, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, newWorkflow Workflow, ) error @@ -110,18 +112,20 @@ type ( namespaceID namespace.ID, workflowID string, runID string, + archetypeID chasm.ArchetypeID, ) (bool, error) GetCurrentWorkflowRunID( ctx context.Context, namespaceID namespace.ID, workflowID string, + archetypeID chasm.ArchetypeID, ) (string, error) LoadWorkflow( ctx context.Context, namespaceID namespace.ID, workflowID string, runID string, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, ) (Workflow, error) } @@ -178,11 +182,13 @@ func NewTransactionManager( func (r *transactionMgrImpl) CreateWorkflow( ctx context.Context, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, ) error { return r.createMgr.dispatchForNewWorkflow( ctx, + archetypeID, targetWorkflow, ) } @@ -190,6 +196,7 @@ func (r *transactionMgrImpl) CreateWorkflow( func (r *transactionMgrImpl) UpdateWorkflow( ctx context.Context, isWorkflowRebuilt bool, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, newWorkflow Workflow, ) error { @@ -197,6 +204,7 @@ func (r *transactionMgrImpl) UpdateWorkflow( return r.updateMgr.dispatchForExistingWorkflow( ctx, isWorkflowRebuilt, + archetypeID, targetWorkflow, newWorkflow, ) @@ -253,7 +261,7 @@ func (r *transactionMgrImpl) backfillWorkflowEventsReapply( targetWorkflowEventsSlice ...*persistence.WorkflowEvents, ) (persistence.UpdateWorkflowMode, historyi.TransactionPolicy, error) { - isCurrentWorkflow, err := r.isWorkflowCurrent(ctx, targetWorkflow) + isCurrentWorkflow, err := r.isWorkflowCurrent(ctx, chasm.WorkflowArchetypeID, targetWorkflow) if err != nil { return 0, historyi.TransactionPolicyActive, err } @@ -366,6 +374,7 @@ func (r *transactionMgrImpl) CheckWorkflowExists( namespaceID namespace.ID, workflowID string, runID string, + archetypeID chasm.ArchetypeID, ) (bool, error) { _, err := r.shardContext.GetWorkflowExecution( @@ -375,6 +384,7 @@ func (r *transactionMgrImpl) CheckWorkflowExists( NamespaceID: namespaceID.String(), WorkflowID: workflowID, RunID: runID, + ArchetypeID: archetypeID, }, ) @@ -392,6 +402,7 @@ func (r *transactionMgrImpl) GetCurrentWorkflowRunID( ctx context.Context, namespaceID namespace.ID, workflowID string, + archetypeID chasm.ArchetypeID, ) (string, error) { resp, err := r.shardContext.GetCurrentExecution( @@ -400,6 +411,7 @@ func (r *transactionMgrImpl) GetCurrentWorkflowRunID( ShardID: r.shardContext.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: archetypeID, }, ) @@ -418,7 +430,7 @@ func (r *transactionMgrImpl) LoadWorkflow( namespaceID namespace.ID, workflowID string, runID string, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, ) (Workflow, error) { weContext, release, err := r.workflowCache.GetOrCreateChasmExecution( @@ -429,7 +441,7 @@ func (r *transactionMgrImpl) LoadWorkflow( WorkflowId: workflowID, RunId: runID, }, - archetype, + archetypeID, locks.PriorityHigh, ) if err != nil { @@ -447,6 +459,7 @@ func (r *transactionMgrImpl) LoadWorkflow( func (r *transactionMgrImpl) isWorkflowCurrent( ctx context.Context, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, ) (bool, error) { @@ -467,6 +480,7 @@ func (r *transactionMgrImpl) isWorkflowCurrent( ctx, namespaceID, workflowID, + archetypeID, ) if err != nil { return false, err diff --git a/service/history/ndc/transaction_manager_existing_workflow.go b/service/history/ndc/transaction_manager_existing_workflow.go index 5901165f107..8f26392acbd 100644 --- a/service/history/ndc/transaction_manager_existing_workflow.go +++ b/service/history/ndc/transaction_manager_existing_workflow.go @@ -17,6 +17,7 @@ type ( dispatchForExistingWorkflow( ctx context.Context, isWorkflowRebuilt bool, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, newWorkflow Workflow, ) error @@ -47,16 +48,19 @@ func newNDCTransactionMgrForExistingWorkflow( func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( ctx context.Context, isWorkflowRebuilt bool, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, newWorkflow Workflow, ) error { + mutableState := targetWorkflow.GetMutableState() + // NOTE: this function does NOT mutate current workflow, target workflow or new workflow, // workflow mutation is done in methods within executeTransaction function // this is a performance optimization so most update does not need to // check whether target workflow is current workflow by calling DB API - if !isWorkflowRebuilt && targetWorkflow.GetMutableState().IsCurrentWorkflowGuaranteed() { + if !isWorkflowRebuilt && mutableState.IsCurrentWorkflowGuaranteed() { // NOTE: if target workflow is rebuilt, then IsCurrentWorkflowGuaranteed is not trustworthy // update to current record, since target workflow is pointed by current record @@ -65,10 +69,10 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( isWorkflowRebuilt, targetWorkflow, newWorkflow, + archetypeID, ) } - mutableState := targetWorkflow.GetMutableState() targetExecutionInfo := mutableState.GetExecutionInfo() targetExecutionState := mutableState.GetExecutionState() namespaceID := namespace.ID(targetExecutionInfo.NamespaceId) @@ -81,6 +85,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( ctx, namespaceID, workflowID, + archetypeID, ) if err != nil { return err @@ -97,6 +102,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( isWorkflowRebuilt, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -106,7 +112,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( namespaceID, workflowID, currentRunID, - chasm.ArchetypeAny, + archetypeID, ) if err != nil { return err @@ -125,6 +131,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( currentWorkflow, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -136,6 +143,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchForExistingWorkflow( currentWorkflow, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -144,6 +152,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchWorkflowUpdateAsCurre isWorkflowRebuilt bool, targetWorkflow Workflow, newWorkflow Workflow, + archetypeID chasm.ArchetypeID, ) error { if !isWorkflowRebuilt { @@ -153,6 +162,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchWorkflowUpdateAsCurre nil, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -162,6 +172,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchWorkflowUpdateAsCurre nil, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -171,6 +182,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchWorkflowUpdateAsZombi currentWorkflow Workflow, targetWorkflow Workflow, newWorkflow Workflow, + archetypeID chasm.ArchetypeID, ) error { if !isWorkflowRebuilt { @@ -180,6 +192,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchWorkflowUpdateAsZombi currentWorkflow, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -189,6 +202,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) dispatchWorkflowUpdateAsZombi currentWorkflow, targetWorkflow, newWorkflow, + archetypeID, ) } @@ -215,6 +229,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) updateAsZombie( currentWorkflow Workflow, targetWorkflow Workflow, newWorkflow Workflow, + archetypeID chasm.ArchetypeID, ) error { targetPolicy, err := targetWorkflow.SuppressBy( @@ -250,6 +265,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) updateAsZombie( namespace.ID(newExecutionInfo.NamespaceId), newExecutionInfo.WorkflowId, newExecutionState.RunId, + archetypeID, ) if err != nil { return err @@ -369,6 +385,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) conflictResolveAsZombie( currentWorkflow Workflow, targetWorkflow Workflow, newWorkflow Workflow, + archetypeID chasm.ArchetypeID, ) error { var err error @@ -406,6 +423,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) conflictResolveAsZombie( namespace.ID(newExecutionInfo.NamespaceId), newExecutionInfo.WorkflowId, newExecutionState.RunId, + archetypeID, ) if err != nil { return err @@ -447,6 +465,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) executeTransaction( currentWorkflow Workflow, targetWorkflow Workflow, newWorkflow Workflow, + archetypeID chasm.ArchetypeID, ) (retError error) { defer func() { @@ -472,6 +491,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) executeTransaction( currentWorkflow, targetWorkflow, newWorkflow, + archetypeID, ) case nDCTransactionPolicySuppressCurrentAndUpdateAsCurrent: @@ -495,6 +515,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) executeTransaction( currentWorkflow, targetWorkflow, newWorkflow, + archetypeID, ) default: diff --git a/service/history/ndc/transaction_manager_existing_workflow_mock.go b/service/history/ndc/transaction_manager_existing_workflow_mock.go index 9c555b60ec6..f1230819e80 100644 --- a/service/history/ndc/transaction_manager_existing_workflow_mock.go +++ b/service/history/ndc/transaction_manager_existing_workflow_mock.go @@ -13,6 +13,7 @@ import ( context "context" reflect "reflect" + chasm "go.temporal.io/server/chasm" gomock "go.uber.org/mock/gomock" ) @@ -41,15 +42,15 @@ func (m *MocktransactionMgrForExistingWorkflow) EXPECT() *MocktransactionMgrForE } // dispatchForExistingWorkflow mocks base method. -func (m *MocktransactionMgrForExistingWorkflow) dispatchForExistingWorkflow(ctx context.Context, isWorkflowRebuilt bool, targetWorkflow, newWorkflow Workflow) error { +func (m *MocktransactionMgrForExistingWorkflow) dispatchForExistingWorkflow(ctx context.Context, isWorkflowRebuilt bool, archetypeID chasm.ArchetypeID, targetWorkflow, newWorkflow Workflow) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "dispatchForExistingWorkflow", ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + ret := m.ctrl.Call(m, "dispatchForExistingWorkflow", ctx, isWorkflowRebuilt, archetypeID, targetWorkflow, newWorkflow) ret0, _ := ret[0].(error) return ret0 } // dispatchForExistingWorkflow indicates an expected call of dispatchForExistingWorkflow. -func (mr *MocktransactionMgrForExistingWorkflowMockRecorder) dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow any) *gomock.Call { +func (mr *MocktransactionMgrForExistingWorkflowMockRecorder) dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, archetypeID, targetWorkflow, newWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "dispatchForExistingWorkflow", reflect.TypeOf((*MocktransactionMgrForExistingWorkflow)(nil).dispatchForExistingWorkflow), ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "dispatchForExistingWorkflow", reflect.TypeOf((*MocktransactionMgrForExistingWorkflow)(nil).dispatchForExistingWorkflow), ctx, isWorkflowRebuilt, archetypeID, targetWorkflow, newWorkflow) } diff --git a/service/history/ndc/transaction_manager_existing_workflow_test.go b/service/history/ndc/transaction_manager_existing_workflow_test.go index 7b855a35762..c34bfbca249 100644 --- a/service/history/ndc/transaction_manager_existing_workflow_test.go +++ b/service/history/ndc/transaction_manager_existing_workflow_test.go @@ -86,7 +86,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newMutableState, ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -139,8 +139,8 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() @@ -161,7 +161,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow historyi.TransactionPolicyPassive.Ptr(), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -215,8 +215,8 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() @@ -237,7 +237,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow historyi.TransactionPolicyPassive.Ptr(), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -294,9 +294,9 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: newRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) - s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(false, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID, chasm.WorkflowArchetypeID).Return(false, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -312,7 +312,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow historyi.TransactionPolicyPassive.Ptr(), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -369,9 +369,9 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: newRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) - s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(true, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID, chasm.WorkflowArchetypeID).Return(true, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -387,7 +387,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow (*historyi.TransactionPolicy)(nil), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -429,7 +429,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(targetRunID, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(targetRunID, nil) targetContext.EXPECT().ConflictResolveWorkflowExecution( gomock.Any(), @@ -445,7 +445,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow (*historyi.TransactionPolicy)(nil), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -497,8 +497,8 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() @@ -519,7 +519,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow historyi.TransactionPolicyActive.Ptr(), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -575,9 +575,9 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: newRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) - s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(false, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID, chasm.WorkflowArchetypeID).Return(false, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -597,7 +597,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow (*historyi.TransactionPolicy)(nil), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) @@ -653,9 +653,9 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: newRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) - s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(true, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().CheckWorkflowExists(ctx, namespaceID, workflowID, newRunID, chasm.WorkflowArchetypeID).Return(true, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -675,7 +675,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow (*historyi.TransactionPolicy)(nil), ).Return(nil) - err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.updateMgr.dispatchForExistingWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(newReleaseCalled) diff --git a/service/history/ndc/transaction_manager_mock.go b/service/history/ndc/transaction_manager_mock.go index bba95e56cfb..cdf7281634c 100644 --- a/service/history/ndc/transaction_manager_mock.go +++ b/service/history/ndc/transaction_manager_mock.go @@ -63,74 +63,74 @@ func (mr *MockTransactionManagerMockRecorder) BackfillWorkflow(ctx, targetWorkfl } // CheckWorkflowExists mocks base method. -func (m *MockTransactionManager) CheckWorkflowExists(ctx context.Context, namespaceID namespace.ID, workflowID, runID string) (bool, error) { +func (m *MockTransactionManager) CheckWorkflowExists(ctx context.Context, namespaceID namespace.ID, workflowID, runID string, archetypeID chasm.ArchetypeID) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CheckWorkflowExists", ctx, namespaceID, workflowID, runID) + ret := m.ctrl.Call(m, "CheckWorkflowExists", ctx, namespaceID, workflowID, runID, archetypeID) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // CheckWorkflowExists indicates an expected call of CheckWorkflowExists. -func (mr *MockTransactionManagerMockRecorder) CheckWorkflowExists(ctx, namespaceID, workflowID, runID any) *gomock.Call { +func (mr *MockTransactionManagerMockRecorder) CheckWorkflowExists(ctx, namespaceID, workflowID, runID, archetypeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CheckWorkflowExists", reflect.TypeOf((*MockTransactionManager)(nil).CheckWorkflowExists), ctx, namespaceID, workflowID, runID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CheckWorkflowExists", reflect.TypeOf((*MockTransactionManager)(nil).CheckWorkflowExists), ctx, namespaceID, workflowID, runID, archetypeID) } // CreateWorkflow mocks base method. -func (m *MockTransactionManager) CreateWorkflow(ctx context.Context, targetWorkflow Workflow) error { +func (m *MockTransactionManager) CreateWorkflow(ctx context.Context, archetypeID chasm.ArchetypeID, targetWorkflow Workflow) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateWorkflow", ctx, targetWorkflow) + ret := m.ctrl.Call(m, "CreateWorkflow", ctx, archetypeID, targetWorkflow) ret0, _ := ret[0].(error) return ret0 } // CreateWorkflow indicates an expected call of CreateWorkflow. -func (mr *MockTransactionManagerMockRecorder) CreateWorkflow(ctx, targetWorkflow any) *gomock.Call { +func (mr *MockTransactionManagerMockRecorder) CreateWorkflow(ctx, archetypeID, targetWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflow", reflect.TypeOf((*MockTransactionManager)(nil).CreateWorkflow), ctx, targetWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflow", reflect.TypeOf((*MockTransactionManager)(nil).CreateWorkflow), ctx, archetypeID, targetWorkflow) } // GetCurrentWorkflowRunID mocks base method. -func (m *MockTransactionManager) GetCurrentWorkflowRunID(ctx context.Context, namespaceID namespace.ID, workflowID string) (string, error) { +func (m *MockTransactionManager) GetCurrentWorkflowRunID(ctx context.Context, namespaceID namespace.ID, workflowID string, archetypeID chasm.ArchetypeID) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCurrentWorkflowRunID", ctx, namespaceID, workflowID) + ret := m.ctrl.Call(m, "GetCurrentWorkflowRunID", ctx, namespaceID, workflowID, archetypeID) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } // GetCurrentWorkflowRunID indicates an expected call of GetCurrentWorkflowRunID. -func (mr *MockTransactionManagerMockRecorder) GetCurrentWorkflowRunID(ctx, namespaceID, workflowID any) *gomock.Call { +func (mr *MockTransactionManagerMockRecorder) GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, archetypeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentWorkflowRunID", reflect.TypeOf((*MockTransactionManager)(nil).GetCurrentWorkflowRunID), ctx, namespaceID, workflowID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentWorkflowRunID", reflect.TypeOf((*MockTransactionManager)(nil).GetCurrentWorkflowRunID), ctx, namespaceID, workflowID, archetypeID) } // LoadWorkflow mocks base method. -func (m *MockTransactionManager) LoadWorkflow(ctx context.Context, namespaceID namespace.ID, workflowID, runID string, archetype chasm.Archetype) (Workflow, error) { +func (m *MockTransactionManager) LoadWorkflow(ctx context.Context, namespaceID namespace.ID, workflowID, runID string, archetypeID chasm.ArchetypeID) (Workflow, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "LoadWorkflow", ctx, namespaceID, workflowID, runID, archetype) + ret := m.ctrl.Call(m, "LoadWorkflow", ctx, namespaceID, workflowID, runID, archetypeID) ret0, _ := ret[0].(Workflow) ret1, _ := ret[1].(error) return ret0, ret1 } // LoadWorkflow indicates an expected call of LoadWorkflow. -func (mr *MockTransactionManagerMockRecorder) LoadWorkflow(ctx, namespaceID, workflowID, runID, archetype any) *gomock.Call { +func (mr *MockTransactionManagerMockRecorder) LoadWorkflow(ctx, namespaceID, workflowID, runID, archetypeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadWorkflow", reflect.TypeOf((*MockTransactionManager)(nil).LoadWorkflow), ctx, namespaceID, workflowID, runID, archetype) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadWorkflow", reflect.TypeOf((*MockTransactionManager)(nil).LoadWorkflow), ctx, namespaceID, workflowID, runID, archetypeID) } // UpdateWorkflow mocks base method. -func (m *MockTransactionManager) UpdateWorkflow(ctx context.Context, isWorkflowRebuilt bool, targetWorkflow, newWorkflow Workflow) error { +func (m *MockTransactionManager) UpdateWorkflow(ctx context.Context, isWorkflowRebuilt bool, archetypeID chasm.ArchetypeID, targetWorkflow, newWorkflow Workflow) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateWorkflow", ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + ret := m.ctrl.Call(m, "UpdateWorkflow", ctx, isWorkflowRebuilt, archetypeID, targetWorkflow, newWorkflow) ret0, _ := ret[0].(error) return ret0 } // UpdateWorkflow indicates an expected call of UpdateWorkflow. -func (mr *MockTransactionManagerMockRecorder) UpdateWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow any) *gomock.Call { +func (mr *MockTransactionManagerMockRecorder) UpdateWorkflow(ctx, isWorkflowRebuilt, archetypeID, targetWorkflow, newWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflow", reflect.TypeOf((*MockTransactionManager)(nil).UpdateWorkflow), ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflow", reflect.TypeOf((*MockTransactionManager)(nil).UpdateWorkflow), ctx, isWorkflowRebuilt, archetypeID, targetWorkflow, newWorkflow) } diff --git a/service/history/ndc/transaction_manager_new_workflow.go b/service/history/ndc/transaction_manager_new_workflow.go index 7c35646c5cb..fbd98eafaa8 100644 --- a/service/history/ndc/transaction_manager_new_workflow.go +++ b/service/history/ndc/transaction_manager_new_workflow.go @@ -17,6 +17,7 @@ type ( transactionMgrForNewWorkflow interface { dispatchForNewWorkflow( ctx context.Context, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, ) error } @@ -45,6 +46,7 @@ func newTransactionMgrForNewWorkflow( func (r *nDCTransactionMgrForNewWorkflowImpl) dispatchForNewWorkflow( ctx context.Context, + archetypeID chasm.ArchetypeID, targetWorkflow Workflow, ) error { @@ -62,6 +64,7 @@ func (r *nDCTransactionMgrForNewWorkflowImpl) dispatchForNewWorkflow( ctx, namespaceID, workflowID, + archetypeID, ) if err != nil { // error out or workflow already created @@ -87,7 +90,7 @@ func (r *nDCTransactionMgrForNewWorkflowImpl) dispatchForNewWorkflow( namespaceID, workflowID, currentRunID, - chasm.ArchetypeAny, + archetypeID, ) if err != nil { return err diff --git a/service/history/ndc/transaction_manager_new_workflow_mock.go b/service/history/ndc/transaction_manager_new_workflow_mock.go index 8d6f868fa00..e08fc452bc7 100644 --- a/service/history/ndc/transaction_manager_new_workflow_mock.go +++ b/service/history/ndc/transaction_manager_new_workflow_mock.go @@ -13,6 +13,7 @@ import ( context "context" reflect "reflect" + chasm "go.temporal.io/server/chasm" gomock "go.uber.org/mock/gomock" ) @@ -41,15 +42,15 @@ func (m *MocktransactionMgrForNewWorkflow) EXPECT() *MocktransactionMgrForNewWor } // dispatchForNewWorkflow mocks base method. -func (m *MocktransactionMgrForNewWorkflow) dispatchForNewWorkflow(ctx context.Context, targetWorkflow Workflow) error { +func (m *MocktransactionMgrForNewWorkflow) dispatchForNewWorkflow(ctx context.Context, archetypeID chasm.ArchetypeID, targetWorkflow Workflow) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "dispatchForNewWorkflow", ctx, targetWorkflow) + ret := m.ctrl.Call(m, "dispatchForNewWorkflow", ctx, archetypeID, targetWorkflow) ret0, _ := ret[0].(error) return ret0 } // dispatchForNewWorkflow indicates an expected call of dispatchForNewWorkflow. -func (mr *MocktransactionMgrForNewWorkflowMockRecorder) dispatchForNewWorkflow(ctx, targetWorkflow any) *gomock.Call { +func (mr *MocktransactionMgrForNewWorkflowMockRecorder) dispatchForNewWorkflow(ctx, archetypeID, targetWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "dispatchForNewWorkflow", reflect.TypeOf((*MocktransactionMgrForNewWorkflow)(nil).dispatchForNewWorkflow), ctx, targetWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "dispatchForNewWorkflow", reflect.TypeOf((*MocktransactionMgrForNewWorkflow)(nil).dispatchForNewWorkflow), ctx, archetypeID, targetWorkflow) } diff --git a/service/history/ndc/transaction_manager_new_workflow_test.go b/service/history/ndc/transaction_manager_new_workflow_test.go index 78beb1b6860..1572af3651e 100644 --- a/service/history/ndc/transaction_manager_new_workflow_test.go +++ b/service/history/ndc/transaction_manager_new_workflow_test.go @@ -69,9 +69,9 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_Dup() { RunId: runID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(runID, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(runID, nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, newWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, newWorkflow) s.ErrorIs(err, consts.ErrDuplicate) } @@ -110,7 +110,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_BrandNew( ) s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID( - ctx, namespaceID, workflowID, + ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID, ).Return("", nil) weContext.EXPECT().CreateWorkflowExecution( @@ -124,7 +124,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_BrandNew( workflowEventsSeq, ).Return(nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, newWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, newWorkflow) s.NoError(err) s.True(releaseCalled) } @@ -172,8 +172,8 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsC targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() @@ -197,7 +197,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsC targetWorkflowEventsSeq, ).Return(nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, targetWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, targetWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(currentReleaseCalled) @@ -249,8 +249,8 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ ) targetMutableState.EXPECT().GetReapplyCandidateEvents().Return(nil) - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -267,7 +267,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ ).Return(nil) targetContext.EXPECT().ReapplyEvents(gomock.Any(), s.mockShard, targetWorkflowEventsSeq).Return(nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, targetWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, targetWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(currentReleaseCalled) @@ -328,8 +328,8 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ } targetMutableState.EXPECT().GetReapplyCandidateEvents().Return(eventReapplyCandidates) - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -346,7 +346,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ ).Return(nil) targetContext.EXPECT().ReapplyEvents(gomock.Any(), s.mockShard, eventsToApply).Return(nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, targetWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, targetWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(currentReleaseCalled) @@ -398,8 +398,8 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ ) targetMutableState.EXPECT().GetReapplyCandidateEvents().Return(nil) - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(historyi.TransactionPolicyPassive, nil) @@ -416,7 +416,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ ).Return(&persistence.WorkflowConditionFailedError{}) targetContext.EXPECT().ReapplyEvents(gomock.Any(), s.mockShard, targetWorkflowEventsSeq).Return(nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, targetWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, targetWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(currentReleaseCalled) @@ -457,8 +457,8 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_SuppressC RunId: targetRunID, }).AnyTimes() - s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID).Return(currentRunID, nil) - s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.ArchetypeAny).Return(currentWorkflow, nil) + s.mockTransactionMgr.EXPECT().GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID).Return(currentRunID, nil) + s.mockTransactionMgr.EXPECT().LoadWorkflow(ctx, namespaceID, workflowID, currentRunID, chasm.WorkflowArchetypeID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() @@ -476,7 +476,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_SuppressC historyi.TransactionPolicyPassive.Ptr(), ).Return(nil) - err := s.createMgr.dispatchForNewWorkflow(ctx, targetWorkflow) + err := s.createMgr.dispatchForNewWorkflow(ctx, chasm.WorkflowArchetypeID, targetWorkflow) s.NoError(err) s.True(targetReleaseCalled) s.True(currentReleaseCalled) diff --git a/service/history/ndc/transaction_manager_test.go b/service/history/ndc/transaction_manager_test.go index 8306f4ddc64..f6407fd22df 100644 --- a/service/history/ndc/transaction_manager_test.go +++ b/service/history/ndc/transaction_manager_test.go @@ -13,6 +13,7 @@ import ( "go.temporal.io/api/serviceerror" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" @@ -100,10 +101,10 @@ func (s *transactionMgrSuite) TestCreateWorkflow() { targetWorkflow := NewMockWorkflow(s.controller) s.mockCreateMgr.EXPECT().dispatchForNewWorkflow( - ctx, targetWorkflow, + ctx, chasm.WorkflowArchetypeID, targetWorkflow, ).Return(nil) - err := s.transactionMgr.CreateWorkflow(ctx, targetWorkflow) + err := s.transactionMgr.CreateWorkflow(ctx, chasm.WorkflowArchetypeID, targetWorkflow) s.NoError(err) } @@ -114,10 +115,10 @@ func (s *transactionMgrSuite) TestUpdateWorkflow() { newWorkflow := NewMockWorkflow(s.controller) s.mockUpdateMgr.EXPECT().dispatchForExistingWorkflow( - ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow, + ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow, ).Return(nil) - err := s.transactionMgr.UpdateWorkflow(ctx, isWorkflowRebuilt, targetWorkflow, newWorkflow) + err := s.transactionMgr.UpdateWorkflow(ctx, isWorkflowRebuilt, chasm.WorkflowArchetypeID, targetWorkflow, newWorkflow) s.NoError(err) } @@ -234,6 +235,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Closed ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{RunID: runID}, nil) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), s.mockShard, workflowEvents).Return(histroySize, nil) @@ -316,6 +318,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Closed_ResetF ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{RunID: runID}, nil) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), s.mockShard, workflowEvents).Return(historySize, nil) @@ -404,6 +407,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_Close ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{RunID: runID}, nil) weContext.EXPECT().ReapplyEvents(gomock.Any(), s.mockShard, []*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), s.mockShard, workflowEvents).Return(historySize, nil) @@ -463,6 +467,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_NotCurrentWorkflow_Active() { ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{RunID: currentRunID}, nil) weContext.EXPECT().ReapplyEvents(gomock.Any(), s.mockShard, []*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), s.mockShard, workflowEvents).Return(historySize, nil) @@ -521,6 +526,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_NotCurrentWorkflow_Passive() ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{RunID: currentRunID}, nil) weContext.EXPECT().ReapplyEvents(gomock.Any(), s.mockShard, []*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), s.mockShard, workflowEvents).Return(historySize, nil) @@ -543,9 +549,10 @@ func (s *transactionMgrSuite) TestCheckWorkflowExists_DoesNotExists() { NamespaceID: namespaceID.String(), WorkflowID: workflowID, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, serviceerror.NewNotFound("")) - exists, err := s.transactionMgr.CheckWorkflowExists(ctx, namespaceID, workflowID, runID) + exists, err := s.transactionMgr.CheckWorkflowExists(ctx, namespaceID, workflowID, runID, chasm.WorkflowArchetypeID) s.NoError(err) s.False(exists) } @@ -561,9 +568,10 @@ func (s *transactionMgrSuite) TestCheckWorkflowExists_DoesExists() { NamespaceID: namespaceID.String(), WorkflowID: workflowID, RunID: runID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetWorkflowExecutionResponse{}, nil) - exists, err := s.transactionMgr.CheckWorkflowExists(ctx, namespaceID, workflowID, runID) + exists, err := s.transactionMgr.CheckWorkflowExists(ctx, namespaceID, workflowID, runID, chasm.WorkflowArchetypeID) s.NoError(err) s.True(exists) } @@ -577,9 +585,10 @@ func (s *transactionMgrSuite) TestGetWorkflowCurrentRunID_Missing() { ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, serviceerror.NewNotFound("")) - currentRunID, err := s.transactionMgr.GetCurrentWorkflowRunID(ctx, namespaceID, workflowID) + currentRunID, err := s.transactionMgr.GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID) s.NoError(err) s.Equal("", currentRunID) } @@ -594,9 +603,10 @@ func (s *transactionMgrSuite) TestGetWorkflowCurrentRunID_Exists() { ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{RunID: runID}, nil) - currentRunID, err := s.transactionMgr.GetCurrentWorkflowRunID(ctx, namespaceID, workflowID) + currentRunID, err := s.transactionMgr.GetCurrentWorkflowRunID(ctx, namespaceID, workflowID, chasm.WorkflowArchetypeID) s.NoError(err) s.Equal(runID, currentRunID) } diff --git a/service/history/ndc/workflow_resetter.go b/service/history/ndc/workflow_resetter.go index bb26153b641..4abf39ab31f 100644 --- a/service/history/ndc/workflow_resetter.go +++ b/service/history/ndc/workflow_resetter.go @@ -15,6 +15,7 @@ import ( "go.temporal.io/api/workflowservice/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/collection" @@ -363,6 +364,7 @@ func (r *workflowResetterImpl) persistToDB( if _, _, err := r.transaction.UpdateWorkflowExecution( ctx, persistence.UpdateWorkflowModeUpdateCurrent, + chasm.WorkflowArchetypeID, currentWorkflow.GetMutableState().GetCurrentVersion(), currentWorkflowMutation, currentWorkflowEventsSeq, @@ -401,6 +403,7 @@ func (r *workflowResetterImpl) persistToDB( if _, _, _, err := r.transaction.ConflictResolveWorkflowExecution( ctx, persistence.ConflictResolveWorkflowModeUpdateCurrent, + chasm.WorkflowArchetypeID, baseWorkflow.GetMutableState().GetCurrentVersion(), baseSnapshot, baseEventsSeq, @@ -448,6 +451,7 @@ func (r *workflowResetterImpl) replayResetWorkflow( workflowID, resetRunID, ), + chasm.WorkflowArchetypeID, r.logger, r.shardContext.GetLogger(), r.shardContext.GetMetricsHandler(), diff --git a/service/history/ndc/workflow_resetter_test.go b/service/history/ndc/workflow_resetter_test.go index 69cf0ae92f0..7e49f49dca9 100644 --- a/service/history/ndc/workflow_resetter_test.go +++ b/service/history/ndc/workflow_resetter_test.go @@ -196,6 +196,7 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentTerminated() { s.mockTransaction.EXPECT().UpdateWorkflowExecution( gomock.Any(), persistence.UpdateWorkflowModeUpdateCurrent, + chasm.WorkflowArchetypeID, int64(0), currentMutation, currentEventsSeq, @@ -260,6 +261,7 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentNotTerminated() { s.mockTransaction.EXPECT().UpdateWorkflowExecution( gomock.Any(), persistence.UpdateWorkflowModeUpdateCurrent, + chasm.WorkflowArchetypeID, int64(0), currentMutation, currentEventsSeq, @@ -712,10 +714,10 @@ func (s *workflowResetterSuite) TestReapplyContinueAsNewWorkflowEvents_WithConti resetContext.EXPECT().Lock(gomock.Any(), locks.PriorityHigh).Return(nil) resetContext.EXPECT().Unlock() resetContext.EXPECT().IsDirty().Return(false).AnyTimes() - resetContext.EXPECT().SetArchetype(chasm.WorkflowArchetype).Times(1) resetMutableState := historyi.NewMockMutableState(s.controller) resetContextCacheKey := wcache.Key{ WorkflowKey: definition.NewWorkflowKey(s.namespaceID.String(), s.workflowID, newRunID), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } resetContext.EXPECT().LoadMutableState(gomock.Any(), s.mockShard).Return(resetMutableState, nil) diff --git a/service/history/ndc/workflow_state_replicator.go b/service/history/ndc/workflow_state_replicator.go index 8b9d59c9b7b..321ac75630a 100644 --- a/service/history/ndc/workflow_state_replicator.go +++ b/service/history/ndc/workflow_state_replicator.go @@ -36,6 +36,7 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" serviceerrors "go.temporal.io/server/common/serviceerror" + "go.temporal.io/server/common/softassert" "go.temporal.io/server/service/history/consts" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/historybuilder" @@ -52,6 +53,7 @@ type ( ) error ReplicateVersionedTransition( ctx context.Context, + archetypeID chasm.ArchetypeID, versionedTransition *replicationspb.VersionedTransitionArtifact, sourceClusterName string, ) error @@ -136,7 +138,7 @@ func (r *WorkflowStateReplicatorImpl) SyncWorkflowState( // no-op, continue to replicate workflow state case nil: if len(request.WorkflowState.ExecutionInfo.TransitionHistory) != 0 { - return r.applySnapshotWhenWorkflowExist(ctx, namespaceID, wid, rid, wfCtx, releaseFn, ms, request.WorkflowState, nil, nil, request.RemoteCluster) + return r.applySnapshotWhenWorkflowExist(ctx, namespaceID, wid, rid, chasm.WorkflowArchetypeID, wfCtx, releaseFn, ms, request.WorkflowState, nil, nil, request.RemoteCluster) } // workflow exists, do resend if version histories are not match. localVersionHistory, err := versionhistory.GetCurrentVersionHistory(ms.GetExecutionInfo().GetVersionHistories()) @@ -188,12 +190,26 @@ func (r *WorkflowStateReplicatorImpl) SyncWorkflowState( return err } skipCloseTransferTask := request.GetIsForceReplication() && request.GetIsCloseTransferTaskAcked() - return r.applySnapshotWhenWorkflowNotExist(ctx, namespaceID, wid, rid, wfCtx, releaseFn, request.GetWorkflowState(), request.RemoteCluster, nil, false, skipCloseTransferTask) + return r.applySnapshotWhenWorkflowNotExist( + ctx, + namespaceID, + wid, + rid, + chasm.WorkflowArchetypeID, + wfCtx, + releaseFn, + request.GetWorkflowState(), + request.RemoteCluster, + nil, + false, + skipCloseTransferTask, + ) } //nolint:revive // cognitive complexity 37 (> max enabled 25) func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( ctx context.Context, + archetypeID chasm.ArchetypeID, versionedTransition *replicationspb.VersionedTransitionArtifact, sourceClusterName string, ) (retError error) { @@ -214,7 +230,7 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( if versionedTransition.IsFirstSync { // this is the first replication task for this workflow // TODO: Handle reset case to reduce the amount of history events write - err := r.handleFirstReplicationTask(ctx, versionedTransition, sourceClusterName) + err := r.handleFirstReplicationTask(ctx, archetypeID, versionedTransition, sourceClusterName) if !errors.Is(err, consts.ErrDuplicate) { // if ErrDuplicate is returned from creation, it means the workflow is already existed, continue to apply mutation return err @@ -240,7 +256,7 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( WorkflowId: wid, RunId: rid, }, - chasm.ArchetypeAny, + archetypeID, locks.PriorityHigh, ) if err != nil { @@ -257,7 +273,7 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( ms, err := wfCtx.LoadMutableState(ctx, r.shardContext) switch err.(type) { case *serviceerror.NotFound: - return r.applySnapshot(ctx, namespaceID, wid, rid, wfCtx, releaseFn, nil, versionedTransition, sourceClusterName) + return r.applySnapshot(ctx, namespaceID, wid, rid, archetypeID, wfCtx, releaseFn, nil, versionedTransition, sourceClusterName) case nil: localTransitionHistory := ms.GetExecutionInfo().TransitionHistory if len(localTransitionHistory) == 0 { @@ -269,6 +285,7 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( namespaceID.String(), wid, rid, + archetypeID, nil, ms.GetExecutionInfo().VersionHistories, ) @@ -303,7 +320,7 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( } if localLastWriteVersion < sourceLastWriteVersion || localLastHistoryItem.GetEventId() <= sourceLastHistoryItem.EventId { - return r.applySnapshot(ctx, namespaceID, wid, rid, wfCtx, releaseFn, ms, versionedTransition, sourceClusterName) + return r.applySnapshot(ctx, namespaceID, wid, rid, archetypeID, wfCtx, releaseFn, ms, versionedTransition, sourceClusterName) } return consts.ErrDuplicate } @@ -316,9 +333,9 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( case errors.Is(err, consts.ErrStaleState): // local is stale, try to apply mutable state update if snapshot != nil { - return r.applySnapshot(ctx, namespaceID, wid, rid, wfCtx, releaseFn, ms, versionedTransition, sourceClusterName) + return r.applySnapshot(ctx, namespaceID, wid, rid, archetypeID, wfCtx, releaseFn, ms, versionedTransition, sourceClusterName) } - return r.applyMutation(ctx, namespaceID, wid, rid, wfCtx, ms, releaseFn, versionedTransition, sourceClusterName) + return r.applyMutation(ctx, namespaceID, wid, rid, archetypeID, wfCtx, ms, releaseFn, versionedTransition, sourceClusterName) case errors.Is(err, consts.ErrStaleReference): releaseFn(nil) return r.backFillEvents(ctx, namespaceID, wid, rid, executionInfo.VersionHistories, versionedTransition.EventBatches, versionedTransition.NewRunInfo, sourceClusterName, transitionhistory.LastVersionedTransition(sourceTransitionHistory)) @@ -332,6 +349,7 @@ func (r *WorkflowStateReplicatorImpl) ReplicateVersionedTransition( func (r *WorkflowStateReplicatorImpl) handleFirstReplicationTask( ctx context.Context, + archetypeID chasm.ArchetypeID, versionedTransition *replicationspb.VersionedTransitionArtifact, sourceClusterName string, ) (retErr error) { @@ -360,7 +378,7 @@ func (r *WorkflowStateReplicatorImpl) handleFirstReplicationTask( WorkflowId: executionInfo.WorkflowId, RunId: executionState.RunId, }, - chasm.ArchetypeAny, + archetypeID, locks.PriorityHigh, ) if err != nil { @@ -387,10 +405,13 @@ func (r *WorkflowStateReplicatorImpl) handleFirstReplicationTask( executionState.RunId, timestamp.TimeValue(executionState.StartTime), ) - err = localMutableState.SetHistoryTree(executionInfo.WorkflowExecutionTimeout, executionInfo.WorkflowRunTimeout, executionState.RunId) - if err != nil { - return err + if archetypeID == chasm.WorkflowArchetypeID { + err = localMutableState.SetHistoryTree(executionInfo.WorkflowExecutionTimeout, executionInfo.WorkflowRunTimeout, executionState.RunId) + if err != nil { + return err + } } + newBranchToken, err := r.bringLocalEventsUpToSourceCurrentBranch( ctx, namespace.ID(executionInfo.NamespaceId), @@ -424,6 +445,7 @@ func (r *WorkflowStateReplicatorImpl) handleFirstReplicationTask( ctx, namespace.ID(executionInfo.NamespaceId), executionInfo.WorkflowId, + archetypeID, versionedTransition.NewRunInfo, localMutableState, true, @@ -440,6 +462,7 @@ func (r *WorkflowStateReplicatorImpl) handleFirstReplicationTask( return r.transactionMgr.CreateWorkflow( ctx, + archetypeID, NewWorkflow( r.clusterMetadata, wfCtx, @@ -469,6 +492,7 @@ func (r *WorkflowStateReplicatorImpl) applyMutation( namespaceID namespace.ID, workflowID string, runID string, + archetypeID chasm.ArchetypeID, wfCtx historyi.WorkflowContext, localMutableState historyi.MutableState, releaseFn historyi.ReleaseWorkflowContextFunc, @@ -485,6 +509,7 @@ func (r *WorkflowStateReplicatorImpl) applyMutation( namespaceID.String(), workflowID, runID, + archetypeID, nil, nil, ) @@ -502,6 +527,7 @@ func (r *WorkflowStateReplicatorImpl) applyMutation( namespaceID.String(), workflowID, runID, + archetypeID, localVersionedTransition, localMutableState.GetExecutionInfo().VersionHistories, ) @@ -535,7 +561,7 @@ func (r *WorkflowStateReplicatorImpl) applyMutation( var newRunWorkflow Workflow if versionedTransition.NewRunInfo != nil { - newRunWorkflow, err = r.getNewRunWorkflow(ctx, namespaceID, workflowID, localMutableState, versionedTransition.NewRunInfo) + newRunWorkflow, err = r.getNewRunWorkflow(ctx, namespaceID, workflowID, archetypeID, localMutableState, versionedTransition.NewRunInfo) if err != nil { return err } @@ -556,6 +582,7 @@ func (r *WorkflowStateReplicatorImpl) applyMutation( return r.transactionMgr.UpdateWorkflow( ctx, false, + archetypeID, targetWorkflow, newRunWorkflow, ) @@ -566,6 +593,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshot( namespaceID namespace.ID, workflowID string, runID string, + archetypeID chasm.ArchetypeID, wfCtx historyi.WorkflowContext, releaseFn historyi.ReleaseWorkflowContextFunc, localMutableState historyi.MutableState, @@ -583,15 +611,42 @@ func (r *WorkflowStateReplicatorImpl) applySnapshot( namespaceID.String(), workflowID, runID, + archetypeID, nil, versionHistories, ) } snapshot := attribute.State if localMutableState == nil { - return r.applySnapshotWhenWorkflowNotExist(ctx, namespaceID, workflowID, runID, wfCtx, releaseFn, snapshot, sourceClusterName, versionedTransition.NewRunInfo, true, versionedTransition.IsCloseTransferTaskAcked && versionedTransition.IsForceReplication) + return r.applySnapshotWhenWorkflowNotExist( + ctx, + namespaceID, + workflowID, + runID, + archetypeID, + wfCtx, + releaseFn, + snapshot, + sourceClusterName, + versionedTransition.NewRunInfo, + true, + versionedTransition.IsCloseTransferTaskAcked && versionedTransition.IsForceReplication, + ) } - return r.applySnapshotWhenWorkflowExist(ctx, namespaceID, workflowID, runID, wfCtx, releaseFn, localMutableState, snapshot, versionedTransition.EventBatches, versionedTransition.NewRunInfo, sourceClusterName) + return r.applySnapshotWhenWorkflowExist( + ctx, + namespaceID, + workflowID, + runID, + archetypeID, + wfCtx, + releaseFn, + localMutableState, + snapshot, + versionedTransition.EventBatches, + versionedTransition.NewRunInfo, + sourceClusterName, + ) } func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowExist( @@ -599,6 +654,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowExist( namespaceID namespace.ID, workflowID string, runID string, + archetypeID chasm.ArchetypeID, wfCtx historyi.WorkflowContext, releaseFn historyi.ReleaseWorkflowContextFunc, localMutableState historyi.MutableState, @@ -624,6 +680,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowExist( namespaceID.String(), workflowID, runID, + archetypeID, localVersionedTransition, localMutableState.GetExecutionInfo().VersionHistories, ) @@ -675,7 +732,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowExist( var newRunWorkflow Workflow if newRunInfo != nil { - newRunWorkflow, err = r.getNewRunWorkflow(ctx, namespaceID, workflowID, localMutableState, newRunInfo) + newRunWorkflow, err = r.getNewRunWorkflow(ctx, namespaceID, workflowID, archetypeID, localMutableState, newRunInfo) if err != nil { return err } @@ -704,6 +761,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowExist( return r.transactionMgr.UpdateWorkflow( ctx, isBranchSwitched, + archetypeID, targetWorkflow, newRunWorkflow, ) @@ -767,6 +825,7 @@ func (r *WorkflowStateReplicatorImpl) getNewRunWorkflow( ctx context.Context, namespaceID namespace.ID, workflowID string, + archetypeID chasm.ArchetypeID, originalMutableState historyi.MutableState, newRunInfo *replicationspb.NewRunInfo, ) (Workflow, error) { @@ -784,6 +843,7 @@ func (r *WorkflowStateReplicatorImpl) getNewRunWorkflow( newExecutionInfo.WorkflowId, newExecutionState.RunId, ), + archetypeID, r.logger, r.shardContext.GetThrottledLogger(), r.shardContext.GetMetricsHandler(), @@ -1154,6 +1214,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowNotExist( namespaceID namespace.ID, workflowID string, runID string, + archtypeID chasm.ArchetypeID, wfCtx historyi.WorkflowContext, releaseFn historyi.ReleaseWorkflowContextFunc, sourceMutableState *persistencespb.WorkflowMutableState, @@ -1213,6 +1274,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowNotExist( ctx, namespaceID, workflowID, + archtypeID, newRunInfo, mutableState, isStateBased, @@ -1229,6 +1291,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshotWhenWorkflowNotExist( } return r.transactionMgr.CreateWorkflow( ctx, + archtypeID, NewWorkflow( r.clusterMetadata, wfCtx, @@ -1242,6 +1305,7 @@ func (r *WorkflowStateReplicatorImpl) createNewRunWorkflow( ctx context.Context, namespaceID namespace.ID, workflowID string, + archetypeID chasm.ArchetypeID, newRunInfo *replicationspb.NewRunInfo, originalMutableState historyi.MutableState, isStateBased bool, @@ -1287,6 +1351,7 @@ func (r *WorkflowStateReplicatorImpl) createNewRunWorkflow( } return r.transactionMgr.CreateWorkflow( ctx, + archetypeID, NewWorkflow( r.clusterMetadata, newRunWfContext, @@ -1330,10 +1395,25 @@ func (r *WorkflowStateReplicatorImpl) backfillHistory( if err != nil { return err } + + archetypeID := mutableState.ChasmTree().ArchetypeID() + if archetypeID != chasm.WorkflowArchetypeID { + return softassert.UnexpectedInternalErr( + r.logger, + "Backfilling history not supported for non-workflow archetype", + nil, + tag.ArchetypeID(archetypeID), + tag.WorkflowNamespaceID(namespaceID.String()), + tag.WorkflowID(workflowID), + tag.WorkflowRunID(runID), + ) + } + backfillBranchToken, err := r.shardContext.GetExecutionManager().GetHistoryBranchUtil().NewHistoryBranch( namespaceID.String(), workflowID, runID, + archetypeID, branchInfo.GetTreeId(), &branchInfo.BranchId, branchInfo.Ancestors, diff --git a/service/history/ndc/workflow_state_replicator_mock.go b/service/history/ndc/workflow_state_replicator_mock.go index cff3d2c9878..5deb525fad1 100644 --- a/service/history/ndc/workflow_state_replicator_mock.go +++ b/service/history/ndc/workflow_state_replicator_mock.go @@ -15,6 +15,7 @@ import ( historyservice "go.temporal.io/server/api/historyservice/v1" repication "go.temporal.io/server/api/replication/v1" + chasm "go.temporal.io/server/chasm" gomock "go.uber.org/mock/gomock" ) @@ -43,17 +44,17 @@ func (m *MockWorkflowStateReplicator) EXPECT() *MockWorkflowStateReplicatorMockR } // ReplicateVersionedTransition mocks base method. -func (m *MockWorkflowStateReplicator) ReplicateVersionedTransition(ctx context.Context, versionedTransition *repication.VersionedTransitionArtifact, sourceClusterName string) error { +func (m *MockWorkflowStateReplicator) ReplicateVersionedTransition(ctx context.Context, archetypeID chasm.ArchetypeID, versionedTransition *repication.VersionedTransitionArtifact, sourceClusterName string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReplicateVersionedTransition", ctx, versionedTransition, sourceClusterName) + ret := m.ctrl.Call(m, "ReplicateVersionedTransition", ctx, archetypeID, versionedTransition, sourceClusterName) ret0, _ := ret[0].(error) return ret0 } // ReplicateVersionedTransition indicates an expected call of ReplicateVersionedTransition. -func (mr *MockWorkflowStateReplicatorMockRecorder) ReplicateVersionedTransition(ctx, versionedTransition, sourceClusterName any) *gomock.Call { +func (mr *MockWorkflowStateReplicatorMockRecorder) ReplicateVersionedTransition(ctx, archetypeID, versionedTransition, sourceClusterName any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReplicateVersionedTransition", reflect.TypeOf((*MockWorkflowStateReplicator)(nil).ReplicateVersionedTransition), ctx, versionedTransition, sourceClusterName) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReplicateVersionedTransition", reflect.TypeOf((*MockWorkflowStateReplicator)(nil).ReplicateVersionedTransition), ctx, archetypeID, versionedTransition, sourceClusterName) } // SyncWorkflowState mocks base method. diff --git a/service/history/ndc/workflow_state_replicator_test.go b/service/history/ndc/workflow_state_replicator_test.go index 9cf482a23f4..14353c51b14 100644 --- a/service/history/ndc/workflow_state_replicator_test.go +++ b/service/history/ndc/workflow_state_replicator_test.go @@ -653,7 +653,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_SameBranch_S WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(mockWeCtx, wcache.NoopReleaseFn, nil) mockMutableState.EXPECT().SetHistoryBuilder(gomock.Any()).Times(1) @@ -670,7 +670,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_SameBranch_S }).AnyTimes() mockMutableState.EXPECT().GetPendingChildIds().Return(nil).Times(1) mockMutableState.EXPECT().ApplySnapshot(versionedTransitionArtifact.GetSyncWorkflowStateSnapshotAttributes().State) - mockTransactionManager.EXPECT().UpdateWorkflow(gomock.Any(), false, gomock.Any(), nil).Return(nil).Times(1) + mockTransactionManager.EXPECT().UpdateWorkflow(gomock.Any(), false, chasm.WorkflowArchetypeID, gomock.Any(), nil).Return(nil).Times(1) mockTaskRefresher.EXPECT(). PartialRefresh(gomock.Any(), gomock.Any(), EqVersionedTransition(&persistencespb.VersionedTransition{ NamespaceFailoverVersion: 2, @@ -678,7 +678,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_SameBranch_S }), nil, false, ).Return(nil).Times(1) - err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), versionedTransitionArtifact, "test") + err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), chasm.WorkflowArchetypeID, versionedTransitionArtifact, "test") s.NoError(err) } @@ -744,7 +744,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_DifferentBra WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(mockWeCtx, wcache.NoopReleaseFn, nil) mockMutableState.EXPECT().SetHistoryBuilder(gomock.Any()).Times(1) @@ -760,10 +760,10 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_DifferentBra mockMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: s.runID, }).AnyTimes() - mockTransactionManager.EXPECT().UpdateWorkflow(gomock.Any(), true, gomock.Any(), nil).Return(nil).Times(1) + mockTransactionManager.EXPECT().UpdateWorkflow(gomock.Any(), true, chasm.WorkflowArchetypeID, gomock.Any(), nil).Return(nil).Times(1) mockTaskRefresher.EXPECT().Refresh(gomock.Any(), mockMutableState, gomock.Any()).Return(nil).Times(1) - err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), versionedTransitionArtifact, "test") + err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), chasm.WorkflowArchetypeID, versionedTransitionArtifact, "test") s.NoError(err) } @@ -832,7 +832,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_SameBranch_S WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(mockWeCtx, wcache.NoopReleaseFn, nil) mockMutableState.EXPECT().SetHistoryBuilder(gomock.Any()).Times(1) @@ -849,7 +849,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_SameBranch_S }).AnyTimes() mockMutableState.EXPECT().GetPendingChildIds().Return(nil).Times(1) mockMutableState.EXPECT().ApplyMutation(versionedTransitionArtifact.GetSyncWorkflowStateMutationAttributes().StateMutation) - mockTransactionManager.EXPECT().UpdateWorkflow(gomock.Any(), false, gomock.Any(), nil).Return(nil).Times(1) + mockTransactionManager.EXPECT().UpdateWorkflow(gomock.Any(), false, chasm.WorkflowArchetypeID, gomock.Any(), nil).Return(nil).Times(1) mockTaskRefresher.EXPECT(). PartialRefresh(gomock.Any(), gomock.Any(), EqVersionedTransition(&persistencespb.VersionedTransition{ NamespaceFailoverVersion: 2, @@ -857,7 +857,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_SameBranch_S }), nil, false, ).Return(nil).Times(1) - err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), versionedTransitionArtifact, "test") + err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), chasm.WorkflowArchetypeID, versionedTransitionArtifact, "test") s.NoError(err) } @@ -911,7 +911,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_FirstTask_Sy WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(mockWeCtx, wcache.NoopReleaseFn, nil) s.mockNamespaceCache.EXPECT().GetNamespaceByID(namespace.ID(namespaceID)).Return(namespace.NewNamespaceForTest( @@ -925,8 +925,9 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_FirstTask_Sy mockTransactionManager.EXPECT().CreateWorkflow( gomock.Any(), + chasm.WorkflowArchetypeID, gomock.AssignableToTypeOf(&WorkflowImpl{}), - ).DoAndReturn(func(ctx context.Context, wf Workflow) error { + ).DoAndReturn(func(ctx context.Context, _ chasm.ArchetypeID, wf Workflow) error { // Capture localMutableState from the workflow localMutableState := wf.GetMutableState() @@ -935,7 +936,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_FirstTask_Sy return nil }).Times(1) - err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), versionedTransitionArtifact, "test") + err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), chasm.WorkflowArchetypeID, versionedTransitionArtifact, "test") s.NoError(err) } @@ -1005,7 +1006,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_MutationProv WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(mockWeCtx, wcache.NoopReleaseFn, nil) mockWeCtx.EXPECT().LoadMutableState(gomock.Any(), s.mockShard).Return(mockMutableState, nil) @@ -1020,7 +1021,7 @@ func (s *workflowReplicatorSuite) Test_ReplicateVersionedTransition_MutationProv RunId: s.runID, }).AnyTimes() - err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), versionedTransitionArtifact, "test") + err := workflowStateReplicator.ReplicateVersionedTransition(context.Background(), chasm.WorkflowArchetypeID, versionedTransitionArtifact, "test") s.IsType(&serviceerrors.SyncState{}, err) } diff --git a/service/history/ndc_standby_task_util.go b/service/history/ndc_standby_task_util.go index 348e9d79f6d..d10a99650e4 100644 --- a/service/history/ndc_standby_task_util.go +++ b/service/history/ndc_standby_task_util.go @@ -10,6 +10,7 @@ import ( "go.temporal.io/server/api/adminservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" taskqueuespb "go.temporal.io/server/api/taskqueue/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/definition" @@ -78,18 +79,32 @@ func standbyTimerTaskPostActionTaskDiscarded( return consts.ErrTaskDiscarded } -func isWorkflowExistOnSource( +func executionExistsOnSource( ctx context.Context, workflowKey definition.WorkflowKey, + archetypeID chasm.ArchetypeID, logger log.Logger, currentCluster string, clientBean client.Bean, registry namespace.Registry, + chasmRegistry *chasm.Registry, ) bool { namespaceEntry, err := registry.GetNamespaceByID(namespace.ID(workflowKey.NamespaceID)) if err != nil { return true } + + archetype, ok := chasmRegistry.ComponentFqnByID(archetypeID) + if !ok { + logger.Error("Unknown archetype ID.", + tag.ArchetypeID(archetypeID), + tag.WorkflowNamespaceID(workflowKey.NamespaceID), + tag.WorkflowID(workflowKey.WorkflowID), + tag.WorkflowRunID(workflowKey.RunID), + ) + return true + } + remoteClusterName, err := getSourceClusterName( currentCluster, registry, @@ -108,6 +123,7 @@ func isWorkflowExistOnSource( WorkflowId: workflowKey.GetWorkflowID(), RunId: workflowKey.GetRunID(), }, + Archetype: archetype, SkipForceReload: true, }) if err != nil { diff --git a/service/history/outbound_queue_active_task_executor_test.go b/service/history/outbound_queue_active_task_executor_test.go index 2e67f86607c..511b4e28101 100644 --- a/service/history/outbound_queue_active_task_executor_test.go +++ b/service/history/outbound_queue_active_task_executor_test.go @@ -96,7 +96,8 @@ func (s *outboundQueueActiveTaskExecutorSuite) SetupTest() { Return(s.namespaceEntry, nil). AnyTimes() - s.mockWorkflowCache.EXPECT().GetOrCreateCurrentWorkflowExecution( + s.mockWorkflowCache.EXPECT().GetOrCreateCurrentExecution( + gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), @@ -138,7 +139,7 @@ func (s *outboundQueueActiveTaskExecutorSuite) TestExecute_ChasmTask() { // Setup successful workflow context loading and CHASM execution s.mockWorkflowCache.EXPECT(). - GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.ArchetypeAny, gomock.Any()). + GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), tests.ArchetypeID, gomock.Any()). Return(s.mockWorkflowContext, func(error) {}, nil) s.mockWorkflowContext.EXPECT(). @@ -165,7 +166,7 @@ func (s *outboundQueueActiveTaskExecutorSuite) TestExecute_ChasmTask() { setupMocks: func(task *tasks.ChasmTask) { // Workflow context loads but mutable state fails s.mockWorkflowCache.EXPECT(). - GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.ArchetypeAny, gomock.Any()). + GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), tests.ArchetypeID, gomock.Any()). Return(s.mockWorkflowContext, func(error) {}, nil) s.mockWorkflowContext.EXPECT(). @@ -186,7 +187,8 @@ func (s *outboundQueueActiveTaskExecutorSuite) TestExecute_ChasmTask() { Category: tasks.CategoryOutbound, Destination: tv.Any().String(), Info: &persistencespb.ChasmTaskInfo{ - TypeId: tv.Any().UInt32(), + TypeId: tv.Any().UInt32(), + ArchetypeId: tests.ArchetypeID, }, } diff --git a/service/history/outbound_queue_standby_task_executor_test.go b/service/history/outbound_queue_standby_task_executor_test.go index f0b2443896d..14146586e71 100644 --- a/service/history/outbound_queue_standby_task_executor_test.go +++ b/service/history/outbound_queue_standby_task_executor_test.go @@ -104,7 +104,8 @@ func (s *outboundQueueStandbyTaskExecutorSuite) SetupTest() { Return(s.namespaceEntry, nil). AnyTimes() - s.mockWorkflowCache.EXPECT().GetOrCreateCurrentWorkflowExecution( + s.mockWorkflowCache.EXPECT().GetOrCreateCurrentExecution( + gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), @@ -150,7 +151,7 @@ func (s *outboundQueueStandbyTaskExecutorSuite) TestExecute_ChasmTask() { // Setup successful workflow context loading and CHASM execution s.mockWorkflowCache.EXPECT(). - GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.ArchetypeAny, gomock.Any()). + GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), tests.ArchetypeID, gomock.Any()). Return(s.mockWorkflowContext, func(error) {}, nil) s.mockWorkflowContext.EXPECT(). @@ -174,7 +175,7 @@ func (s *outboundQueueStandbyTaskExecutorSuite) TestExecute_ChasmTask() { setupMocks: func(task *tasks.ChasmTask) { // Workflow context loads but mutable state fails s.mockWorkflowCache.EXPECT(). - GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), chasm.ArchetypeAny, gomock.Any()). + GetOrCreateChasmExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), tests.ArchetypeID, gomock.Any()). Return(s.mockWorkflowContext, func(error) {}, nil) s.mockWorkflowContext.EXPECT(). @@ -195,7 +196,8 @@ func (s *outboundQueueStandbyTaskExecutorSuite) TestExecute_ChasmTask() { Category: tasks.CategoryOutbound, Destination: tv.Any().String(), Info: &persistencespb.ChasmTaskInfo{ - TypeId: tv.Any().UInt32(), + TypeId: tv.Any().UInt32(), + ArchetypeId: tests.ArchetypeID, }, VisibilityTimestamp: s.now, } diff --git a/service/history/replication/ack_manager_test.go b/service/history/replication/ack_manager_test.go index 208b11782e8..7e564616bce 100644 --- a/service/history/replication/ack_manager_test.go +++ b/service/history/replication/ack_manager_test.go @@ -13,6 +13,7 @@ import ( "go.temporal.io/api/serviceerror" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" @@ -257,6 +258,7 @@ func (s *ackManagerSuite) TestGetTasks_FirstPersistenceErrorReturnsErrorAndEmpty NamespaceID: tasksResponse.Tasks[0].GetNamespaceID(), WorkflowID: tasksResponse.Tasks[0].GetWorkflowID(), RunID: tasksResponse.Tasks[0].GetRunID(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, gweErr) replicationTasks, lastTaskID, err := s.replicationAckManager.getTasks(ctx, cluster.TestCurrentClusterName, minTaskID, maxTaskID) diff --git a/service/history/replication/executable_sync_versioned_transition_task.go b/service/history/replication/executable_sync_versioned_transition_task.go index 0b36fd2d205..f55c92501b2 100644 --- a/service/history/replication/executable_sync_versioned_transition_task.go +++ b/service/history/replication/executable_sync_versioned_transition_task.go @@ -8,6 +8,7 @@ import ( "go.temporal.io/api/serviceerror" historyspb "go.temporal.io/server/api/history/v1" replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/headers" "go.temporal.io/server/common/log/tag" @@ -42,6 +43,9 @@ func NewExecutableSyncVersionedTransitionTask( replicationTask *replicationspb.ReplicationTask, ) *ExecutableSyncVersionedTransitionTask { task := replicationTask.GetSyncVersionedTransitionTaskAttributes() + if task.ArchetypeId == chasm.UnspecifiedArchetypeID { + task.ArchetypeId = chasm.WorkflowArchetypeID + } return &ExecutableSyncVersionedTransitionTask{ ProcessToolBox: processToolBox, @@ -104,7 +108,12 @@ func (e *ExecutableSyncVersionedTransitionTask) Execute() error { if err != nil { return err } - return engine.ReplicateVersionedTransition(ctx, e.taskAttr.VersionedTransitionArtifact, e.SourceClusterName()) + return engine.ReplicateVersionedTransition( + ctx, + e.taskAttr.GetArchetypeId(), + e.taskAttr.VersionedTransitionArtifact, + e.SourceClusterName(), + ) } func (e *ExecutableSyncVersionedTransitionTask) HandleErr(err error) error { diff --git a/service/history/replication/executable_task.go b/service/history/replication/executable_task.go index 3001a27452b..ce99aaea2dc 100644 --- a/service/history/replication/executable_task.go +++ b/service/history/replication/executable_task.go @@ -628,6 +628,7 @@ func (e *ExecutableTaskImpl) SyncState( WorkflowId: syncStateErr.WorkflowId, RunId: syncStateErr.RunId, }, + ArchetypeId: syncStateErr.ArchetypeId, VersionedTransition: syncStateErr.VersionedTransition, VersionHistories: syncStateErr.VersionHistories, TargetClusterId: int32(targetClusterInfo.InitialFailoverVersion), @@ -690,7 +691,7 @@ func (e *ExecutableTaskImpl) SyncState( if err != nil { return false, err } - err = engine.ReplicateVersionedTransition(ctx, resp.VersionedTransitionArtifact, e.SourceClusterName()) + err = engine.ReplicateVersionedTransition(ctx, syncStateErr.ArchetypeId, resp.VersionedTransitionArtifact, e.SourceClusterName()) if err == nil || errors.Is(err, consts.ErrDuplicate) { return true, nil } diff --git a/service/history/replication/executable_task_test.go b/service/history/replication/executable_task_test.go index 5332937f025..4f01f863b15 100644 --- a/service/history/replication/executable_task_test.go +++ b/service/history/replication/executable_task_test.go @@ -21,6 +21,7 @@ import ( "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/client" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/collection" @@ -549,6 +550,7 @@ func (s *executableTaskSuite) TestResend_TransitionHistoryDisabled() { NamespaceId: uuid.NewString(), WorkflowId: uuid.NewString(), RunId: uuid.NewString(), + ArchetypeId: chasm.WorkflowArchetypeID, VersionedTransition: &persistencespb.VersionedTransition{ NamespaceFailoverVersion: rand.Int63(), TransitionCount: rand.Int63(), @@ -576,6 +578,7 @@ func (s *executableTaskSuite) TestResend_TransitionHistoryDisabled() { WorkflowId: syncStateErr.WorkflowId, RunId: syncStateErr.RunId, }, + ArchetypeId: syncStateErr.ArchetypeId, VersionedTransition: syncStateErr.VersionedTransition, VersionHistories: syncStateErr.VersionHistories, TargetClusterId: int32(s.clusterMetadata.GetAllClusterInfo()[s.clusterMetadata.GetCurrentClusterName()].InitialFailoverVersion), @@ -603,6 +606,7 @@ func (s *executableTaskSuite) TestSyncState_SourceMutableStateHasUnFlushedBuffer NamespaceId: uuid.NewString(), WorkflowId: uuid.NewString(), RunId: uuid.NewString(), + ArchetypeId: chasm.WorkflowArchetypeID, VersionedTransition: &persistencespb.VersionedTransition{ NamespaceFailoverVersion: rand.Int63(), TransitionCount: rand.Int63(), @@ -630,6 +634,7 @@ func (s *executableTaskSuite) TestSyncState_SourceMutableStateHasUnFlushedBuffer WorkflowId: syncStateErr.WorkflowId, RunId: syncStateErr.RunId, }, + ArchetypeId: chasm.WorkflowArchetypeID, VersionedTransition: syncStateErr.VersionedTransition, VersionHistories: syncStateErr.VersionHistories, TargetClusterId: int32(s.clusterMetadata.GetAllClusterInfo()[s.clusterMetadata.GetCurrentClusterName()].InitialFailoverVersion), @@ -1071,6 +1076,7 @@ func (s *executableTaskSuite) TestSyncState() { NamespaceId: uuid.NewString(), WorkflowId: uuid.NewString(), RunId: uuid.NewString(), + ArchetypeId: chasm.WorkflowArchetypeID, VersionedTransition: &persistencespb.VersionedTransition{ NamespaceFailoverVersion: rand.Int63(), TransitionCount: rand.Int63(), @@ -1109,6 +1115,7 @@ func (s *executableTaskSuite) TestSyncState() { WorkflowId: syncStateErr.WorkflowId, RunId: syncStateErr.RunId, }, + ArchetypeId: chasm.WorkflowArchetypeID, VersionedTransition: syncStateErr.VersionedTransition, VersionHistories: syncStateErr.VersionHistories, TargetClusterId: int32(s.clusterMetadata.GetAllClusterInfo()[s.clusterMetadata.GetCurrentClusterName()].InitialFailoverVersion), @@ -1124,7 +1131,7 @@ func (s *executableTaskSuite) TestSyncState() { syncStateErr.WorkflowId, ).Return(shardContext, nil).AnyTimes() shardContext.EXPECT().GetEngine(gomock.Any()).Return(engine, nil).AnyTimes() - engine.EXPECT().ReplicateVersionedTransition(gomock.Any(), versionedTransitionArtifact, s.sourceCluster).Return(nil) + engine.EXPECT().ReplicateVersionedTransition(gomock.Any(), chasm.WorkflowArchetypeID, versionedTransitionArtifact, s.sourceCluster).Return(nil) doContinue, err := s.task.SyncState(context.Background(), syncStateErr, ResendAttempt) s.NoError(err) diff --git a/service/history/replication/executable_verify_versioned_transition_task.go b/service/history/replication/executable_verify_versioned_transition_task.go index a90b48cc2a8..79785144ec6 100644 --- a/service/history/replication/executable_verify_versioned_transition_task.go +++ b/service/history/replication/executable_verify_versioned_transition_task.go @@ -50,6 +50,9 @@ func NewExecutableVerifyVersionedTransitionTask( replicationTask *replicationspb.ReplicationTask, ) *ExecutableVerifyVersionedTransitionTask { task := replicationTask.GetVerifyVersionedTransitionTaskAttributes() + if task.ArchetypeId == chasm.UnspecifiedArchetypeID { + task.ArchetypeId = chasm.WorkflowArchetypeID + } return &ExecutableVerifyVersionedTransitionTask{ ProcessToolBox: processToolBox, @@ -111,6 +114,7 @@ func (e *ExecutableVerifyVersionedTransitionTask) Execute() error { e.NamespaceID, e.WorkflowID, e.RunID, + e.taskAttr.GetArchetypeId(), nil, nil, ) @@ -126,6 +130,7 @@ func (e *ExecutableVerifyVersionedTransitionTask) Execute() error { e.NamespaceID, e.WorkflowID, e.RunID, + e.taskAttr.GetArchetypeId(), nil, ms.GetExecutionInfo().VersionHistories, ) @@ -149,6 +154,7 @@ func (e *ExecutableVerifyVersionedTransitionTask) Execute() error { e.NamespaceID, e.WorkflowID, e.RunID, + e.taskAttr.GetArchetypeId(), transitionhistory.LastVersionedTransition(transitionHistory), ms.GetExecutionInfo().VersionHistories, ) @@ -229,7 +235,7 @@ func (e *ExecutableVerifyVersionedTransitionTask) getMutableState(ctx context.Co WorkflowId: e.WorkflowID, RunId: runId, }, - chasm.ArchetypeAny, + e.taskAttr.GetArchetypeId(), locks.PriorityHigh, ) if err != nil { diff --git a/service/history/replication/executable_verify_versioned_transition_task_test.go b/service/history/replication/executable_verify_versioned_transition_task_test.go index fcd8d1aca21..23733060d22 100644 --- a/service/history/replication/executable_verify_versioned_transition_task_test.go +++ b/service/history/replication/executable_verify_versioned_transition_task_test.go @@ -126,6 +126,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) SetupTest() { NamespaceId: s.namespaceID, WorkflowId: s.workflowID, RunId: s.runID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ @@ -164,6 +165,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) TestExecute_CurrentBranch RunId: s.runID, NextEventId: taskNextEvent, NewRunId: s.newRunID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ @@ -220,6 +222,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) TestExecute_CurrentBranch RunId: s.runID, NextEventId: taskNextEvent, NewRunId: s.newRunID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ @@ -286,7 +289,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) mockGetMutableState( WorkflowId: workflowId, RunId: runId, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ).Return(wfCtx, func(err error) {}, err) } @@ -303,6 +306,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) TestExecute_CurrentBranch RunId: s.runID, NextEventId: taskNextEvent, NewRunId: s.newRunID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ @@ -359,6 +363,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) TestExecute_MissingVersio RunId: s.runID, NextEventId: taskNextEvent, NewRunId: s.newRunID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ @@ -418,6 +423,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) TestExecute_NonCurrentBra Version: 1, }, }, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ @@ -507,6 +513,7 @@ func (s *executableVerifyVersionedTransitionTaskSuite) TestExecute_NonCurrentBra Version: 1, }, }, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: &persistencespb.VersionedTransition{ diff --git a/service/history/replication/raw_task_converter.go b/service/history/replication/raw_task_converter.go index f3456c1a342..44d99517f57 100644 --- a/service/history/replication/raw_task_converter.go +++ b/service/history/replication/raw_task_converter.go @@ -122,7 +122,7 @@ func convertActivityStateReplicationTask( ctx, shardContext, definition.NewWorkflowKey(taskInfo.NamespaceID, taskInfo.WorkflowID, taskInfo.RunID), - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, workflowCache, func(mutableState historyi.MutableState, releaseFunc historyi.ReleaseWorkflowContextFunc) (*replicationspb.ReplicationTask, error) { if !mutableState.IsWorkflowExecutionRunning() { @@ -210,7 +210,7 @@ func convertWorkflowStateReplicationTask( ctx, shardContext, definition.NewWorkflowKey(taskInfo.NamespaceID, taskInfo.WorkflowID, taskInfo.RunID), - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, workflowCache, func(mutableState historyi.MutableState, releaseFunc historyi.ReleaseWorkflowContextFunc) (*replicationspb.ReplicationTask, error) { state, _ := mutableState.GetWorkflowStateStatus() @@ -255,7 +255,7 @@ func convertSyncHSMReplicationTask( ctx, shardContext, definition.NewWorkflowKey(taskInfo.NamespaceID, taskInfo.WorkflowID, taskInfo.RunID), - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, workflowCache, func(mutableState historyi.MutableState, releaseFunc historyi.ReleaseWorkflowContextFunc) (*replicationspb.ReplicationTask, error) { // HSM can be updated after workflow is completed @@ -303,11 +303,14 @@ func convertSyncVersionedTransitionTask( targetClusterID int32, converter *syncVersionedTransitionTaskConverter, ) (*replicationspb.ReplicationTask, error) { + if taskInfo.ArchetypeID == chasm.UnspecifiedArchetypeID { + taskInfo.ArchetypeID = chasm.WorkflowArchetypeID + } return generateStateReplicationTask( ctx, converter.shardContext, definition.NewWorkflowKey(taskInfo.NamespaceID, taskInfo.WorkflowID, taskInfo.RunID), - chasm.ArchetypeAny, // SyncVersionedTransitionTask works for all Archetypes. + taskInfo.ArchetypeID, converter.workflowCache, func(mutableState historyi.MutableState, releaseFunc historyi.ReleaseWorkflowContextFunc) (*replicationspb.ReplicationTask, error) { return converter.convert(ctx, taskInfo, targetClusterID, mutableState, releaseFunc) @@ -382,7 +385,7 @@ func generateStateReplicationTask( ctx context.Context, shardContext historyi.ShardContext, workflowKey definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, workflowCache wcache.Cache, action func(mutableState historyi.MutableState, releaseFunc historyi.ReleaseWorkflowContextFunc) (*replicationspb.ReplicationTask, error), ) (retReplicationTask *replicationspb.ReplicationTask, retError error) { @@ -394,7 +397,7 @@ func generateStateReplicationTask( WorkflowId: workflowKey.WorkflowID, RunId: workflowKey.RunID, }, - archetype, + archetypeID, locks.PriorityLow, ) if err != nil { @@ -652,7 +655,11 @@ func (c *syncVersionedTransitionTaskConverter) convert( // If workflow is not on any versionedTransition (in an unknown state from state-based replication perspective), // we can't convert this raw task to a replication task, instead we need to rely on its task equivalents. if len(executionInfo.TransitionHistory) == 0 { + isWorkflow := mutableState.IsWorkflow() releaseFunc(nil) + if !isWorkflow { + return nil, serviceerror.NewInternalf("chasm execution not on any versioned transition, is state-based replication enabled? execution key: %v", taskInfo.WorkflowKey) + } return c.convertTaskEquivalents(ctx, taskInfo, targetClusterID) } @@ -745,6 +752,7 @@ func (c *syncVersionedTransitionTaskConverter) convert( NamespaceId: taskInfo.NamespaceID, WorkflowId: taskInfo.WorkflowID, RunId: taskInfo.RunID, + ArchetypeId: taskInfo.ArchetypeID, }, }, VersionedTransition: taskInfo.VersionedTransition, @@ -794,6 +802,7 @@ func (c *syncVersionedTransitionTaskConverter) generateVerifyVersionedTransition NamespaceId: taskInfo.NamespaceID, WorkflowId: taskInfo.WorkflowID, RunId: taskInfo.RunID, + ArchetypeId: taskInfo.ArchetypeID, NewRunId: taskInfo.NewRunID, EventVersionHistory: eventVersionHistory, NextEventId: nextEventId, @@ -930,6 +939,7 @@ func (c *syncVersionedTransitionTaskConverter) convertTaskEquivalents( ShardID: c.shardID, NamespaceID: taskInfo.NamespaceID, WorkflowID: taskInfo.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, // only workflow has task equivalents Tasks: map[tasks.Category][]tasks.Task{ tasks.CategoryReplication: taskInfo.TaskEquivalents, }, diff --git a/service/history/replication/raw_task_converter_test.go b/service/history/replication/raw_task_converter_test.go index fb84c32b35e..bfb63441d15 100644 --- a/service/history/replication/raw_task_converter_test.go +++ b/service/history/replication/raw_task_converter_test.go @@ -179,7 +179,7 @@ func (s *rawTaskConverterSuite) TestConvertActivityStateReplicationTask_Workflow WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(nil, serviceerror.NewNotFound("")) @@ -214,7 +214,7 @@ func (s *rawTaskConverterSuite) TestConvertActivityStateReplicationTask_Workflow WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil) @@ -250,7 +250,7 @@ func (s *rawTaskConverterSuite) TestConvertActivityStateReplicationTask_Activity WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil) @@ -287,7 +287,7 @@ func (s *rawTaskConverterSuite) TestConvertActivityStateReplicationTask_Activity WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) @@ -397,7 +397,7 @@ func (s *rawTaskConverterSuite) TestConvertActivityStateReplicationTask_Activity WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) @@ -506,7 +506,7 @@ func (s *rawTaskConverterSuite) TestConvertWorkflowStateReplicationTask_Workflow WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil) @@ -540,7 +540,7 @@ func (s *rawTaskConverterSuite) TestConvertWorkflowStateReplicationTask_Workflow WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil) @@ -929,7 +929,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncHSMTask_WorkflowMissing() { WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(nil, serviceerror.NewNotFound("")) @@ -961,7 +961,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncHSMTask_WorkflowFound() { WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil) @@ -1054,7 +1054,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncHSMTask_BufferedEvents() { WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil) @@ -1098,6 +1098,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_Backfill( ), VisibilityTimestamp: time.Now().UTC(), TaskID: taskID, + ArchetypeID: chasm.WorkflowArchetypeID, FirstEventID: firstEventID, FirstEventVersion: version, NextEventID: nextEventID, @@ -1142,7 +1143,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_Backfill( WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil).Times(1) s.workflowCache.EXPECT().GetOrCreateWorkflowExecution( @@ -1276,6 +1277,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionTransitionTask_ConvertTask WorkflowKey: workflowKey, VisibilityTimestamp: visibilityTimestamp, TaskID: taskID, + ArchetypeID: chasm.WorkflowArchetypeID, VersionedTransition: &persistencespb.VersionedTransition{ NamespaceFailoverVersion: version, TransitionCount: 165, @@ -1296,13 +1298,14 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionTransitionTask_ConvertTask WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil).Times(1) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil).Times(1) s.mutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ TransitionHistory: nil, }).Times(1) + s.mutableState.EXPECT().IsWorkflow().Return(true).AnyTimes() expectedReplicationTask := &replicationspb.ReplicationTask{ TaskType: enumsspb.REPLICATION_TASK_TYPE_SYNC_ACTIVITY_TASK, SourceTaskId: taskID, @@ -1362,6 +1365,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionTransitionTask_AddTaskEqui WorkflowKey: workflowKey, VisibilityTimestamp: visibilityTimestamp, TaskID: taskID, + ArchetypeID: chasm.WorkflowArchetypeID, VersionedTransition: &persistencespb.VersionedTransition{ NamespaceFailoverVersion: version, TransitionCount: 165, @@ -1376,13 +1380,14 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionTransitionTask_AddTaskEqui WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil).Times(1) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil).Times(1) s.mutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ TransitionHistory: nil, }).Times(1) + s.mutableState.EXPECT().IsWorkflow().Return(true).AnyTimes() mockExecutionManager := s.shardContext.Resource.ExecutionMgr mockExecutionManager.EXPECT().AddHistoryTasks(gomock.Any(), gomock.Any()).DoAndReturn( func(_ context.Context, request *persistence.AddHistoryTasksRequest) error { @@ -1423,6 +1428,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_Mutation( ), VisibilityTimestamp: time.Now().UTC(), TaskID: taskID, + ArchetypeID: chasm.WorkflowArchetypeID, FirstEventID: firstEventID, NextEventID: nextEventID, VersionedTransition: &persistencespb.VersionedTransition{ @@ -1461,7 +1467,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_Mutation( WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil).Times(1) @@ -1532,6 +1538,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_Mutation( NamespaceId: s.namespaceID, WorkflowId: s.workflowID, RunId: s.runID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: task.VersionedTransition, @@ -1555,6 +1562,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_FirstTask ), VisibilityTimestamp: time.Now().UTC(), TaskID: taskID, + ArchetypeID: chasm.WorkflowArchetypeID, FirstEventID: firstEventID, NextEventID: nextEventID, VersionedTransition: &persistencespb.VersionedTransition{ @@ -1594,7 +1602,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_FirstTask WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil).Times(1) @@ -1664,6 +1672,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_FirstTask NamespaceId: s.namespaceID, WorkflowId: s.workflowID, RunId: s.runID, + ArchetypeId: chasm.WorkflowArchetypeID, }, }, VersionedTransition: task.VersionedTransition, @@ -1687,6 +1696,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_HasBuffer ), VisibilityTimestamp: time.Now().UTC(), TaskID: taskID, + ArchetypeID: chasm.WorkflowArchetypeID, FirstEventID: firstEventID, NextEventID: nextEventID, VersionedTransition: &persistencespb.VersionedTransition{ @@ -1707,7 +1717,7 @@ func (s *rawTaskConverterSuite) TestConvertSyncVersionedTransitionTask_HasBuffer WorkflowId: s.workflowID, RunId: s.runID, }, - chasm.ArchetypeAny, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(s.workflowContext, s.releaseFn, nil) s.workflowContext.EXPECT().LoadMutableState(gomock.Any(), s.shardContext).Return(s.mutableState, nil).Times(1) diff --git a/service/history/replication/sync_state_retriever.go b/service/history/replication/sync_state_retriever.go index 120d9115739..48a2a9289c7 100644 --- a/service/history/replication/sync_state_retriever.go +++ b/service/history/replication/sync_state_retriever.go @@ -46,6 +46,7 @@ type ( ctx context.Context, namespaceID string, execution *commonpb.WorkflowExecution, + archetypeID chasm.ArchetypeID, targetVersionedTransition *persistencespb.VersionedTransition, targetVersionHistories *historyspb.VersionHistories, ) (*SyncStateResult, error) @@ -100,6 +101,7 @@ func (s *SyncStateRetrieverImpl) GetSyncWorkflowStateArtifact( ctx context.Context, namespaceID string, execution *commonpb.WorkflowExecution, + archetypeID chasm.ArchetypeID, targetCurrentVersionedTransition *persistencespb.VersionedTransition, targetVersionHistories *historyspb.VersionHistories, ) (_ *SyncStateResult, retError error) { @@ -117,7 +119,7 @@ func (s *SyncStateRetrieverImpl) GetSyncWorkflowStateArtifact( WorkflowID: execution.WorkflowId, RunID: execution.RunId, }, - chasm.ArchetypeAny, // SyncWorkflowState API works on all archetypes + archetypeID, locks.PriorityLow, ) if err != nil { diff --git a/service/history/replication/sync_state_retriever_mock.go b/service/history/replication/sync_state_retriever_mock.go index 9eca8d2c2b7..1be85677c63 100644 --- a/service/history/replication/sync_state_retriever_mock.go +++ b/service/history/replication/sync_state_retriever_mock.go @@ -16,6 +16,7 @@ import ( common "go.temporal.io/api/common/v1" history "go.temporal.io/server/api/history/v1" persistence "go.temporal.io/server/api/persistence/v1" + chasm "go.temporal.io/server/chasm" interfaces "go.temporal.io/server/service/history/interfaces" gomock "go.uber.org/mock/gomock" ) @@ -45,18 +46,18 @@ func (m *MockSyncStateRetriever) EXPECT() *MockSyncStateRetrieverMockRecorder { } // GetSyncWorkflowStateArtifact mocks base method. -func (m *MockSyncStateRetriever) GetSyncWorkflowStateArtifact(ctx context.Context, namespaceID string, execution *common.WorkflowExecution, targetVersionedTransition *persistence.VersionedTransition, targetVersionHistories *history.VersionHistories) (*SyncStateResult, error) { +func (m *MockSyncStateRetriever) GetSyncWorkflowStateArtifact(ctx context.Context, namespaceID string, execution *common.WorkflowExecution, archetypeID chasm.ArchetypeID, targetVersionedTransition *persistence.VersionedTransition, targetVersionHistories *history.VersionHistories) (*SyncStateResult, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSyncWorkflowStateArtifact", ctx, namespaceID, execution, targetVersionedTransition, targetVersionHistories) + ret := m.ctrl.Call(m, "GetSyncWorkflowStateArtifact", ctx, namespaceID, execution, archetypeID, targetVersionedTransition, targetVersionHistories) ret0, _ := ret[0].(*SyncStateResult) ret1, _ := ret[1].(error) return ret0, ret1 } // GetSyncWorkflowStateArtifact indicates an expected call of GetSyncWorkflowStateArtifact. -func (mr *MockSyncStateRetrieverMockRecorder) GetSyncWorkflowStateArtifact(ctx, namespaceID, execution, targetVersionedTransition, targetVersionHistories any) *gomock.Call { +func (mr *MockSyncStateRetrieverMockRecorder) GetSyncWorkflowStateArtifact(ctx, namespaceID, execution, archetypeID, targetVersionedTransition, targetVersionHistories any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncWorkflowStateArtifact", reflect.TypeOf((*MockSyncStateRetriever)(nil).GetSyncWorkflowStateArtifact), ctx, namespaceID, execution, targetVersionedTransition, targetVersionHistories) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncWorkflowStateArtifact", reflect.TypeOf((*MockSyncStateRetriever)(nil).GetSyncWorkflowStateArtifact), ctx, namespaceID, execution, archetypeID, targetVersionedTransition, targetVersionHistories) } // GetSyncWorkflowStateArtifactFromMutableState mocks base method. diff --git a/service/history/replication/sync_state_retriever_test.go b/service/history/replication/sync_state_retriever_test.go index c85465424d2..6cf9656f0db 100644 --- a/service/history/replication/sync_state_retriever_test.go +++ b/service/history/replication/sync_state_retriever_test.go @@ -112,7 +112,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_TransitionHistoryDisabled NamespaceID: s.namespaceID, WorkflowID: s.execution.WorkflowId, RunID: s.execution.RunId, - }, chasm.ArchetypeAny, locks.PriorityLow).Return( + }, chasm.WorkflowArchetypeID, locks.PriorityLow).Return( api.NewWorkflowLease(nil, func(err error) {}, mu), nil) executionInfo := &persistencespb.WorkflowExecutionInfo{ @@ -124,6 +124,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_TransitionHistoryDisabled context.Background(), s.namespaceID, s.execution, + chasm.WorkflowArchetypeID, nil, nil, ) @@ -138,7 +139,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_UnFlushedBufferedEvents() NamespaceID: s.namespaceID, WorkflowID: s.execution.WorkflowId, RunID: s.execution.RunId, - }, chasm.ArchetypeAny, locks.PriorityLow).Return( + }, chasm.WorkflowArchetypeID, locks.PriorityLow).Return( api.NewWorkflowLease(nil, func(err error) {}, mu), nil) mu.EXPECT().HasBufferedEvents().Return(true) @@ -146,6 +147,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_UnFlushedBufferedEvents() context.Background(), s.namespaceID, s.execution, + chasm.WorkflowArchetypeID, nil, nil, ) @@ -160,7 +162,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_ReturnMutation() { NamespaceID: s.namespaceID, WorkflowID: s.execution.WorkflowId, RunID: s.execution.RunId, - }, chasm.ArchetypeAny, locks.PriorityLow).Return( + }, chasm.WorkflowArchetypeID, locks.PriorityLow).Return( api.NewWorkflowLease(nil, func(err error) {}, mu), nil) versionHistories := &historyspb.VersionHistories{ CurrentVersionHistoryIndex: 0, @@ -228,6 +230,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_ReturnMutation() { context.Background(), s.namespaceID, s.execution, + chasm.WorkflowArchetypeID, &persistencespb.VersionedTransition{ NamespaceFailoverVersion: 1, TransitionCount: 12, @@ -513,7 +516,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_ReturnSnapshot() { NamespaceID: s.namespaceID, WorkflowID: s.execution.WorkflowId, RunID: s.execution.RunId, - }, chasm.ArchetypeAny, locks.PriorityLow).Return( + }, chasm.WorkflowArchetypeID, locks.PriorityLow).Return( api.NewWorkflowLease(nil, func(err error) {}, mu), nil) versionHistories, transitions, tombstoneBatches, breakPoint := tc.infoFn() executionInfo := &persistencespb.WorkflowExecutionInfo{ @@ -531,6 +534,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_ReturnSnapshot() { context.Background(), s.namespaceID, s.execution, + chasm.WorkflowArchetypeID, &persistencespb.VersionedTransition{ NamespaceFailoverVersion: 1, TransitionCount: 13, @@ -551,7 +555,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_NoVersionTransitionProvid NamespaceID: s.namespaceID, WorkflowID: s.execution.WorkflowId, RunID: s.execution.RunId, - }, chasm.ArchetypeAny, locks.PriorityLow).Return( + }, chasm.WorkflowArchetypeID, locks.PriorityLow).Return( api.NewWorkflowLease(nil, func(err error) {}, mu), nil) versionHistories := &historyspb.VersionHistories{ CurrentVersionHistoryIndex: 0, @@ -586,6 +590,7 @@ func (s *syncWorkflowStateSuite) TestSyncWorkflowState_NoVersionTransitionProvid context.Background(), s.namespaceID, s.execution, + chasm.WorkflowArchetypeID, nil, versionHistories) s.NoError(err) diff --git a/service/history/shard/context_impl.go b/service/history/shard/context_impl.go index 8906678697f..648a47aed6e 100644 --- a/service/history/shard/context_impl.go +++ b/service/history/shard/context_impl.go @@ -941,6 +941,7 @@ func (s *ContextImpl) AppendHistoryEvents( func (s *ContextImpl) DeleteWorkflowExecution( ctx context.Context, key definition.WorkflowKey, + archetypeID chasm.ArchetypeID, branchToken []byte, closeVisibilityTaskId int64, workflowCloseTime time.Time, @@ -1028,6 +1029,7 @@ func (s *ContextImpl) DeleteWorkflowExecution( ShardID: s.shardID, NamespaceID: key.NamespaceID, WorkflowID: key.WorkflowID, + ArchetypeID: archetypeID, Tasks: newTasks, } @@ -1048,10 +1050,12 @@ func (s *ContextImpl) DeleteWorkflowExecution( return err } defer cancel() + delCurRequest := &persistence.DeleteCurrentWorkflowExecutionRequest{ ShardID: s.shardID, NamespaceID: key.NamespaceID, WorkflowID: key.WorkflowID, + ArchetypeID: archetypeID, RunID: key.RunID, } if err := s.GetExecutionManager().DeleteCurrentWorkflowExecution( @@ -1070,13 +1074,16 @@ func (s *ContextImpl) DeleteWorkflowExecution( return err } defer cancel() - delRequest := &persistence.DeleteWorkflowExecutionRequest{ - ShardID: s.shardID, - NamespaceID: key.NamespaceID, - WorkflowID: key.WorkflowID, - RunID: key.RunID, - } - if err = s.GetExecutionManager().DeleteWorkflowExecution(ctx, delRequest); err != nil { + if err := s.GetExecutionManager().DeleteWorkflowExecution( + ctx, + &persistence.DeleteWorkflowExecutionRequest{ + ShardID: s.shardID, + NamespaceID: key.NamespaceID, + WorkflowID: key.WorkflowID, + RunID: key.RunID, + ArchetypeID: archetypeID, + }, + ); err != nil { return err } } diff --git a/service/history/shard/context_test.go b/service/history/shard/context_test.go index 9370aa88e90..303014d4ad7 100644 --- a/service/history/shard/context_test.go +++ b/service/history/shard/context_test.go @@ -13,6 +13,7 @@ import ( enumspb "go.temporal.io/api/enums/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/clock" @@ -142,6 +143,7 @@ func (s *contextSuite) TestOverwriteScheduledTaskTimestamp() { ShardID: s.mockShard.GetShardID(), NamespaceID: workflowKey.NamespaceID, WorkflowID: workflowKey.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, Tasks: testTasks, }, ) @@ -166,6 +168,7 @@ func (s *contextSuite) TestAddTasks_Success() { ShardID: s.mockShard.GetShardID(), NamespaceID: tests.NamespaceID.String(), WorkflowID: tests.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, Tasks: testTasks, } @@ -195,6 +198,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_Success() { err := s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -220,6 +224,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_Continue_Success() { err := s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -234,6 +239,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_Continue_Success() { err = s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -247,6 +253,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_Continue_Success() { err = s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -271,6 +278,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_ErrorAndContinue_Success() { err := s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -284,6 +292,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_ErrorAndContinue_Success() { err = s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -297,6 +306,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_ErrorAndContinue_Success() { err = s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -309,6 +319,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_ErrorAndContinue_Success() { err = s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -332,6 +343,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_DeleteVisibilityTaskNotificti err := s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, @@ -347,6 +359,7 @@ func (s *contextSuite) TestDeleteWorkflowExecution_DeleteVisibilityTaskNotificti err = s.mockShard.DeleteWorkflowExecution( context.Background(), workflowKey, + chasm.WorkflowArchetypeID, branchToken, 0, time.Time{}, diff --git a/service/history/statemachine_environment.go b/service/history/statemachine_environment.go index 52a1c3990de..0b516a6aeec 100644 --- a/service/history/statemachine_environment.go +++ b/service/history/statemachine_environment.go @@ -28,29 +28,32 @@ func taskWorkflowKey(task tasks.Task) definition.WorkflowKey { return definition.NewWorkflowKey(task.GetNamespaceID(), task.GetWorkflowID(), task.GetRunID()) } +func getTaskArchetypeID(task tasks.Task) chasm.ArchetypeID { + archetypeID := chasm.WorkflowArchetypeID + if hasArchetypeID, ok := task.(tasks.HasArchetypeID); ok { + archetypeID = hasArchetypeID.GetArchetypeID() + + // For backward compatibility, old tasks for workflow may not have archetypeID set. + if archetypeID == chasm.UnspecifiedArchetypeID { + archetypeID = chasm.WorkflowArchetypeID + } + } + + return archetypeID +} + func getWorkflowExecutionContextForTask( ctx context.Context, shardContext historyi.ShardContext, workflowCache wcache.Cache, task tasks.Task, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, error) { - archetype := chasm.WorkflowArchetype - switch task.GetType() { - case enumsspb.TASK_TYPE_CHASM, - enumsspb.TASK_TYPE_CHASM_PURE, - enumsspb.TASK_TYPE_DELETE_HISTORY_EVENT, // retention timer - enumsspb.TASK_TYPE_TRANSFER_DELETE_EXECUTION, - enumsspb.TASK_TYPE_VISIBILITY_DELETE_EXECUTION: - // Those tasks work for all archetypes. - archetype = chasm.ArchetypeAny - } - return getWorkflowExecutionContext( ctx, shardContext, workflowCache, taskWorkflowKey(task), - archetype, + getTaskArchetypeID(task), locks.PriorityLow, ) } @@ -60,7 +63,7 @@ func getWorkflowExecutionContext( shardContext historyi.ShardContext, workflowCache wcache.Cache, key definition.WorkflowKey, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, error) { if key.GetRunID() == "" { @@ -70,7 +73,7 @@ func getWorkflowExecutionContext( workflowCache, key.NamespaceID, key.WorkflowID, - archetype, + archetypeID, lockPriority, ) } @@ -87,7 +90,7 @@ func getWorkflowExecutionContext( shardContext, namespaceID, execution, - archetype, + archetypeID, lockPriority, ) if common.IsContextDeadlineExceededErr(err) { @@ -103,7 +106,7 @@ func getCurrentWorkflowExecutionContext( workflowCache wcache.Cache, namespaceID string, workflowID string, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, error) { currentRunID, err := wcache.GetCurrentRunID( @@ -112,6 +115,7 @@ func getCurrentWorkflowExecutionContext( workflowCache, namespaceID, workflowID, + archetypeID, lockPriority, ) if err != nil { @@ -123,7 +127,7 @@ func getCurrentWorkflowExecutionContext( shardContext, workflowCache, definition.NewWorkflowKey(namespaceID, workflowID, currentRunID), - archetype, + archetypeID, lockPriority, ) if err != nil { @@ -149,6 +153,7 @@ func getCurrentWorkflowExecutionContext( workflowCache, namespaceID, workflowID, + archetypeID, lockPriority, ) if err != nil { @@ -326,7 +331,7 @@ func (e *stateMachineEnvironment) getValidatedMutableState( key definition.WorkflowKey, validate func(workflowContext historyi.WorkflowContext, ms historyi.MutableState, potentialStaleState bool) error, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, historyi.MutableState, error) { - wfCtx, release, err := getWorkflowExecutionContext(ctx, e.shardContext, e.cache, key, chasm.WorkflowArchetype, locks.PriorityLow) + wfCtx, release, err := getWorkflowExecutionContext(ctx, e.shardContext, e.cache, key, chasm.WorkflowArchetypeID, locks.PriorityLow) if err != nil { return nil, nil, nil, err } diff --git a/service/history/statemachine_environment_test.go b/service/history/statemachine_environment_test.go index b998ef277d5..f94b6ff116e 100644 --- a/service/history/statemachine_environment_test.go +++ b/service/history/statemachine_environment_test.go @@ -276,7 +276,7 @@ func TestValidateStateMachineRef(t *testing.T) { tc.mutateNode(node) tc.mutateRef(&ref) - workflowContext := workflow.NewContext(s.mockShard.GetConfig(), mutableState.GetWorkflowKey(), log.NewTestLogger(), log.NewTestLogger(), metrics.NoopMetricsHandler) + workflowContext := workflow.NewContext(s.mockShard.GetConfig(), mutableState.GetWorkflowKey(), chasm.WorkflowArchetypeID, log.NewTestLogger(), log.NewTestLogger(), metrics.NoopMetricsHandler) if tc.clearTransitionHistory { mutableState.GetExecutionInfo().TransitionHistory = nil } @@ -499,11 +499,12 @@ func TestGetCurrentWorkflowExecutionContext(t *testing.T) { mockWorkflowContext.EXPECT().GetWorkflowKey().Return(definition.NewWorkflowKey(namespaceID.String(), workflowID, currentRunID)).AnyTimes() mockWorkflowCache := cache.NewMockCache(controller) - mockWorkflowCache.EXPECT().GetOrCreateCurrentWorkflowExecution( + mockWorkflowCache.EXPECT().GetOrCreateCurrentExecution( gomock.Any(), mockShard, namespaceID, workflowID, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(cache.NoopReleaseFn, nil).AnyTimes() mockWorkflowCache.EXPECT().GetOrCreateChasmExecution( @@ -514,7 +515,7 @@ func TestGetCurrentWorkflowExecutionContext(t *testing.T) { WorkflowId: workflowID, RunId: currentRunID, }, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(mockWorkflowContext, cache.NoopReleaseFn, nil).Times(1) @@ -523,6 +524,7 @@ func TestGetCurrentWorkflowExecutionContext(t *testing.T) { ShardID: mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ RunID: currentRunID, }, nil).Times(1) @@ -536,6 +538,7 @@ func TestGetCurrentWorkflowExecutionContext(t *testing.T) { ShardID: mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: workflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ RunID: currentRunID, }, nil).Times(1) @@ -547,7 +550,7 @@ func TestGetCurrentWorkflowExecutionContext(t *testing.T) { mockWorkflowCache, namespaceID.String(), workflowID, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ) if tc.currentRunChanged { diff --git a/service/history/tasks/chasm_task.go b/service/history/tasks/chasm_task.go index 5444f21200b..5adb45f761a 100644 --- a/service/history/tasks/chasm_task.go +++ b/service/history/tasks/chasm_task.go @@ -16,10 +16,11 @@ type ChasmTaskPure struct { definition.WorkflowKey // Task interface assumes WorkflowKey. VisibilityTimestamp time.Time TaskID int64 - Category Category // Set based on the task's queue. + ArchetypeID uint32 } var _ Task = &ChasmTaskPure{} +var _ HasArchetypeID = &ChasmTaskPure{} func (t *ChasmTaskPure) GetTaskID() int64 { return t.TaskID @@ -38,7 +39,7 @@ func (t *ChasmTaskPure) SetVisibilityTime(timestamp time.Time) { } func (t *ChasmTaskPure) GetCategory() Category { - return t.Category + return CategoryTimer } func (t *ChasmTaskPure) GetType() enumsspb.TaskType { @@ -53,6 +54,10 @@ func (t *ChasmTaskPure) GetKey() Key { return NewImmediateKey(t.TaskID) } +func (t *ChasmTaskPure) GetArchetypeID() uint32 { + return t.ArchetypeID +} + // ChasmTask is a task with side effects generated by a CHASM component. type ChasmTask struct { definition.WorkflowKey // Task interface assumes WorkflowKey. @@ -67,6 +72,7 @@ type ChasmTask struct { } var _ Task = &ChasmTask{} +var _ HasArchetypeID = &ChasmTask{} func (t *ChasmTask) GetCategory() Category { return t.Category @@ -99,3 +105,6 @@ func (t *ChasmTask) GetVisibilityTime() time.Time { func (t *ChasmTask) SetVisibilityTime(timestamp time.Time) { t.VisibilityTimestamp = timestamp } +func (t *ChasmTask) GetArchetypeID() uint32 { + return t.Info.GetArchetypeId() +} diff --git a/service/history/tasks/delete_execution_task.go b/service/history/tasks/delete_execution_task.go index 62dbe7570bd..9a1ac839cb2 100644 --- a/service/history/tasks/delete_execution_task.go +++ b/service/history/tasks/delete_execution_task.go @@ -9,12 +9,14 @@ import ( ) var _ Task = (*DeleteExecutionTask)(nil) +var _ HasArchetypeID = (*DeleteExecutionTask)(nil) type ( DeleteExecutionTask struct { definition.WorkflowKey VisibilityTimestamp time.Time TaskID int64 + ArchetypeID uint32 ProcessStage DeleteWorkflowExecutionStage } @@ -48,6 +50,10 @@ func (a *DeleteExecutionTask) GetType() enumsspb.TaskType { return enumsspb.TASK_TYPE_TRANSFER_DELETE_EXECUTION } +func (a *DeleteExecutionTask) GetArchetypeID() uint32 { + return a.ArchetypeID +} + func (a *DeleteExecutionTask) String() string { return fmt.Sprintf("DeleteExecutionTask{WorkflowKey: %s, VisibilityTimestamp: %v, TaskID: %v, ProcessStage: %v}", a.WorkflowKey.String(), diff --git a/service/history/tasks/delete_visibility_task.go b/service/history/tasks/delete_visibility_task.go index de9670e96ab..8e771a5270a 100644 --- a/service/history/tasks/delete_visibility_task.go +++ b/service/history/tasks/delete_visibility_task.go @@ -8,12 +8,14 @@ import ( ) var _ Task = (*DeleteExecutionVisibilityTask)(nil) +var _ HasArchetypeID = (*DeleteExecutionVisibilityTask)(nil) type ( DeleteExecutionVisibilityTask struct { definition.WorkflowKey VisibilityTimestamp time.Time TaskID int64 + ArchetypeID uint32 CloseExecutionVisibilityTaskID int64 CloseTime time.Time } @@ -46,3 +48,7 @@ func (t *DeleteExecutionVisibilityTask) GetCategory() Category { func (t *DeleteExecutionVisibilityTask) GetType() enumsspb.TaskType { return enumsspb.TASK_TYPE_VISIBILITY_DELETE_EXECUTION } + +func (t *DeleteExecutionVisibilityTask) GetArchetypeID() uint32 { + return t.ArchetypeID +} diff --git a/service/history/tasks/sync_versioned_transition_task.go b/service/history/tasks/sync_versioned_transition_task.go index 727afb0ea6b..b0d52f97eaa 100644 --- a/service/history/tasks/sync_versioned_transition_task.go +++ b/service/history/tasks/sync_versioned_transition_task.go @@ -11,12 +11,14 @@ import ( ) var _ Task = (*SyncVersionedTransitionTask)(nil) +var _ HasArchetypeID = (*SyncVersionedTransitionTask)(nil) type ( SyncVersionedTransitionTask struct { definition.WorkflowKey VisibilityTimestamp time.Time TaskID int64 + ArchetypeID uint32 Priority enumsspb.TaskPriority TargetClusters []string @@ -61,6 +63,10 @@ func (a *SyncVersionedTransitionTask) GetType() enumsspb.TaskType { return enumsspb.TASK_TYPE_REPLICATION_SYNC_VERSIONED_TRANSITION } +func (a *SyncVersionedTransitionTask) GetArchetypeID() uint32 { + return a.ArchetypeID +} + func (a *SyncVersionedTransitionTask) String() string { return fmt.Sprintf("SyncVersionedTransitionTask{WorkflowKey: %v, TaskID: %v, Priority: %v, VersionedTransition: %v, FirstEventID: %v, FirstEventVersion: %v, NextEventID: %v, NewRunID: %v}", a.WorkflowKey, a.TaskID, a.Priority, a.VersionedTransition, a.FirstEventID, a.FirstEventVersion, a.NextEventID, a.NewRunID) diff --git a/service/history/tasks/task.go b/service/history/tasks/task.go index d2f68ebc5b1..d0c5996ff8e 100644 --- a/service/history/tasks/task.go +++ b/service/history/tasks/task.go @@ -44,6 +44,10 @@ type ( HasDestination interface { GetDestination() string } + + HasArchetypeID interface { + GetArchetypeID() uint32 + } ) // GetShardIDForTask computes the shardID for a given task using the task's namespace, workflow ID and the number of diff --git a/service/history/tasks/task_mock.go b/service/history/tasks/task_mock.go index f588f2c81bb..76d5a0f46d1 100644 --- a/service/history/tasks/task_mock.go +++ b/service/history/tasks/task_mock.go @@ -290,3 +290,41 @@ func (mr *MockHasDestinationMockRecorder) GetDestination() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDestination", reflect.TypeOf((*MockHasDestination)(nil).GetDestination)) } + +// MockHasArchetypeID is a mock of HasArchetypeID interface. +type MockHasArchetypeID struct { + ctrl *gomock.Controller + recorder *MockHasArchetypeIDMockRecorder + isgomock struct{} +} + +// MockHasArchetypeIDMockRecorder is the mock recorder for MockHasArchetypeID. +type MockHasArchetypeIDMockRecorder struct { + mock *MockHasArchetypeID +} + +// NewMockHasArchetypeID creates a new mock instance. +func NewMockHasArchetypeID(ctrl *gomock.Controller) *MockHasArchetypeID { + mock := &MockHasArchetypeID{ctrl: ctrl} + mock.recorder = &MockHasArchetypeIDMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHasArchetypeID) EXPECT() *MockHasArchetypeIDMockRecorder { + return m.recorder +} + +// GetArchetypeID mocks base method. +func (m *MockHasArchetypeID) GetArchetypeID() uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetArchetypeID") + ret0, _ := ret[0].(uint32) + return ret0 +} + +// GetArchetypeID indicates an expected call of GetArchetypeID. +func (mr *MockHasArchetypeIDMockRecorder) GetArchetypeID() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetArchetypeID", reflect.TypeOf((*MockHasArchetypeID)(nil).GetArchetypeID)) +} diff --git a/service/history/tasks/workflow_cleanup_timer.go b/service/history/tasks/workflow_cleanup_timer.go index 75316a983e3..063ba8a9b6d 100644 --- a/service/history/tasks/workflow_cleanup_timer.go +++ b/service/history/tasks/workflow_cleanup_timer.go @@ -9,6 +9,7 @@ import ( ) var _ Task = (*DeleteHistoryEventTask)(nil) +var _ HasArchetypeID = (*DeleteHistoryEventTask)(nil) type ( DeleteHistoryEventTask struct { @@ -17,7 +18,9 @@ type ( TaskID int64 Version int64 BranchToken []byte - ProcessStage DeleteWorkflowExecutionStage + ArchetypeID uint32 + + ProcessStage DeleteWorkflowExecutionStage } ) @@ -57,6 +60,10 @@ func (a *DeleteHistoryEventTask) GetType() enumsspb.TaskType { return enumsspb.TASK_TYPE_DELETE_HISTORY_EVENT } +func (a *DeleteHistoryEventTask) GetArchetypeID() uint32 { + return a.ArchetypeID +} + func (a *DeleteHistoryEventTask) String() string { return fmt.Sprintf("DeleteHistoryEventTask{WorkflowKey: %s, VisibilityTimestamp: %v, TaskID: %v, Version: %v, ProcessStage: %v}", a.WorkflowKey.String(), diff --git a/service/history/tests/vars.go b/service/history/tests/vars.go index 6197d3f82a6..ce113cbe3b1 100644 --- a/service/history/tests/vars.go +++ b/service/history/tests/vars.go @@ -6,6 +6,7 @@ import ( enumspb "go.temporal.io/api/enums/v1" namespacepb "go.temporal.io/api/namespace/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" @@ -35,6 +36,7 @@ var ( WorkflowID = "mock-workflow-id" RunID = "0d00698f-08e1-4d36-a3e2-3bf109f5d2d6" WorkflowKey = definition.NewWorkflowKey(NamespaceID.String(), WorkflowID, RunID) + ArchetypeID = chasm.ArchetypeID(1234) LocalNamespaceEntry = namespace.NewLocalNamespaceForTest( &persistencespb.NamespaceInfo{Id: NamespaceID.String(), Name: Namespace.String()}, diff --git a/service/history/timer_queue_active_task_executor.go b/service/history/timer_queue_active_task_executor.go index c422a0ad763..cebead3c09b 100644 --- a/service/history/timer_queue_active_task_executor.go +++ b/service/history/timer_queue_active_task_executor.go @@ -753,6 +753,7 @@ func (t *timerQueueActiveTaskExecutor) executeWorkflowRunTimeoutTask( newExecutionInfo.WorkflowId, newExecutionState.RunId, ), + chasm.WorkflowArchetypeID, t.logger, t.shardContext.GetThrottledLogger(), t.shardContext.GetMetricsHandler(), diff --git a/service/history/timer_queue_active_task_executor_test.go b/service/history/timer_queue_active_task_executor_test.go index 192da847bea..33a0a46f2d7 100644 --- a/service/history/timer_queue_active_task_executor_test.go +++ b/service/history/timer_queue_active_task_executor_test.go @@ -1814,6 +1814,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestWorkflowExecutionTimeout_Fire() ShardID: s.mockShard.GetShardID(), NamespaceID: s.namespaceID.String(), WorkflowID: execution.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ StartRequestID: persistenceExecutionState.CreateRequestId, RunID: persistenceExecutionState.RunId, @@ -1877,6 +1878,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestWorkflowExecutionTimeout_Noop() ShardID: s.mockShard.GetShardID(), NamespaceID: s.namespaceID.String(), WorkflowID: execution.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ StartRequestID: persistenceExecutionState.CreateRequestId, RunID: persistenceExecutionState.RunId, @@ -2006,6 +2008,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestExecuteChasmSideEffectTimerTask_ Data: &commonpb.DataBlob{ EncodingType: enumspb.ENCODING_TYPE_PROTO3, }, + ArchetypeId: tests.ArchetypeID, }, } @@ -2014,7 +2017,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestExecuteChasmSideEffectTimerTask_ mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, gomock.Any(), execution, chasm.ArchetypeAny, locks.PriorityLow, + gomock.Any(), s.mockShard, gomock.Any(), execution, tests.ArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil) //nolint:revive // unchecked-type-assertion @@ -2073,6 +2076,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestExecuteChasmPureTimerTask_Execut ), VisibilityTimestamp: s.now, TaskID: s.mustGenerateTaskID(), + ArchetypeID: tests.ArchetypeID, } wfCtx := historyi.NewMockWorkflowContext(s.controller) @@ -2081,7 +2085,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestExecuteChasmPureTimerTask_Execut mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, gomock.Any(), execution, chasm.ArchetypeAny, locks.PriorityLow, + gomock.Any(), s.mockShard, gomock.Any(), execution, tests.ArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil) //nolint:revive // unchecked-type-assertion @@ -2190,7 +2194,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestExecuteStateMachineTimerTask_Exe mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetype, locks.PriorityLow, + gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil) task := &tasks.StateMachineTimerTask{ @@ -2240,6 +2244,7 @@ func (s *timerQueueActiveTaskExecutorSuite) getMutableStateFromCache( ) historyi.MutableState { key := wcache.Key{ WorkflowKey: workflowKey, + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), } return wcache.GetMutableState(s.workflowCache, key) @@ -2250,6 +2255,7 @@ func (s *timerQueueActiveTaskExecutorSuite) clearMutableStateFromCache( ) { wcache.ClearMutableState(s.workflowCache, wcache.Key{ WorkflowKey: workflowKey, + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: s.mockShard.GetOwner(), }) } diff --git a/service/history/timer_queue_standby_task_executor.go b/service/history/timer_queue_standby_task_executor.go index 9b5535262ae..b400f039dfc 100644 --- a/service/history/timer_queue_standby_task_executor.go +++ b/service/history/timer_queue_standby_task_executor.go @@ -162,7 +162,7 @@ func (t *timerQueueStandbyTaskExecutor) executeChasmPureTimerTask( task, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(task.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -191,8 +191,7 @@ func (t *timerQueueStandbyTaskExecutor) executeChasmSideEffectTimerTask( task, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(task.GetType()), - // TODO - replace this with a method for CHASM components - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -241,7 +240,7 @@ func (t *timerQueueStandbyTaskExecutor) executeUserTimerTimeoutTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -347,7 +346,7 @@ func (t *timerQueueStandbyTaskExecutor) executeActivityTimeoutTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -450,7 +449,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowTaskTimeoutTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -492,7 +491,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowBackoffTimerTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -527,7 +526,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowRunTimeoutTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -562,7 +561,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowExecutionTimeoutTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -626,7 +625,7 @@ func (t *timerQueueStandbyTaskExecutor) executeStateMachineTimerTask( timerTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(timerTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -744,7 +743,7 @@ func (t *timerQueueStandbyTaskExecutor) getCurrentTime() time.Time { return t.shardContext.GetCurrentTime(t.clusterName) } -func (t *timerQueueStandbyTaskExecutor) checkWorkflowStillExistOnSourceBeforeDiscard( +func (t *timerQueueStandbyTaskExecutor) checkExecutionStillExistsOnSourceBeforeDiscard( ctx context.Context, taskInfo tasks.Task, postActionInfo interface{}, @@ -753,7 +752,16 @@ func (t *timerQueueStandbyTaskExecutor) checkWorkflowStillExistOnSourceBeforeDis if postActionInfo == nil { return nil } - if !isWorkflowExistOnSource(ctx, taskWorkflowKey(taskInfo), logger, t.clusterName, t.clientBean, t.shardContext.GetNamespaceRegistry()) { + if !executionExistsOnSource( + ctx, + taskWorkflowKey(taskInfo), + getTaskArchetypeID(taskInfo), + logger, + t.clusterName, + t.clientBean, + t.shardContext.GetNamespaceRegistry(), + t.shardContext.ChasmRegistry(), + ) { return standbyTimerTaskPostActionTaskDiscarded(ctx, taskInfo, nil, logger) } return standbyTimerTaskPostActionTaskDiscarded(ctx, taskInfo, postActionInfo, logger) diff --git a/service/history/timer_queue_standby_task_executor_test.go b/service/history/timer_queue_standby_task_executor_test.go index 34d95d27b72..812fd385cc9 100644 --- a/service/history/timer_queue_standby_task_executor_test.go +++ b/service/history/timer_queue_standby_task_executor_test.go @@ -1309,6 +1309,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestProcessWorkflowExecutionTimeout ShardID: s.mockShard.GetShardID(), NamespaceID: s.namespaceID.String(), WorkflowID: execution.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ StartRequestID: persistenceExecutionState.CreateRequestId, RunID: persistenceExecutionState.RunId, @@ -1379,6 +1380,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestProcessWorkflowExecutionTimeout ShardID: s.mockShard.GetShardID(), NamespaceID: s.namespaceID.String(), WorkflowID: execution.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ StartRequestID: persistenceExecutionState.CreateRequestId, RunID: persistenceExecutionState.RunId, @@ -1792,7 +1794,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteStateMachineTimerTask_Ex mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetype, locks.PriorityLow, + gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil) task := &tasks.StateMachineTimerTask{ @@ -1900,7 +1902,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteStateMachineTimerTask_Va mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetype, locks.PriorityLow, + gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil) task := &tasks.StateMachineTimerTask{ @@ -2003,7 +2005,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteStateMachineTimerTask_St mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetype, locks.PriorityLow, + gomock.Any(), s.mockShard, tests.NamespaceID, we, chasm.WorkflowArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil) task := &tasks.StateMachineTimerTask{ @@ -2101,7 +2103,9 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteChasmSideEffectTimerTask ), VisibilityTimestamp: s.now, TaskID: s.mustGenerateTaskID(), - Info: &persistencespb.ChasmTaskInfo{}, + Info: &persistencespb.ChasmTaskInfo{ + ArchetypeId: tests.ArchetypeID, + }, } wfCtx := historyi.NewMockWorkflowContext(s.controller) @@ -2109,7 +2113,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteChasmSideEffectTimerTask mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, gomock.Any(), execution, chasm.ArchetypeAny, locks.PriorityLow, + gomock.Any(), s.mockShard, gomock.Any(), execution, tests.ArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil).AnyTimes() //nolint:revive // unchecked-type-assertion @@ -2181,6 +2185,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteChasmPureTimerTask_Valid ), VisibilityTimestamp: s.now, TaskID: s.mustGenerateTaskID(), + ArchetypeID: tests.ArchetypeID, } wfCtx := historyi.NewMockWorkflowContext(s.controller) @@ -2188,7 +2193,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestExecuteChasmPureTimerTask_Valid mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, gomock.Any(), execution, chasm.ArchetypeAny, locks.PriorityLow, + gomock.Any(), s.mockShard, gomock.Any(), execution, tests.ArchetypeID, locks.PriorityLow, ).Return(wfCtx, wcache.NoopReleaseFn, nil).AnyTimes() //nolint:revive // unchecked-type-assertion diff --git a/service/history/timer_queue_task_executor_base.go b/service/history/timer_queue_task_executor_base.go index 3e1b339215e..3afdec0843c 100644 --- a/service/history/timer_queue_task_executor_base.go +++ b/service/history/timer_queue_task_executor_base.go @@ -90,12 +90,16 @@ func (t *timerQueueTaskExecutorBase) executeDeleteHistoryEventTask( RunId: task.GetRunID(), } + if task.ArchetypeID == chasm.UnspecifiedArchetypeID { + task.ArchetypeID = chasm.WorkflowArchetypeID + } + weContext, release, err := t.cache.GetOrCreateChasmExecution( ctx, t.shardContext, namespace.ID(task.GetNamespaceID()), workflowExecution, - chasm.ArchetypeAny, // Retention time logic works on all Archetypes. + task.ArchetypeID, locks.PriorityLow, ) if err != nil { diff --git a/service/history/timer_queue_task_executor_base_test.go b/service/history/timer_queue_task_executor_base_test.go index 07fe2f30000..a312efeecdb 100644 --- a/service/history/timer_queue_task_executor_base_test.go +++ b/service/history/timer_queue_task_executor_base_test.go @@ -100,6 +100,7 @@ func (s *timerQueueTaskExecutorBaseSuite) Test_ExecuteDeleteHistoryEventTask_NoE Version: 123, TaskID: 12345, VisibilityTimestamp: time.Now().UTC(), + ArchetypeID: tests.ArchetypeID, } we := &commonpb.WorkflowExecution{ WorkflowId: tests.WorkflowID, @@ -109,7 +110,7 @@ func (s *timerQueueTaskExecutorBaseSuite) Test_ExecuteDeleteHistoryEventTask_NoE mockWeCtx := historyi.NewMockWorkflowContext(s.controller) mockMutableState := historyi.NewMockMutableState(s.controller) - s.mockCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), s.testShardContext, tests.NamespaceID, we, chasm.ArchetypeAny, locks.PriorityLow).Return(mockWeCtx, wcache.NoopReleaseFn, nil) + s.mockCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), s.testShardContext, tests.NamespaceID, we, tests.ArchetypeID, locks.PriorityLow).Return(mockWeCtx, wcache.NoopReleaseFn, nil) mockWeCtx.EXPECT().LoadMutableState(gomock.Any(), s.testShardContext).Return(mockMutableState, nil) mockMutableState.EXPECT().GetWorkflowKey().Return(task.WorkflowKey).AnyTimes() @@ -145,6 +146,7 @@ func (s *timerQueueTaskExecutorBaseSuite) TestArchiveHistory_DeleteFailed() { Version: 123, TaskID: 12345, VisibilityTimestamp: time.Now().UTC(), + ArchetypeID: tests.ArchetypeID, } we := &commonpb.WorkflowExecution{ WorkflowId: tests.WorkflowID, @@ -154,7 +156,7 @@ func (s *timerQueueTaskExecutorBaseSuite) TestArchiveHistory_DeleteFailed() { mockWeCtx := historyi.NewMockWorkflowContext(s.controller) mockMutableState := historyi.NewMockMutableState(s.controller) - s.mockCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), s.testShardContext, tests.NamespaceID, we, chasm.ArchetypeAny, locks.PriorityLow).Return(mockWeCtx, wcache.NoopReleaseFn, nil) + s.mockCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), s.testShardContext, tests.NamespaceID, we, tests.ArchetypeID, locks.PriorityLow).Return(mockWeCtx, wcache.NoopReleaseFn, nil) mockWeCtx.EXPECT().LoadMutableState(gomock.Any(), s.testShardContext).Return(mockMutableState, nil) mockMutableState.EXPECT().GetWorkflowKey().Return(task.WorkflowKey).AnyTimes() diff --git a/service/history/transfer_queue_active_task_executor.go b/service/history/transfer_queue_active_task_executor.go index c72299aa747..c24ad5918ce 100644 --- a/service/history/transfer_queue_active_task_executor.go +++ b/service/history/transfer_queue_active_task_executor.go @@ -470,6 +470,7 @@ func (t *transferQueueActiveTaskExecutor) processCloseExecution( err = t.deleteExecution( ctx, task, + chasm.WorkflowArchetypeID, false, &task.DeleteProcessStage, ) @@ -1121,7 +1122,7 @@ func (t *transferQueueActiveTaskExecutor) verifyChildWorkflow( t.shardContext, t.cache, wfKey, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ) if err != nil { @@ -1177,6 +1178,7 @@ func (t *transferQueueActiveTaskExecutor) processResetWorkflow( ShardID: t.shardContext.GetShardID(), NamespaceID: task.NamespaceID, WorkflowID: task.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }) if err != nil { return err @@ -1237,7 +1239,7 @@ func (t *transferQueueActiveTaskExecutor) processResetWorkflow( t.shardContext, t.cache, definition.NewWorkflowKey(task.NamespaceID, task.WorkflowID, resetPoint.GetRunId()), - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, locks.PriorityLow, ) if err != nil { diff --git a/service/history/transfer_queue_active_task_executor_test.go b/service/history/transfer_queue_active_task_executor_test.go index 6d94017c952..3e734b17390 100644 --- a/service/history/transfer_queue_active_task_executor_test.go +++ b/service/history/transfer_queue_active_task_executor_test.go @@ -338,6 +338,7 @@ func (s *transferQueueActiveTaskExecutorSuite) TestExecuteChasmSideEffectTransfe Data: &commonpb.DataBlob{ EncodingType: enumspb.ENCODING_TYPE_PROTO3, }, + ArchetypeId: tests.ArchetypeID, }, } @@ -346,7 +347,7 @@ func (s *transferQueueActiveTaskExecutorSuite) TestExecuteChasmSideEffectTransfe mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, gomock.Any(), execution, chasm.ArchetypeAny, gomock.Any(), + gomock.Any(), s.mockShard, gomock.Any(), execution, tests.ArchetypeID, gomock.Any(), ).Return(wfCtx, wcache.NoopReleaseFn, nil) //nolint:revive // unchecked-type-assertion @@ -2813,7 +2814,7 @@ func (s *transferQueueActiveTaskExecutorSuite) TestPendingCloseExecutionTasks() mockWorkflowCache := wcache.NewMockCache(ctrl) mockWorkflowCache.EXPECT().GetOrCreateChasmExecution(gomock.Any(), mockShard, gomock.Any(), gomock.Any(), - chasm.ArchetypeAny, gomock.Any(), + chasm.WorkflowArchetypeID, gomock.Any(), ).Return(mockWorkflowContext, historyi.ReleaseWorkflowContextFunc(func(err error) { }), nil) diff --git a/service/history/transfer_queue_standby_task_executor.go b/service/history/transfer_queue_standby_task_executor.go index 28da661178c..e84c5dfd474 100644 --- a/service/history/transfer_queue_standby_task_executor.go +++ b/service/history/transfer_queue_standby_task_executor.go @@ -144,8 +144,7 @@ func (t *transferQueueStandbyTaskExecutor) executeChasmSideEffectTransferTask( task, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(task.GetType()), - // TODO - replace this with a method for CHASM components - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -376,7 +375,7 @@ func (t *transferQueueStandbyTaskExecutor) processCancelExecution( transferTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(transferTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -409,7 +408,7 @@ func (t *transferQueueStandbyTaskExecutor) processSignalExecution( transferTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(transferTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -497,7 +496,7 @@ func (t *transferQueueStandbyTaskExecutor) processStartChildExecution( transferTask, t.getCurrentTime, t.config.StandbyTaskMissingEventsDiscardDelay(transferTask.GetType()), - t.checkWorkflowStillExistOnSourceBeforeDiscard, + t.checkExecutionStillExistsOnSourceBeforeDiscard, ), ) } @@ -619,7 +618,7 @@ func (e *verificationErr) Unwrap() error { return e.err } -func (t *transferQueueStandbyTaskExecutor) checkWorkflowStillExistOnSourceBeforeDiscard( +func (t *transferQueueStandbyTaskExecutor) checkExecutionStillExistsOnSourceBeforeDiscard( ctx context.Context, taskInfo tasks.Task, postActionInfo interface{}, @@ -628,7 +627,16 @@ func (t *transferQueueStandbyTaskExecutor) checkWorkflowStillExistOnSourceBefore if postActionInfo == nil { return nil } - if !isWorkflowExistOnSource(ctx, taskWorkflowKey(taskInfo), logger, t.clusterName, t.clientBean, t.shardContext.GetNamespaceRegistry()) { + if !executionExistsOnSource( + ctx, + taskWorkflowKey(taskInfo), + getTaskArchetypeID(taskInfo), + logger, + t.clusterName, + t.clientBean, + t.shardContext.GetNamespaceRegistry(), + t.shardContext.ChasmRegistry(), + ) { return standbyTransferTaskPostActionTaskDiscarded(ctx, taskInfo, nil, logger) } return standbyTransferTaskPostActionTaskDiscarded(ctx, taskInfo, postActionInfo, logger) @@ -648,7 +656,16 @@ func (t *transferQueueStandbyTaskExecutor) checkParentWorkflowStillExistOnSource return standbyTransferTaskPostActionTaskDiscarded(ctx, taskInfo, postActionInfo, logger) } - if !isWorkflowExistOnSource(ctx, *pushActivityInfo.parentWorkflowKey, logger, t.clusterName, t.clientBean, t.shardContext.GetNamespaceRegistry()) { + if !executionExistsOnSource( + ctx, + *pushActivityInfo.parentWorkflowKey, + getTaskArchetypeID(taskInfo), + logger, + t.clusterName, + t.clientBean, + t.shardContext.GetNamespaceRegistry(), + t.shardContext.ChasmRegistry(), + ) { return standbyTransferTaskPostActionTaskDiscarded(ctx, taskInfo, nil, logger) } return standbyTransferTaskPostActionTaskDiscarded(ctx, taskInfo, postActionInfo, logger) diff --git a/service/history/transfer_queue_standby_task_executor_test.go b/service/history/transfer_queue_standby_task_executor_test.go index 9051708990f..087e77a136a 100644 --- a/service/history/transfer_queue_standby_task_executor_test.go +++ b/service/history/transfer_queue_standby_task_executor_test.go @@ -320,7 +320,9 @@ func (s *transferQueueStandbyTaskExecutorSuite) TestExecuteChasmSideEffectTransf ), VisibilityTimestamp: s.now, TaskID: s.mustGenerateTaskID(), - Info: &persistencespb.ChasmTaskInfo{}, + Info: &persistencespb.ChasmTaskInfo{ + ArchetypeId: tests.ArchetypeID, + }, } wfCtx := historyi.NewMockWorkflowContext(s.controller) @@ -328,7 +330,7 @@ func (s *transferQueueStandbyTaskExecutorSuite) TestExecuteChasmSideEffectTransf mockCache := wcache.NewMockCache(s.controller) mockCache.EXPECT().GetOrCreateChasmExecution( - gomock.Any(), s.mockShard, gomock.Any(), execution, chasm.ArchetypeAny, gomock.Any(), + gomock.Any(), s.mockShard, gomock.Any(), execution, tests.ArchetypeID, gomock.Any(), ).Return(wfCtx, wcache.NoopReleaseFn, nil).AnyTimes() //nolint:revive // unchecked-type-assertion @@ -799,6 +801,7 @@ func (s *transferQueueStandbyTaskExecutorSuite) TestProcessCloseExecution() { Namespace: tests.ParentNamespace.String(), Execution: parentExecution, SkipForceReload: true, + Archetype: chasm.WorkflowArchetype, })).Return(nil, serviceerror.NewInternal("some error")).AnyTimes() persistenceMutableState := s.createPersistenceMutableState(mutableState, event.GetEventId(), event.GetVersion()) diff --git a/service/history/transfer_queue_task_executor_base.go b/service/history/transfer_queue_task_executor_base.go index db598c235a4..989b9d780a2 100644 --- a/service/history/transfer_queue_task_executor_base.go +++ b/service/history/transfer_queue_task_executor_base.go @@ -203,12 +203,16 @@ func (t *transferQueueTaskExecutorBase) processDeleteExecutionTask( task *tasks.DeleteExecutionTask, ensureNoPendingCloseTask bool, ) error { - return t.deleteExecution(ctx, task, ensureNoPendingCloseTask, &task.ProcessStage) + if task.ArchetypeID == chasm.UnspecifiedArchetypeID { + task.ArchetypeID = chasm.WorkflowArchetypeID + } + return t.deleteExecution(ctx, task, task.ArchetypeID, ensureNoPendingCloseTask, &task.ProcessStage) } func (t *transferQueueTaskExecutorBase) deleteExecution( ctx context.Context, task tasks.Task, + archetypeID chasm.ArchetypeID, ensureNoPendingCloseTask bool, stage *tasks.DeleteWorkflowExecutionStage, ) (retError error) { @@ -225,7 +229,7 @@ func (t *transferQueueTaskExecutorBase) deleteExecution( t.shardContext, namespace.ID(task.GetNamespaceID()), &workflowExecution, - chasm.ArchetypeAny, // deletion logic works for all Archetypes. + archetypeID, locks.PriorityLow, ) if err != nil { diff --git a/service/history/visibility_queue_task_executor_test.go b/service/history/visibility_queue_task_executor_test.go index 8cc57ae07f5..8dba9040b42 100644 --- a/service/history/visibility_queue_task_executor_test.go +++ b/service/history/visibility_queue_task_executor_test.go @@ -769,6 +769,9 @@ func (s *visibilityQueueTaskExecutorSuite) buildChasmVisTask( visTaskTypeID, ok := s.mockShard.ChasmRegistry().TaskIDFor(&persistencespb.ChasmVisibilityTaskData{}) s.True(ok) + archetypeID, ok := s.mockShard.ChasmRegistry().ComponentIDFor(&testComponent{}) + s.True(ok) + return &tasks.ChasmTask{ WorkflowKey: key, VisibilityTimestamp: time.Now().UTC(), @@ -783,6 +786,7 @@ func (s *visibilityQueueTaskExecutorSuite) buildChasmVisTask( Data: data, EncodingType: enumspb.ENCODING_TYPE_PROTO3, }, + ArchetypeId: archetypeID, }, } } diff --git a/service/history/workflow/cache/cache.go b/service/history/workflow/cache/cache.go index 9ef51a0ecc5..02bfa08d66b 100644 --- a/service/history/workflow/cache/cache.go +++ b/service/history/workflow/cache/cache.go @@ -29,12 +29,12 @@ import ( type ( Cache interface { - // TODO: rename this to GetOrCreateCurrentRun - GetOrCreateCurrentWorkflowExecution( + GetOrCreateCurrentExecution( ctx context.Context, shardContext historyi.ShardContext, namespaceID namespace.ID, workflowID string, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (historyi.ReleaseWorkflowContextFunc, error) @@ -51,7 +51,7 @@ type ( shardContext historyi.ShardContext, namespaceID namespace.ID, execution *commonpb.WorkflowExecution, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, error) } @@ -73,6 +73,7 @@ type ( // Those are exported because some unit tests uses the cache directly. // TODO: Update the unit tests and make those fields private. WorkflowKey definition.WorkflowKey + ArchetypeID chasm.ArchetypeID ShardUUID string } ) @@ -162,16 +163,17 @@ func (c *cacheImpl) GetOrCreateWorkflowExecution( shardContext, namespaceID, execution, - chasm.WorkflowArchetype, + chasm.WorkflowArchetypeID, lockPriority, ) } -func (c *cacheImpl) GetOrCreateCurrentWorkflowExecution( +func (c *cacheImpl) GetOrCreateCurrentExecution( ctx context.Context, shardContext historyi.ShardContext, namespaceID namespace.ID, workflowID string, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (historyi.ReleaseWorkflowContextFunc, error) { if err := c.validateWorkflowID(workflowID); err != nil { @@ -198,9 +200,7 @@ func (c *cacheImpl) GetOrCreateCurrentWorkflowExecution( shardContext, namespaceID, &execution, - // we don't care about the archetype for current entity. - // It's only for limiting the concurrency of loading the current runID. - chasm.ArchetypeAny, + archetypeID, handler, true, lockPriority, @@ -217,11 +217,11 @@ func (c *cacheImpl) GetOrCreateChasmExecution( shardContext historyi.ShardContext, namespaceID namespace.ID, execution *commonpb.WorkflowExecution, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, error) { - if err := c.validateWorkflowExecutionInfo(ctx, shardContext, namespaceID, execution, lockPriority); err != nil { + if err := c.validateWorkflowExecutionInfo(ctx, shardContext, namespaceID, execution, archetypeID, lockPriority); err != nil { return nil, nil, err } @@ -239,7 +239,7 @@ func (c *cacheImpl) GetOrCreateChasmExecution( shardContext, namespaceID, execution, - archetype, + archetypeID, handler, false, lockPriority, @@ -256,13 +256,14 @@ func (c *cacheImpl) getOrCreateWorkflowExecutionInternal( shardContext historyi.ShardContext, namespaceID namespace.ID, execution *commonpb.WorkflowExecution, - archetype chasm.Archetype, + archetypeID chasm.ArchetypeID, handler metrics.Handler, forceClearContext bool, lockPriority locks.Priority, ) (historyi.WorkflowContext, historyi.ReleaseWorkflowContextFunc, error) { cacheKey := Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), execution.GetWorkflowId(), execution.GetRunId()), + ArchetypeID: archetypeID, ShardUUID: shardContext.GetOwner(), } item, cacheHit := c.Get(cacheKey).(*cacheItem) @@ -274,6 +275,7 @@ func (c *cacheImpl) getOrCreateWorkflowExecutionInternal( workflowCtx = workflow.NewContext( shardContext.GetConfig(), cacheKey.WorkflowKey, + archetypeID, shardContext.GetLogger(), shardContext.GetThrottledLogger(), shardContext.GetMetricsHandler(), @@ -296,9 +298,6 @@ func (c *cacheImpl) getOrCreateWorkflowExecutionInternal( return nil, nil, err } - // Set the expected Archetype only AFTER the lock is acquired. - workflowCtx.SetArchetype(archetype) - // TODO This will create a closure on every request. // Consider revisiting this if it causes too much GC activity releaseFunc := c.makeReleaseFunc(cacheKey, shardContext, workflowCtx, forceClearContext, handler, time.Now()) @@ -391,6 +390,7 @@ func (c *cacheImpl) validateWorkflowExecutionInfo( shardContext historyi.ShardContext, namespaceID namespace.ID, execution *commonpb.WorkflowExecution, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) error { @@ -406,6 +406,7 @@ func (c *cacheImpl) validateWorkflowExecutionInfo( c, namespaceID.String(), execution.GetWorkflowId(), + archetypeID, lockPriority, ) if err != nil { @@ -434,13 +435,15 @@ func GetCurrentRunID( workflowCache Cache, namespaceID string, workflowID string, + archetypeID chasm.ArchetypeID, lockPriority locks.Priority, ) (runID string, retErr error) { - currentRelease, err := workflowCache.GetOrCreateCurrentWorkflowExecution( + currentRelease, err := workflowCache.GetOrCreateCurrentExecution( ctx, shardContext, namespace.ID(namespaceID), workflowID, + archetypeID, lockPriority, ) if err != nil { @@ -454,6 +457,7 @@ func GetCurrentRunID( ShardID: shardContext.GetShardID(), NamespaceID: namespaceID, WorkflowID: workflowID, + ArchetypeID: archetypeID, }, ) if err != nil { diff --git a/service/history/workflow/cache/cache_mock.go b/service/history/workflow/cache/cache_mock.go index 1f5957950b8..0bc25f10845 100644 --- a/service/history/workflow/cache/cache_mock.go +++ b/service/history/workflow/cache/cache_mock.go @@ -46,9 +46,9 @@ func (m *MockCache) EXPECT() *MockCacheMockRecorder { } // GetOrCreateChasmExecution mocks base method. -func (m *MockCache) GetOrCreateChasmExecution(ctx context.Context, shardContext interfaces.ShardContext, namespaceID namespace.ID, execution *common.WorkflowExecution, archetype chasm.Archetype, lockPriority locks.Priority) (interfaces.WorkflowContext, interfaces.ReleaseWorkflowContextFunc, error) { +func (m *MockCache) GetOrCreateChasmExecution(ctx context.Context, shardContext interfaces.ShardContext, namespaceID namespace.ID, execution *common.WorkflowExecution, archetypeID chasm.ArchetypeID, lockPriority locks.Priority) (interfaces.WorkflowContext, interfaces.ReleaseWorkflowContextFunc, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetOrCreateChasmExecution", ctx, shardContext, namespaceID, execution, archetype, lockPriority) + ret := m.ctrl.Call(m, "GetOrCreateChasmExecution", ctx, shardContext, namespaceID, execution, archetypeID, lockPriority) ret0, _ := ret[0].(interfaces.WorkflowContext) ret1, _ := ret[1].(interfaces.ReleaseWorkflowContextFunc) ret2, _ := ret[2].(error) @@ -56,24 +56,24 @@ func (m *MockCache) GetOrCreateChasmExecution(ctx context.Context, shardContext } // GetOrCreateChasmExecution indicates an expected call of GetOrCreateChasmExecution. -func (mr *MockCacheMockRecorder) GetOrCreateChasmExecution(ctx, shardContext, namespaceID, execution, archetype, lockPriority any) *gomock.Call { +func (mr *MockCacheMockRecorder) GetOrCreateChasmExecution(ctx, shardContext, namespaceID, execution, archetypeID, lockPriority any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrCreateChasmExecution", reflect.TypeOf((*MockCache)(nil).GetOrCreateChasmExecution), ctx, shardContext, namespaceID, execution, archetype, lockPriority) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrCreateChasmExecution", reflect.TypeOf((*MockCache)(nil).GetOrCreateChasmExecution), ctx, shardContext, namespaceID, execution, archetypeID, lockPriority) } -// GetOrCreateCurrentWorkflowExecution mocks base method. -func (m *MockCache) GetOrCreateCurrentWorkflowExecution(ctx context.Context, shardContext interfaces.ShardContext, namespaceID namespace.ID, workflowID string, lockPriority locks.Priority) (interfaces.ReleaseWorkflowContextFunc, error) { +// GetOrCreateCurrentExecution mocks base method. +func (m *MockCache) GetOrCreateCurrentExecution(ctx context.Context, shardContext interfaces.ShardContext, namespaceID namespace.ID, workflowID string, archetypeID chasm.ArchetypeID, lockPriority locks.Priority) (interfaces.ReleaseWorkflowContextFunc, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetOrCreateCurrentWorkflowExecution", ctx, shardContext, namespaceID, workflowID, lockPriority) + ret := m.ctrl.Call(m, "GetOrCreateCurrentExecution", ctx, shardContext, namespaceID, workflowID, archetypeID, lockPriority) ret0, _ := ret[0].(interfaces.ReleaseWorkflowContextFunc) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetOrCreateCurrentWorkflowExecution indicates an expected call of GetOrCreateCurrentWorkflowExecution. -func (mr *MockCacheMockRecorder) GetOrCreateCurrentWorkflowExecution(ctx, shardContext, namespaceID, workflowID, lockPriority any) *gomock.Call { +// GetOrCreateCurrentExecution indicates an expected call of GetOrCreateCurrentExecution. +func (mr *MockCacheMockRecorder) GetOrCreateCurrentExecution(ctx, shardContext, namespaceID, workflowID, archetypeID, lockPriority any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrCreateCurrentWorkflowExecution", reflect.TypeOf((*MockCache)(nil).GetOrCreateCurrentWorkflowExecution), ctx, shardContext, namespaceID, workflowID, lockPriority) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrCreateCurrentExecution", reflect.TypeOf((*MockCache)(nil).GetOrCreateCurrentExecution), ctx, shardContext, namespaceID, workflowID, archetypeID, lockPriority) } // GetOrCreateWorkflowExecution mocks base method. diff --git a/service/history/workflow/cache/cache_test.go b/service/history/workflow/cache/cache_test.go index becf38c3771..6a228c037e6 100644 --- a/service/history/workflow/cache/cache_test.go +++ b/service/history/workflow/cache/cache_test.go @@ -15,6 +15,7 @@ import ( "go.temporal.io/api/serviceerror" enumsspb "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/cache" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" @@ -411,11 +412,12 @@ func (s *workflowCacheSuite) TestHistoryCache_CacheLatencyMetricContext() { s.cache = NewHostLevelCache(s.mockShard.GetConfig(), s.mockShard.GetLogger(), metrics.NoopMetricsHandler) ctx := metrics.AddMetricsContext(context.Background()) - currentRelease, err := s.cache.GetOrCreateCurrentWorkflowExecution( + currentRelease, err := s.cache.GetOrCreateCurrentExecution( ctx, s.mockShard, tests.NamespaceID, tests.WorkflowID, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ) s.NoError(err) @@ -450,11 +452,12 @@ func (s *workflowCacheSuite) TestHistoryCache_CacheHoldTimeMetricContext() { s.mockShard.SetMetricsHandler(metricsHandler) s.cache = NewHostLevelCache(s.mockShard.GetConfig(), s.mockShard.GetLogger(), metricsHandler) - release1, err := s.cache.GetOrCreateCurrentWorkflowExecution( + release1, err := s.cache.GetOrCreateCurrentExecution( context.Background(), s.mockShard, tests.NamespaceID, tests.WorkflowID, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ) s.NoError(err) @@ -466,11 +469,12 @@ func (s *workflowCacheSuite) TestHistoryCache_CacheHoldTimeMetricContext() { }, 150*time.Millisecond, 100*time.Millisecond) capture = metricsHandler.StartCapture() - release2, err := s.cache.GetOrCreateCurrentWorkflowExecution( + release2, err := s.cache.GetOrCreateCurrentExecution( context.Background(), s.mockShard, tests.NamespaceID, tests.WorkflowID, + chasm.WorkflowArchetypeID, locks.PriorityHigh, ) s.NoError(err) @@ -535,9 +539,17 @@ func (s *workflowCacheSuite) TestCacheImpl_lockWorkflowExecution() { } cacheKey := Key{ WorkflowKey: definition.NewWorkflowKey(namespaceID.String(), execution.GetWorkflowId(), execution.GetRunId()), + ArchetypeID: chasm.WorkflowArchetypeID, ShardUUID: uuid.New(), } - workflowCtx := workflow.NewContext(s.mockShard.GetConfig(), cacheKey.WorkflowKey, s.mockShard.GetLogger(), s.mockShard.GetThrottledLogger(), s.mockShard.GetMetricsHandler()) + workflowCtx := workflow.NewContext( + s.mockShard.GetConfig(), + cacheKey.WorkflowKey, + chasm.WorkflowArchetypeID, + s.mockShard.GetLogger(), + s.mockShard.GetThrottledLogger(), + s.mockShard.GetMetricsHandler(), + ) ctx := headers.SetCallerType(context.Background(), tt.callerType) ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() @@ -819,6 +831,7 @@ func (s *workflowCacheSuite) TestCacheImpl_GetCurrentRunID_CurrentRunExists() { ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: execution.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(&persistence.GetCurrentExecutionResponse{ StartRequestID: uuid.New(), RunID: currentRunID, @@ -853,6 +866,7 @@ func (s *workflowCacheSuite) TestCacheImpl_GetCurrentRunID_NoCurrentRun() { ShardID: s.mockShard.GetShardID(), NamespaceID: namespaceID.String(), WorkflowID: execution.GetWorkflowId(), + ArchetypeID: chasm.WorkflowArchetypeID, }).Return(nil, serviceerror.NewNotFound("current worflow not found")).Times(1) ctx, release, err := s.cache.GetOrCreateWorkflowExecution( diff --git a/service/history/workflow/context.go b/service/history/workflow/context.go index eb44445a8d7..bf03019d7a9 100644 --- a/service/history/workflow/context.go +++ b/service/history/workflow/context.go @@ -2,6 +2,8 @@ package workflow import ( "context" + "runtime/debug" + "strconv" "go.opentelemetry.io/otel/trace" commonpb "go.temporal.io/api/common/v1" @@ -20,6 +22,7 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/common/softassert" "go.temporal.io/server/common/util" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" @@ -31,7 +34,7 @@ import ( type ( ContextImpl struct { workflowKey definition.WorkflowKey - archetype chasm.Archetype + archetypeID chasm.ArchetypeID logger log.Logger throttledLogger log.ThrottledLogger metricsHandler metrics.Handler @@ -48,6 +51,7 @@ var _ historyi.WorkflowContext = (*ContextImpl)(nil) func NewContext( config *configs.Config, workflowKey definition.WorkflowKey, + archetypeID chasm.ArchetypeID, logger log.Logger, throttledLogger log.ThrottledLogger, metricsHandler metrics.Handler, @@ -59,15 +63,23 @@ func NewContext( tag.WorkflowRunID(workflowKey.RunID), } } - return &ContextImpl{ + contextImpl := &ContextImpl{ workflowKey: workflowKey, - archetype: chasm.ArchetypeAny, + archetypeID: archetypeID, logger: log.NewLazyLogger(logger, tags), throttledLogger: log.NewLazyLogger(throttledLogger, tags), metricsHandler: metricsHandler.WithTags(metrics.OperationTag(metrics.WorkflowContextScope)), config: config, lock: locks.NewPrioritySemaphore(1), } + softassert.That( + contextImpl.throttledLogger, + contextImpl.archetypeID != chasm.UnspecifiedArchetypeID, + "Creating execution context with unspecified archetype ID", + tag.SysStackTrace(string(debug.Stack())), + ) + + return contextImpl } func (c *ContextImpl) Lock( @@ -115,10 +127,6 @@ func (c *ContextImpl) GetNamespace(shardContext historyi.ShardContext) namespace return namespaceEntry.Name() } -func (c *ContextImpl) SetArchetype(archetype chasm.Archetype) { - c.archetype = archetype -} - func (c *ContextImpl) LoadExecutionStats(ctx context.Context, shardContext historyi.ShardContext) (*persistencespb.ExecutionStats, error) { _, err := c.LoadMutableState(ctx, shardContext) if err != nil { @@ -141,6 +149,7 @@ func (c *ContextImpl) LoadMutableState(ctx context.Context, shardContext history NamespaceID: c.workflowKey.NamespaceID, WorkflowID: c.workflowKey.WorkflowID, RunID: c.workflowKey.RunID, + ArchetypeID: c.archetypeID, }) if err != nil { return nil, err @@ -166,25 +175,31 @@ func (c *ContextImpl) LoadMutableState(ctx context.Context, shardContext history c.MutableState = mutableState } - // TODO: Use archetype ID instead of name to do the comparsion - // after adding archetypeID to chasm tasks as well and chasm.ArchetypeAny is removed. - actualArchetype, err := c.MutableState.ChasmTree().Archetype() - if err != nil { - return nil, err - } + mutableStateArchetypeID := c.MutableState.ChasmTree().ArchetypeID() + if c.archetypeID != chasm.UnspecifiedArchetypeID && c.archetypeID != mutableStateArchetypeID { + chasmRegistry := shardContext.ChasmRegistry() + contextArchetype, ok := chasmRegistry.ComponentFqnByID(c.archetypeID) + if !ok { + contextArchetype = strconv.FormatUint(uint64(c.archetypeID), 10) + } + + mutableStateArchetype, ok := chasmRegistry.ComponentFqnByID(mutableStateArchetypeID) + if !ok { + mutableStateArchetype = strconv.FormatUint(uint64(mutableStateArchetypeID), 10) + } - if actualArchetype != "" && c.archetype != chasm.ArchetypeAny && c.archetype != actualArchetype { c.logger.Warn("Potential ID conflict across different archetypes", - tag.Archetype(c.archetype), - tag.NewStringTag("actual-archetype", actualArchetype), + tag.Archetype(contextArchetype), + tag.NewStringTag("mutable-state-archetype", mutableStateArchetype), ) return nil, serviceerror.NewNotFoundf( "CHASM Archetype missmatch for %v, expected: %s, actual: %s", c.workflowKey, - c.archetype, - actualArchetype, + contextArchetype, + mutableStateArchetype, ) } + c.archetypeID = mutableStateArchetypeID flushBeforeReady, err := c.MutableState.StartTransaction(namespaceEntry) if err != nil { @@ -244,6 +259,8 @@ func (c *ContextImpl) CreateWorkflowExecution( PreviousRunID: prevRunID, PreviousLastWriteVersion: prevLastWriteVersion, + ArchetypeID: c.archetypeID, + NewWorkflowSnapshot: *newWorkflow, NewWorkflowEvents: newWorkflowEvents, } @@ -362,6 +379,7 @@ func (c *ContextImpl) ConflictResolveWorkflowExecution( if _, _, _, err := NewTransaction(shardContext).ConflictResolveWorkflowExecution( ctx, conflictResolveMode, + c.archetypeID, resetMutableState.GetCurrentVersion(), resetWorkflow, resetWorkflowEventsSeq, @@ -579,6 +597,7 @@ func (c *ContextImpl) UpdateWorkflowExecutionWithNew( if _, _, err := NewTransaction(shardContext).UpdateWorkflowExecution( ctx, updateMode, + c.archetypeID, c.MutableState.GetCurrentVersion(), updateWorkflow, updateWorkflowEventsSeq, @@ -636,6 +655,7 @@ func (c *ContextImpl) SubmitClosedWorkflowSnapshot( return NewTransaction(shardContext).SetWorkflowExecution( ctx, + c.archetypeID, resetWorkflowSnapshot, ) } diff --git a/service/history/workflow/context_test.go b/service/history/workflow/context_test.go index a3d81a71119..963cd39c639 100644 --- a/service/history/workflow/context_test.go +++ b/service/history/workflow/context_test.go @@ -13,6 +13,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/definition" @@ -72,6 +73,7 @@ func (s *contextSuite) SetupTest() { s.workflowContext = NewContext( configs, tests.WorkflowKey, + chasm.WorkflowArchetypeID, log.NewNoopLogger(), log.NewNoopLogger(), metrics.NoopMetricsHandler, diff --git a/service/history/workflow/mutable_state_impl.go b/service/history/workflow/mutable_state_impl.go index bbead180e75..4de1e782886 100644 --- a/service/history/workflow/mutable_state_impl.go +++ b/service/history/workflow/mutable_state_impl.go @@ -890,8 +890,21 @@ func (ms *MutableStateImpl) SetHistoryTree( ) error { // NOTE: Unfortunately execution timeout and run timeout are not yet initialized into ms.executionInfo at this point. // TODO: Consider explicitly initializing mutable state with these timeout parameters instead of passing them in. - workflowKey := ms.GetWorkflowKey() + + archetypeID := ms.ChasmTree().ArchetypeID() + if archetypeID != chasm.WorkflowArchetypeID { + return softassert.UnexpectedInternalErr( + ms.logger, + "Backfilling history not supported for non-workflow archetype", + nil, + tag.ArchetypeID(archetypeID), + tag.WorkflowNamespaceID(workflowKey.NamespaceID), + tag.WorkflowID(workflowKey.WorkflowID), + tag.WorkflowRunID(workflowKey.RunID), + ) + } + var retentionDuration *durationpb.Duration if duration := ms.namespaceEntry.Retention(); duration > 0 { retentionDuration = durationpb.New(duration) @@ -900,6 +913,7 @@ func (ms *MutableStateImpl) SetHistoryTree( workflowKey.NamespaceID, workflowKey.WorkflowID, workflowKey.RunID, + archetypeID, treeID, nil, []*persistencespb.HistoryBranchRange{}, @@ -7216,6 +7230,12 @@ func (ms *MutableStateImpl) closeTransactionPrepareReplicationTasks( replicationTasks = append(replicationTasks, ms.syncActivityToReplicationTask(transactionPolicy)...) replicationTasks = append(replicationTasks, ms.dirtyHSMToReplicationTask(transactionPolicy, eventBatches, clearBufferEvents)...) + archetypeID := ms.ChasmTree().ArchetypeID() + isWorkflow := archetypeID == chasm.WorkflowArchetypeID + if !isWorkflow && len(replicationTasks) != 0 { + return softassert.UnexpectedInternalErr(ms.logger, "chasm execution generated workflow replication tasks", nil) + } + if ms.transitionHistoryEnabled { switch transactionPolicy { case historyi.TransactionPolicyActive: @@ -7258,6 +7278,7 @@ func (ms *MutableStateImpl) closeTransactionPrepareReplicationTasks( syncVersionedTransitionTask := &tasks.SyncVersionedTransitionTask{ WorkflowKey: workflowKey, VisibilityTimestamp: now, + ArchetypeID: archetypeID, Priority: enumsspb.TASK_PRIORITY_HIGH, VersionedTransition: currentVersionedTransition, FirstEventID: firstEventID, @@ -7282,11 +7303,13 @@ func (ms *MutableStateImpl) closeTransactionPrepareReplicationTasks( default: panic(fmt.Sprintf("unknown transaction policy: %v", transactionPolicy)) } - } else { + } else if isWorkflow { ms.InsertTasks[tasks.CategoryReplication] = append( ms.InsertTasks[tasks.CategoryReplication], replicationTasks..., ) + } else { + return softassert.UnexpectedInternalErr(ms.logger, "state-based replication not enabled for chasm execution", nil) } if transactionPolicy == historyi.TransactionPolicyPassive && diff --git a/service/history/workflow/mutable_state_impl_test.go b/service/history/workflow/mutable_state_impl_test.go index 9a8090e6e59..ca7075437c2 100644 --- a/service/history/workflow/mutable_state_impl_test.go +++ b/service/history/workflow/mutable_state_impl_test.go @@ -4254,6 +4254,7 @@ func (s *mutableStateSuite) TestCloseTransactionPrepareReplicationTasks_SyncVers } expectedTask := &tasks.SyncVersionedTransitionTask{ WorkflowKey: s.mutableState.GetWorkflowKey(), + ArchetypeID: chasm.WorkflowArchetypeID, VisibilityTimestamp: now, Priority: enumsspb.TASK_PRIORITY_HIGH, VersionedTransition: transitionHistory[0], @@ -4265,6 +4266,7 @@ func (s *mutableStateSuite) TestCloseTransactionPrepareReplicationTasks_SyncVers s.True(ok) s.Equal(expectedTask.WorkflowKey, actualTask.WorkflowKey) s.Equal(expectedTask.VersionedTransition, actualTask.VersionedTransition) + s.Equal(expectedTask.ArchetypeID, actualTask.ArchetypeID) s.Equal(3, len(actualTask.TaskEquivalents)) s.Equal(historyTasks[0], actualTask.TaskEquivalents[0]) s.Equal(historyTasks[1], actualTask.TaskEquivalents[1]) @@ -4802,7 +4804,7 @@ func (s *mutableStateSuite) TestCloseTransactionTrackTombstones_OnlyTrackFirstEm s.Equal(int64(1), tombstoneBatches[0].VersionedTransition.TransitionCount) } -func (s *mutableStateSuite) TestCloseTransactionGenerateCHASMRetentionTask() { +func (s *mutableStateSuite) TestCloseTransactionGenerateCHASMRetentionTask_Workflow() { dbState := s.buildWorkflowMutableState() mutableState, err := NewMutableStateFromDB(s.mockShard, s.mockEventsCache, s.logger, s.namespaceEntry, dbState, 123) @@ -4820,20 +4822,38 @@ func (s *mutableStateSuite) TestCloseTransactionGenerateCHASMRetentionTask() { // Is workflow, should not generate retention task mockChasmTree.EXPECT().IsStateDirty().Return(true).AnyTimes() - mockChasmTree.EXPECT().ArchetypeID().Return(chasm.WorkflowArchetypeID).Times(1) + mockChasmTree.EXPECT().ArchetypeID().Return(chasm.WorkflowArchetypeID).AnyTimes() mockChasmTree.EXPECT().CloseTransaction().Return(chasm.NodesMutation{}, nil).AnyTimes() mutation, _, err := mutableState.CloseTransactionAsMutation(historyi.TransactionPolicyActive) s.NoError(err) s.Empty(mutation.Tasks[tasks.CategoryTimer]) +} + +func (s *mutableStateSuite) TestCloseTransactionGenerateCHASMRetentionTask_NonWorkflow() { + dbState := s.buildWorkflowMutableState() + + mutableState, err := NewMutableStateFromDB(s.mockShard, s.mockEventsCache, s.logger, s.namespaceEntry, dbState, 123) + s.NoError(err) + + // First close transaction once to get rid of unrelated tasks like UserTimer and ActivityTimeout + _, err = mutableState.StartTransaction(s.namespaceEntry) + s.NoError(err) + _, _, err = mutableState.CloseTransactionAsMutation(historyi.TransactionPolicyActive) + s.NoError(err) + + // Switch to a mock CHASM tree + mockChasmTree := historyi.NewMockChasmTree(s.controller) + mutableState.chasmTree = mockChasmTree - // Now make the mutable state non-workflow. - mockChasmTree.EXPECT().ArchetypeID().Return(chasm.WorkflowArchetypeID + 101).Times(2) // One time for each CloseTransactionAsMutation call + mockChasmTree.EXPECT().IsStateDirty().Return(true).AnyTimes() + mockChasmTree.EXPECT().ArchetypeID().Return(chasm.WorkflowArchetypeID + 101).AnyTimes() + mockChasmTree.EXPECT().CloseTransaction().Return(chasm.NodesMutation{}, nil).AnyTimes() _, err = mutableState.UpdateWorkflowStateStatus( enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED, ) s.NoError(err) - mutation, _, err = mutableState.CloseTransactionAsMutation(historyi.TransactionPolicyActive) + mutation, _, err := mutableState.CloseTransactionAsMutation(historyi.TransactionPolicyActive) s.NoError(err) s.Len(mutation.Tasks[tasks.CategoryTimer], 1) s.Equal(enumsspb.TASK_TYPE_DELETE_HISTORY_EVENT, mutation.Tasks[tasks.CategoryTimer][0].GetType()) @@ -5813,7 +5833,6 @@ func (s *mutableStateSuite) TestAddTasks_CHASMPureTask() { for i := 0; i < totalTasks; i++ { task := &tasks.ChasmTaskPure{ VisibilityTimestamp: visTimestamp, - Category: tasks.CategoryTimer, } s.mutableState.AddTasks(task) s.LessOrEqual(len(s.mutableState.chasmPureTasks), s.mockConfig.ChasmMaxInMemoryPureTasks()) @@ -5824,7 +5843,6 @@ func (s *mutableStateSuite) TestAddTasks_CHASMPureTask() { s.mockConfig.ChasmMaxInMemoryPureTasks = dynamicconfig.GetIntPropertyFn(2) s.mutableState.AddTasks(&tasks.ChasmTaskPure{ VisibilityTimestamp: visTimestamp, - Category: tasks.CategoryTimer, }) s.Len(s.mutableState.chasmPureTasks, 2) } @@ -5859,15 +5877,12 @@ func (s *mutableStateSuite) TestDeleteCHASMPureTasks() { s.mutableState.chasmPureTasks = []*tasks.ChasmTaskPure{ { VisibilityTimestamp: now.Add(3 * time.Minute), - Category: tasks.CategoryTimer, }, { VisibilityTimestamp: now.Add(2 * time.Minute), - Category: tasks.CategoryTimer, }, { VisibilityTimestamp: now.Add(time.Minute), - Category: tasks.CategoryTimer, }, } s.mutableState.BestEffortDeleteTasks = make(map[tasks.Category][]tasks.Key) diff --git a/service/history/workflow/noop_chasm_tree.go b/service/history/workflow/noop_chasm_tree.go index 3265e43823c..cfbb3c45397 100644 --- a/service/history/workflow/noop_chasm_tree.go +++ b/service/history/workflow/noop_chasm_tree.go @@ -13,6 +13,8 @@ import ( var _ historyi.ChasmTree = (*noopChasmTree)(nil) +var NoopChasmTree = &noopChasmTree{} + type noopChasmTree struct{} func (*noopChasmTree) CloseTransaction() (chasm.NodesMutation, error) { diff --git a/service/history/workflow/task_generator.go b/service/history/workflow/task_generator.go index 86956096815..ec6b89eb35d 100644 --- a/service/history/workflow/task_generator.go +++ b/service/history/workflow/task_generator.go @@ -11,6 +11,7 @@ import ( "go.temporal.io/api/serviceerror" enumsspb "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/log" @@ -19,6 +20,7 @@ import ( "go.temporal.io/server/common/persistence/transitionhistory" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/common/softassert" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/hsm" historyi "go.temporal.io/server/service/history/interfaces" @@ -352,6 +354,7 @@ func (r *TaskGeneratorImpl) GenerateDeleteHistoryEventTask(closeTime time.Time) VisibilityTimestamp: deleteTime, Version: closeVersion, BranchToken: branchToken, + ArchetypeID: r.mutableState.ChasmTree().ArchetypeID(), }) return nil } @@ -360,6 +363,7 @@ func (r *TaskGeneratorImpl) GenerateDeleteExecutionTask() (*tasks.DeleteExecutio return &tasks.DeleteExecutionTask{ // TaskID, VisibilityTimestamp is set by shard WorkflowKey: r.mutableState.GetWorkflowKey(), + ArchetypeID: r.mutableState.ChasmTree().ArchetypeID(), }, nil } @@ -753,16 +757,21 @@ func (r *TaskGeneratorImpl) GenerateMigrationTasks(targetClusters []string) ([]t } now := time.Now().UTC() workflowKey := r.mutableState.GetWorkflowKey() + var taskEquivalents []tasks.Task + archetypeID := r.mutableState.ChasmTree().ArchetypeID() + isWorkflow := archetypeID == chasm.WorkflowArchetypeID if r.mutableState.GetExecutionState().State == enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED { - syncWorkflowStateTask := []tasks.Task{&tasks.SyncWorkflowStateTask{ - // TaskID, VisibilityTimestamp is set by shard - WorkflowKey: workflowKey, - Version: lastItem.GetVersion(), - Priority: enumsspb.TASK_PRIORITY_LOW, - TargetClusters: targetClusters, - IsForceReplication: true, - }} + if isWorkflow { + taskEquivalents = []tasks.Task{&tasks.SyncWorkflowStateTask{ + // TaskID, VisibilityTimestamp is set by shard + WorkflowKey: workflowKey, + Version: lastItem.GetVersion(), + Priority: enumsspb.TASK_PRIORITY_LOW, + TargetClusters: targetClusters, + IsForceReplication: true, + }} + } if r.mutableState.IsTransitionHistoryEnabled() && // even though current cluster may enabled state transition, but transition history can be cleared // by processing a replication task from a cluster that has state transition disabled @@ -771,45 +780,55 @@ func (r *TaskGeneratorImpl) GenerateMigrationTasks(targetClusters []string) ([]t transitionHistory := executionInfo.TransitionHistory return []tasks.Task{&tasks.SyncVersionedTransitionTask{ WorkflowKey: workflowKey, + ArchetypeID: archetypeID, Priority: enumsspb.TASK_PRIORITY_LOW, VersionedTransition: transitionhistory.LastVersionedTransition(transitionHistory), FirstEventID: executionInfo.LastFirstEventId, FirstEventVersion: lastItem.Version, NextEventID: lastItem.GetEventId() + 1, - TaskEquivalents: syncWorkflowStateTask, + TaskEquivalents: taskEquivalents, TargetClusters: targetClusters, IsForceReplication: true, }}, 1, nil } - return syncWorkflowStateTask, 1, nil + if !isWorkflow { + return nil, 0, softassert.UnexpectedInternalErr(r.logger, "state-based replication not enabled for chasm execution", nil, + tag.WorkflowNamespaceID(r.mutableState.GetExecutionInfo().GetNamespaceId()), + tag.WorkflowID(r.mutableState.GetExecutionInfo().GetWorkflowId()), + tag.WorkflowRunID(r.mutableState.GetExecutionState().GetRunId()), + ) + } + return taskEquivalents, 1, nil } - replicationTasks := make([]tasks.Task, 0, len(r.mutableState.GetPendingActivityInfos())+1) - replicationTasks = append(replicationTasks, &tasks.HistoryReplicationTask{ - // TaskID, VisibilityTimestamp is set by shard - WorkflowKey: workflowKey, - FirstEventID: executionInfo.LastFirstEventId, - NextEventID: lastItem.GetEventId() + 1, - Version: lastItem.GetVersion(), - TargetClusters: targetClusters, - }) - activityIDs := make(map[int64]struct{}, len(r.mutableState.GetPendingActivityInfos())) - for activityID := range r.mutableState.GetPendingActivityInfos() { - activityIDs[activityID] = struct{}{} - } - replicationTasks = append(replicationTasks, convertSyncActivityInfos( - now, - workflowKey, - r.mutableState.GetPendingActivityInfos(), - activityIDs, - targetClusters, - )...) - if r.config.EnableNexus() { - replicationTasks = append(replicationTasks, &tasks.SyncHSMTask{ - WorkflowKey: workflowKey, - // TaskID and VisibilityTimestamp are set by shard + if isWorkflow { + taskEquivalents = make([]tasks.Task, 0, len(r.mutableState.GetPendingActivityInfos())+1) + taskEquivalents = append(taskEquivalents, &tasks.HistoryReplicationTask{ + // TaskID, VisibilityTimestamp is set by shard + WorkflowKey: workflowKey, + FirstEventID: executionInfo.LastFirstEventId, + NextEventID: lastItem.GetEventId() + 1, + Version: lastItem.GetVersion(), TargetClusters: targetClusters, }) + activityIDs := make(map[int64]struct{}, len(r.mutableState.GetPendingActivityInfos())) + for activityID := range r.mutableState.GetPendingActivityInfos() { + activityIDs[activityID] = struct{}{} + } + taskEquivalents = append(taskEquivalents, convertSyncActivityInfos( + now, + workflowKey, + r.mutableState.GetPendingActivityInfos(), + activityIDs, + targetClusters, + )...) + if r.config.EnableNexus() { + taskEquivalents = append(taskEquivalents, &tasks.SyncHSMTask{ + WorkflowKey: workflowKey, + // TaskID and VisibilityTimestamp are set by shard + TargetClusters: targetClusters, + }) + } } if r.mutableState.IsTransitionHistoryEnabled() && @@ -820,17 +839,25 @@ func (r *TaskGeneratorImpl) GenerateMigrationTasks(targetClusters []string) ([]t transitionHistory := executionInfo.TransitionHistory return []tasks.Task{&tasks.SyncVersionedTransitionTask{ WorkflowKey: workflowKey, + ArchetypeID: archetypeID, Priority: enumsspb.TASK_PRIORITY_LOW, VersionedTransition: transitionhistory.LastVersionedTransition(transitionHistory), FirstEventID: executionInfo.LastFirstEventId, FirstEventVersion: lastItem.GetVersion(), NextEventID: lastItem.GetEventId() + 1, - TaskEquivalents: replicationTasks, + TaskEquivalents: taskEquivalents, TargetClusters: targetClusters, IsForceReplication: true, }}, 1, nil } - return replicationTasks, executionInfo.StateTransitionCount, nil + if !isWorkflow { + return nil, 0, softassert.UnexpectedInternalErr(r.logger, "state-based replication not enabled for chasm execution", nil, + tag.WorkflowNamespaceID(r.mutableState.GetExecutionInfo().GetNamespaceId()), + tag.WorkflowID(r.mutableState.GetExecutionInfo().GetWorkflowId()), + tag.WorkflowRunID(r.mutableState.GetExecutionState().GetRunId()), + ) + } + return taskEquivalents, executionInfo.StateTransitionCount, nil } func (r *TaskGeneratorImpl) getTimerSequence() TimerSequence { diff --git a/service/history/workflow/task_generator_test.go b/service/history/workflow/task_generator_test.go index dc28c6982bb..a9bb6d1efc0 100644 --- a/service/history/workflow/task_generator_test.go +++ b/service/history/workflow/task_generator_test.go @@ -13,6 +13,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/cluster" @@ -227,6 +228,7 @@ func TestTaskGeneratorImpl_GenerateWorkflowCloseTasks(t *testing.T) { namespaceEntry.ID().String(), tests.WorkflowID, tests.RunID, )).AnyTimes() mutableState.EXPECT().GetCurrentBranchToken().Return(nil, nil).AnyTimes() + mutableState.EXPECT().ChasmTree().Return(NoopChasmTree).AnyTimes() retentionTimerDelay := time.Second cfg := &configs.Config{ RetentionTimerJitterDuration: func() time.Duration { @@ -802,6 +804,7 @@ func TestTaskGeneratorImpl_GenerateMigrationTasks(t *testing.T) { State: tc.workflowState, }).AnyTimes() mockMutableState.EXPECT().IsTransitionHistoryEnabled().Return(tc.transitionHistoryEnabled).AnyTimes() + mockMutableState.EXPECT().ChasmTree().Return(NoopChasmTree).AnyTimes() mockShard := shard.NewTestContext( controller, &persistencespb.ShardInfo{ @@ -825,6 +828,7 @@ func TestTaskGeneratorImpl_GenerateMigrationTasks(t *testing.T) { require.Equal(t, tc.expectedTaskTypes[0].String(), resultTasks[0].GetType().String()) syncVersionTask, ok := resultTasks[0].(*tasks.SyncVersionedTransitionTask) require.True(t, ok) + require.Equal(t, chasm.WorkflowArchetypeID, syncVersionTask.GetArchetypeID()) taskEquivalent := syncVersionTask.TaskEquivalents require.Equal(t, len(tc.expectedTaskEquivalentTypes), len(taskEquivalent)) for i, equivalent := range taskEquivalent { diff --git a/service/history/workflow/transaction.go b/service/history/workflow/transaction.go index d32d0b60ba1..b65af5a2ba3 100644 --- a/service/history/workflow/transaction.go +++ b/service/history/workflow/transaction.go @@ -3,6 +3,7 @@ package workflow import ( "context" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/persistence" ) @@ -12,6 +13,7 @@ type ( CreateWorkflowExecution( ctx context.Context, createMode persistence.CreateWorkflowMode, + archetypeID chasm.ArchetypeID, newWorkflowFailoverVersion int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, @@ -21,6 +23,7 @@ type ( ConflictResolveWorkflowExecution( ctx context.Context, conflictResolveMode persistence.ConflictResolveWorkflowMode, + archetypeID chasm.ArchetypeID, resetWorkflowFailoverVersion int64, resetWorkflowSnapshot *persistence.WorkflowSnapshot, resetWorkflowEventsSeq []*persistence.WorkflowEvents, @@ -36,6 +39,7 @@ type ( UpdateWorkflowExecution( ctx context.Context, updateMode persistence.UpdateWorkflowMode, + archetypeID chasm.ArchetypeID, currentWorkflowFailoverVersion int64, currentWorkflowMutation *persistence.WorkflowMutation, currentWorkflowEventsSeq []*persistence.WorkflowEvents, @@ -47,6 +51,7 @@ type ( SetWorkflowExecution( ctx context.Context, + archetypeID chasm.ArchetypeID, workflowSnapshot *persistence.WorkflowSnapshot, ) error } diff --git a/service/history/workflow/transaction_impl.go b/service/history/workflow/transaction_impl.go index f9507a48527..6301e4a591d 100644 --- a/service/history/workflow/transaction_impl.go +++ b/service/history/workflow/transaction_impl.go @@ -6,6 +6,7 @@ import ( commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" "go.temporal.io/api/serviceerror" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -48,6 +49,7 @@ func NewTransaction( func (t *TransactionImpl) CreateWorkflowExecution( ctx context.Context, createMode persistence.CreateWorkflowMode, + archetypeID chasm.ArchetypeID, newWorkflowFailoverVersion int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, @@ -67,6 +69,7 @@ func (t *TransactionImpl) CreateWorkflowExecution( ShardID: t.shard.GetShardID(), // RangeID , this is set by shard context Mode: createMode, + ArchetypeID: archetypeID, NewWorkflowSnapshot: *newWorkflowSnapshot, NewWorkflowEvents: newWorkflowEventsSeq, }, @@ -89,6 +92,7 @@ func (t *TransactionImpl) CreateWorkflowExecution( func (t *TransactionImpl) ConflictResolveWorkflowExecution( ctx context.Context, conflictResolveMode persistence.ConflictResolveWorkflowMode, + archetypeID chasm.ArchetypeID, resetWorkflowFailoverVersion int64, resetWorkflowSnapshot *persistence.WorkflowSnapshot, resetWorkflowEventsSeq []*persistence.WorkflowEvents, @@ -116,6 +120,7 @@ func (t *TransactionImpl) ConflictResolveWorkflowExecution( ShardID: t.shard.GetShardID(), // RangeID , this is set by shard context Mode: conflictResolveMode, + ArchetypeID: archetypeID, ResetWorkflowSnapshot: *resetWorkflowSnapshot, ResetWorkflowEvents: resetWorkflowEventsSeq, NewWorkflowSnapshot: newWorkflowSnapshot, @@ -158,6 +163,7 @@ func (t *TransactionImpl) ConflictResolveWorkflowExecution( func (t *TransactionImpl) UpdateWorkflowExecution( ctx context.Context, updateMode persistence.UpdateWorkflowMode, + archetypeID chasm.ArchetypeID, currentWorkflowFailoverVersion int64, currentWorkflowMutation *persistence.WorkflowMutation, currentWorkflowEventsSeq []*persistence.WorkflowEvents, @@ -180,6 +186,7 @@ func (t *TransactionImpl) UpdateWorkflowExecution( ShardID: t.shard.GetShardID(), // RangeID , this is set by shard context Mode: updateMode, + ArchetypeID: archetypeID, UpdateWorkflowMutation: *currentWorkflowMutation, UpdateWorkflowEvents: currentWorkflowEventsSeq, NewWorkflowSnapshot: newWorkflowSnapshot, @@ -211,6 +218,7 @@ func (t *TransactionImpl) UpdateWorkflowExecution( func (t *TransactionImpl) SetWorkflowExecution( ctx context.Context, + archetypeID chasm.ArchetypeID, workflowSnapshot *persistence.WorkflowSnapshot, ) error { @@ -221,6 +229,7 @@ func (t *TransactionImpl) SetWorkflowExecution( _, err = setWorkflowExecution(ctx, t.shard, &persistence.SetWorkflowExecutionRequest{ ShardID: t.shard.GetShardID(), // RangeID , this is set by shard context + ArchetypeID: archetypeID, SetWorkflowSnapshot: *workflowSnapshot, }) if persistence.OperationPossiblySucceeded(err) { diff --git a/service/history/workflow/transaction_mock.go b/service/history/workflow/transaction_mock.go index 201d4fc1588..91786e787e4 100644 --- a/service/history/workflow/transaction_mock.go +++ b/service/history/workflow/transaction_mock.go @@ -13,6 +13,7 @@ import ( context "context" reflect "reflect" + chasm "go.temporal.io/server/chasm" persistence "go.temporal.io/server/common/persistence" gomock "go.uber.org/mock/gomock" ) @@ -42,9 +43,9 @@ func (m *MockTransaction) EXPECT() *MockTransactionMockRecorder { } // ConflictResolveWorkflowExecution mocks base method. -func (m *MockTransaction) ConflictResolveWorkflowExecution(ctx context.Context, conflictResolveMode persistence.ConflictResolveWorkflowMode, resetWorkflowFailoverVersion int64, resetWorkflowSnapshot *persistence.WorkflowSnapshot, resetWorkflowEventsSeq []*persistence.WorkflowEvents, newWorkflowFailoverVersion *int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, currentWorkflowFailoverVersion *int64, currentWorkflowMutation *persistence.WorkflowMutation, currentWorkflowEventsSeq []*persistence.WorkflowEvents, isWorkflow bool) (int64, int64, int64, error) { +func (m *MockTransaction) ConflictResolveWorkflowExecution(ctx context.Context, conflictResolveMode persistence.ConflictResolveWorkflowMode, archetypeID chasm.ArchetypeID, resetWorkflowFailoverVersion int64, resetWorkflowSnapshot *persistence.WorkflowSnapshot, resetWorkflowEventsSeq []*persistence.WorkflowEvents, newWorkflowFailoverVersion *int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, currentWorkflowFailoverVersion *int64, currentWorkflowMutation *persistence.WorkflowMutation, currentWorkflowEventsSeq []*persistence.WorkflowEvents, isWorkflow bool) (int64, int64, int64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConflictResolveWorkflowExecution", ctx, conflictResolveMode, resetWorkflowFailoverVersion, resetWorkflowSnapshot, resetWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, isWorkflow) + ret := m.ctrl.Call(m, "ConflictResolveWorkflowExecution", ctx, conflictResolveMode, archetypeID, resetWorkflowFailoverVersion, resetWorkflowSnapshot, resetWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, isWorkflow) ret0, _ := ret[0].(int64) ret1, _ := ret[1].(int64) ret2, _ := ret[2].(int64) @@ -53,44 +54,44 @@ func (m *MockTransaction) ConflictResolveWorkflowExecution(ctx context.Context, } // ConflictResolveWorkflowExecution indicates an expected call of ConflictResolveWorkflowExecution. -func (mr *MockTransactionMockRecorder) ConflictResolveWorkflowExecution(ctx, conflictResolveMode, resetWorkflowFailoverVersion, resetWorkflowSnapshot, resetWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, isWorkflow any) *gomock.Call { +func (mr *MockTransactionMockRecorder) ConflictResolveWorkflowExecution(ctx, conflictResolveMode, archetypeID, resetWorkflowFailoverVersion, resetWorkflowSnapshot, resetWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, isWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConflictResolveWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).ConflictResolveWorkflowExecution), ctx, conflictResolveMode, resetWorkflowFailoverVersion, resetWorkflowSnapshot, resetWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, isWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConflictResolveWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).ConflictResolveWorkflowExecution), ctx, conflictResolveMode, archetypeID, resetWorkflowFailoverVersion, resetWorkflowSnapshot, resetWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, isWorkflow) } // CreateWorkflowExecution mocks base method. -func (m *MockTransaction) CreateWorkflowExecution(ctx context.Context, createMode persistence.CreateWorkflowMode, newWorkflowFailoverVersion int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, isWorkflow bool) (int64, error) { +func (m *MockTransaction) CreateWorkflowExecution(ctx context.Context, createMode persistence.CreateWorkflowMode, archetypeID chasm.ArchetypeID, newWorkflowFailoverVersion int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, isWorkflow bool) (int64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateWorkflowExecution", ctx, createMode, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) + ret := m.ctrl.Call(m, "CreateWorkflowExecution", ctx, createMode, archetypeID, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) ret0, _ := ret[0].(int64) ret1, _ := ret[1].(error) return ret0, ret1 } // CreateWorkflowExecution indicates an expected call of CreateWorkflowExecution. -func (mr *MockTransactionMockRecorder) CreateWorkflowExecution(ctx, createMode, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow any) *gomock.Call { +func (mr *MockTransactionMockRecorder) CreateWorkflowExecution(ctx, createMode, archetypeID, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).CreateWorkflowExecution), ctx, createMode, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).CreateWorkflowExecution), ctx, createMode, archetypeID, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) } // SetWorkflowExecution mocks base method. -func (m *MockTransaction) SetWorkflowExecution(ctx context.Context, workflowSnapshot *persistence.WorkflowSnapshot) error { +func (m *MockTransaction) SetWorkflowExecution(ctx context.Context, archetypeID chasm.ArchetypeID, workflowSnapshot *persistence.WorkflowSnapshot) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetWorkflowExecution", ctx, workflowSnapshot) + ret := m.ctrl.Call(m, "SetWorkflowExecution", ctx, archetypeID, workflowSnapshot) ret0, _ := ret[0].(error) return ret0 } // SetWorkflowExecution indicates an expected call of SetWorkflowExecution. -func (mr *MockTransactionMockRecorder) SetWorkflowExecution(ctx, workflowSnapshot any) *gomock.Call { +func (mr *MockTransactionMockRecorder) SetWorkflowExecution(ctx, archetypeID, workflowSnapshot any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).SetWorkflowExecution), ctx, workflowSnapshot) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).SetWorkflowExecution), ctx, archetypeID, workflowSnapshot) } // UpdateWorkflowExecution mocks base method. -func (m *MockTransaction) UpdateWorkflowExecution(ctx context.Context, updateMode persistence.UpdateWorkflowMode, currentWorkflowFailoverVersion int64, currentWorkflowMutation *persistence.WorkflowMutation, currentWorkflowEventsSeq []*persistence.WorkflowEvents, newWorkflowFailoverVersion *int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, isWorkflow bool) (int64, int64, error) { +func (m *MockTransaction) UpdateWorkflowExecution(ctx context.Context, updateMode persistence.UpdateWorkflowMode, archetypeID chasm.ArchetypeID, currentWorkflowFailoverVersion int64, currentWorkflowMutation *persistence.WorkflowMutation, currentWorkflowEventsSeq []*persistence.WorkflowEvents, newWorkflowFailoverVersion *int64, newWorkflowSnapshot *persistence.WorkflowSnapshot, newWorkflowEventsSeq []*persistence.WorkflowEvents, isWorkflow bool) (int64, int64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateWorkflowExecution", ctx, updateMode, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) + ret := m.ctrl.Call(m, "UpdateWorkflowExecution", ctx, updateMode, archetypeID, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) ret0, _ := ret[0].(int64) ret1, _ := ret[1].(int64) ret2, _ := ret[2].(error) @@ -98,7 +99,7 @@ func (m *MockTransaction) UpdateWorkflowExecution(ctx context.Context, updateMod } // UpdateWorkflowExecution indicates an expected call of UpdateWorkflowExecution. -func (mr *MockTransactionMockRecorder) UpdateWorkflowExecution(ctx, updateMode, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow any) *gomock.Call { +func (mr *MockTransactionMockRecorder) UpdateWorkflowExecution(ctx, updateMode, archetypeID, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).UpdateWorkflowExecution), ctx, updateMode, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecution", reflect.TypeOf((*MockTransaction)(nil).UpdateWorkflowExecution), ctx, updateMode, archetypeID, currentWorkflowFailoverVersion, currentWorkflowMutation, currentWorkflowEventsSeq, newWorkflowFailoverVersion, newWorkflowSnapshot, newWorkflowEventsSeq, isWorkflow) } diff --git a/service/history/workflow/transaction_test.go b/service/history/workflow/transaction_test.go index 964f22100b9..a86f7cf71a0 100644 --- a/service/history/workflow/transaction_test.go +++ b/service/history/workflow/transaction_test.go @@ -12,6 +12,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/cluster/clustertest" "go.temporal.io/server/common/log" @@ -103,6 +104,7 @@ func (s *transactionSuite) TestCreateWorkflowExecution_NotifyTaskWhenFailed() { _, err := s.transaction.CreateWorkflowExecution( context.Background(), persistence.CreateWorkflowModeBrandNew, + chasm.WorkflowArchetypeID, 0, &persistence.WorkflowSnapshot{ ExecutionInfo: &persistencespb.WorkflowExecutionInfo{ @@ -130,6 +132,7 @@ func (s *transactionSuite) TestUpdateWorkflowExecution_NotifyTaskWhenFailed() { _, _, err := s.transaction.UpdateWorkflowExecution( context.Background(), persistence.UpdateWorkflowModeUpdateCurrent, + chasm.WorkflowArchetypeID, 0, &persistence.WorkflowMutation{ ExecutionInfo: &persistencespb.WorkflowExecutionInfo{ @@ -189,6 +192,7 @@ func (s *transactionSuite) TestUpdateWorkflowExecution_CompletionMetrics() { _, _, err := s.transaction.UpdateWorkflowExecution( context.Background(), tc.updateMode, + chasm.WorkflowArchetypeID, 0, &persistence.WorkflowMutation{ ExecutionInfo: &persistencespb.WorkflowExecutionInfo{ @@ -237,6 +241,7 @@ func (s *transactionSuite) TestConflictResolveWorkflowExecution_NotifyTaskWhenFa _, _, _, err := s.transaction.ConflictResolveWorkflowExecution( context.Background(), persistence.ConflictResolveWorkflowModeUpdateCurrent, + chasm.WorkflowArchetypeID, 0, &persistence.WorkflowSnapshot{ ExecutionInfo: &persistencespb.WorkflowExecutionInfo{ diff --git a/service/history/workflow_rebuilder.go b/service/history/workflow_rebuilder.go index 5fd81f9c5ad..e85aa4b1757 100644 --- a/service/history/workflow_rebuilder.go +++ b/service/history/workflow_rebuilder.go @@ -9,6 +9,7 @@ import ( commonpb "go.temporal.io/api/common/v1" "go.temporal.io/api/serviceerror" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/definition" "go.temporal.io/server/common/locks" "go.temporal.io/server/common/log" @@ -114,6 +115,7 @@ func (r *workflowRebuilderImpl) getRebuildSpecFromMutableState( ShardID: r.shard.GetShardID(), NamespaceID: workflowKey.NamespaceID, WorkflowID: workflowKey.WorkflowID, + ArchetypeID: chasm.WorkflowArchetypeID, }, ) if err != nil && resp == nil { @@ -128,6 +130,7 @@ func (r *workflowRebuilderImpl) getRebuildSpecFromMutableState( NamespaceID: workflowKey.NamespaceID, WorkflowID: workflowKey.WorkflowID, RunID: workflowKey.RunID, + ArchetypeID: chasm.WorkflowArchetypeID, }, ) if err != nil && resp == nil { @@ -198,6 +201,7 @@ func (r *workflowRebuilderImpl) overwriteToDB( return r.transaction.SetWorkflowExecution( ctx, + chasm.WorkflowArchetypeID, resetWorkflowSnapshot, ) } diff --git a/service/worker/migration/activities.go b/service/worker/migration/activities.go index 3f92c9f520b..18c9a38b99c 100644 --- a/service/worker/migration/activities.go +++ b/service/worker/migration/activities.go @@ -5,7 +5,9 @@ import ( "fmt" "math" "sort" + "strconv" "time" + "unicode" "github.com/pkg/errors" commonpb "go.temporal.io/api/common/v1" @@ -18,6 +20,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/api/historyservice/v1" replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" serverClient "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" @@ -26,22 +29,19 @@ import ( "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" + "go.temporal.io/server/common/payload" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/rpc/interceptor" + "go.temporal.io/server/common/searchattribute/sadefs" "google.golang.org/grpc/metadata" ) type ( - SkippedWorkflowExecution struct { - WorkflowExecution *commonpb.WorkflowExecution - Reason string - } - replicationTasksHeartbeatDetails struct { NextIndex int CheckPoint time.Time - LastNotVerifiedWorkflowExecution *commonpb.WorkflowExecution + LastNotVerifiedWorkflowExecution *replicationspb.MigrationExecutionInfo } verifyStatus int @@ -51,7 +51,7 @@ type ( } listWorkflowsResponse struct { - Executions []*commonpb.WorkflowExecution + Executions []*replicationspb.MigrationExecutionInfo NextPageToken []byte Error error @@ -66,7 +66,7 @@ type ( generateReplicationTasksRequest struct { NamespaceID string - Executions []*commonpb.WorkflowExecution + Executions []*replicationspb.MigrationExecutionInfo RPS float64 GetParentInfoRPS float64 TargetClusters []string @@ -78,7 +78,7 @@ type ( TargetClusterEndpoint string TargetClusterName string VerifyInterval time.Duration `validate:"gte=0"` - Executions []*commonpb.WorkflowExecution + Executions []*replicationspb.MigrationExecutionInfo } verifyReplicationTasksResponse struct { @@ -117,6 +117,7 @@ type ( generateMigrationTaskViaFrontend dynamicconfig.BoolPropertyFn enableHistoryRateLimiter dynamicconfig.BoolPropertyFn workflowVerifier WorkflowVerifier + chasmRegistry *chasm.Registry } WorkflowVerifier func( @@ -125,7 +126,7 @@ type ( remoteAdminClient adminservice.AdminServiceClient, localAdminClient adminservice.AdminServiceClient, ns *namespace.Namespace, - we *commonpb.WorkflowExecution, + execution *replicationspb.MigrationExecutionInfo, mu *adminservice.DescribeMutableStateResponse, ) (verifyResult, error) ) @@ -358,7 +359,7 @@ func (a *activities) generateWorkflowReplicationTask( rateLimiter quotas.RateLimiter, namespaceName string, namespaceID string, - we *commonpb.WorkflowExecution, + execution *replicationspb.MigrationExecutionInfo, targetClusters []string, generateViaFrontend bool, ) error { @@ -372,9 +373,27 @@ func (a *activities) generateWorkflowReplicationTask( var stateTransitionCount, historyLength int64 if generateViaFrontend { + archetype, ok := a.chasmRegistry.ComponentFqnByID(execution.ArchetypeId) + if !ok { + activityInfo := activity.GetInfo(ctx) + err := fmt.Errorf("unknown archetypeID: %v", execution.ArchetypeId) + a.logger.Error("force-replication failed to translate archetypeID to name", + tag.Error(err), + tag.ArchetypeID(execution.ArchetypeId), + tag.WorkflowNamespace(activityInfo.WorkflowNamespace), + tag.WorkflowID(activityInfo.WorkflowExecution.ID), + tag.WorkflowRunID(activityInfo.WorkflowExecution.RunID), + ) + return err + } + resp, err := a.adminClient.GenerateLastHistoryReplicationTasks(ctx, &adminservice.GenerateLastHistoryReplicationTasksRequest{ - Namespace: namespaceName, - Execution: we, + Namespace: namespaceName, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution.BusinessId, + RunId: execution.RunId, + }, + Archetype: archetype, TargetClusters: targetClusters, }) if err != nil { @@ -384,8 +403,12 @@ func (a *activities) generateWorkflowReplicationTask( historyLength = resp.HistoryLength } else { resp, err := a.historyClient.GenerateLastHistoryReplicationTasks(ctx, &historyservice.GenerateLastHistoryReplicationTasksRequest{ - NamespaceId: namespaceID, - Execution: we, + NamespaceId: namespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution.BusinessId, + RunId: execution.RunId, + }, + ArchetypeId: execution.ArchetypeId, TargetClusters: targetClusters, }) if err != nil { @@ -474,9 +497,39 @@ func (a *activities) ListWorkflows(ctx context.Context, request *workflowservice } var lastCloseTime, lastStartTime time.Time - executions := make([]*commonpb.WorkflowExecution, len(resp.Executions)) - for i, e := range resp.Executions { - executions[i] = e.Execution + executions := make([]*replicationspb.MigrationExecutionInfo, 0, len(resp.Executions)) + for _, e := range resp.Executions { + executionInfo := &replicationspb.MigrationExecutionInfo{ + BusinessId: e.Execution.GetWorkflowId(), + RunId: e.Execution.GetRunId(), + // Ideally we should use chasm.WorkflowArchetypeID by default, + // but for backward compatibility reason we need this field to be 0 + // to avoid unmarshaling errors since the previous type returned in + // ListWorkflowExecutions.Executions is commonpb.WorkflowExecution + // which does not have ArchetypeId field. + // + // TODO: switch to chasm.WorkflowArchetypeID in release 1.31.0 + ArchetypeId: chasm.UnspecifiedArchetypeID, + } + + if indexedField := e.SearchAttributes.GetIndexedFields(); indexedField != nil { + if nsDivisionPayload, ok := indexedField[sadefs.TemporalNamespaceDivision]; ok { + var nsDivisionStr string + if err := payload.Decode(nsDivisionPayload, &nsDivisionStr); err != nil { + return nil, fmt.Errorf("failed to decode TemporalNamespaceDivision field: %w", err) + } + + if len(nsDivisionStr) != 0 && unicode.IsDigit(rune(nsDivisionStr[0])) { + archetypeID, err := strconv.ParseUint(nsDivisionStr, 10, 32) + if err != nil { + return nil, fmt.Errorf("failed to parse archetypeID: %w", err) + } + executionInfo.ArchetypeId = chasm.ArchetypeID(archetypeID) + } + } + } + + executions = append(executions, executionInfo) if e.CloseTime != nil { lastCloseTime = e.CloseTime.AsTime() @@ -486,7 +539,12 @@ func (a *activities) ListWorkflows(ctx context.Context, request *workflowservice lastStartTime = e.StartTime.AsTime() } } - return &listWorkflowsResponse{Executions: executions, NextPageToken: resp.NextPageToken, LastCloseTime: lastCloseTime, LastStartTime: lastStartTime}, nil + return &listWorkflowsResponse{ + Executions: executions, + NextPageToken: resp.NextPageToken, + LastCloseTime: lastCloseTime, + LastStartTime: lastStartTime, + }, nil } func (a *activities) CountWorkflow(ctx context.Context, request *workflowservice.CountWorkflowExecutionsRequest) (*countWorkflowResponse, error) { @@ -540,7 +598,7 @@ func (a *activities) GenerateReplicationTasks(ctx context.Context, request *gene if !common.IsNotFoundError(err) { a.logger.Error("force-replication failed to generate replication task", tag.WorkflowNamespaceID(request.NamespaceID), - tag.WorkflowID(we.GetWorkflowId()), + tag.WorkflowID(we.GetBusinessId()), tag.WorkflowRunID(we.GetRunId()), tag.Error(err)) return err @@ -548,7 +606,7 @@ func (a *activities) GenerateReplicationTasks(ctx context.Context, request *gene a.logger.Warn("force-replication ignore replication task due to NotFoundServiceError", tag.WorkflowNamespaceID(request.NamespaceID), - tag.WorkflowID(we.GetWorkflowId()), + tag.WorkflowID(we.GetBusinessId()), tag.WorkflowRunID(we.GetRunId()), tag.Error(err)) } @@ -653,14 +711,18 @@ func (a *activities) SeedReplicationQueueWithUserDataEntries(ctx context.Context func (a *activities) checkSkipWorkflowExecution( ctx context.Context, request *verifyReplicationTasksRequest, - we *commonpb.WorkflowExecution, + execution *replicationspb.MigrationExecutionInfo, ns *namespace.Namespace, ) (verifyResult, error) { namespaceID := request.NamespaceID - tags := []tag.Tag{tag.WorkflowNamespaceID(namespaceID), tag.WorkflowID(we.WorkflowId), tag.WorkflowRunID(we.RunId)} + tags := []tag.Tag{tag.WorkflowNamespaceID(namespaceID), tag.WorkflowID(execution.BusinessId), tag.WorkflowRunID(execution.RunId)} resp, err := a.historyClient.DescribeMutableState(ctx, &historyservice.DescribeMutableStateRequest{ - NamespaceId: namespaceID, - Execution: we, + NamespaceId: namespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution.BusinessId, + RunId: execution.RunId, + }, + ArchetypeId: execution.ArchetypeId, SkipForceReload: true, }) @@ -713,20 +775,41 @@ func (a *activities) verifySingleReplicationTask( request *verifyReplicationTasksRequest, remotAdminClient adminservice.AdminServiceClient, ns *namespace.Namespace, - we *commonpb.WorkflowExecution, + execution *replicationspb.MigrationExecutionInfo, ) (verifyResult, error) { s := time.Now() // Check if execution exists on remote cluster + + archetype, ok := a.chasmRegistry.ComponentFqnByID(execution.ArchetypeId) + if !ok { + activityInfo := activity.GetInfo(ctx) + err := fmt.Errorf("unknown archetypeID: %v", execution.ArchetypeId) + a.logger.Error("force-replication failed to translate archetypeID to name", + tag.Error(err), + tag.ArchetypeID(execution.ArchetypeId), + tag.WorkflowNamespace(activityInfo.WorkflowNamespace), + tag.WorkflowID(activityInfo.WorkflowExecution.ID), + tag.WorkflowRunID(activityInfo.WorkflowExecution.RunID), + ) + return verifyResult{ + status: notVerified, + }, err + } + mu, err := remotAdminClient.DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ - Namespace: request.Namespace, - Execution: we, + Namespace: request.Namespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution.BusinessId, + RunId: execution.RunId, + }, + Archetype: archetype, SkipForceReload: true, }) a.forceReplicationMetricsHandler.Timer(metrics.VerifyDescribeMutableStateLatency.Name()).Record(time.Since(s)) switch err.(type) { case nil: - result, err := a.workflowVerifier(ctx, request, remotAdminClient, a.adminClient, ns, we, mu) + result, err := a.workflowVerifier(ctx, request, remotAdminClient, a.adminClient, ns, execution, mu) if err == nil && result.status == verified { a.forceReplicationMetricsHandler.WithTags(metrics.NamespaceTag(request.Namespace)).Counter(metrics.VerifyReplicationTaskSuccess.Name()).Record(1) } @@ -736,7 +819,7 @@ func (a *activities) verifySingleReplicationTask( a.forceReplicationMetricsHandler.WithTags(metrics.NamespaceTag(request.Namespace)).Counter(metrics.VerifyReplicationTaskNotFound.Name()).Record(1) // Calling checkSkipWorkflowExecution for every NotFound is sub-optimal as most common case to skip is workflow being deleted due to retention. // A better solution is to only check the existence for workflow which is close to retention period. - return a.checkSkipWorkflowExecution(ctx, request, we, ns) + return a.checkSkipWorkflowExecution(ctx, request, execution, ns) case *serviceerror.NamespaceNotFound: return verifyResult{ diff --git a/service/worker/migration/activities_test.go b/service/worker/migration/activities_test.go index 35f6d742e31..f449599c231 100644 --- a/service/worker/migration/activities_test.go +++ b/service/worker/migration/activities_test.go @@ -5,11 +5,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commonpb "go.temporal.io/api/common/v1" replicationpb "go.temporal.io/api/replication/v1" "go.temporal.io/api/serviceerror" "go.temporal.io/api/workflowservice/v1" + "go.temporal.io/sdk/converter" "go.temporal.io/sdk/interceptor" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/worker" @@ -19,6 +21,9 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/api/historyservicemock/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" + chasmworkflow "go.temporal.io/server/chasm/lib/workflow" "go.temporal.io/server/client" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" @@ -35,6 +40,7 @@ import ( type activitiesSuite struct { suite.Suite + *require.Assertions protoassert.ProtoAssertions testsuite.WorkflowTestSuite @@ -63,14 +69,16 @@ const ( ) var ( - execution1 = &commonpb.WorkflowExecution{ - WorkflowId: "workflow1", - RunId: "run1", + execution1 = &replicationspb.MigrationExecutionInfo{ + BusinessId: "workflow1", + RunId: "run1", + ArchetypeId: chasm.WorkflowArchetypeID, } - execution2 = &commonpb.WorkflowExecution{ - WorkflowId: "workflow2", - RunId: "run2", + execution2 = &replicationspb.MigrationExecutionInfo{ + BusinessId: "workflow2", + RunId: "run2", + ArchetypeId: chasm.WorkflowArchetypeID, } completeState = &historyservice.DescribeMutableStateResponse{ @@ -97,6 +105,7 @@ func TestActivitiesSuite(t *testing.T) { } func (s *activitiesSuite) SetupTest() { + s.Assertions = require.New(s.T()) s.ProtoAssertions = protoassert.New(s.T()) s.controller = gomock.NewController(s.T()) s.mockTaskManager = persistence.NewMockTaskManager(s.controller) @@ -120,6 +129,10 @@ func (s *activitiesSuite) SetupTest() { s.mockNamespaceRegistry.EXPECT().GetNamespace(gomock.Any()). Return(&testNamespace, nil).AnyTimes() + chasmRegistry := chasm.NewRegistry(s.logger) + err := chasmRegistry.Register(chasmworkflow.NewLibrary()) + s.NoError(err) + s.a = &activities{ namespaceRegistry: s.mockNamespaceRegistry, namespaceReplicationQueue: s.mockNamespaceReplicationQueue, @@ -129,12 +142,13 @@ func (s *activitiesSuite) SetupTest() { frontendClient: s.mockFrontendClient, adminClient: s.mockAdminClient, historyClient: s.mockHistoryClient, - logger: log.NewCLILogger(), + logger: s.logger, metricsHandler: s.mockMetricsHandler, forceReplicationMetricsHandler: s.mockMetricsHandler, generateMigrationTaskViaFrontend: dynamicconfig.GetBoolPropertyFn(false), enableHistoryRateLimiter: dynamicconfig.GetBoolPropertyFn(false), workflowVerifier: workflowVerifierProvider(), + chasmRegistry: chasmRegistry, } } @@ -158,13 +172,17 @@ func (s *activitiesSuite) TestVerifyReplicationTasks_Success() { Namespace: mockedNamespace, NamespaceID: mockedNamespaceID, TargetClusterName: remoteCluster, - Executions: []*commonpb.WorkflowExecution{execution1, execution2}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1, execution2}, } // Immediately replicated s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(&adminservice.DescribeMutableStateResponse{}, nil).Times(1) @@ -180,15 +198,23 @@ func (s *activitiesSuite) TestVerifyReplicationTasks_Success() { for _, r := range replicationSlowReponses { s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution2, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution2.BusinessId, + RunId: execution2.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(r.resp, r.err).Times(1) } s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution2, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution2.BusinessId, + RunId: execution2.RunId, + }, + ArchetypeId: execution2.ArchetypeId, SkipForceReload: true, })).Return(completeState, nil).Times(2) @@ -235,21 +261,29 @@ func (s *activitiesSuite) TestVerifyReplicationTasks_SkipWorkflowExecution() { Namespace: mockedNamespace, NamespaceID: mockedNamespaceID, TargetClusterName: remoteCluster, - Executions: []*commonpb.WorkflowExecution{execution1}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1}, } start := time.Now() for _, t := range testcases { env, iceptor := s.initEnv() s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(nil, serviceerror.NewNotFound("")).Times(1) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution1, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + ArchetypeId: execution1.ArchetypeId, SkipForceReload: true, })).Return(t.resp, t.err).Times(1) @@ -275,19 +309,27 @@ func (s *activitiesSuite) TestVerifyReplicationTasks_FailedNotFound() { Namespace: mockedNamespace, NamespaceID: mockedNamespaceID, TargetClusterName: remoteCluster, - Executions: []*commonpb.WorkflowExecution{execution1}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1}, } s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution1, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + ArchetypeId: execution1.ArchetypeId, SkipForceReload: true, })).Return(completeState, nil) // Workflow not found at target cluster. s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(nil, serviceerror.NewNotFound("")).AnyTimes() @@ -304,7 +346,7 @@ func (s *activitiesSuite) TestVerifyReplicationTasks_FailedNotFound() { s.Greater(len(iceptor.replicationRecordedHeartbeats), 0) lastHeartBeat := iceptor.replicationRecordedHeartbeats[len(iceptor.replicationRecordedHeartbeats)-1] s.Equal(0, lastHeartBeat.NextIndex) - s.Equal(execution1, lastHeartBeat.LastNotVerifiedWorkflowExecution) + s.ProtoEqual(execution1, lastHeartBeat.LastNotVerifiedWorkflowExecution) } func (s *activitiesSuite) TestVerifyReplicationTasks_AlreadyVerified() { @@ -313,7 +355,7 @@ func (s *activitiesSuite) TestVerifyReplicationTasks_AlreadyVerified() { Namespace: mockedNamespace, NamespaceID: mockedNamespaceID, TargetClusterName: remoteCluster, - Executions: []*commonpb.WorkflowExecution{execution1, execution2}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1, execution2}, } // Set NextIndex to indicate all executions have been verified. No additional mock is needed. @@ -333,13 +375,17 @@ func (s *activitiesSuite) Test_verifySingleReplicationTask() { Namespace: mockedNamespace, NamespaceID: mockedNamespaceID, TargetClusterName: remoteCluster, - Executions: []*commonpb.WorkflowExecution{execution1, execution2}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1, execution2}, } ctx := context.TODO() s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(&adminservice.DescribeMutableStateResponse{}, nil).Times(1) result, err := s.a.verifySingleReplicationTask(ctx, &request, s.mockRemoteAdminClient, &testNamespace, request.Executions[0]) @@ -348,14 +394,22 @@ func (s *activitiesSuite) Test_verifySingleReplicationTask() { // Test not verified workflow s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution2, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution2.BusinessId, + RunId: execution2.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(&adminservice.DescribeMutableStateResponse{}, serviceerror.NewNotFound("")).Times(1) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution2, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution2.BusinessId, + RunId: execution2.RunId, + }, + ArchetypeId: execution2.ArchetypeId, SkipForceReload: true, })).Return(completeState, nil).AnyTimes() @@ -372,8 +426,12 @@ const ( executionErr executionState = 2 ) -func createExecutions(mockAdminCliednt *adminservicemock.MockAdminServiceClient, states []executionState, nextIndex int) []*commonpb.WorkflowExecution { - var executions []*commonpb.WorkflowExecution +func createExecutions( + mockAdminCliednt *adminservicemock.MockAdminServiceClient, + states []executionState, + nextIndex int, +) []*replicationspb.MigrationExecutionInfo { + var executions []*replicationspb.MigrationExecutionInfo for i := 0; i < len(states); i++ { executions = append(executions, execution1) @@ -384,21 +442,33 @@ Loop: switch states[i] { case executionFound: mockAdminCliednt.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(&adminservice.DescribeMutableStateResponse{}, nil).Times(1) case executionNotfound: mockAdminCliednt.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(nil, serviceerror.NewNotFound("")).Times(1) break Loop case executionErr: mockAdminCliednt.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(nil, serviceerror.NewInternal("")).Times(1) } @@ -466,8 +536,12 @@ func (s *activitiesSuite) Test_verifyReplicationTasks() { } s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution1, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + ArchetypeId: execution1.ArchetypeId, SkipForceReload: true, })).Return(completeState, nil).AnyTimes() @@ -511,8 +585,12 @@ func (s *activitiesSuite) Test_verifyReplicationTasksNoProgress() { } s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution1, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + ArchetypeId: execution1.ArchetypeId, SkipForceReload: true, })).Return(completeState, nil).AnyTimes() @@ -534,8 +612,12 @@ func (s *activitiesSuite) Test_verifyReplicationTasksNoProgress() { // Mock for one more NotFound call s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(nil, serviceerror.NewNotFound("")).Times(1) @@ -551,7 +633,7 @@ func (s *activitiesSuite) Test_verifyReplicationTasksSkipRetention() { Namespace: mockedNamespace, NamespaceID: mockedNamespaceID, TargetClusterName: remoteCluster, - Executions: []*commonpb.WorkflowExecution{execution1}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1}, } var tests = []struct { @@ -575,14 +657,22 @@ func (s *activitiesSuite) Test_verifyReplicationTasksSkipRetention() { closeTime := deleteTime.Add(-retention) s.mockRemoteAdminClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&adminservice.DescribeMutableStateRequest{ - Namespace: mockedNamespace, - Execution: execution1, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + Archetype: chasm.WorkflowArchetype, SkipForceReload: true, })).Return(nil, serviceerror.NewNotFound("")).Times(1) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ - NamespaceId: mockedNamespaceID, - Execution: execution1, + NamespaceId: mockedNamespaceID, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + ArchetypeId: execution1.ArchetypeId, SkipForceReload: true, })).Return(&historyservice.DescribeMutableStateResponse{ DatabaseMutableState: &persistencespb.WorkflowMutableState{ @@ -619,14 +709,18 @@ func (s *activitiesSuite) TestGenerateReplicationTasks_Success() { NamespaceID: mockedNamespaceID, RPS: 10, GetParentInfoRPS: 10, - Executions: []*commonpb.WorkflowExecution{execution1, execution2}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1, execution2}, } for i := 0; i < len(request.Executions); i++ { - we := request.Executions[i] + execution := request.Executions[i] s.mockHistoryClient.EXPECT().GenerateLastHistoryReplicationTasks(gomock.Any(), protomock.Eq(&historyservice.GenerateLastHistoryReplicationTasksRequest{ NamespaceId: mockedNamespaceID, - Execution: we, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution.BusinessId, + RunId: execution.RunId, + }, + ArchetypeId: execution.ArchetypeId, })).Return(&historyservice.GenerateLastHistoryReplicationTasksResponse{}, nil).Times(1) } @@ -646,17 +740,25 @@ func (s *activitiesSuite) TestGenerateReplicationTasks_Failed() { NamespaceID: mockedNamespaceID, RPS: 10, GetParentInfoRPS: 10, - Executions: []*commonpb.WorkflowExecution{execution1, execution2}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1, execution2}, } s.mockHistoryClient.EXPECT().GenerateLastHistoryReplicationTasks(gomock.Any(), protomock.Eq(&historyservice.GenerateLastHistoryReplicationTasksRequest{ NamespaceId: mockedNamespaceID, - Execution: execution1, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + }, + ArchetypeId: execution1.ArchetypeId, })).Return(&historyservice.GenerateLastHistoryReplicationTasksResponse{}, nil).Times(1) s.mockHistoryClient.EXPECT().GenerateLastHistoryReplicationTasks(gomock.Any(), protomock.Eq(&historyservice.GenerateLastHistoryReplicationTasksRequest{ NamespaceId: mockedNamespaceID, - Execution: execution2, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution2.BusinessId, + RunId: execution2.RunId, + }, + ArchetypeId: execution2.ArchetypeId, })).Return(nil, serviceerror.NewInternal("")).Times(1) _, err := env.ExecuteActivity(s.a.GenerateReplicationTasks, &request) @@ -677,17 +779,20 @@ func (s *activitiesSuite) TestGenerateReplicationTasks_Success_ViaFrontend() { NamespaceID: mockedNamespaceID, RPS: 10, GetParentInfoRPS: 10, - Executions: []*commonpb.WorkflowExecution{execution1, execution2}, + Executions: []*replicationspb.MigrationExecutionInfo{execution1, execution2}, TargetClusters: []string{remoteCluster}, } // Test startIndex logic, and it should be 1 when running the activity. env.SetHeartbeatDetails(0) - we := request.Executions[1] s.mockAdminClient.EXPECT().GenerateLastHistoryReplicationTasks(gomock.Any(), protomock.Eq(&adminservice.GenerateLastHistoryReplicationTasksRequest{ - Namespace: mockedNamespace, - Execution: we, + Namespace: mockedNamespace, + Execution: &commonpb.WorkflowExecution{ + WorkflowId: execution2.BusinessId, + RunId: execution2.RunId, + }, + Archetype: chasm.WorkflowArchetype, TargetClusters: []string{remoteCluster}, })).Return(&adminservice.GenerateLastHistoryReplicationTasksResponse{}, nil).Times(1) @@ -775,3 +880,31 @@ func (s *activitiesSuite) TestWaitCatchUp() { _, err := env.ExecuteActivity(s.a.WaitCatchup, request) s.NoError(err) } + +func (s *activitiesSuite) TestMigrationExecutionInfoCompatibility() { + workflowExecution := &commonpb.WorkflowExecution{ + WorkflowId: execution1.BusinessId, + RunId: execution1.RunId, + } + + dataConverter := converter.GetDefaultDataConverter() + payload, err := dataConverter.ToPayload(workflowExecution) + s.NoError(err) + + var migrationExecution *replicationspb.MigrationExecutionInfo + err = dataConverter.FromPayload(payload, &migrationExecution) + s.NoError(err) + s.Equal(execution1.BusinessId, migrationExecution.BusinessId) + s.Equal(execution1.RunId, migrationExecution.RunId) + s.Equal(chasm.UnspecifiedArchetypeID, migrationExecution.ArchetypeId) + + payload, err = dataConverter.ToPayload(migrationExecution) + s.NoError(err) + + workflowExecution = &commonpb.WorkflowExecution{} + err = dataConverter.FromPayload(payload, &workflowExecution) + s.NoError(err) + + s.Equal(execution1.BusinessId, workflowExecution.WorkflowId) + s.Equal(execution1.RunId, workflowExecution.RunId) +} diff --git a/service/worker/migration/force_replication_workflow.go b/service/worker/migration/force_replication_workflow.go index bd91337beae..cc9096bffde 100644 --- a/service/worker/migration/force_replication_workflow.go +++ b/service/worker/migration/force_replication_workflow.go @@ -4,11 +4,11 @@ import ( "fmt" "time" - commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" "go.temporal.io/api/workflowservice/v1" "go.temporal.io/sdk/temporal" "go.temporal.io/sdk/workflow" + replicationspb "go.temporal.io/server/api/replication/v1" "go.temporal.io/server/common/metrics" ) @@ -162,22 +162,22 @@ func ForceReplicationWorkflow(ctx workflow.Context, params ForceReplicationParam } } - workflowExecutionsCh := workflow.NewBufferedChannel(ctx, params.PageCountPerExecution) - var listWorkflowsErr error + executionsCh := workflow.NewBufferedChannel(ctx, params.PageCountPerExecution) + var listExecutions error workflow.Go(ctx, func(ctx workflow.Context) { - listWorkflowsErr = listWorkflowsForReplication(ctx, workflowExecutionsCh, ¶ms) + listExecutions = listExecutionsForReplication(ctx, executionsCh, ¶ms) // enqueueReplicationTasks only returns when workflowExecutionsCh is closed (or if it encounters an error). // Therefore, listWorkflowsErr will be set prior to their use and params will be updated. - workflowExecutionsCh.Close() + executionsCh.Close() }) - if err := enqueueReplicationTasks(ctx, workflowExecutionsCh, metadataResp.NamespaceID, ¶ms); err != nil { + if err := enqueueReplicationTasks(ctx, executionsCh, metadataResp.NamespaceID, ¶ms); err != nil { return err } - if listWorkflowsErr != nil { - return listWorkflowsErr + if listExecutions != nil { + return listExecutions } if params.NextPageToken == nil { @@ -248,7 +248,7 @@ func ForceReplicationWorkflowV2(ctx workflow.Context, params ForceReplicationPar workflowExecutionsCh := workflow.NewBufferedChannel(ctx, params.PageCountPerExecution) var listWorkflowsErr error workflow.Go(ctx, func(ctx workflow.Context) { - listWorkflowsErr = listWorkflowsForReplication(ctx, workflowExecutionsCh, ¶ms) + listWorkflowsErr = listExecutionsForReplication(ctx, workflowExecutionsCh, ¶ms) // enqueueReplicationTasks only returns when workflowExecutionsCh is closed (or if it encounters an error). // Therefore, listWorkflowsErr will be set prior to their use and params will be updated. @@ -406,7 +406,7 @@ func getClusterMetadata(ctx workflow.Context, params ForceReplicationParams) (me return metadataResp, err } -func listWorkflowsForReplication(ctx workflow.Context, workflowExecutionsCh workflow.Channel, params *ForceReplicationParams) error { +func listExecutionsForReplication(ctx workflow.Context, executionsCh workflow.Channel, params *ForceReplicationParams) error { ao := workflow.ActivityOptions{ StartToCloseTimeout: time.Hour, HeartbeatTimeout: time.Second * 30, @@ -431,7 +431,7 @@ func listWorkflowsForReplication(ctx workflow.Context, workflowExecutionsCh work return err } - workflowExecutionsCh.Send(ctx, listResp.Executions) + executionsCh.Send(ctx, listResp.Executions) params.NextPageToken = listResp.NextPageToken params.LastCloseTime = listResp.LastCloseTime @@ -466,7 +466,7 @@ func countWorkflowForReplication(ctx workflow.Context, params ForceReplicationPa return output.WorkflowCount, nil } -func enqueueReplicationTasks(ctx workflow.Context, workflowExecutionsCh workflow.Channel, namespaceID string, params *ForceReplicationParams) error { +func enqueueReplicationTasks(ctx workflow.Context, executionsCh workflow.Channel, namespaceID string, params *ForceReplicationParams) error { selector := workflow.NewSelector(ctx) pendingGenerateTasks := 0 pendingVerifyTasks := 0 @@ -478,7 +478,7 @@ func enqueueReplicationTasks(ctx workflow.Context, workflowExecutionsCh workflow } actx := workflow.WithActivityOptions(ctx, ao) - var workflowExecutions []*commonpb.WorkflowExecution + var migrationExecutions []*replicationspb.MigrationExecutionInfo var lastActivityErr error var a *activities @@ -487,13 +487,13 @@ func enqueueReplicationTasks(ctx workflow.Context, workflowExecutionsCh workflow targetClusters = []string{params.TargetClusterName} } - for workflowExecutionsCh.Receive(ctx, &workflowExecutions) { + for executionsCh.Receive(ctx, &migrationExecutions) { generateTaskFuture := workflow.ExecuteActivity( actx, a.GenerateReplicationTasks, &generateReplicationTasksRequest{ NamespaceID: namespaceID, - Executions: workflowExecutions, + Executions: migrationExecutions, RPS: params.OverallRps / float64(params.ConcurrentActivityCount), GetParentInfoRPS: params.GetParentInfoRPS / float64(params.ConcurrentActivityCount), TargetClusters: targetClusters, @@ -517,7 +517,7 @@ func enqueueReplicationTasks(ctx workflow.Context, workflowExecutionsCh workflow TargetClusterName: params.TargetClusterName, Namespace: params.Namespace, NamespaceID: namespaceID, - Executions: workflowExecutions, + Executions: migrationExecutions, VerifyInterval: time.Duration(params.VerifyIntervalInSeconds) * time.Second, }) @@ -562,7 +562,12 @@ func enqueueReplicationTasks(ctx workflow.Context, workflowExecutionsCh workflow return nil } -func enqueueReplicationTasksLocal(ctx workflow.Context, workflowExecutionsCh workflow.Channel, namespaceID string, params *ForceReplicationParams) error { +func enqueueReplicationTasksLocal( + ctx workflow.Context, + executionsCh workflow.Channel, + namespaceID string, + params *ForceReplicationParams, +) error { selector := workflow.NewSelector(ctx) pendingGenerateTasks := 0 pendingVerifyTasks := 0 @@ -573,7 +578,7 @@ func enqueueReplicationTasksLocal(ctx workflow.Context, workflowExecutionsCh wor } lactx := workflow.WithLocalActivityOptions(ctx, lao) - var workflowExecutions []*commonpb.WorkflowExecution + var migrationExecutions []*replicationspb.MigrationExecutionInfo var lastActivityErr error var a *activities @@ -582,8 +587,8 @@ func enqueueReplicationTasksLocal(ctx workflow.Context, workflowExecutionsCh wor targetClusters = []string{params.TargetClusterName} } - for workflowExecutionsCh.Receive(ctx, &workflowExecutions) { - executions := workflowExecutions + for executionsCh.Receive(ctx, &migrationExecutions) { + executions := migrationExecutions verifyTaskDone := func(f workflow.Future) { var verifyTaskResponse verifyReplicationTasksResponse diff --git a/service/worker/migration/force_replication_workflow_test.go b/service/worker/migration/force_replication_workflow_test.go index 7fef0a09cbd..124b3dcbb8e 100644 --- a/service/worker/migration/force_replication_workflow_test.go +++ b/service/worker/migration/force_replication_workflow_test.go @@ -15,7 +15,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - commonpb "go.temporal.io/api/common/v1" namespacepb "go.temporal.io/api/namespace/v1" "go.temporal.io/api/workflowservice/v1" "go.temporal.io/sdk/interceptor" @@ -83,7 +82,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestForceReplicationWorkflow() { currentPageCount++ if currentPageCount < totalPageCount { return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{{WorkflowId: "wf-1"}}, + Executions: []*replicationspb.MigrationExecutionInfo{{BusinessId: "wf-1"}}, NextPageToken: []byte("fake-page-token"), LastStartTime: startTime, LastCloseTime: closeTime, @@ -91,7 +90,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestForceReplicationWorkflow() { } // your mock function implementation return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: nil, // last page LastStartTime: startTime, LastCloseTime: closeTime, @@ -145,7 +144,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestContinueAsNew() { currentPageCount++ if currentPageCount < totalPageCount { return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: []byte(fmt.Sprintf("fake-page-token-%d", currentPageCount)), LastStartTime: startTime, LastCloseTime: closeTime, @@ -153,7 +152,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestContinueAsNew() { } // your mock function implementation return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: nil, // last page }, nil } @@ -362,13 +361,13 @@ func (s *ForceReplicationWorkflowTestSuite) TestGenerateReplicationTaskRetryable currentPageCount++ if currentPageCount < totalPageCount { return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: []byte("fake-page-token"), }, nil } // your mock function implementation return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: nil, // last page }, nil }).Times(totalPageCount) @@ -411,13 +410,13 @@ func (s *ForceReplicationWorkflowTestSuite) TestGenerateReplicationTaskNonRetrya currentPageCount++ if currentPageCount < totalPageCount { return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: []byte("fake-page-token"), }, nil } // your mock function implementation return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: nil, // last page }, nil }) @@ -467,13 +466,13 @@ func (s *ForceReplicationWorkflowTestSuite) TestVerifyReplicationTaskNonRetryabl currentPageCount++ if currentPageCount < totalPageCount { return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: []byte("fake-page-token"), }, nil } // your mock function implementation return &listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: nil, // last page }, nil }) @@ -517,7 +516,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestTaskQueueReplicationFailure() { env.OnActivity(a.GetMetadata, mock.Anything, metadataRequest{Namespace: "test-ns"}).Return(&metadataResponse{ShardCount: 4, NamespaceID: namespaceID}, nil) env.OnActivity(a.ListWorkflows, mock.Anything, mock.Anything).Return(&listWorkflowsResponse{ - Executions: []*commonpb.WorkflowExecution{}, + Executions: []*replicationspb.MigrationExecutionInfo{}, NextPageToken: nil, // last page }, nil) env.OnActivity(a.GenerateReplicationTasks, mock.Anything, mock.Anything).Return(nil) @@ -559,10 +558,10 @@ func (s *ForceReplicationWorkflowTestSuite) TestVerifyPerIterationExecutions() { env.OnActivity(a.CountWorkflow, mock.Anything, mock.Anything).Return(&countWorkflowResponse{WorkflowCount: 3}, nil) env.OnActivity(a.GetMetadata, mock.Anything, metadataRequest{Namespace: "test-ns"}).Return(&metadataResponse{ShardCount: 1, NamespaceID: namespaceID}, nil) - pages := [][]*commonpb.WorkflowExecution{ - {{WorkflowId: "wf-1a"}}, - {{WorkflowId: "wf-2a"}, {WorkflowId: "wf-2b"}}, - {{WorkflowId: "wf-3a"}}, + pages := [][]*replicationspb.MigrationExecutionInfo{ + {{BusinessId: "wf-1a"}}, + {{BusinessId: "wf-2a"}, {BusinessId: "wf-2b"}}, + {{BusinessId: "wf-3a"}}, } totalPageCount := len(pages) @@ -581,7 +580,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestVerifyPerIterationExecutions() { env.OnActivity(a.GenerateReplicationTasks, mock.Anything, mock.Anything).Return(func(ctx context.Context, req *generateReplicationTasksRequest) error { ids := make([]string, len(req.Executions)) for i, we := range req.Executions { - ids[i] = we.GetWorkflowId() + ids[i] = we.GetBusinessId() } capturedGenerateMu.Lock() capturedGenerate = append(capturedGenerate, ids) @@ -596,7 +595,7 @@ func (s *ForceReplicationWorkflowTestSuite) TestVerifyPerIterationExecutions() { env.OnActivity(a.VerifyReplicationTasks, mock.Anything, mock.Anything).Return(func(ctx context.Context, req *verifyReplicationTasksRequest) (verifyReplicationTasksResponse, error) { ids := make([]string, len(req.Executions)) for i, we := range req.Executions { - ids[i] = we.GetWorkflowId() + ids[i] = we.GetBusinessId() } capturedVerifyMu.Lock() capturedVerify = append(capturedVerify, ids) diff --git a/service/worker/migration/fx.go b/service/worker/migration/fx.go index 67245ee018f..5169e5a4845 100644 --- a/service/worker/migration/fx.go +++ b/service/worker/migration/fx.go @@ -3,11 +3,12 @@ package migration import ( "context" - commonpb "go.temporal.io/api/common/v1" "go.temporal.io/api/workflowservice/v1" sdkworker "go.temporal.io/sdk/worker" "go.temporal.io/sdk/workflow" "go.temporal.io/server/api/adminservice/v1" + replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" serverClient "go.temporal.io/server/client" "go.temporal.io/server/common/config" "go.temporal.io/server/common/dynamicconfig" @@ -38,6 +39,7 @@ type ( MetricsHandler metrics.Handler DynamicCollection *dynamicconfig.Collection WorkflowVerifier WorkflowVerifier + ChasmRegistry *chasm.Registry } fxResult struct { @@ -98,7 +100,7 @@ func workflowVerifierProvider() WorkflowVerifier { remoteAdminClient adminservice.AdminServiceClient, localAdminClient adminservice.AdminServiceClient, ns *namespace.Namespace, - we *commonpb.WorkflowExecution, + execution *replicationspb.MigrationExecutionInfo, mu *adminservice.DescribeMutableStateResponse, ) (verifyResult, error) { return verifyResult{ @@ -124,5 +126,6 @@ func (wc *replicationWorkerComponent) activities() *activities { generateMigrationTaskViaFrontend: dynamicconfig.WorkerGenerateMigrationTaskViaFrontend.Get(wc.DynamicCollection), enableHistoryRateLimiter: dynamicconfig.WorkerEnableHistoryRateLimiter.Get(wc.DynamicCollection), workflowVerifier: wc.WorkflowVerifier, + chasmRegistry: wc.ChasmRegistry, } } diff --git a/service/worker/scanner/executions/history_event_id_validator.go b/service/worker/scanner/executions/history_event_id_validator.go index fa37c0aea2a..e651235f424 100644 --- a/service/worker/scanner/executions/history_event_id_validator.go +++ b/service/worker/scanner/executions/history_event_id_validator.go @@ -4,6 +4,7 @@ import ( "context" "go.temporal.io/api/serviceerror" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" @@ -46,6 +47,10 @@ func (v *historyEventIDValidator) Validate( return nil, err } + if versionhistory.IsEmptyVersionHistory(currentVersionHistory) { + return nil, nil + } + // TODO currently history event ID validator only verifies // the first event batch exists, before doing whole history // validation, ensure not too much capacity is consumed @@ -68,6 +73,9 @@ func (v *historyEventIDValidator) Validate( NamespaceID: mutableState.GetExecutionInfo().NamespaceId, WorkflowID: mutableState.GetExecutionInfo().WorkflowId, RunID: mutableState.GetExecutionState().RunId, + // TODO: for now only workflow has events and non-empty event version history + // Later when supporting events for non-workflow component, we need to get ArchetypeID from MutableState. + ArchetypeID: chasm.WorkflowArchetypeID, }) switch err.(type) { case nil: diff --git a/service/worker/scanner/executions/task.go b/service/worker/scanner/executions/task.go index 3d445dba837..29c881243b9 100644 --- a/service/worker/scanner/executions/task.go +++ b/service/worker/scanner/executions/task.go @@ -9,6 +9,7 @@ import ( "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/collection" "go.temporal.io/server/common/dynamicconfig" @@ -230,6 +231,7 @@ func (t *task) handleFailures( WorkflowId: executionInfo.GetWorkflowId(), RunId: runID, }, + Archetype: chasm.WorkflowArchetype, }) switch err.(type) { case *serviceerror.NotFound, diff --git a/service/worker/scanner/history/scavenger.go b/service/worker/scanner/history/scavenger.go index f1eb319f855..aa21f40210f 100644 --- a/service/worker/scanner/history/scavenger.go +++ b/service/worker/scanner/history/scavenger.go @@ -12,6 +12,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/collection" "go.temporal.io/server/common/dynamicconfig" @@ -258,6 +259,7 @@ func (s *Scavenger) handleTask( WorkflowId: task.workflowID, RunId: task.runID, }, + ArchetypeId: chasm.WorkflowArchetypeID, }) switch err.(type) { case nil: @@ -354,6 +356,7 @@ func (s *Scavenger) cleanUpWorkflowPastRetention( WorkflowId: executionInfo.GetWorkflowId(), RunId: mutableState.GetExecutionState().GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) if err != nil { // This is experimental. Ignoring the error so it will not block the history scavenger. diff --git a/service/worker/scanner/history/scavenger_test.go b/service/worker/scanner/history/scavenger_test.go index c5eea8480bd..79be26873fd 100644 --- a/service/worker/scanner/history/scavenger_test.go +++ b/service/worker/scanner/history/scavenger_test.go @@ -16,6 +16,7 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/api/historyservicemock/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" @@ -291,6 +292,7 @@ func (s *ScavengerTestSuite) TestNoGarbageTwoPages() { WorkflowId: "workflowID1", RunId: "runID1", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(ms, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID2", @@ -298,6 +300,7 @@ func (s *ScavengerTestSuite) TestNoGarbageTwoPages() { WorkflowId: "workflowID2", RunId: "runID2", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(ms, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID3", @@ -305,6 +308,7 @@ func (s *ScavengerTestSuite) TestNoGarbageTwoPages() { WorkflowId: "workflowID3", RunId: "runID3", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(ms, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID4", @@ -312,6 +316,7 @@ func (s *ScavengerTestSuite) TestNoGarbageTwoPages() { WorkflowId: "workflowID4", RunId: "runID4", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(ms, nil) hbd, err := s.scavenger.Run(context.Background()) @@ -377,6 +382,7 @@ func (s *ScavengerTestSuite) TestDeletingBranchesTwoPages() { WorkflowId: "workflowID1", RunId: "runID1", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(nil, serviceerror.NewNotFound("")) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID2", @@ -384,6 +390,7 @@ func (s *ScavengerTestSuite) TestDeletingBranchesTwoPages() { WorkflowId: "workflowID2", RunId: "runID2", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(nil, serviceerror.NewNotFound("")) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID3", @@ -391,6 +398,7 @@ func (s *ScavengerTestSuite) TestDeletingBranchesTwoPages() { WorkflowId: "workflowID3", RunId: "runID3", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(nil, serviceerror.NewNotFound("")) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID4", @@ -398,26 +406,27 @@ func (s *ScavengerTestSuite) TestDeletingBranchesTwoPages() { WorkflowId: "workflowID4", RunId: "runID4", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(nil, serviceerror.NewNotFound("")) - branchToken1, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), treeID1, &branchID1, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) + branchToken1, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), chasm.WorkflowArchetypeID, treeID1, &branchID1, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) s.Nil(err) s.mockExecutionManager.EXPECT().DeleteHistoryBranch(gomock.Any(), protomock.Eq(&persistence.DeleteHistoryBranchRequest{ BranchToken: branchToken1, ShardID: common.WorkflowIDToHistoryShard("namespaceID1", "workflowID1", s.numShards), })).Return(nil) - branchToken2, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), treeID2, &branchID2, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) + branchToken2, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), chasm.WorkflowArchetypeID, treeID2, &branchID2, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) s.Nil(err) s.mockExecutionManager.EXPECT().DeleteHistoryBranch(gomock.Any(), protomock.Eq(&persistence.DeleteHistoryBranchRequest{ BranchToken: branchToken2, ShardID: common.WorkflowIDToHistoryShard("namespaceID2", "workflowID2", s.numShards), })).Return(nil) - branchToken3, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), treeID3, &branchID3, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) + branchToken3, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), chasm.WorkflowArchetypeID, treeID3, &branchID3, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) s.Nil(err) s.mockExecutionManager.EXPECT().DeleteHistoryBranch(gomock.Any(), protomock.Eq(&persistence.DeleteHistoryBranchRequest{ BranchToken: branchToken3, ShardID: common.WorkflowIDToHistoryShard("namespaceID3", "workflowID3", s.numShards), })).Return(nil) - branchToken4, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), treeID4, &branchID4, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) + branchToken4, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), chasm.WorkflowArchetypeID, treeID4, &branchID4, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) s.Nil(err) s.mockExecutionManager.EXPECT().DeleteHistoryBranch(gomock.Any(), protomock.Eq(&persistence.DeleteHistoryBranchRequest{ BranchToken: branchToken4, @@ -515,6 +524,7 @@ func (s *ScavengerTestSuite) TestMixesTwoPages() { WorkflowId: "workflowID3", RunId: "runID3", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(nil, serviceerror.NewNotFound("")) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ @@ -523,6 +533,7 @@ func (s *ScavengerTestSuite) TestMixesTwoPages() { WorkflowId: "workflowID4", RunId: "runID4", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(nil, serviceerror.NewNotFound("")) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID5", @@ -530,16 +541,17 @@ func (s *ScavengerTestSuite) TestMixesTwoPages() { WorkflowId: "workflowID5", RunId: "runID5", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(ms, nil) - branchToken3, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), treeID3, &branchID3, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) + branchToken3, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), chasm.WorkflowArchetypeID, treeID3, &branchID3, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) s.Nil(err) s.mockExecutionManager.EXPECT().DeleteHistoryBranch(gomock.Any(), protomock.Eq(&persistence.DeleteHistoryBranchRequest{ BranchToken: branchToken3, ShardID: common.WorkflowIDToHistoryShard("namespaceID3", "workflowID3", s.numShards), })).Return(nil) - branchToken4, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), treeID4, &branchID4, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) + branchToken4, err := s.historyBranchUtil.NewHistoryBranch(uuid.New(), uuid.New(), uuid.New(), chasm.WorkflowArchetypeID, treeID4, &branchID4, []*persistencespb.HistoryBranchRange{}, 0, 0, 0) s.Nil(err) s.mockExecutionManager.EXPECT().DeleteHistoryBranch(gomock.Any(), protomock.Eq(&persistence.DeleteHistoryBranchRequest{ BranchToken: branchToken4, @@ -672,6 +684,7 @@ func (s *ScavengerTestSuite) TestDeleteWorkflowAfterRetention() { WorkflowId: "workflowID1", RunId: "runID1", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(workflowInRetention, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID2", @@ -679,6 +692,7 @@ func (s *ScavengerTestSuite) TestDeleteWorkflowAfterRetention() { WorkflowId: "workflowID2", RunId: "runID2", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(workflowPastRetention2, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID3", @@ -686,6 +700,7 @@ func (s *ScavengerTestSuite) TestDeleteWorkflowAfterRetention() { WorkflowId: "workflowID3", RunId: "runID3", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(workflowInRetention, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID4", @@ -693,6 +708,7 @@ func (s *ScavengerTestSuite) TestDeleteWorkflowAfterRetention() { WorkflowId: "workflowID4", RunId: "runID4", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(workflowPastRetention4, nil) s.mockHistoryClient.EXPECT().DescribeMutableState(gomock.Any(), protomock.Eq(&historyservice.DescribeMutableStateRequest{ NamespaceId: "namespaceID5", @@ -700,18 +716,21 @@ func (s *ScavengerTestSuite) TestDeleteWorkflowAfterRetention() { WorkflowId: "workflowID5", RunId: "runID5", }, + ArchetypeId: chasm.WorkflowArchetypeID, })).Return(runningWorkflow5, nil) s.mockAdminClient.EXPECT().DeleteWorkflowExecution(gomock.Any(), protomock.Eq(&adminservice.DeleteWorkflowExecutionRequest{ Execution: &commonpb.WorkflowExecution{ WorkflowId: "workflowID2", RunId: "runID2", }, + Archetype: chasm.WorkflowArchetype, })).Return(nil, nil).Times(1) s.mockAdminClient.EXPECT().DeleteWorkflowExecution(gomock.Any(), protomock.Eq(&adminservice.DeleteWorkflowExecutionRequest{ Execution: &commonpb.WorkflowExecution{ WorkflowId: "workflowID4", RunId: "runID4", }, + Archetype: chasm.WorkflowArchetype, })).Return(nil, nil).Times(1) hbd, err := s.scavenger.Run(context.Background()) diff --git a/tests/admin_test.go b/tests/admin_test.go index 41a05c3710c..de0ffb7d2b8 100644 --- a/tests/admin_test.go +++ b/tests/admin_test.go @@ -12,6 +12,7 @@ import ( "go.temporal.io/sdk/workflow" "go.temporal.io/server/api/adminservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/tests/testcore" ) @@ -72,6 +73,7 @@ func (s *AdminTestSuite) TestAdminRebuildMutableState() { WorkflowId: workflowID, RunId: runID, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) if response1.DatabaseMutableState.ExecutionInfo.StateTransitionCount == 3 { @@ -95,6 +97,7 @@ func (s *AdminTestSuite) TestAdminRebuildMutableState() { WorkflowId: workflowID, RunId: runID, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(response1.DatabaseMutableState.ExecutionInfo.VersionHistories, response2.DatabaseMutableState.ExecutionInfo.VersionHistories) diff --git a/tests/archival_test.go b/tests/archival_test.go index 6f9e8a1f180..4ed6d81f28d 100644 --- a/tests/archival_test.go +++ b/tests/archival_test.go @@ -17,6 +17,7 @@ import ( workflowpb "go.temporal.io/api/workflow/v1" "go.temporal.io/api/workflowservice/v1" "go.temporal.io/server/api/adminservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/convert" @@ -265,6 +266,7 @@ func (s *ArchivalSuite) mutableStateIsDeleted(namespaceID namespace.ID, executio NamespaceID: namespaceID.String(), WorkflowID: execution.WorkflowId, RunID: execution.RunId, + ArchetypeID: chasm.WorkflowArchetypeID, } s.Eventually(func() bool { @@ -415,6 +417,7 @@ func (s *ArchivalSuite) getBranchToken( descResp, err := s.AdminClient().DescribeMutableState(testcore.NewContext(), &adminservice.DescribeMutableStateRequest{ Namespace: nsName.String(), Execution: execution, + Archetype: chasm.WorkflowArchetype, }) if err != nil { return nil, err diff --git a/tests/chasm_test.go b/tests/chasm_test.go index 3e1be970d4e..584596f5382 100644 --- a/tests/chasm_test.go +++ b/tests/chasm_test.go @@ -3,6 +3,7 @@ package tests import ( "context" "fmt" + "strconv" "testing" "time" @@ -15,6 +16,7 @@ import ( "go.temporal.io/server/common/debug" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/payload" + "go.temporal.io/server/common/searchattribute/sadefs" "go.temporal.io/server/common/testing/testvars" "go.temporal.io/server/tests/testcore" ) @@ -254,10 +256,15 @@ func (s *ChasmTestSuite) TestPayloadStoreVisibility() { s.Equal(0, totalCount) var totalSize int s.NoError(payload.Decode(visRecord.SearchAttributes.IndexedFields["TemporalInt02"], &totalSize)) + s.Equal(0, totalSize) var scheduledByID string s.NoError(payload.Decode(visRecord.SearchAttributes.IndexedFields["TemporalScheduledById"], &scheduledByID)) s.Equal(tests.TestScheduleID, scheduledByID) - s.Equal(0, totalSize) + var archetypeIDStr string + s.NoError(payload.Decode(visRecord.SearchAttributes.IndexedFields[sadefs.TemporalNamespaceDivision], &archetypeIDStr)) + parsedArchetypeID, err := strconv.ParseUint(archetypeIDStr, 10, 32) + s.NoError(err) + s.Equal(archetypeID, chasm.ArchetypeID(parsedArchetypeID)) addPayloadResp, err := tests.AddPayloadHandler( engineContext, diff --git a/tests/client_misc_test.go b/tests/client_misc_test.go index ad192a57730..8188066ac61 100644 --- a/tests/client_misc_test.go +++ b/tests/client_misc_test.go @@ -25,6 +25,7 @@ import ( "go.temporal.io/sdk/worker" "go.temporal.io/sdk/workflow" "go.temporal.io/server/api/adminservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/rpc" @@ -258,6 +259,7 @@ func (s *ClientMiscTestSuite) TestTooManyCancelRequests() { NamespaceID: s.NamespaceID().String(), WorkflowID: cancelerWorkflowId, RunID: run.GetRunID(), + ArchetypeID: chasm.WorkflowArchetypeID, }) s.NoError(err) numCancelRequests := len(workflowExecution.State.RequestCancelInfos) @@ -429,6 +431,7 @@ func (s *ClientMiscTestSuite) TestStickyAutoReset() { Execution: &commonpb.WorkflowExecution{ WorkflowId: future.GetID(), }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) stickyQueue = ms.DatabaseMutableState.ExecutionInfo.StickyTaskQueue @@ -463,6 +466,7 @@ func (s *ClientMiscTestSuite) TestStickyAutoReset() { Execution: &commonpb.WorkflowExecution{ WorkflowId: future.GetID(), }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.NotEmpty(ms.DatabaseMutableState.ExecutionInfo.StickyTaskQueue) @@ -843,6 +847,7 @@ func (s *ClientMiscTestSuite) Test_BufferedQuery() { WorkflowId: id, RunId: workflowRun.GetRunID(), }, + Archetype: chasm.WorkflowArchetype, }) s.Assert().NoError(err) }() diff --git a/tests/namespace_delete_test.go b/tests/namespace_delete_test.go index aa1e5504d86..098dea3638a 100644 --- a/tests/namespace_delete_test.go +++ b/tests/namespace_delete_test.go @@ -18,6 +18,7 @@ import ( "go.temporal.io/api/serviceerror" taskqueuepb "go.temporal.io/api/taskqueue/v1" "go.temporal.io/api/workflowservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/persistence" @@ -347,6 +348,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { NamespaceID: nsID, WorkflowID: execution.GetWorkflowId(), RunID: execution.GetRunId(), + ArchetypeID: chasm.WorkflowArchetypeID, }) s.NoError(err) } diff --git a/tests/ndc/replication_migration_back_test.go b/tests/ndc/replication_migration_back_test.go index e07f0bda2e7..91bbc704e44 100644 --- a/tests/ndc/replication_migration_back_test.go +++ b/tests/ndc/replication_migration_back_test.go @@ -21,6 +21,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" replicationspb "go.temporal.io/server/api/replication/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" @@ -187,6 +188,7 @@ func (s *ReplicationMigrationBackTestSuite) TestHistoryReplication_MultiRunMigra WorkflowId: workflowId, RunId: runId1, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) @@ -196,6 +198,7 @@ func (s *ReplicationMigrationBackTestSuite) TestHistoryReplication_MultiRunMigra WorkflowId: workflowId, RunId: runId2, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) @@ -242,6 +245,7 @@ func (s *ReplicationMigrationBackTestSuite) longRunningMigrationBackReplicationT WorkflowId: workflowID, RunId: runID, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) @@ -313,6 +317,7 @@ func (s *ReplicationMigrationBackTestSuite) TestHistoryReplication_LongRunningMi WorkflowId: workflowId, RunId: runId, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) diff --git a/tests/nexus_workflow_test.go b/tests/nexus_workflow_test.go index 3bbe47aa20c..7f1d8980eca 100644 --- a/tests/nexus_workflow_test.go +++ b/tests/nexus_workflow_test.go @@ -36,6 +36,7 @@ import ( "go.temporal.io/server/api/adminservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" tokenspb "go.temporal.io/server/api/token/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/authorization" "go.temporal.io/server/common/dynamicconfig" @@ -395,6 +396,7 @@ func (s *NexusWorkflowTestSuite) TestNexusOperationSyncCompletion() { Execution: &commonpb.WorkflowExecution{ WorkflowId: run.GetID(), }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Len(desc.DatabaseMutableState.GetExecutionInfo().SubStateMachinesByType, 0) diff --git a/tests/update_workflow_test.go b/tests/update_workflow_test.go index 567a7a7adb3..99cbd3dafc9 100644 --- a/tests/update_workflow_test.go +++ b/tests/update_workflow_test.go @@ -18,6 +18,7 @@ import ( updatepb "go.temporal.io/api/update/v1" "go.temporal.io/api/workflowservice/v1" "go.temporal.io/server/api/adminservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log/tag" @@ -2953,6 +2954,7 @@ func (s *UpdateWorkflowSuite) TestStartedSpeculativeWorkflowTask_TerminateWorkfl msResp, err := s.AdminClient().DescribeMutableState(testcore.NewContext(), &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: tv.WorkflowExecution(), + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.EqualValues(7, msResp.GetDatabaseMutableState().GetExecutionInfo().GetCompletionEventBatchId(), "completion_event_batch_id should point to WTFailed event") @@ -3038,6 +3040,7 @@ func (s *UpdateWorkflowSuite) TestScheduledSpeculativeWorkflowTask_TerminateWork msResp, err := s.AdminClient().DescribeMutableState(testcore.NewContext(), &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: tv.WorkflowExecution(), + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.EqualValues(5, msResp.GetDatabaseMutableState().GetExecutionInfo().GetCompletionEventBatchId(), "completion_event_batch_id should point to WFTerminated event") diff --git a/tests/versioning_test.go b/tests/versioning_test.go index cb7003a2a2e..46ee88a5ada 100644 --- a/tests/versioning_test.go +++ b/tests/versioning_test.go @@ -29,6 +29,7 @@ import ( "go.temporal.io/server/api/matchingservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" taskqueuespb "go.temporal.io/server/api/taskqueue/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/common/tqid" @@ -4978,6 +4979,7 @@ func (s *VersioningIntegSuite) getStickyQueueName(ctx context.Context, id string ms, err := s.AdminClient().DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: &commonpb.WorkflowExecution{WorkflowId: id}, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) return ms.DatabaseMutableState.ExecutionInfo.StickyTaskQueue diff --git a/tests/workflow_reset_test.go b/tests/workflow_reset_test.go index 3ec60ee153f..864b1cf006c 100644 --- a/tests/workflow_reset_test.go +++ b/tests/workflow_reset_test.go @@ -18,6 +18,7 @@ import ( "go.temporal.io/api/workflowservice/v1" "go.temporal.io/sdk/client" "go.temporal.io/server/api/adminservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/payloads" "go.temporal.io/server/tests/testcore" "google.golang.org/protobuf/types/known/durationpb" @@ -56,6 +57,7 @@ func (s *WorkflowResetSuite) TestNoBaseCurrentRunning() { currentMutableState, err := s.AdminClient().DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: &commonpb.WorkflowExecution{WorkflowId: workflowID, RunId: currentRunID}, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(currentMutableState.GetDatabaseMutableState().ExecutionInfo.ResetRunId, newRunID) @@ -84,6 +86,7 @@ func (s *WorkflowResetSuite) TestNoBaseCurrentClosed() { currentMutableState, err := s.AdminClient().DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: &commonpb.WorkflowExecution{WorkflowId: workflowID, RunId: currentRunID}, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(currentMutableState.GetDatabaseMutableState().ExecutionInfo.ResetRunId, newRunID) @@ -192,6 +195,7 @@ func (s *WorkflowResetSuite) TestOriginalExecutionRunId() { baseMutableState, err := s.AdminClient().DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: &commonpb.WorkflowExecution{WorkflowId: workflowID, RunId: currentRunID}, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(baseRunID, baseMutableState.GetDatabaseMutableState().ExecutionInfo.OriginalExecutionRunId) @@ -419,6 +423,7 @@ func (s *WorkflowResetSuite) assertMutableStateStatus(ctx context.Context, workf ms, err := s.AdminClient().DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: &commonpb.WorkflowExecution{WorkflowId: workflowID, RunId: runID}, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(expectedStatus, ms.GetDatabaseMutableState().ExecutionState.Status) @@ -429,6 +434,7 @@ func (s *WorkflowResetSuite) assertResetWorkflowLink(ctx context.Context, workfl baseMutableState, err := s.AdminClient().DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{ Namespace: s.Namespace().String(), Execution: &commonpb.WorkflowExecution{WorkflowId: workflowID, RunId: runID}, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(expectedLinkRunID, baseMutableState.GetDatabaseMutableState().ExecutionInfo.ResetRunId) diff --git a/tests/xdc/failover_test.go b/tests/xdc/failover_test.go index 7d5141f1bbb..bc3a6156c9e 100644 --- a/tests/xdc/failover_test.go +++ b/tests/xdc/failover_test.go @@ -26,6 +26,7 @@ import ( "go.temporal.io/sdk/temporal" "go.temporal.io/sdk/workflow" "go.temporal.io/server/api/adminservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/config" "go.temporal.io/server/common/convert" "go.temporal.io/server/common/failure" @@ -2391,6 +2392,7 @@ func (s *FunctionalClustersTestSuite) TestLocalNamespaceMigration() { Execution: &commonpb.WorkflowExecution{ WorkflowId: wfID, }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) s.Equal(expectedRunID, desc1.DatabaseMutableState.ExecutionState.RunId) diff --git a/tests/xdc/stream_based_replication_test.go b/tests/xdc/stream_based_replication_test.go index c19f293b210..d107f9d9592 100644 --- a/tests/xdc/stream_based_replication_test.go +++ b/tests/xdc/stream_based_replication_test.go @@ -29,6 +29,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" "go.temporal.io/server/api/historyservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/client" "go.temporal.io/server/client/history" "go.temporal.io/server/common" @@ -178,6 +179,7 @@ func (s *streamBasedReplicationTestSuite) TestReplicateHistoryEvents_ForceReplic _, err := historyClient0.GenerateLastHistoryReplicationTasks(ctx, &historyservice.GenerateLastHistoryReplicationTasksRequest{ NamespaceId: s.namespaceID, Execution: execution, + ArchetypeId: chasm.WorkflowArchetypeID, }) s.NoError(err) } @@ -509,6 +511,7 @@ func (s *streamBasedReplicationTestSuite) TestForceReplicateResetWorkflow_BaseWo WorkflowId: id, RunId: resetResp.GetRunId(), }, + ArchetypeId: chasm.WorkflowArchetypeID, }) s.NoError(err) @@ -626,6 +629,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: we.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) return err == nil }, @@ -640,6 +644,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp1.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) return err == nil }, @@ -654,6 +659,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp2.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) return err == nil }, @@ -667,6 +673,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: we.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) _, err = s.clusters[1].AdminClient().DeleteWorkflowExecution(testcore.NewContext(), &adminservice.DeleteWorkflowExecutionRequest{ @@ -675,6 +682,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp1.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) _, err = s.clusters[1].AdminClient().DeleteWorkflowExecution(testcore.NewContext(), &adminservice.DeleteWorkflowExecutionRequest{ @@ -683,6 +691,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp2.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) s.NoError(err) @@ -695,6 +704,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: we.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) var expectedErr *serviceerror.NotFound return errors.As(err, &expectedErr) @@ -710,6 +720,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp1.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) var expectedErr *serviceerror.NotFound return errors.As(err, &expectedErr) @@ -725,6 +736,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp2.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) var expectedErr *serviceerror.NotFound return errors.As(err, &expectedErr) @@ -738,6 +750,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: we.GetRunId(), }, + ArchetypeId: chasm.WorkflowArchetypeID, }) s.NoError(err) s.Eventually(func() bool { @@ -749,6 +762,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: we.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) return err == nil }, @@ -761,6 +775,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp1.GetRunId(), }, + ArchetypeId: chasm.WorkflowArchetypeID, }) s.NoError(err) s.Eventually(func() bool { @@ -772,6 +787,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp1.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) return err == nil }, @@ -784,6 +800,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp2.GetRunId(), }, + ArchetypeId: chasm.WorkflowArchetypeID, }) s.NoError(err) s.Eventually(func() bool { @@ -795,6 +812,7 @@ func (s *streamBasedReplicationTestSuite) TestResetWorkflow_SyncWorkflowState() WorkflowId: id, RunId: resetResp2.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) return err == nil }, @@ -885,6 +903,7 @@ func (s *streamBasedReplicationTestSuite) TestCloseTransferTaskAckedReplication( WorkflowId: workflowID, RunId: startResp.GetRunId(), }, + ArchetypeId: chasm.WorkflowArchetypeID, }) s.Require().NoError(err, "Failed to describe mutable state") s.Require().NotNil(mutableStateResp.GetDatabaseMutableState(), "Database mutable state is nil") @@ -938,6 +957,7 @@ func (s *streamBasedReplicationTestSuite) TestCloseTransferTaskAckedReplication( WorkflowId: workflowID, RunId: startResp.GetRunId(), }, + Archetype: chasm.WorkflowArchetype, }) s.Require().NoError(err, "Failed to generate last history replication tasks") s.T().Log("Generated last history replication tasks to force replication of completed workflow") diff --git a/tests/xdc/workflow_task_reported_problems_test.go b/tests/xdc/workflow_task_reported_problems_test.go index 56153a93c49..fbedbf3c20f 100644 --- a/tests/xdc/workflow_task_reported_problems_test.go +++ b/tests/xdc/workflow_task_reported_problems_test.go @@ -17,6 +17,7 @@ import ( "go.temporal.io/sdk/workflow" "go.temporal.io/server/api/adminservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/searchattribute/sadefs" @@ -100,6 +101,7 @@ func (s *WorkflowTaskReportedProblemsReplicationSuite) getWFTFailure(admin admin WorkflowId: wfid, RunId: runid, }, + Archetype: chasm.WorkflowArchetype, }) require.NoError(s.T(), err) require.NotNil(s.T(), resp) diff --git a/tools/tdbg/commands.go b/tools/tdbg/commands.go index 3715b2a0ab4..6bb17575958 100644 --- a/tools/tdbg/commands.go +++ b/tools/tdbg/commands.go @@ -15,6 +15,7 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common" "go.temporal.io/server/common/codec" "go.temporal.io/server/common/namespace" @@ -305,6 +306,7 @@ func describeMutableState(c *cli.Context, clientFactory ClientFactory) (*adminse WorkflowId: wid, RunId: rid, }, + Archetype: getArchetypeWithDefault(c, chasm.WorkflowArchetype), }) if err != nil { return nil, fmt.Errorf("unable to get Workflow Mutable State: %s", err) @@ -342,6 +344,7 @@ func AdminDeleteWorkflow(c *cli.Context, clientFactory ClientFactory, prompter * WorkflowId: wid, RunId: rid, }, + Archetype: getArchetypeWithDefault(c, chasm.WorkflowArchetype), }) if err != nil { return fmt.Errorf("unable to delete workflow execution: %s", err) @@ -661,6 +664,7 @@ func AdminRefreshWorkflowTasks(c *cli.Context, clientFactory ClientFactory) erro WorkflowId: wid, RunId: rid, }, + Archetype: getArchetypeWithDefault(c, chasm.WorkflowArchetype), }) if err != nil { return fmt.Errorf("unable to refresh Workflow Task: %s", err) @@ -731,6 +735,7 @@ func AdminReplicateWorkflow( WorkflowId: wid, RunId: rid, }, + Archetype: getArchetypeWithDefault(c, chasm.WorkflowArchetype), }) if err != nil { return fmt.Errorf("unable to replicate workflow: %w", err) diff --git a/tools/tdbg/flags.go b/tools/tdbg/flags.go index e08ab4f898f..a7a33de836d 100644 --- a/tools/tdbg/flags.go +++ b/tools/tdbg/flags.go @@ -12,6 +12,7 @@ var ( FlagWorkflowIDAlias = []string{"wid"} FlagRunID = "run-id" FlagRunIDAlias = []string{"rid"} + FlagArchetype = "archetype" FlagNumberOfShards = "number-of-shards" FlagMinEventID = "min-event-id" FlagMaxEventID = "max-event-id" diff --git a/tools/tdbg/tdbg_commands.go b/tools/tdbg/tdbg_commands.go index 500cf4050d7..cbc376353e7 100644 --- a/tools/tdbg/tdbg_commands.go +++ b/tools/tdbg/tdbg_commands.go @@ -9,6 +9,7 @@ import ( "github.com/urfave/cli/v2" commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/service/history/tasks" "go.uber.org/multierr" ) @@ -149,6 +150,11 @@ func newAdminWorkflowCommands(clientFactory ClientFactory, prompterFactory Promp Aliases: FlagRunIDAlias, Usage: "Run ID", }, + &cli.StringFlag{ + Name: FlagArchetype, + Usage: "Fully qualified archetype name of the execution", + DefaultText: chasm.WorkflowArchetype, + }, }, Action: func(c *cli.Context) error { return AdminDescribeWorkflow(c, clientFactory) @@ -169,6 +175,11 @@ func newAdminWorkflowCommands(clientFactory ClientFactory, prompterFactory Promp Aliases: FlagRunIDAlias, Usage: "Run ID", }, + &cli.StringFlag{ + Name: FlagArchetype, + Usage: "Fully qualified archetype name of the execution", + DefaultText: chasm.WorkflowArchetype, + }, }, Action: func(c *cli.Context) error { return AdminRefreshWorkflowTasks(c, clientFactory) @@ -209,6 +220,11 @@ func newAdminWorkflowCommands(clientFactory ClientFactory, prompterFactory Promp Aliases: FlagRunIDAlias, Usage: "Run ID", }, + &cli.StringFlag{ + Name: FlagArchetype, + Usage: "Fully qualified archetype name of the execution", + DefaultText: chasm.WorkflowArchetype, + }, }, Action: func(c *cli.Context) error { return AdminReplicateWorkflow(c, clientFactory) @@ -229,6 +245,11 @@ func newAdminWorkflowCommands(clientFactory ClientFactory, prompterFactory Promp Aliases: FlagRunIDAlias, Usage: "Run ID", }, + &cli.StringFlag{ + Name: FlagArchetype, + Usage: "Fully qualified archetype name of the execution", + DefaultText: chasm.WorkflowArchetype, + }, }, Action: func(c *cli.Context) error { return AdminDeleteWorkflow(c, clientFactory, prompterFactory(c)) diff --git a/tools/tdbg/util.go b/tools/tdbg/util.go index c33e83484c2..77845b8ea2f 100644 --- a/tools/tdbg/util.go +++ b/tools/tdbg/util.go @@ -15,6 +15,7 @@ import ( "github.com/olekukonko/tablewriter" "github.com/urfave/cli/v2" "go.temporal.io/api/workflowservice/v1" + "go.temporal.io/server/chasm" "go.temporal.io/server/common/codec" "go.temporal.io/server/common/collection" "go.temporal.io/server/common/namespace" @@ -291,3 +292,14 @@ func getNamespaceID(c *cli.Context, clientFactory ClientFactory, nsName namespac return namespace.ID(nsResponse.NamespaceInfo.GetId()), nil } + +func getArchetypeWithDefault( + c *cli.Context, + defaultAchetype chasm.Archetype, +) chasm.Archetype { + archetype := c.String(FlagArchetype) + if archetype != "" { + return archetype + } + return defaultAchetype +}