Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add unit tests for helper functions in sql execution store util #5571

Merged
merged 1 commit into from
Dec 29, 2023
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
5 changes: 4 additions & 1 deletion common/persistence/dataStoreInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ func (d *DataBlob) ToNilSafeDataBlob() *DataBlob {
}

func (d *DataBlob) GetEncodingString() string {
if d == nil {
return ""
}
return string(d.Encoding)
}

Expand All @@ -955,7 +958,7 @@ func (d *DataBlob) GetData() []byte {

// GetEncoding returns encoding type
func (d *DataBlob) GetEncoding() common.EncodingType {
encodingStr := string(d.Encoding)
encodingStr := d.GetEncodingString()

switch common.EncodingType(encodingStr) {
case common.EncodingTypeGob:
Expand Down
2 changes: 1 addition & 1 deletion common/persistence/serialization/persistence_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func FromInternalWorkflowExecutionInfo(executionInfo *persistence.InternalWorkfl
RetryNonRetryableErrors: executionInfo.NonRetriableErrors,
EventStoreVersion: persistence.EventStoreVersion,
EventBranchToken: executionInfo.BranchToken,
AutoResetPoints: executionInfo.AutoResetPoints.Data,
AutoResetPoints: executionInfo.AutoResetPoints.GetData(),
AutoResetPointsEncoding: string(executionInfo.AutoResetPoints.GetEncoding()),
SearchAttributes: executionInfo.SearchAttributes,
Memo: executionInfo.Memo,
Expand Down
6 changes: 3 additions & 3 deletions common/persistence/sql/sql_execution_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (m *sqlExecutionStore) createWorkflowExecutionTx(
return nil, err
}

if err := m.applyWorkflowSnapshotTxAsNew(ctx, tx, shardID, &request.NewWorkflowSnapshot, m.parser); err != nil {
if err := applyWorkflowSnapshotTxAsNew(ctx, tx, shardID, &request.NewWorkflowSnapshot, m.parser); err != nil {
return nil, err
}

Expand Down Expand Up @@ -490,7 +490,7 @@ func (m *sqlExecutionStore) updateWorkflowExecutionTx(
return err
}
if newWorkflow != nil {
if err := m.applyWorkflowSnapshotTxAsNew(ctx, tx, shardID, newWorkflow, m.parser); err != nil {
if err := applyWorkflowSnapshotTxAsNew(ctx, tx, shardID, newWorkflow, m.parser); err != nil {
return err
}
}
Expand Down Expand Up @@ -611,7 +611,7 @@ func (m *sqlExecutionStore) conflictResolveWorkflowExecutionTx(
}
}
if newWorkflow != nil {
if err := m.applyWorkflowSnapshotTxAsNew(ctx, tx, shardID, newWorkflow, m.parser); err != nil {
if err := applyWorkflowSnapshotTxAsNew(ctx, tx, shardID, newWorkflow, m.parser); err != nil {
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"golang.org/x/sync/errgroup"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/log/tag"
p "github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/serialization"
"github.com/uber/cadence/common/persistence/sql/sqlplugin"
Expand Down Expand Up @@ -632,7 +631,7 @@ func applyWorkflowMutationAsyncTx(
return g.Wait()
}

func (m *sqlExecutionStore) applyWorkflowSnapshotTxAsNew(
func applyWorkflowSnapshotTxAsNew(
ctx context.Context,
tx sqlplugin.Tx,
shardID int,
Expand All @@ -648,7 +647,7 @@ func (m *sqlExecutionStore) applyWorkflowSnapshotTxAsNew(
workflowID := executionInfo.WorkflowID
runID := serialization.MustParseUUID(executionInfo.RunID)

if err := m.createExecution(
if err := createExecution(
ctx,
tx,
executionInfo,
Expand Down Expand Up @@ -777,7 +776,7 @@ func (m *sqlExecutionStore) applyWorkflowSnapshotAsyncTxAsNew(

g.Go(func() (e error) {
defer func() { recoverPanic(recover(), &e) }()
e = m.createExecution(
e = createExecution(
ctx,
tx,
executionInfo,
Expand Down Expand Up @@ -1748,7 +1747,7 @@ func buildExecutionRow(
}, nil
}

func (m *sqlExecutionStore) createExecution(
func createExecution(
ctx context.Context,
tx sqlplugin.Tx,
executionInfo *p.InternalWorkflowExecutionInfo,
Expand All @@ -1767,13 +1766,9 @@ func (m *sqlExecutionStore) createExecution(
}

now := time.Now()
// TODO: this case seems to be always false
if executionInfo.StartTimestamp.IsZero() {
executionInfo.StartTimestamp = now
m.logger.Error("Workflow startTimestamp not set, fallback to now",
tag.WorkflowDomainID(executionInfo.DomainID),
tag.WorkflowID(executionInfo.WorkflowID),
tag.WorkflowRunID(executionInfo.RunID),
)
}

row, err := buildExecutionRow(
Expand All @@ -1789,7 +1784,7 @@ func (m *sqlExecutionStore) createExecution(
}
result, err := tx.InsertIntoExecutions(ctx, row)
if err != nil {
if m.db.IsDupEntryError(err) {
if tx.IsDupEntryError(err) {
return &p.WorkflowExecutionAlreadyStartedError{
Msg: fmt.Sprintf("Workflow execution already running. WorkflowId: %v", executionInfo.WorkflowID),
StartRequestID: executionInfo.CreateRequestID,
Expand Down
Loading