workflow_state_replicator.go ×16

Frontier kind: Joint frontier

unlabeled · c_d024d71922bb

1 test · 6666 LOC · 221 files · introduces 1 test · 82 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges82 lines · 1 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1263 ranges6666 lines · 221 files · Browse complete extent
All tests (intent)
1 testBrowse 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.

1 test introduced at this concept.

Introduced code

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

1 file ranked by introduced lines: 82 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/ndc/workflow_state_replicator.go 82 introduced LOC · 16 ranges

Open complete file

1773 originalRunID := branchInfo.GetTreeId()
1774 if runID != originalRunID {
1775 > // At this point, it already acquired the workflow lock on the run ID. workflow_state_replicator.go
1776 > // Get the lock of root run id to make sure no concurrent backfill history across multiple runs.
1777 > //
1778 > // CHASM runs have no history, so we can continue to use GetOrCreateWorkflowExecution here.
1779 > _, rootRunReleaseFn, err := r.workflowCache.GetOrCreateWorkflowExecution(
1780 > ctx,
1781 > r.shardContext,
1782 > namespaceID,
1783 > &commonpb.WorkflowExecution{
1784 > WorkflowId: workflowID,
1785 > RunId: originalRunID,
1786 > },
1787 > locks.PriorityHigh,
1788 > )
1789 > if err != nil {
1790 return err
1791 }
1792 > defer func() { workflow_state_replicator.go
1793 > if rec := recover(); rec != nil {
1794 rootRunReleaseFn(errPanic)
1795 panic(rec)
1796 }
1797 > rootRunReleaseFn(retError) workflow_state_replicator.go
1798 }()
1799 }
1809 localHistoryBatch, err := localHistoryIterator.Next()
1810 switch err.(type) {
1811 > case nil: workflow_state_replicator.go
1812 > if len(localHistoryBatch.GetEvents()) > 0 {
1813 > lastBatchNodeID = localHistoryBatch.GetEvents()[0].GetEventId()
1814 > }
1815 case *serviceerror.NotFound:
1816 default:
1864 BackfillLoop:
1865 for remoteHistoryIterator.HasNext() {
1866 > historyBlob, err := remoteHistoryIterator.Next() workflow_state_replicator.go
1867 > if err != nil {
1868 return err
1869 }
1870
1871 > if isStateBased { workflow_state_replicator.go
1872 // If backfill suceeds but later event reapply fails, during task's next retry,
1873 // we still need to reapply events that have been stored in local DB.
1882 }
1883
1884 > if historyBlob.nodeID <= lastBatchNodeID { workflow_state_replicator.go
1885 > // The history batch already in DB.
1886 > if len(sortedAncestors) > sortedAncestorsIdx {
1887 > currentAncestor := sortedAncestors[sortedAncestorsIdx]
1888 >
1889 > if historyBlob.nodeID >= currentAncestor.GetEndNodeId() {
1890 // Update ancestor.
1891 ancestors = append(ancestors, currentAncestor)
1893 }
1894 }
1895 > continue BackfillLoop workflow_state_replicator.go
1896 }
1897
1898 > branchID := historyBranch.GetBranchId() workflow_state_replicator.go
1899 > if sortedAncestorsIdx < len(sortedAncestors) {
1900 > currentAncestor := sortedAncestors[sortedAncestorsIdx]
1901 > if historyBlob.nodeID >= currentAncestor.GetEndNodeId() {
1902 > // update ancestor
1903 > ancestors = append(ancestors, currentAncestor)
1904 > sortedAncestorsIdx++
1905 > }
1906 > if sortedAncestorsIdx < len(sortedAncestors) {
1907 > // use ancestor branch id
1908 > currentAncestor = sortedAncestors[sortedAncestorsIdx]
1909 > branchID = currentAncestor.GetBranchId()
1910 > if historyBlob.nodeID < currentAncestor.GetBeginNodeId() || historyBlob.nodeID >= currentAncestor.GetEndNodeId() {
1911 return serviceerror.NewInternalf(
1912 "The backfill history blob node id %d is not in acestoer range [%d, %d]",
1919 }
1920
1921 > filteredHistoryBranch, err := historyBranchUtil.UpdateHistoryBranchInfo( workflow_state_replicator.go
1922 > backfillBranchToken,
1923 > &persistencespb.HistoryBranch{
1924 > TreeId: historyBranch.GetTreeId(),
1925 > BranchId: branchID,
1926 > Ancestors: ancestors,
1927 > },
1928 > runID,
1929 > )
1930 > if err != nil {
1931 return err
1932 }
1933 > txnID, err := r.shardContext.GenerateTaskID() workflow_state_replicator.go
1934 > if err != nil {
1935 return err
1936 }
1937
1938 > if r.enablePersistenceRateLimiter(nsName) { workflow_state_replicator.go
1939 if err := r.persistenceRateLimiter.Wait(ctx, quotaRequest); err != nil {
1940 return err
1941 }
1942 }
1943 > _, err = r.executionMgr.AppendRawHistoryNodes(ctx, &persistence.AppendRawHistoryNodesRequest{ workflow_state_replicator.go
1944 > ShardID: r.shardContext.GetShardID(),
1945 > IsNewBranch: prevBranchID != branchID,
1946 > BranchToken: filteredHistoryBranch,
1947 > History: historyBlob.rawHistory,
1948 > PrevTransactionID: prevTxnID,
1949 > TransactionID: txnID,
1950 > NodeID: historyBlob.nodeID,
1951 > Info: persistence.BuildHistoryGarbageCleanupInfo(
1952 > namespaceID.String(),
1953 > workflowID,
1954 > runID,
1955 > ),
1956 > })
1957 > if err != nil {
1958 return err
1959 }
1960 > prevTxnID = txnID workflow_state_replicator.go
1961 > prevBranchID = branchID
1962 }
1963
1984 return nil, nil, err
1985 }
1986 > return slices.Clone(response.History), response.NextPageToken, nil workflow_state_replicator.go
1987 }
1988 }
2064 func sortAncestors(ans []*persistencespb.HistoryBranchRange) []*persistencespb.HistoryBranchRange {
2065 if len(ans) > 0 {
2066 > // sort ans based onf EndNodeID so that we can set BeginNodeID workflow_state_replicator.go
2067 > sort.Slice(ans, func(i, j int) bool { return ans[i].GetEndNodeId() < ans[j].GetEndNodeId() })
2068 > ans[0].BeginNodeId = int64(1)
2069 > for i := 1; i < len(ans); i++ {
2070 > ans[i].BeginNodeId = ans[i-1].GetEndNodeId()
2071 > }
2072 }
2073 return ans