mutable_state_impl.go ×16

Frontier kind: Code frontier

unlabeled · c_f680a39613c7

321 tests · 3967 LOC · 164 files · introduces 0 tests · 92 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges92 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
624 ranges3967 lines · 164 files · Browse complete extent
All tests (intent)
321 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.

3 files ranked by introduced lines: 92 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/workflow/mutable_state_impl.go 83 introduced LOC · 16 ranges

Open complete file

668 }
669
670 > func (ms *MutableStateImpl) IsWorkflow() bool { mutable_state_impl.go
671 > return ms.chasmTree.ArchetypeID() == chasm.WorkflowArchetypeID
672 > }
673
674 func (ms *MutableStateImpl) HSM() *hsm.Node {
7416 // isStateDirty is used upon closing transaction to determine if application data has been updated, and
7417 // mutable state should move to a new versioned transition.
7418 > func (ms *MutableStateImpl) isStateDirty() bool { mutable_state_impl.go
7419 > // TODO: we need to track more workflow state changes
7420 > // e.g. changes to executionInfo.CancelRequested
7421 > // They are mostly covered by history builder check today.
7422 > return ms.hBuilder.IsDirty() ||
7423 > len(ms.activityInfosUserDataUpdated) > 0 ||
7424 > len(ms.deleteActivityInfos) > 0 ||
7425 > len(ms.timerInfosUserDataUpdated) > 0 ||
7426 > len(ms.deleteTimerInfos) > 0 ||
7427 > len(ms.updateChildExecutionInfos) > 0 ||
7428 > len(ms.deleteChildExecutionInfos) > 0 ||
7429 > len(ms.updateRequestCancelInfos) > 0 ||
7430 > len(ms.deleteRequestCancelInfos) > 0 ||
7431 > len(ms.updateSignalInfos) > 0 ||
7432 > len(ms.deleteSignalInfos) > 0 ||
7433 > len(ms.updateSignalRequestedIDs) > 0 ||
7434 > len(ms.deleteSignalRequestedIDs) > 0 ||
7435 > len(ms.updateInfoUpdated) > 0 ||
7436 > ms.visibilityUpdated ||
7437 > ms.executionStateUpdated ||
7438 > ms.workflowTaskUpdated ||
7439 > (ms.stateMachineNode != nil && ms.stateMachineNode.Dirty()) ||
7440 > ms.chasmTree.IsStateDirty() ||
7441 > ms.isResetStateUpdated ||
7442 > ms.timeSkippingInfoUpdated
7443 > }
7444
7445 func (ms *MutableStateImpl) IsTransitionHistoryEnabled() bool {
7669 }
7670
7671 > if err := ms.closeTransactionHandleWorkflowTask( mutable_state_impl.go
7672 > transactionPolicy,
7673 > ); err != nil {
7674 return closeTransactionResult{}, err
7675 }
7681 // and need to reconsider the sequence of time skipping close trx handling in this function
7682 // when supporting chasm.
7683 > regenTimerTasksForWorkflowTimeSkipping := ms.closeTransactionHandleWorkflowTimeSkipping(ctx, transactionPolicy) mutable_state_impl.go
7684 >
7685 > // Save if the state is dirty before closeTransactionPrepareEvents since it flushes the buffer
7686 > // events, and therefore change the dirty state.
7687 > isStateDirty := ms.isStateDirty()
7688 >
7689 > // closeTransactionPrepareEvents must be called after closeTransactionHandleWorkflowTask because
7690 > // the latter might fail the workflow task and buffered events must be flushed afterwards.
7691 > // We need to save the value of ms.isStateDirty() before calling closeTransactionPrepareEvents
7692 > // because flushing the buffered events might change the dirty state.
7693 > workflowEventsSeq, eventBatches, bufferEvents, clearBuffer, err := ms.closeTransactionPrepareEvents(transactionPolicy)
7694 > if err != nil {
7695 return closeTransactionResult{}, err
7696 }
7798 func (ms *MutableStateImpl) closeTransactionHandleWorkflowTask(
7799 transactionPolicy historyi.TransactionPolicy,
7800 > ) error { mutable_state_impl.go
7801 > if err := ms.closeTransactionHandleBufferedEventsLimit(
7802 > transactionPolicy,
7803 > ); err != nil {
7804 return err
7805 }
7806
7807 > if err := ms.closeTransactionHandleWorkflowTaskScheduling( mutable_state_impl.go
7808 > transactionPolicy,
7809 > ); err != nil {
7810 return err
7811 }
7812
7813 > return ms.closeTransactionHandleSpeculativeWorkflowTask(transactionPolicy) mutable_state_impl.go
7814 }
7815
7816 func (ms *MutableStateImpl) closeTransactionHandleWorkflowTaskScheduling(
7817 transactionPolicy historyi.TransactionPolicy,
7818 > ) error { mutable_state_impl.go
7819 > if transactionPolicy == historyi.TransactionPolicyPassive ||
7820 > !ms.IsWorkflowExecutionRunning() {
7821 return nil
7822 }
7845 func (ms *MutableStateImpl) closeTransactionHandleSpeculativeWorkflowTask(
7846 transactionPolicy historyi.TransactionPolicy,
7847 > ) error { mutable_state_impl.go
7848 > if transactionPolicy == historyi.TransactionPolicyPassive ||
7849 > !ms.IsWorkflowExecutionRunning() {
7850 return nil
7851 }
8412 func (ms *MutableStateImpl) closeTransactionPrepareEvents(
8413 transactionPolicy historyi.TransactionPolicy,
8414 > ) ([]*persistence.WorkflowEvents, [][]*historypb.HistoryEvent, []*historypb.HistoryEvent, bool, error) { mutable_state_impl.go
8415 > currentBranchToken, err := ms.GetCurrentBranchToken()
8416 > if err != nil {
8417 return nil, nil, nil, false, err
8418 }
8419
8420 > historyMutation, err := ms.hBuilder.Finish(!ms.HasStartedWorkflowTask()) mutable_state_impl.go
8421 > if err != nil {
8422 return nil, nil, nil, false, err
8423 }
8424
8425 // TODO @wxing1292 need more refactoring to make the logic clean
8426 > ms.bufferEventsInDB = historyMutation.MemBufferBatch mutable_state_impl.go
8427 > newBufferBatch := historyMutation.DBBufferBatch
8428 > clearBuffer := historyMutation.DBClearBuffer
8429 > newEventsBatches := historyMutation.DBEventsBatches
8430 > ms.updatePendingEventIDs(historyMutation.ScheduledIDToStartedID, historyMutation.RequestIDToEventID)
8431 >
8432 > workflowEventsSeq := make([]*persistence.WorkflowEvents, len(newEventsBatches))
8433 > historyNodeTxnIDs, err := ms.shard.GenerateTaskIDs(len(newEventsBatches))
8434 > if err != nil {
8435 return nil, nil, nil, false, err
8436 }
8437 > for index, eventBatch := range newEventsBatches { mutable_state_impl.go
8438 workflowEventsSeq[index] = &persistence.WorkflowEvents{
8439 NamespaceID: ms.executionInfo.NamespaceId,
8459 }
8460
8461 > if err := ms.validateNoEventsAfterWorkflowFinish( mutable_state_impl.go
8462 > transactionPolicy,
8463 > workflowEventsSeq,
8464 > ); err != nil {
8465 return nil, nil, nil, false, err
8466 }
8646 transactionPolicy historyi.TransactionPolicy,
8647 workflowEventSeq []*persistence.WorkflowEvents,
8648 > ) error { mutable_state_impl.go
8649 > if transactionPolicy == historyi.TransactionPolicyPassive ||
8650 > len(workflowEventSeq) == 0 {
8651 return nil
8652 }
8839 func (ms *MutableStateImpl) closeTransactionHandleBufferedEventsLimit(
8840 transactionPolicy historyi.TransactionPolicy,
8841 > ) error { mutable_state_impl.go
8842 > if transactionPolicy == historyi.TransactionPolicyPassive ||
8843 > !ms.IsWorkflowExecutionRunning() {
8844 return nil
8845 }
go.temporal.io/server/service/history/shard/context_impl.go 7 introduced LOC · 2 ranges

Open complete file

332 }
333
334 > func (s *ContextImpl) GenerateTaskIDs(number int) ([]int64, error) { context_impl.go
335 > s.wLock()
336 > defer s.wUnlock()
337 >
338 > result := []int64{}
339 > for range number {
340 id, err := s.generateTaskIDLocked()
341 if err != nil {
344 result = append(result, id)
345 }
346 > return result, nil context_impl.go
347 }
348
go.temporal.io/server/service/history/workflow/timeskipping.go 2 introduced LOC · 1 range

Open complete file

433 ctx context.Context,
434 transactionPolicy historyi.TransactionPolicy,
435 > ) (needRegenTasks bool) { timeskipping.go
436 > if !ms.IsWorkflow() {
437 return false
438 }