160
targetBranchToken []byte,
161
currentMutableState *persistencespb.WorkflowMutableState,
163
>
// Use the original start request ID handlers can still correlate rebuilt callbacks to the correct BufferedStart entry.
164
>
rebuiltMutableState, lastTxnId, err := r.buildMutableStateFromEvent(
165
>
ctx,
166
>
now,
167
>
baseWorkflowIdentifier,
168
>
baseBranchToken,
169
>
baseLastEventID,
170
>
baseLastEventVersion,
171
>
targetWorkflowIdentifier,
172
>
targetBranchToken,
173
>
findStartRequestID(currentMutableState.GetExecutionState()),
174
>
)
175
>
if err != nil {
176
return nil, RebuildStats{}, err
177
}
178
>
copyToRebuildMutableState(rebuiltMutableState, currentMutableState)
state_rebuilder.go
179
>
versionHistories := rebuiltMutableState.GetExecutionInfo().GetVersionHistories()
180
>
currentVersionHistory, err := versionhistory.GetCurrentVersionHistory(versionHistories)
181
>
if err != nil {
182
return nil, RebuildStats{}, err
183
}
184
>
items := versionhistory.CopyVersionHistoryItems(currentVersionHistory.Items)
state_rebuilder.go
185
>
186
>
// This is a workaround to bypass the version history update check:
187
>
// We need to use Active policy to close the transaction. We need to clear the version history items here to
188
>
// let it pass the version history update logic and then re-assign the version history items after transaction.
189
>
currentVersionHistory.Items = nil
190
>
191
>
// close rebuilt mutable state transaction clearing all generated tasks, etc.
192
>
_, _, err = rebuiltMutableState.CloseTransactionAsSnapshot(ctx, historyi.TransactionPolicyActive)
193
>
if err != nil {
194
return nil, RebuildStats{}, err
195
}
197
>
198
>
rebuiltMutableState.GetExecutionInfo().LastFirstEventTxnId = lastTxnId
199
>
200
>
// refresh tasks to be generated
201
>
// TODO: ideally the executionTimeoutTimerTaskStatus field should be carried over
202
>
// from the base run. However, RefreshTasks always resets that field and
203
>
// force regenerates the execution timeout timer task.
204
>
if err := r.taskRefresher.Refresh(ctx, rebuiltMutableState, false); err != nil {
205
return nil, RebuildStats{}, err
206
}
207
209
>
HistorySize: r.rebuiltHistorySize,
210
>
ExternalPayloadSize: r.rebuiltExternalPayloadSize,
211
>
ExternalPayloadCount: r.rebuiltExternalPayloadCount,
212
>
}, nil
213
}
214