• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 018f1248-bf4e-4f7f-ada2-77eea52238e3

24 Apr 2024 10:45PM UTC coverage: 67.714% (-0.02%) from 67.734%
018f1248-bf4e-4f7f-ada2-77eea52238e3

push

buildkite

web-flow
Fix slice reuse in cassandra/domain.go (#5937)

While reading domains from Cassandra the isolationGroups and asncWFConfigData are not properly reset for each row. This can result in the same backing array being reused across multiple rows, resulting in an incorrect or corrupted value being read. Notably this is used for the domain cache, so any operation relying on it may be unable to get the correct values of these fields.

4 of 19 new or added lines in 2 files covered. (21.05%)

66 existing lines in 11 files now uncovered.

99255 of 146579 relevant lines covered (67.71%)

2400.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.79
/common/persistence/statsComputer.go
1
// Copyright (c) 2017-2020 Uber Technologies, Inc.
2
// Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy
5
// of this software and associated documentation files (the "Software"), to deal
6
// in the Software without restriction, including without limitation the rights
7
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
// copies of the Software, and to permit persons to whom the Software is
9
// furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
// THE SOFTWARE.
21

22
package persistence
23

24
type (
25
        // statsComputer is to computing struct sizes after serialization
26
        statsComputer struct{}
27
)
28

29
func (sc *statsComputer) computeMutableStateStats(req *InternalGetWorkflowExecutionResponse) *MutableStateStats {
734✔
30
        executionInfoSize := computeExecutionInfoSize(req.State.ExecutionInfo)
734✔
31

734✔
32
        activityInfoCount := 0
734✔
33
        activityInfoSize := 0
734✔
34
        for _, ai := range req.State.ActivityInfos {
842✔
35
                activityInfoCount++
108✔
36
                activityInfoSize += computeActivityInfoSize(ai)
108✔
37
        }
108✔
38

39
        timerInfoCount := 0
734✔
40
        timerInfoSize := 0
734✔
41
        for _, ti := range req.State.TimerInfos {
736✔
42
                timerInfoCount++
2✔
43
                timerInfoSize += computeTimerInfoSize(ti)
2✔
44
        }
2✔
45

46
        childExecutionInfoCount := 0
734✔
47
        childExecutionInfoSize := 0
734✔
48
        for _, ci := range req.State.ChildExecutionInfos {
738✔
49
                childExecutionInfoCount++
4✔
50
                childExecutionInfoSize += computeChildInfoSize(ci)
4✔
51
        }
4✔
52

53
        signalInfoCount := 0
734✔
54
        signalInfoSize := 0
734✔
55
        for _, si := range req.State.SignalInfos {
734✔
UNCOV
56
                signalInfoCount++
×
UNCOV
57
                signalInfoSize += computeSignalInfoSize(si)
×
UNCOV
58
        }
×
59

60
        bufferedEventsCount := 0
734✔
61
        bufferedEventsSize := 0
734✔
62

734✔
63
        for _, be := range req.State.BufferedEvents {
737✔
64
                bufferedEventsCount++
3✔
65
                bufferedEventsSize += len(be.Data)
3✔
66
        }
3✔
67

68
        requestCancelInfoCount := len(req.State.RequestCancelInfos)
734✔
69

734✔
70
        totalSize := executionInfoSize
734✔
71
        totalSize += activityInfoSize
734✔
72
        totalSize += timerInfoSize
734✔
73
        totalSize += childExecutionInfoSize
734✔
74
        totalSize += signalInfoSize
734✔
75
        totalSize += bufferedEventsSize
734✔
76

734✔
77
        return &MutableStateStats{
734✔
78
                MutableStateSize:       totalSize,
734✔
79
                ExecutionInfoSize:      executionInfoSize,
734✔
80
                ActivityInfoSize:       activityInfoSize,
734✔
81
                TimerInfoSize:          timerInfoSize,
734✔
82
                ChildInfoSize:          childExecutionInfoSize,
734✔
83
                SignalInfoSize:         signalInfoSize,
734✔
84
                BufferedEventsSize:     bufferedEventsSize,
734✔
85
                ActivityInfoCount:      activityInfoCount,
734✔
86
                TimerInfoCount:         timerInfoCount,
734✔
87
                ChildInfoCount:         childExecutionInfoCount,
734✔
88
                SignalInfoCount:        signalInfoCount,
734✔
89
                BufferedEventsCount:    bufferedEventsCount,
734✔
90
                RequestCancelInfoCount: requestCancelInfoCount,
734✔
91
        }
734✔
92
}
93

94
func (sc *statsComputer) computeMutableStateUpdateStats(req *InternalUpdateWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
4,360✔
95
        if req.NewWorkflowSnapshot != nil {
4,535✔
96
                return mergeMutableStateUpdateSessionStats(sc.computeWorkflowMutationStats(&req.UpdateWorkflowMutation), sc.computeWorkflowSnapshotStats(req.NewWorkflowSnapshot))
175✔
97
        }
175✔
98
        return sc.computeWorkflowMutationStats(&req.UpdateWorkflowMutation)
4,188✔
99
}
100

101
func (sc *statsComputer) computeMutableStateCreateStats(req *InternalCreateWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
522✔
102
        return sc.computeWorkflowSnapshotStats(&req.NewWorkflowSnapshot)
522✔
103
}
522✔
104

105
func (sc *statsComputer) computeMutableStateConflictResolveStats(req *InternalConflictResolveWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
3✔
106
        mss := sc.computeWorkflowSnapshotStats(&req.ResetWorkflowSnapshot)
3✔
107
        if req.NewWorkflowSnapshot != nil {
3✔
108
                mss = mergeMutableStateUpdateSessionStats(mss, sc.computeWorkflowSnapshotStats(req.NewWorkflowSnapshot))
×
109
        }
×
110
        if req.CurrentWorkflowMutation != nil {
4✔
111
                mss = mergeMutableStateUpdateSessionStats(mss, sc.computeWorkflowMutationStats(req.CurrentWorkflowMutation))
1✔
112
        }
1✔
113
        return mss
3✔
114
}
115

116
func (sc *statsComputer) computeWorkflowMutationStats(req *InternalWorkflowMutation) *MutableStateUpdateSessionStats {
4,361✔
117
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
4,361✔
118

4,361✔
119
        activityInfoCount := 0
4,361✔
120
        activityInfoSize := 0
4,361✔
121
        for _, ai := range req.UpsertActivityInfos {
5,597✔
122
                activityInfoCount++
1,236✔
123
                activityInfoSize += computeActivityInfoSize(ai)
1,236✔
124
        }
1,236✔
125

126
        timerInfoCount := 0
4,361✔
127
        timerInfoSize := 0
4,361✔
128
        for _, ti := range req.UpsertTimerInfos {
4,397✔
129
                timerInfoCount++
36✔
130
                timerInfoSize += computeTimerInfoSize(ti)
36✔
131
        }
36✔
132

133
        childExecutionInfoCount := 0
4,361✔
134
        childExecutionInfoSize := 0
4,361✔
135
        for _, ci := range req.UpsertChildExecutionInfos {
4,404✔
136
                childExecutionInfoCount++
43✔
137
                childExecutionInfoSize += computeChildInfoSize(ci)
43✔
138
        }
43✔
139

140
        signalInfoCount := 0
4,361✔
141
        signalInfoSize := 0
4,361✔
142
        for _, si := range req.UpsertSignalInfos {
4,377✔
143
                signalInfoCount++
16✔
144
                signalInfoSize += computeSignalInfoSize(si)
16✔
145
        }
16✔
146

147
        bufferedEventsSize := 0
4,361✔
148
        if req.NewBufferedEvents != nil {
5,004✔
149
                bufferedEventsSize = len(req.NewBufferedEvents.Data)
643✔
150
        }
643✔
151

152
        requestCancelInfoCount := len(req.UpsertRequestCancelInfos)
4,361✔
153

4,361✔
154
        deleteActivityInfoCount := len(req.DeleteActivityInfos)
4,361✔
155

4,361✔
156
        deleteTimerInfoCount := len(req.DeleteTimerInfos)
4,361✔
157

4,361✔
158
        deleteChildInfoCount := len(req.DeleteChildExecutionInfos)
4,361✔
159

4,361✔
160
        deleteSignalInfoCount := len(req.DeleteSignalInfos)
4,361✔
161

4,361✔
162
        deleteRequestCancelInfoCount := len(req.DeleteRequestCancelInfos)
4,361✔
163

4,361✔
164
        transferTasksCount := len(req.TransferTasks)
4,361✔
165
        crossClusterTasksCount := len(req.CrossClusterTasks)
4,361✔
166
        timerTasksCount := len(req.TimerTasks)
4,361✔
167
        replicationTasksCount := len(req.ReplicationTasks)
4,361✔
168

4,361✔
169
        totalSize := executionInfoSize
4,361✔
170
        totalSize += activityInfoSize
4,361✔
171
        totalSize += timerInfoSize
4,361✔
172
        totalSize += childExecutionInfoSize
4,361✔
173
        totalSize += signalInfoSize
4,361✔
174
        totalSize += bufferedEventsSize
4,361✔
175

4,361✔
176
        return &MutableStateUpdateSessionStats{
4,361✔
177
                MutableStateSize:             totalSize,
4,361✔
178
                ExecutionInfoSize:            executionInfoSize,
4,361✔
179
                ActivityInfoSize:             activityInfoSize,
4,361✔
180
                TimerInfoSize:                timerInfoSize,
4,361✔
181
                ChildInfoSize:                childExecutionInfoSize,
4,361✔
182
                SignalInfoSize:               signalInfoSize,
4,361✔
183
                BufferedEventsSize:           bufferedEventsSize,
4,361✔
184
                ActivityInfoCount:            activityInfoCount,
4,361✔
185
                TimerInfoCount:               timerInfoCount,
4,361✔
186
                ChildInfoCount:               childExecutionInfoCount,
4,361✔
187
                SignalInfoCount:              signalInfoCount,
4,361✔
188
                RequestCancelInfoCount:       requestCancelInfoCount,
4,361✔
189
                DeleteActivityInfoCount:      deleteActivityInfoCount,
4,361✔
190
                DeleteTimerInfoCount:         deleteTimerInfoCount,
4,361✔
191
                DeleteChildInfoCount:         deleteChildInfoCount,
4,361✔
192
                DeleteSignalInfoCount:        deleteSignalInfoCount,
4,361✔
193
                DeleteRequestCancelInfoCount: deleteRequestCancelInfoCount,
4,361✔
194
                TransferTasksCount:           transferTasksCount,
4,361✔
195
                CrossClusterTaskCount:        crossClusterTasksCount,
4,361✔
196
                TimerTasksCount:              timerTasksCount,
4,361✔
197
                ReplicationTasksCount:        replicationTasksCount,
4,361✔
198
        }
4,361✔
199
}
200

201
func (sc *statsComputer) computeWorkflowSnapshotStats(req *InternalWorkflowSnapshot) *MutableStateUpdateSessionStats {
695✔
202
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
695✔
203

695✔
204
        activityInfoCount := 0
695✔
205
        activityInfoSize := 0
695✔
206
        for _, ai := range req.ActivityInfos {
718✔
207
                activityInfoCount++
23✔
208
                activityInfoSize += computeActivityInfoSize(ai)
23✔
209
        }
23✔
210

211
        timerInfoCount := 0
695✔
212
        timerInfoSize := 0
695✔
213
        for _, ti := range req.TimerInfos {
698✔
214
                timerInfoCount++
3✔
215
                timerInfoSize += computeTimerInfoSize(ti)
3✔
216
        }
3✔
217

218
        childExecutionInfoCount := 0
695✔
219
        childExecutionInfoSize := 0
695✔
220
        for _, ci := range req.ChildExecutionInfos {
699✔
221
                childExecutionInfoCount++
4✔
222
                childExecutionInfoSize += computeChildInfoSize(ci)
4✔
223
        }
4✔
224

225
        signalInfoCount := 0
695✔
226
        signalInfoSize := 0
695✔
227
        for _, si := range req.SignalInfos {
696✔
228
                signalInfoCount++
1✔
229
                signalInfoSize += computeSignalInfoSize(si)
1✔
230
        }
1✔
231

232
        requestCancelInfoCount := len(req.RequestCancelInfos)
695✔
233

695✔
234
        transferTasksCount := len(req.TransferTasks)
695✔
235
        crossClusterTasksCount := len(req.CrossClusterTasks)
695✔
236
        timerTasksCount := len(req.TimerTasks)
695✔
237
        replicationTasksCount := len(req.ReplicationTasks)
695✔
238

695✔
239
        totalSize := executionInfoSize
695✔
240
        totalSize += activityInfoSize
695✔
241
        totalSize += timerInfoSize
695✔
242
        totalSize += childExecutionInfoSize
695✔
243
        totalSize += signalInfoSize
695✔
244

695✔
245
        return &MutableStateUpdateSessionStats{
695✔
246
                MutableStateSize:       totalSize,
695✔
247
                ExecutionInfoSize:      executionInfoSize,
695✔
248
                ActivityInfoSize:       activityInfoSize,
695✔
249
                TimerInfoSize:          timerInfoSize,
695✔
250
                ChildInfoSize:          childExecutionInfoSize,
695✔
251
                SignalInfoSize:         signalInfoSize,
695✔
252
                ActivityInfoCount:      activityInfoCount,
695✔
253
                TimerInfoCount:         timerInfoCount,
695✔
254
                ChildInfoCount:         childExecutionInfoCount,
695✔
255
                SignalInfoCount:        signalInfoCount,
695✔
256
                RequestCancelInfoCount: requestCancelInfoCount,
695✔
257
                TransferTasksCount:     transferTasksCount,
695✔
258
                CrossClusterTaskCount:  crossClusterTasksCount,
695✔
259
                TimerTasksCount:        timerTasksCount,
695✔
260
                ReplicationTasksCount:  replicationTasksCount,
695✔
261
        }
695✔
262
}
263

264
func mergeMutableStateUpdateSessionStats(stats ...*MutableStateUpdateSessionStats) *MutableStateUpdateSessionStats {
175✔
265
        result := &MutableStateUpdateSessionStats{}
175✔
266
        for _, s := range stats {
522✔
267
                result.MutableStateSize += s.MutableStateSize
347✔
268

347✔
269
                result.ExecutionInfoSize += s.ExecutionInfoSize
347✔
270
                result.ActivityInfoSize += s.ActivityInfoSize
347✔
271
                result.TimerInfoSize += s.TimerInfoSize
347✔
272
                result.ChildInfoSize += s.ChildInfoSize
347✔
273
                result.SignalInfoSize += s.SignalInfoSize
347✔
274
                result.BufferedEventsSize += s.BufferedEventsSize
347✔
275

347✔
276
                result.ActivityInfoCount += s.ActivityInfoCount
347✔
277
                result.TimerInfoCount += s.TimerInfoCount
347✔
278
                result.ChildInfoCount += s.ChildInfoCount
347✔
279
                result.SignalInfoCount += s.SignalInfoCount
347✔
280
                result.RequestCancelInfoCount += s.RequestCancelInfoCount
347✔
281

347✔
282
                result.DeleteActivityInfoCount += s.DeleteActivityInfoCount
347✔
283
                result.DeleteTimerInfoCount += s.DeleteTimerInfoCount
347✔
284
                result.DeleteChildInfoCount += s.DeleteChildInfoCount
347✔
285
                result.DeleteSignalInfoCount += s.DeleteSignalInfoCount
347✔
286
                result.DeleteRequestCancelInfoCount += s.DeleteRequestCancelInfoCount
347✔
287

347✔
288
                result.TransferTasksCount += s.TransferTasksCount
347✔
289
                result.CrossClusterTaskCount += s.CrossClusterTaskCount
347✔
290
                result.TimerInfoCount += s.TimerInfoCount
347✔
291
                result.ReplicationTasksCount += s.ReplicationTasksCount
347✔
292
        }
347✔
293
        return result
175✔
294
}
295

296
func computeExecutionInfoSize(executionInfo *InternalWorkflowExecutionInfo) int {
5,786✔
297
        size := len(executionInfo.WorkflowID)
5,786✔
298
        size += len(executionInfo.TaskList)
5,786✔
299
        size += len(executionInfo.WorkflowTypeName)
5,786✔
300
        size += len(executionInfo.ParentWorkflowID)
5,786✔
301

5,786✔
302
        return size
5,786✔
303
}
5,786✔
304

305
func computeActivityInfoSize(ai *InternalActivityInfo) int {
1,363✔
306
        size := len(ai.ActivityID)
1,363✔
307
        if ai.ScheduledEvent != nil {
1,365✔
308
                size += len(ai.ScheduledEvent.Data)
2✔
309
        }
2✔
310
        if ai.StartedEvent != nil {
1,365✔
311
                size += len(ai.StartedEvent.Data)
2✔
312
        }
2✔
313
        size += len(ai.Details)
1,363✔
314

1,363✔
315
        return size
1,363✔
316
}
317

318
func computeTimerInfoSize(ti *TimerInfo) int {
42✔
319
        size := len(ti.TimerID)
42✔
320

42✔
321
        return size
42✔
322
}
42✔
323

324
func computeChildInfoSize(ci *InternalChildExecutionInfo) int {
52✔
325
        size := 0
52✔
326
        if ci.InitiatedEvent != nil {
52✔
327
                size += len(ci.InitiatedEvent.Data)
×
328
        }
×
329
        if ci.StartedEvent != nil {
52✔
330
                size += len(ci.StartedEvent.Data)
×
331
        }
×
332
        return size
52✔
333
}
334

335
func computeSignalInfoSize(si *SignalInfo) int {
19✔
336
        size := len(si.SignalName)
19✔
337
        size += len(si.Input)
19✔
338
        size += len(si.Control)
19✔
339

19✔
340
        return size
19✔
341
}
19✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc