68
}
69
}
71
>
// this is the case the new branch will inherit all ancestors from forking branch
72
>
newAncestors = forkBranch.Ancestors
73
>
newAncestors = append(newAncestors, &persistencespb.HistoryBranchRange{
74
>
BranchId: forkBranch.GetBranchId(),
75
>
BeginNodeId: beginNodeID,
76
>
EndNodeId: request.ForkNodeID,
77
>
})
78
>
}
79
>
newBranchInfo := &persistencespb.HistoryBranch{
80
>
TreeId: forkBranch.TreeId,
81
>
BranchId: uuid.NewString(),
82
>
Ancestors: newAncestors,
83
>
}
84
>
85
>
// The above newBranchInfo is a lossy construction of the forked branch token from the original opaque branch token.
86
>
// It only initializes with the fields it understands, which may inadvertently discard other misc fields. The
87
>
// following is the replacement logic to correctly apply the updated fields into the original opaque branch token.
88
>
newBranchToken, err := m.GetHistoryBranchUtil().UpdateHistoryBranchInfo(
89
>
request.ForkBranchToken,
90
>
newBranchInfo,
91
>
request.NewRunID,
92
>
)
93
>
if err != nil {
94
return nil, err
95
}
96
98
>
BranchToken: newBranchToken,
99
>
BranchInfo: newBranchInfo,
100
>
ForkTime: timestamp.TimeNowPtrUtc(),
101
>
Info: request.Info,
102
>
}
103
>
104
>
treeInfoBlob, err := m.serializer.HistoryTreeInfoToBlob(treeInfo)
105
>
if err != nil {
106
return nil, err
107
}
108
110
>
NewBranchToken: newBranchToken,
111
>
ForkBranchInfo: forkBranch,
112
>
TreeInfo: treeInfoBlob,
113
>
ForkNodeID: request.ForkNodeID,
114
>
NewBranchID: newBranchInfo.BranchId,
115
>
Info: request.Info,
116
>
ShardID: request.ShardID,
117
>
}
118
>
119
>
err = m.persistence.ForkHistoryBranch(ctx, req)
120
>
if err != nil {
121
return nil, err
122
}
123
125
>
NewBranchToken: newBranchToken,
126
>
}, nil
127
}
128