scavenger.go ×13

Frontier kind: Code frontier

unlabeled · c_e3a450c6fa07

6 tests · 2124 LOC · 95 files · introduces 0 tests · 81 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges81 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
331 ranges2124 lines · 95 files · Browse complete extent
All tests (intent)
6 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.

2 files ranked by introduced lines: 81 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/worker/scanner/history/scavenger.go 70 introduced LOC · 13 ranges

Open complete file

96 logger log.Logger,
97 serializer serialization.Serializer,
98 > ) *Scavenger { scavenger.go
99 > return &Scavenger{
100 > numShards: numShards,
101 > db: db,
102 > client: client,
103 > adminClient: adminClient,
104 > registry: registry,
105 > rateLimiter: quotas.NewDefaultOutgoingRateLimiter(
106 > func() float64 { return float64(rps) },
107 ),
108 historyDataMinAge: historyDataMinAge,
117
118 // Run runs the scavenger
119 > func (s *Scavenger) Run(ctx context.Context) (ScavengerHeartbeatDetails, error) { scavenger.go
120 > reqCh := make(chan taskDetail, pageSize)
121 >
122 > go s.loadTasks(ctx, reqCh)
123 > for range numWorker {
124 > s.Add(1)
125 > go s.taskWorker(ctx, reqCh)
126 > }
127
128 > s.Wait() scavenger.go
129 >
130 > s.Lock()
131 > defer s.Unlock()
132 > return s.hbd, nil
133 }
134
136 ctx context.Context,
137 reqCh chan taskDetail,
138 > ) error { scavenger.go
139 >
140 > defer close(reqCh)
141 >
142 > iter := collection.NewPagingIteratorWithToken(s.getPaginationFn(ctx), s.hbd.NextPageToken)
143 > for iter.HasNext() {
144 > if err := s.rateLimiter.Wait(ctx); err != nil {
145 // context done
146 return err
147 }
148
149 > item, err := iter.Next() scavenger.go
150 > if err != nil {
151 return err
152 }
153
154 // Heartbeat to prevent heartbeat timeout.
155 > s.heartbeat(ctx) scavenger.go
156 >
157 > task := s.filterTask(item)
158 > if task == nil {
159 continue
160 }
175 ctx context.Context,
176 taskCh chan taskDetail,
177 > ) { scavenger.go
178 >
179 > defer s.Done()
180 >
181 > for {
182 > select {
183 case <-ctx.Done():
184 return
185
186 > case task, ok := <-taskCh: scavenger.go
187 > if !ok {
188 > return
189 > }
190
191 s.heartbeat(ctx)
195 }
196
197 > func (s *Scavenger) heartbeat(ctx context.Context) { scavenger.go
198 > s.Lock()
199 > defer s.Unlock()
200 >
201 > if !s.isInTest {
202 activity.RecordHeartbeat(ctx, s.hbd)
203 }
206 func (s *Scavenger) filterTask(
207 branch persistence.HistoryBranchDetail,
208 > ) *taskDetail { scavenger.go
209 >
210 > if time.Now().UTC().Add(-s.historyDataMinAge()).Before(timestamp.TimeValue(branch.ForkTime)) {
211 metrics.HistoryScavengerSkipCount.With(s.metricsHandler).Record(1)
212
306 func (s *Scavenger) getPaginationFn(
307 ctx context.Context,
308 > ) collection.PaginationFn[persistence.HistoryBranchDetail] { scavenger.go
309 > return func(paginationToken []byte) ([]persistence.HistoryBranchDetail, []byte, error) {
310 > req := &persistence.GetAllHistoryTreeBranchesRequest{
311 > PageSize: pageSize,
312 > NextPageToken: paginationToken,
313 > }
314 > resp, err := s.db.GetAllHistoryTreeBranches(ctx, req)
315 > if err != nil {
316 return nil, nil, err
317 }
318 > paginateItems := resp.Branches scavenger.go
319 >
320 > s.Lock()
321 > s.hbd.CurrentPage++
322 > s.hbd.NextPageToken = resp.NextPageToken
323 > s.Unlock()
324 >
325 > return paginateItems, resp.NextPageToken, nil
326 }
327 }
go.temporal.io/server/common/persistence/data_interfaces_mock.go 11 introduced LOC · 2 ranges

Open complete file

343
344 // GetAllHistoryTreeBranches mocks base method.
345 > func (m *MockExecutionManager) GetAllHistoryTreeBranches(ctx context.Context, request *GetAllHistoryTreeBranchesRequest) (*GetAllHistoryTreeBranchesResponse, error) { data_interfaces_mock.go
346 > m.ctrl.T.Helper()
347 > ret := m.ctrl.Call(m, "GetAllHistoryTreeBranches", ctx, request)
348 > ret0, _ := ret[0].(*GetAllHistoryTreeBranchesResponse)
349 > ret1, _ := ret[1].(error)
350 > return ret0, ret1
351 > }
352
353 // GetAllHistoryTreeBranches indicates an expected call of GetAllHistoryTreeBranches.
354 > func (mr *MockExecutionManagerMockRecorder) GetAllHistoryTreeBranches(ctx, request any) *gomock.Call { data_interfaces_mock.go
355 > mr.mock.ctrl.T.Helper()
356 > return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllHistoryTreeBranches", reflect.TypeOf((*MockExecutionManager)(nil).GetAllHistoryTreeBranches), ctx, request)
357 > }
358
359 // GetCurrentExecution mocks base method.