Skip to content

Commit

Permalink
Add more logging message to monitor branch token update (#5058)
Browse files Browse the repository at this point in the history
<!-- Describe what has changed in this PR -->
**What changed?**
Add more logging message to monitor branch token update

<!-- Tell your future self why have you made these changes -->
**Why?**
better debugging.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
only logging.

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**


<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**

---------

Co-authored-by: Stephan Behnke <stephanos@users.noreply.github.com>
  • Loading branch information
yux0 and stephanos committed Nov 21, 2023
1 parent 6ba388c commit 1f04629
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions service/history/api/get_workflow_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common"
"go.temporal.io/server/common/definition"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/common/persistence/versionhistory"
serviceerrors "go.temporal.io/server/common/serviceerror"
Expand All @@ -53,6 +54,7 @@ func GetOrPollMutableState(
eventNotifier events.Notifier,
) (*historyservice.GetMutableStateResponse, error) {

logger := shardContext.GetLogger()
namespaceID := namespace.ID(request.GetNamespaceId())
err := ValidateNamespaceUUID(namespaceID)
if err != nil {
Expand Down Expand Up @@ -94,6 +96,14 @@ func GetOrPollMutableState(
// We return the full version histories. Callers need to fetch the last version history item from current branch
// and use the last version history item in following calls.
if !versionhistory.ContainsVersionHistoryItem(currentVersionHistory, request.VersionHistoryItem) {
logItem, err := versionhistory.GetLastVersionHistoryItem(currentVersionHistory)
if err != nil {
return nil, err
}
logger.Warn("Request history branch and current history branch don't match",
tag.Value(logItem),
tag.TokenLastEventVersion(request.VersionHistoryItem.GetVersion()),
tag.TokenLastEventID(request.VersionHistoryItem.GetEventId()))
return nil, serviceerrors.NewCurrentBranchChanged(response.CurrentBranchToken, request.CurrentBranchToken)
}

Expand Down Expand Up @@ -121,6 +131,14 @@ func GetOrPollMutableState(
return nil, err
}
if !versionhistory.ContainsVersionHistoryItem(currentVersionHistory, request.VersionHistoryItem) {
logItem, err := versionhistory.GetLastVersionHistoryItem(currentVersionHistory)
if err != nil {
return nil, err
}
logger.Warn("Request history branch and current history branch don't match prior to polling the mutable state",
tag.Value(logItem),
tag.TokenLastEventVersion(request.VersionHistoryItem.GetVersion()),
tag.TokenLastEventID(request.VersionHistoryItem.GetEventId()))
return nil, serviceerrors.NewCurrentBranchChanged(response.CurrentBranchToken, request.CurrentBranchToken)
}
if expectedNextEventID < response.GetNextEventId() || response.GetWorkflowStatus() != enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING {
Expand Down Expand Up @@ -152,6 +170,14 @@ func GetOrPollMutableState(
response.CurrentBranchToken = latestVersionHistory.GetBranchToken()
response.VersionHistories = event.VersionHistories
if !versionhistory.ContainsVersionHistoryItem(latestVersionHistory, request.VersionHistoryItem) {
logItem, err := versionhistory.GetLastVersionHistoryItem(currentVersionHistory)
if err != nil {
return nil, err
}
logger.Warn("Request history branch and current history branch don't match after polling the mutable state",
tag.Value(logItem),
tag.TokenLastEventVersion(request.VersionHistoryItem.GetVersion()),
tag.TokenLastEventID(request.VersionHistoryItem.GetEventId()))
return nil, serviceerrors.NewCurrentBranchChanged(response.CurrentBranchToken, request.CurrentBranchToken)
}
if expectedNextEventID < response.GetNextEventId() || response.GetWorkflowStatus() != enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING {
Expand Down

0 comments on commit 1f04629

Please sign in to comment.