history_manager.go ×9

Frontier kind: Code frontier

unlabeled · c_ba8a1fd2691f

35 tests · 3382 LOC · 157 files · introduces 0 tests · 47 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
9 ranges47 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
545 ranges3382 lines · 157 files · Browse complete extent
All tests (intent)
35 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.

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

go.temporal.io/server/common/persistence/history_manager.go 47 introduced LOC · 9 ranges

Open complete file

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.
143 > brsToDelete := branch.Ancestors history_manager.go
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
159 > branchInfos, err := m.deserializeBranchInfos(historyTreeResp) history_manager.go
160 > if err != nil {
161 return err
162 }
163
164 // usedBranches record branches referenced by others
165 > usedBranches := map[string]int64{} history_manager.go
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
177 }
178
179 > var deleteRanges []InternalDeleteHistoryBranchRange history_manager.go
180 > // for each branch range to delete, we iterate from bottom up, and stop when the range is also used by others
181 > findDeleteRanges:
182 > for i := len(brsToDelete) - 1; i >= 0; i-- {
183 > br := brsToDelete[i]
184 > if maxEndNode, ok := usedBranches[br.GetBranchId()]; ok {
185 // branch is used by others, we can only delete from the maxEndNode
186 if maxEndNode != common.LastEventID {
192 // all ancestors are also used, no need to go up further,
193 break findDeleteRanges
194 > } else { history_manager.go
195 > // No other branch is using this range, we can delete all of it
196 > deleteRanges = append(deleteRanges, InternalDeleteHistoryBranchRange{
197 > BranchId: br.BranchId,
198 > BeginNodeId: br.BeginNodeId,
199 > })
200 > }
201 }
202
203 > req := &InternalDeleteHistoryBranchRequest{ history_manager.go
204 > BranchToken: request.BranchToken,
205 > BranchInfo: branch,
206 > ShardID: request.ShardID,
207 > BranchRanges: deleteRanges,
208 > }
209 > return m.persistence.DeleteHistoryBranch(ctx, req)
210 }
211
310 func (m *executionManagerImpl) deserializeBranchInfos(
311 historyTreeResp *InternalGetHistoryTreeContainingBranchResponse,
312 > ) ([]*persistencespb.HistoryBranch, error) { history_manager.go
313 > branchInfos := make([]*persistencespb.HistoryBranch, 0, len(historyTreeResp.TreeInfos))
314 > for _, blob := range historyTreeResp.TreeInfos {
315 > treeInfo, err := m.serializer.HistoryTreeInfoFromBlob(blob)
316 > if err != nil {
317 return nil, err
318 }
319 > branchInfos = append(branchInfos, treeInfo.BranchInfo) history_manager.go
320 }
321 > return branchInfos, nil history_manager.go
322 }
323