Skip to content

Commit 78cb0a1

Browse files
authored
Split mutable_state_util.go by purpose (#6577)
It's rather confusing that this file is half test-only helpers and half "used TONS of locations" utils. So let's split it up. Since these are used in multiple packages, I can't make them private, and they also use private things in this package so I can't move them out. So it's just split. Not ideal but an improvement at least.
1 parent e20443c commit 78cb0a1

File tree

2 files changed

+283
-254
lines changed

2 files changed

+283
-254
lines changed

service/history/execution/mutable_state_util.go

Lines changed: 0 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
package execution
2323

2424
import (
25-
"encoding/json"
26-
"testing"
27-
28-
"golang.org/x/exp/slices"
29-
3025
"github.com/uber/cadence/common/cache"
3126
"github.com/uber/cadence/common/clock"
3227
"github.com/uber/cadence/common/persistence"
@@ -144,234 +139,6 @@ func FindAutoResetPoint(
144139
return "", nil
145140
}
146141

147-
// CreatePersistenceMutableState creates a persistence mutable state based on the its in-memory version
148-
func CreatePersistenceMutableState(t *testing.T, ms MutableState) *persistence.WorkflowMutableState {
149-
builder := ms.(*mutableStateBuilder)
150-
builder.FlushBufferedEvents() //nolint:errcheck
151-
info := CopyWorkflowExecutionInfo(t, builder.GetExecutionInfo())
152-
stats := &persistence.ExecutionStats{}
153-
activityInfos := make(map[int64]*persistence.ActivityInfo)
154-
for id, info := range builder.GetPendingActivityInfos() {
155-
activityInfos[id] = CopyActivityInfo(t, info)
156-
}
157-
timerInfos := make(map[string]*persistence.TimerInfo)
158-
for id, info := range builder.GetPendingTimerInfos() {
159-
timerInfos[id] = CopyTimerInfo(t, info)
160-
}
161-
cancellationInfos := make(map[int64]*persistence.RequestCancelInfo)
162-
for id, info := range builder.GetPendingRequestCancelExternalInfos() {
163-
cancellationInfos[id] = CopyCancellationInfo(t, info)
164-
}
165-
signalInfos := make(map[int64]*persistence.SignalInfo)
166-
for id, info := range builder.GetPendingSignalExternalInfos() {
167-
signalInfos[id] = CopySignalInfo(t, info)
168-
}
169-
childInfos := make(map[int64]*persistence.ChildExecutionInfo)
170-
for id, info := range builder.GetPendingChildExecutionInfos() {
171-
childInfos[id] = CopyChildInfo(t, info)
172-
}
173-
174-
builder.FlushBufferedEvents() //nolint:errcheck
175-
var bufferedEvents []*types.HistoryEvent
176-
if len(builder.bufferedEvents) > 0 {
177-
bufferedEvents = append(bufferedEvents, builder.bufferedEvents...)
178-
}
179-
if len(builder.updateBufferedEvents) > 0 {
180-
bufferedEvents = append(bufferedEvents, builder.updateBufferedEvents...)
181-
}
182-
183-
var versionHistories *persistence.VersionHistories
184-
if ms.GetVersionHistories() != nil {
185-
versionHistories = ms.GetVersionHistories().Duplicate()
186-
}
187-
return &persistence.WorkflowMutableState{
188-
ExecutionInfo: info,
189-
ExecutionStats: stats,
190-
ActivityInfos: activityInfos,
191-
TimerInfos: timerInfos,
192-
BufferedEvents: bufferedEvents,
193-
SignalInfos: signalInfos,
194-
RequestCancelInfos: cancellationInfos,
195-
ChildExecutionInfos: childInfos,
196-
VersionHistories: versionHistories,
197-
}
198-
}
199-
200-
// CopyWorkflowExecutionInfo copies WorkflowExecutionInfo
201-
func CopyWorkflowExecutionInfo(t *testing.T, sourceInfo *persistence.WorkflowExecutionInfo) *persistence.WorkflowExecutionInfo {
202-
return &persistence.WorkflowExecutionInfo{
203-
DomainID: sourceInfo.DomainID,
204-
WorkflowID: sourceInfo.WorkflowID,
205-
RunID: sourceInfo.RunID,
206-
FirstExecutionRunID: sourceInfo.FirstExecutionRunID,
207-
ParentDomainID: sourceInfo.ParentDomainID,
208-
ParentWorkflowID: sourceInfo.ParentWorkflowID,
209-
ParentRunID: sourceInfo.ParentRunID,
210-
IsCron: sourceInfo.IsCron,
211-
InitiatedID: sourceInfo.InitiatedID,
212-
CompletionEventBatchID: sourceInfo.CompletionEventBatchID,
213-
CompletionEvent: sourceInfo.CompletionEvent,
214-
TaskList: sourceInfo.TaskList,
215-
StickyTaskList: sourceInfo.StickyTaskList,
216-
StickyScheduleToStartTimeout: sourceInfo.StickyScheduleToStartTimeout,
217-
WorkflowTypeName: sourceInfo.WorkflowTypeName,
218-
WorkflowTimeout: sourceInfo.WorkflowTimeout,
219-
DecisionStartToCloseTimeout: sourceInfo.DecisionStartToCloseTimeout,
220-
ExecutionContext: sourceInfo.ExecutionContext,
221-
State: sourceInfo.State,
222-
CloseStatus: sourceInfo.CloseStatus,
223-
LastFirstEventID: sourceInfo.LastFirstEventID,
224-
LastEventTaskID: sourceInfo.LastEventTaskID,
225-
NextEventID: sourceInfo.NextEventID,
226-
LastProcessedEvent: sourceInfo.LastProcessedEvent,
227-
StartTimestamp: sourceInfo.StartTimestamp,
228-
LastUpdatedTimestamp: sourceInfo.LastUpdatedTimestamp,
229-
CreateRequestID: sourceInfo.CreateRequestID,
230-
SignalCount: sourceInfo.SignalCount,
231-
DecisionVersion: sourceInfo.DecisionVersion,
232-
DecisionScheduleID: sourceInfo.DecisionScheduleID,
233-
DecisionStartedID: sourceInfo.DecisionStartedID,
234-
DecisionRequestID: sourceInfo.DecisionRequestID,
235-
DecisionTimeout: sourceInfo.DecisionTimeout,
236-
DecisionAttempt: sourceInfo.DecisionAttempt,
237-
DecisionScheduledTimestamp: sourceInfo.DecisionScheduledTimestamp,
238-
DecisionStartedTimestamp: sourceInfo.DecisionStartedTimestamp,
239-
DecisionOriginalScheduledTimestamp: sourceInfo.DecisionOriginalScheduledTimestamp,
240-
CancelRequested: sourceInfo.CancelRequested,
241-
CancelRequestID: sourceInfo.CancelRequestID,
242-
CronSchedule: sourceInfo.CronSchedule,
243-
ClientLibraryVersion: sourceInfo.ClientLibraryVersion,
244-
ClientFeatureVersion: sourceInfo.ClientFeatureVersion,
245-
ClientImpl: sourceInfo.ClientImpl,
246-
AutoResetPoints: sourceInfo.AutoResetPoints,
247-
Memo: sourceInfo.Memo,
248-
SearchAttributes: sourceInfo.SearchAttributes,
249-
PartitionConfig: sourceInfo.PartitionConfig,
250-
Attempt: sourceInfo.Attempt,
251-
HasRetryPolicy: sourceInfo.HasRetryPolicy,
252-
InitialInterval: sourceInfo.InitialInterval,
253-
BackoffCoefficient: sourceInfo.BackoffCoefficient,
254-
MaximumInterval: sourceInfo.MaximumInterval,
255-
ExpirationTime: sourceInfo.ExpirationTime,
256-
MaximumAttempts: sourceInfo.MaximumAttempts,
257-
NonRetriableErrors: sourceInfo.NonRetriableErrors,
258-
BranchToken: sourceInfo.BranchToken,
259-
ExpirationSeconds: sourceInfo.ExpirationSeconds,
260-
}
261-
}
262-
263-
// CopyActivityInfo copies ActivityInfo
264-
func CopyActivityInfo(t *testing.T, sourceInfo *persistence.ActivityInfo) *persistence.ActivityInfo {
265-
details := slices.Clone(sourceInfo.Details)
266-
267-
return &persistence.ActivityInfo{
268-
Version: sourceInfo.Version,
269-
ScheduleID: sourceInfo.ScheduleID,
270-
ScheduledEventBatchID: sourceInfo.ScheduledEventBatchID,
271-
ScheduledEvent: deepCopyHistoryEvent(t, sourceInfo.ScheduledEvent),
272-
StartedID: sourceInfo.StartedID,
273-
StartedEvent: deepCopyHistoryEvent(t, sourceInfo.StartedEvent),
274-
ActivityID: sourceInfo.ActivityID,
275-
RequestID: sourceInfo.RequestID,
276-
Details: details,
277-
ScheduledTime: sourceInfo.ScheduledTime,
278-
StartedTime: sourceInfo.StartedTime,
279-
ScheduleToStartTimeout: sourceInfo.ScheduleToStartTimeout,
280-
ScheduleToCloseTimeout: sourceInfo.ScheduleToCloseTimeout,
281-
StartToCloseTimeout: sourceInfo.StartToCloseTimeout,
282-
HeartbeatTimeout: sourceInfo.HeartbeatTimeout,
283-
LastHeartBeatUpdatedTime: sourceInfo.LastHeartBeatUpdatedTime,
284-
CancelRequested: sourceInfo.CancelRequested,
285-
CancelRequestID: sourceInfo.CancelRequestID,
286-
TimerTaskStatus: sourceInfo.TimerTaskStatus,
287-
Attempt: sourceInfo.Attempt,
288-
DomainID: sourceInfo.DomainID,
289-
StartedIdentity: sourceInfo.StartedIdentity,
290-
TaskList: sourceInfo.TaskList,
291-
HasRetryPolicy: sourceInfo.HasRetryPolicy,
292-
InitialInterval: sourceInfo.InitialInterval,
293-
BackoffCoefficient: sourceInfo.BackoffCoefficient,
294-
MaximumInterval: sourceInfo.MaximumInterval,
295-
ExpirationTime: sourceInfo.ExpirationTime,
296-
MaximumAttempts: sourceInfo.MaximumAttempts,
297-
NonRetriableErrors: sourceInfo.NonRetriableErrors,
298-
LastFailureReason: sourceInfo.LastFailureReason,
299-
LastWorkerIdentity: sourceInfo.LastWorkerIdentity,
300-
LastFailureDetails: sourceInfo.LastFailureDetails,
301-
// Not written to database - This is used only for deduping heartbeat timer creation
302-
LastHeartbeatTimeoutVisibilityInSeconds: sourceInfo.LastHeartbeatTimeoutVisibilityInSeconds,
303-
}
304-
}
305-
306-
// CopyTimerInfo copies TimerInfo
307-
func CopyTimerInfo(t *testing.T, sourceInfo *persistence.TimerInfo) *persistence.TimerInfo {
308-
return &persistence.TimerInfo{
309-
Version: sourceInfo.Version,
310-
TimerID: sourceInfo.TimerID,
311-
StartedID: sourceInfo.StartedID,
312-
ExpiryTime: sourceInfo.ExpiryTime,
313-
TaskStatus: sourceInfo.TaskStatus,
314-
}
315-
}
316-
317-
// CopyCancellationInfo copies RequestCancelInfo
318-
func CopyCancellationInfo(t *testing.T, sourceInfo *persistence.RequestCancelInfo) *persistence.RequestCancelInfo {
319-
return &persistence.RequestCancelInfo{
320-
Version: sourceInfo.Version,
321-
InitiatedID: sourceInfo.InitiatedID,
322-
InitiatedEventBatchID: sourceInfo.InitiatedEventBatchID,
323-
CancelRequestID: sourceInfo.CancelRequestID,
324-
}
325-
}
326-
327-
// CopySignalInfo copies SignalInfo
328-
func CopySignalInfo(t *testing.T, sourceInfo *persistence.SignalInfo) *persistence.SignalInfo {
329-
return &persistence.SignalInfo{
330-
Version: sourceInfo.Version,
331-
InitiatedEventBatchID: sourceInfo.InitiatedEventBatchID,
332-
InitiatedID: sourceInfo.InitiatedID,
333-
SignalRequestID: sourceInfo.SignalRequestID,
334-
SignalName: sourceInfo.SignalName,
335-
Input: slices.Clone(sourceInfo.Input),
336-
Control: slices.Clone(sourceInfo.Control),
337-
}
338-
}
339-
340-
// CopyChildInfo copies ChildExecutionInfo
341-
func CopyChildInfo(t *testing.T, sourceInfo *persistence.ChildExecutionInfo) *persistence.ChildExecutionInfo {
342-
return &persistence.ChildExecutionInfo{
343-
Version: sourceInfo.Version,
344-
InitiatedID: sourceInfo.InitiatedID,
345-
InitiatedEventBatchID: sourceInfo.InitiatedEventBatchID,
346-
StartedID: sourceInfo.StartedID,
347-
StartedWorkflowID: sourceInfo.StartedWorkflowID,
348-
StartedRunID: sourceInfo.StartedRunID,
349-
CreateRequestID: sourceInfo.CreateRequestID,
350-
DomainID: sourceInfo.DomainID,
351-
DomainNameDEPRECATED: sourceInfo.DomainNameDEPRECATED,
352-
WorkflowTypeName: sourceInfo.WorkflowTypeName,
353-
ParentClosePolicy: sourceInfo.ParentClosePolicy,
354-
InitiatedEvent: deepCopyHistoryEvent(t, sourceInfo.InitiatedEvent),
355-
StartedEvent: deepCopyHistoryEvent(t, sourceInfo.StartedEvent),
356-
}
357-
}
358-
359-
func deepCopyHistoryEvent(t *testing.T, e *types.HistoryEvent) *types.HistoryEvent {
360-
if e == nil {
361-
return nil
362-
}
363-
bytes, err := json.Marshal(e)
364-
if err != nil {
365-
panic(err)
366-
}
367-
var copy types.HistoryEvent
368-
err = json.Unmarshal(bytes, &copy)
369-
if err != nil {
370-
panic(err)
371-
}
372-
return &copy
373-
}
374-
375142
// GetChildExecutionDomainName gets domain name for the child workflow
376143
// NOTE: DomainName in ChildExecutionInfo is being deprecated, and
377144
// we should always use DomainID field instead.
@@ -412,27 +179,6 @@ func GetChildExecutionDomainID(
412179
return parentDomainEntry.GetInfo().ID, nil
413180
}
414181

415-
// GetChildExecutionDomainEntry get domain entry for the child workflow
416-
// NOTE: DomainName in ChildExecutionInfo is being deprecated, and
417-
// we should always use DomainID field instead.
418-
// this function exists for backward compatibility reason
419-
func GetChildExecutionDomainEntry(
420-
t *testing.T,
421-
childInfo *persistence.ChildExecutionInfo,
422-
domainCache cache.DomainCache,
423-
parentDomainEntry *cache.DomainCacheEntry,
424-
) (*cache.DomainCacheEntry, error) {
425-
if childInfo.DomainID != "" {
426-
return domainCache.GetDomainByID(childInfo.DomainID)
427-
}
428-
429-
if childInfo.DomainNameDEPRECATED != "" {
430-
return domainCache.GetDomain(childInfo.DomainNameDEPRECATED)
431-
}
432-
433-
return parentDomainEntry, nil
434-
}
435-
436182
func trimBinaryChecksums(recentBinaryChecksums []string, currResetPoints []*types.ResetPointInfo, maxResetPoints int) ([]string, []*types.ResetPointInfo) {
437183
numResetPoints := len(currResetPoints)
438184
if numResetPoints >= maxResetPoints {

0 commit comments

Comments
 (0)