Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle data corruption in history resend #5398

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions service/history/replication/executable_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/api/serviceerror"

"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common"
"go.temporal.io/server/common/backoff"
Expand Down Expand Up @@ -234,7 +235,7 @@ func (e *ExecutableTaskImpl) Reschedule() {

func (e *ExecutableTaskImpl) IsRetryableError(err error) bool {
switch err.(type) {
case *serviceerror.InvalidArgument:
case *serviceerror.InvalidArgument, *serviceerror.DataLoss:
return false
default:
return true
Expand Down Expand Up @@ -355,25 +356,39 @@ func (e *ExecutableTaskImpl) Resend(
// c. attempt failed due to old workflow does not exist
// d. return error to resend new workflow before the branching point

if resendErr.NamespaceId == retryErr.NamespaceId &&
resendErr.WorkflowId == retryErr.WorkflowId &&
resendErr.RunId == retryErr.RunId {
e.Logger.Error("error resend history on the same workflow run",
tag.WorkflowNamespaceID(retryErr.NamespaceId),
tag.WorkflowID(retryErr.WorkflowId),
tag.WorkflowRunID(retryErr.RunId),
tag.NewStringTag("first-resend-error", retryErr.Error()),
tag.NewStringTag("second-resend-error", resendErr.Error()),
)
return false, serviceerror.NewDataLoss("failed to get requested data while resending history")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yycptt any concern to use data loss error here?

}
// handle 2nd resend error, then 1st resend error
if _, err := e.Resend(ctx, remoteCluster, resendErr, remainingAttempt); err == nil {
_, err := e.Resend(ctx, remoteCluster, resendErr, remainingAttempt)
if err == nil {
return e.Resend(ctx, remoteCluster, retryErr, remainingAttempt)
}
e.Logger.Error("error resend history for history event",
tag.WorkflowNamespaceID(retryErr.NamespaceId),
tag.WorkflowID(retryErr.WorkflowId),
tag.WorkflowRunID(retryErr.RunId),
tag.Value(retryErr),
tag.Error(resendErr),
e.Logger.Error("error resend 2nd workflow history for history event",
tag.WorkflowNamespaceID(resendErr.NamespaceId),
tag.WorkflowID(resendErr.WorkflowId),
tag.WorkflowRunID(resendErr.RunId),
tag.NewStringTag("first-resend-error", retryErr.Error()),
tag.NewStringTag("second-resend-error", resendErr.Error()),
tag.Error(err),
)
return false, resendErr
default:
e.Logger.Error("error resend history for history event",
tag.WorkflowNamespaceID(retryErr.NamespaceId),
tag.WorkflowID(retryErr.WorkflowId),
tag.WorkflowRunID(retryErr.RunId),
tag.Value(retryErr),
tag.Error(resendErr),
tag.NewStringTag("first-resend-error", retryErr.Error()),
tag.NewStringTag("second-resend-error", resendErr.Error()),
)
return false, resendErr
}
Expand Down
45 changes: 43 additions & 2 deletions service/history/replication/executable_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/stretchr/testify/suite"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/api/serviceerror"

"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/service/history/configs"
"go.temporal.io/server/service/history/replication/eventhandler"
Expand Down Expand Up @@ -351,7 +352,7 @@ func (s *executableTaskSuite) TestResend_ResendError_Success() {
anotherResendErr := &serviceerrors.RetryReplication{
NamespaceId: resendErr.NamespaceId,
WorkflowId: resendErr.WorkflowId,
RunId: resendErr.RunId,
RunId: uuid.NewString(),
StartEventId: rand.Int63(),
StartEventVersion: rand.Int63(),
EndEventId: rand.Int63(),
Expand Down Expand Up @@ -414,7 +415,7 @@ func (s *executableTaskSuite) TestResend_ResendError_Error() {
anotherResendErr := &serviceerrors.RetryReplication{
NamespaceId: resendErr.NamespaceId,
WorkflowId: resendErr.WorkflowId,
RunId: resendErr.RunId,
RunId: uuid.NewString(),
StartEventId: rand.Int63(),
StartEventVersion: rand.Int63(),
EndEventId: rand.Int63(),
Expand Down Expand Up @@ -451,6 +452,46 @@ func (s *executableTaskSuite) TestResend_ResendError_Error() {
s.False(doContinue)
}

func (s *executableTaskSuite) TestResend_SecondResendError_SameWorkflowRun() {
remoteCluster := cluster.TestAlternativeClusterName
resendErr := &serviceerrors.RetryReplication{
NamespaceId: uuid.NewString(),
WorkflowId: uuid.NewString(),
RunId: uuid.NewString(),
StartEventId: rand.Int63(),
StartEventVersion: rand.Int63(),
EndEventId: rand.Int63(),
EndEventVersion: rand.Int63(),
}

anotherResendErr := &serviceerrors.RetryReplication{
NamespaceId: resendErr.NamespaceId,
WorkflowId: resendErr.WorkflowId,
RunId: resendErr.RunId,
StartEventId: rand.Int63(),
StartEventVersion: rand.Int63(),
EndEventId: rand.Int63(),
EndEventVersion: rand.Int63(),
}

s.ndcHistoryResender.EXPECT().SendSingleWorkflowHistory(
gomock.Any(),
remoteCluster,
namespace.ID(resendErr.NamespaceId),
resendErr.WorkflowId,
resendErr.RunId,
resendErr.StartEventId,
resendErr.StartEventVersion,
resendErr.EndEventId,
resendErr.EndEventVersion,
).Return(anotherResendErr)

doContinue, err := s.task.Resend(context.Background(), remoteCluster, resendErr, ResendAttempt)
var dataLossErr *serviceerror.DataLoss
s.ErrorAs(err, &dataLossErr)
s.False(doContinue)
}

func (s *executableTaskSuite) TestResend_Error() {
remoteCluster := cluster.TestAlternativeClusterName
resendErr := &serviceerrors.RetryReplication{
Expand Down
Loading