141
// However, it is possible that part of the target branch (or its ancestors) is used as ancestors by other branch.
142
// We need to avoid deleting those referenced parts. This is similar to reference count in garbage collection.
144
>
brsToDelete = append(brsToDelete, &persistencespb.HistoryBranchRange{
145
>
BranchId: branch.GetBranchId(),
146
>
BeginNodeId: GetBeginNodeID(branch),
147
>
})
148
>
149
>
// Get the history tree containing the branch to be delelted,
150
>
// so we know if any part of the target branch is referenced by other branches.
151
>
historyTreeResp, err := m.persistence.GetHistoryTreeContainingBranch(ctx, &InternalGetHistoryTreeContainingBranchRequest{
152
>
BranchToken: request.BranchToken,
153
>
ShardID: request.ShardID,
154
>
})
155
>
if err != nil {
156
return err
157
}
158
160
>
if err != nil {
161
return err
162
}
163
164
// usedBranches record branches referenced by others
166
>
for _, branchInfo := range branchInfos {
167
>
if branchInfo.BranchId == branch.BranchId {
168
>
// skip the target branch
169
>
continue
170
}
171
usedBranches[branchInfo.BranchId] = common.LastEventID