execution_util.go ×26

Frontier kind: Code frontier

unlabeled · c_06965126fc60

268 tests · 3928 LOC · 168 files · introduces 0 tests · 236 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
55 ranges236 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
717 ranges3928 lines · 168 files · Browse complete extent
All tests (intent)
268 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

4 files ranked by introduced lines: 236 introduced LOC across 55 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/sql/execution_util.go 148 introduced LOC · 26 ranges

Open complete file

421 shardID int32,
422 workflowSnapshot *p.InternalWorkflowSnapshot,
423 > ) error { execution_util.go
424 >
425 > lastWriteVersion := workflowSnapshot.LastWriteVersion
426 > workflowID := workflowSnapshot.WorkflowID
427 > namespaceID := workflowSnapshot.NamespaceID
428 > runID := workflowSnapshot.ExecutionState.RunId
429 > namespaceIDBytes, err := primitives.ParseUUID(namespaceID)
430 > if err != nil {
431 return err
432 }
433 > runIDBytes, err := primitives.ParseUUID(runID) execution_util.go
434 > if err != nil {
435 return err
436 }
437
438 > if err := m.createExecution(ctx, execution_util.go
439 > tx,
440 > namespaceID,
441 > workflowID,
442 > workflowSnapshot.ExecutionInfoBlob,
443 > workflowSnapshot.ExecutionState,
444 > workflowSnapshot.NextEventID,
445 > lastWriteVersion,
446 > workflowSnapshot.DBRecordVersion,
447 > shardID,
448 > ); err != nil {
449 return err
450 }
451
452 > if err := applyTasks(ctx, execution_util.go
453 > tx,
454 > shardID,
455 > workflowSnapshot.Tasks,
456 > ); err != nil {
457 return err
458 }
459
460 > if err := updateActivityInfos(ctx, execution_util.go
461 > tx,
462 > workflowSnapshot.ActivityInfos,
463 > nil,
464 > shardID,
465 > namespaceIDBytes,
466 > workflowID,
467 > runIDBytes,
468 > ); err != nil {
469 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to insert into activity info map after clearing. Error: %v", err)
470 }
471
472 > if err := updateTimerInfos(ctx, execution_util.go
473 > tx,
474 > workflowSnapshot.TimerInfos,
475 > nil,
476 > shardID,
477 > namespaceIDBytes,
478 > workflowID,
479 > runIDBytes,
480 > ); err != nil {
481 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to insert into timer info map after clearing. Error: %v", err)
482 }
483
484 > if err := updateChildExecutionInfos(ctx, execution_util.go
485 > tx,
486 > workflowSnapshot.ChildExecutionInfos,
487 > nil,
488 > shardID,
489 > namespaceIDBytes,
490 > workflowID,
491 > runIDBytes,
492 > ); err != nil {
493 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to insert into activity info map after clearing. Error: %v", err)
494 }
495
496 > if err := updateRequestCancelInfos(ctx, execution_util.go
497 > tx,
498 > workflowSnapshot.RequestCancelInfos,
499 > nil,
500 > shardID,
501 > namespaceIDBytes,
502 > workflowID,
503 > runIDBytes,
504 > ); err != nil {
505 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to insert into request cancel info map after clearing. Error: %v", err)
506 }
507
508 > if err := updateSignalInfos(ctx, execution_util.go
509 > tx,
510 > workflowSnapshot.SignalInfos,
511 > nil,
512 > shardID,
513 > namespaceIDBytes,
514 > workflowID,
515 > runIDBytes,
516 > ); err != nil {
517 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to insert into signal info map after clearing. Error: %v", err)
518 }
519
520 > if err := updateSignalsRequested(ctx, execution_util.go
521 > tx,
522 > workflowSnapshot.SignalRequestedIDs,
523 > nil,
524 > shardID,
525 > namespaceIDBytes,
526 > workflowID,
527 > runIDBytes,
528 > ); err != nil {
529 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to insert into signals requested set after clearing. Error: %v", err)
530 }
531
532 > if err := updateChasmNodes(ctx, execution_util.go
533 > tx,
534 > workflowSnapshot.ChasmNodes,
535 > nil,
536 > shardID,
537 > namespaceIDBytes,
538 > workflowID,
539 > runIDBytes,
540 > ); err != nil {
541 return serviceerror.NewUnavailablef("applyWorkflowSnapshotTxAsNew failed. Failed to update CHASM nodes. Error: %v", err)
542 }
543
544 > return nil execution_util.go
545 }
546
580 workflowID string,
581 archetypeID chasm.ArchetypeID,
582 > ) (*sqlplugin.CurrentExecutionsRow, error) { execution_util.go
583 > rows, err := tx.LockCurrentExecutionsJoinExecutions(ctx, sqlplugin.CurrentExecutionsFilter{
584 > ShardID: shardID,
585 > NamespaceID: namespaceID,
586 > WorkflowID: workflowID,
587 > ArchetypeID: archetypeID,
588 > })
589 > if err != nil {
590 if err != sql.ErrNoRows {
591 return nil, serviceerror.NewUnavailablef("lockCurrentExecutionIfExists failed. Failed to get current_executions row for (shard,namespace,workflow) = (%v, %v, %v). Error: %v", shardID, namespaceID, workflowID, err)
592 }
593 }
594 > size := len(rows) execution_util.go
595 > if size > 1 {
596 return nil, serviceerror.NewUnavailablef("lockCurrentExecutionIfExists failed. Multiple current_executions rows for (shard,namespace,workflow) = (%v, %v, %v).", shardID, namespaceID, workflowID)
597 }
598 > if size == 0 { execution_util.go
599 > return nil, nil
600 > }
601 return &rows[0], nil
602 }
607 row sqlplugin.CurrentExecutionsRow,
608 createMode p.CreateWorkflowMode,
609 > ) error { execution_util.go
610 >
611 > switch createMode {
612 case p.CreateWorkflowModeUpdateCurrent:
613 if err := updateCurrentExecution(ctx, tx, row); err != nil {
1088 dbRecordVersion int64,
1089 shardID int32,
1090 > ) (row *sqlplugin.ExecutionsRow, err error) { execution_util.go
1091 > // TODO: double encoding execution state? executionState could've been passed to the function as
1092 > // *commonpb.DataBlob like executionInfo
1093 > stateBlob, err := m.serializer.WorkflowExecutionStateToBlob(executionState)
1094 > if err != nil {
1095 return nil, err
1096 }
1097
1098 > nsBytes, err := primitives.ParseUUID(namespaceID) execution_util.go
1099 > if err != nil {
1100 return nil, err
1101 }
1102
1103 > ridBytes, err := primitives.ParseUUID(executionState.RunId) execution_util.go
1104 > if err != nil {
1105 return nil, err
1106 }
1107
1108 > return &sqlplugin.ExecutionsRow{ execution_util.go
1109 > ShardID: shardID,
1110 > NamespaceID: nsBytes,
1111 > WorkflowID: workflowID,
1112 > RunID: ridBytes,
1113 > NextEventID: nextEventID,
1114 > LastWriteVersion: lastWriteVersion,
1115 > Data: executionInfo.Data,
1116 > DataEncoding: executionInfo.EncodingType.String(),
1117 > State: stateBlob.Data,
1118 > StateEncoding: stateBlob.EncodingType.String(),
1119 > DBRecordVersion: dbRecordVersion,
1120 > }, nil
1121 }
1122
1132 dbRecordVersion int64,
1133 shardID int32,
1134 > ) error { execution_util.go
1135 >
1136 > row, err := m.buildExecutionRow(
1137 > namespaceID,
1138 > workflowID,
1139 > executionInfo,
1140 > executionState,
1141 > nextEventID,
1142 > lastWriteVersion,
1143 > dbRecordVersion,
1144 > shardID,
1145 > )
1146 > if err != nil {
1147 return err
1148 }
1149 > result, err := tx.InsertIntoExecutions(ctx, row) execution_util.go
1150 > if err != nil {
1151 if m.DB.IsDupEntryError(err) {
1152 return &p.WorkflowConditionFailedError{
1158 return serviceerror.NewUnavailablef("createExecution failed. Erorr: %v", err)
1159 }
1160 > rowsAffected, err := result.RowsAffected() execution_util.go
1161 > if err != nil {
1162 return serviceerror.NewUnavailablef("createExecution failed. Failed to verify number of rows affected. Erorr: %v", err)
1163 }
1164 > if rowsAffected != 1 { execution_util.go
1165 return serviceerror.NewNotFoundf("createExecution failed. Affected %v rows updated instead of 1.", rowsAffected)
1166 }
1167
1168 > return nil execution_util.go
1169 }
1170
go.temporal.io/server/common/persistence/sql/execution.go 54 introduced LOC · 8 ranges

Open complete file

61 ctx context.Context,
62 request *p.InternalCreateWorkflowExecutionRequest,
63 > ) (response *p.InternalCreateWorkflowExecutionResponse, err error) { execution.go
64 > for _, req := range request.NewWorkflowNewEvents {
65 if err := m.AppendHistoryNodes(ctx, req); err != nil {
66 return nil, err
68 }
69
70 > err = m.txExecuteShardLocked(ctx, execution.go
71 > "CreateWorkflowExecution",
72 > request.ShardID,
73 > request.RangeID,
74 > func(tx sqlplugin.Tx) error {
75 > response, err = m.createWorkflowExecutionTx(ctx, tx, request)
76 > return err
77 > })
78 > return
79 }
80
83 tx sqlplugin.Tx,
84 request *p.InternalCreateWorkflowExecutionRequest,
85 > ) (*p.InternalCreateWorkflowExecutionResponse, error) { execution.go
86 >
87 > newWorkflow := request.NewWorkflowSnapshot
88 > lastWriteVersion := newWorkflow.LastWriteVersion
89 > shardID := request.ShardID
90 > namespaceID := primitives.MustParseUUID(newWorkflow.NamespaceID)
91 > workflowID := newWorkflow.WorkflowID
92 > runID := primitives.MustParseUUID(newWorkflow.RunID)
93 >
94 > var err error
95 > var currentRow *sqlplugin.CurrentExecutionsRow
96 > if currentRow, err = lockCurrentExecutionIfExists(ctx,
97 > tx,
98 > shardID,
99 > namespaceID,
100 > workflowID,
101 > request.ArchetypeID,
102 > ); err != nil {
103 return nil, err
104 }
105
106 // current run ID, last write version, current workflow state check
107 > switch request.Mode { execution.go
108 case p.CreateWorkflowModeBrandNew:
109 if currentRow == nil {
178 }
179
180 > row := sqlplugin.CurrentExecutionsRow{ execution.go
181 > ShardID: shardID,
182 > NamespaceID: namespaceID,
183 > WorkflowID: workflowID,
184 > RunID: runID,
185 > ArchetypeID: request.ArchetypeID,
186 > CreateRequestID: newWorkflow.ExecutionState.CreateRequestId,
187 > State: newWorkflow.ExecutionState.State,
188 > Status: newWorkflow.ExecutionState.Status,
189 > LastWriteVersion: lastWriteVersion,
190 > StartTime: getStartTimeFromState(newWorkflow.ExecutionState),
191 > Data: newWorkflow.ExecutionStateBlob.Data,
192 > DataEncoding: newWorkflow.ExecutionStateBlob.EncodingType.String(),
193 > }
194 >
195 > if err := createOrUpdateCurrentExecution(ctx, tx, row, request.Mode); err != nil {
196 return nil, err
197 }
198
199 > if err := m.applyWorkflowSnapshotTxAsNew(ctx, execution.go
200 > tx,
201 > shardID,
202 > &request.NewWorkflowSnapshot,
203 > ); err != nil {
204 return nil, err
205 }
206
207 > return &p.InternalCreateWorkflowExecutionResponse{}, nil execution.go
208 }
209
745 }
746
747 > func getStartTimeFromState(state *persistencespb.WorkflowExecutionState) *time.Time { execution.go
748 > if state == nil || state.StartTime == nil {
749 return nil
750 }
go.temporal.io/server/common/persistence/sql/execution_state_map.go 29 introduced LOC · 18 ranges

Open complete file

23 workflowID string,
24 runID primitives.UUID,
25 > ) error { execution_state_map.go
26 >
27 > if len(activityInfos) > 0 {
28 rows := make([]sqlplugin.ActivityInfoMapsRow, 0, len(activityInfos))
29 for scheduledEventId, blob := range activityInfos {
44 }
45
46 > if len(deleteIDs) > 0 { execution_state_map.go
47 if _, err := tx.DeleteFromActivityInfoMaps(ctx, sqlplugin.ActivityInfoMapsFilter{
48 ShardID: shardID,
114 workflowID string,
115 runID primitives.UUID,
116 > ) error { execution_state_map.go
117 >
118 > if len(timerInfos) > 0 {
119 rows := make([]sqlplugin.TimerInfoMapsRow, 0, len(timerInfos))
120 for timerID, blob := range timerInfos {
134 }
135
136 > if len(deleteIDs) > 0 { execution_state_map.go
137 if _, err := tx.DeleteFromTimerInfoMaps(ctx, sqlplugin.TimerInfoMapsFilter{
138 ShardID: shardID,
203 workflowID string,
204 runID primitives.UUID,
205 > ) error { execution_state_map.go
206 >
207 > if len(childExecutionInfos) > 0 {
208 rows := make([]sqlplugin.ChildExecutionInfoMapsRow, 0, len(childExecutionInfos))
209 for initiatedID, blob := range childExecutionInfos {
223 }
224
225 > if len(deleteIDs) > 0 { execution_state_map.go
226 if _, err := tx.DeleteFromChildExecutionInfoMaps(ctx, sqlplugin.ChildExecutionInfoMapsFilter{
227 ShardID: shardID,
293 workflowID string,
294 runID primitives.UUID,
295 > ) error { execution_state_map.go
296 >
297 > if len(requestCancelInfos) > 0 {
298 rows := make([]sqlplugin.RequestCancelInfoMapsRow, 0, len(requestCancelInfos))
299 for initiatedID, blob := range requestCancelInfos {
314 }
315
316 > if len(deleteIDs) > 0 { execution_state_map.go
317 if _, err := tx.DeleteFromRequestCancelInfoMaps(ctx, sqlplugin.RequestCancelInfoMapsFilter{
318 ShardID: shardID,
384 workflowID string,
385 runID primitives.UUID,
386 > ) error { execution_state_map.go
387 >
388 > if len(signalInfos) > 0 {
389 rows := make([]sqlplugin.SignalInfoMapsRow, 0, len(signalInfos))
390 for initiatedId, blob := range signalInfos {
405 }
406
407 > if len(deleteIDs) > 0 { execution_state_map.go
408 if _, err := tx.DeleteFromSignalInfoMaps(ctx, sqlplugin.SignalInfoMapsFilter{
409 ShardID: shardID,
475 workflowID string,
476 runID primitives.UUID,
477 > ) error { execution_state_map.go
478 > if len(chasmNodes) > 0 {
479 rows := make([]sqlplugin.ChasmNodeMapsRow, 0, len(chasmNodes))
480 for path, node := range chasmNodes {
499 }
500
501 > if len(deleteIDs) > 0 { execution_state_map.go
502 if _, err := tx.DeleteFromChasmNodeMaps(ctx, sqlplugin.ChasmNodeMapsFilter{
503 ShardID: shardID,
go.temporal.io/server/common/persistence/sql/execution_state_non_map.go 5 introduced LOC · 3 ranges

Open complete file

22 workflowID string,
23 runID primitives.UUID,
25 >
26 > if len(signalRequestedIDs) > 0 {
27 rows := make([]sqlplugin.SignalsRequestedSetsRow, 0, len(signalRequestedIDs))
28 for signalRequestedID := range signalRequestedIDs {
40 }
41
42 > if len(deleteIDs) > 0 { execution_state_non_map.go
43 if _, err := tx.DeleteFromSignalsRequestedSets(ctx, sqlplugin.SignalsRequestedSetsFilter{
44 ShardID: shardID,