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

Refactoring Cassandra workflow persistence manager for NoSQL support : Part 1 #4251

Merged
merged 24 commits into from
Jun 18, 2021

Conversation

longquanzheng
Copy link
Collaborator

@longquanzheng longquanzheng commented Jun 5, 2021

What changed?

  1. Create NoSQL interface for create workflow operation
  2. Extract the logic of Cassandra to implement the interface
  3. Replace executionStore with NoSQL plugin db style

Why?
For #3514

How did you test it?
existing tests. Working on adding more test to the PR.

Potential risks
Medium risks.
Even though the goal of the PR is to keep the same behavior, it's still some uknown and this is the critical persistence for Cadence.

Release notes
No

Documentation Changes
No

@coveralls
Copy link

coveralls commented Jun 6, 2021

Pull Request Test Coverage Report for Build 4bca07ed-b04b-4019-ae05-fc60729236e7

  • 756 of 1222 (61.87%) changed or added relevant lines in 6 files are covered.
  • 98 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.005%) to 60.19%

Changes Missing Coverage Covered Lines Changed/Added Lines %
common/persistence/persistence-tests/executionManagerTest.go 0 4 0.0%
common/persistence/nosql/nosqlplugin/interfaces.go 3 8 37.5%
common/persistence/nosql/nosqlplugin/cassandra/workflow.go 35 61 57.38%
common/persistence/cassandra/cassandraPersistence.go 226 418 54.07%
common/persistence/nosql/nosqlplugin/cassandra/workflowUtils.go 484 723 66.94%
Files with Coverage Reduction New Missed Lines %
common/persistence/executionManager.go 2 75.75%
common/persistence/statsComputer.go 2 96.43%
common/task/fifoTaskScheduler.go 2 85.57%
service/history/execution/mutable_state_builder.go 2 69.87%
common/persistence/cassandra/cassandraPersistence.go 6 52.14%
service/history/shard/context.go 9 65.93%
service/history/execution/context.go 17 68.39%
common/persistence/sql/sqlExecutionStore.go 21 59.54%
common/persistence/cassandra/cassandraPersistenceUtil.go 37 86.56%
Totals Coverage Status
Change from base Build d9a172e8-c3fd-4266-a2a9-db1ebd63d763: 0.005%
Covered Lines: 89914
Relevant Lines: 149383

💛 - Coveralls

@longquanzheng longquanzheng requested a review from yycptt June 9, 2021 16:18
common/persistence/nosql/nosqlplugin/interfaces.go Outdated Show resolved Hide resolved
common/persistence/nosql/nosqlplugin/interfaces.go Outdated Show resolved Hide resolved
Comment on lines 353 to 354
* cross_cluster_task is to store also background tasks that need to be processed right after the transaction, and only for
* but only for CrossDC(XDC) replication feature. Each record is a replication task generated for a target cluster.
* CrossCluster task stores information similar to TransferTask.
Copy link
Contributor

Choose a reason for hiding this comment

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

There's some mismatch here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which part? I probably don't understand it well. Do you mean it's not XDC or not replication? Feel free to correct it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is "and only for but only for CrossDC(XDC) replication feature" under cross cluster task. I think it is just cross cluster execution feature. What do you think? @yycptt

common/persistence/persistenceInterface.go Outdated Show resolved Hide resolved
signalInfoMap map[int64]*persistence.SignalInfo,
signalRequestedIDs []string,
shardCondition *ShardCondition,
) (*ConditionFailureReason, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we define/reuse some (existing) error types for those failure cause, and return them as part of error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So I kinda invented this way for strongly typed experience. It's also in shardCRUD and taskCRUD:

InsertShard(ctx context.Context, row *ShardRow) (previous *ConflictedShardRow, err error)

InsertTasks(ctx context.Context, tasksToInsert []*TaskRowForInsert, tasklistCondition *TaskListRow) (previous *TaskListRow, err error)

The benefits is that we don't need to do type any casting from error interface into a struct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just did some research. Seems like using error struct is the standard way in Golang. I will change that here. Also created #4273 to change taskCRUD and shardCRUD.

Comment on lines +803 to +804
executionInfo, versionHistories, checkSum,
nowTimestamp, lastWriteVersion,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: separate them per line?

}

func (d *cassandraPersistence) prepareTimerTasksForWorkflowTxn(
domainID, workflowID, runID string,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: separate them per line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think they are all strings and quite related. This should read more fluently :P
LMK if you have a strong opinion on that. I actually did that intentionally.

rowTypeShardTaskID,
request.RangeID,
)
activityInfos, err := d.prepareActivityInfosForWorkflowTxn(newWorkflow.ActivityInfos)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this in create workflow operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed offline. This is probably not being used but I have to keep the same behavior for refactoring.

if err != nil {
return nil, err
}
childWorkflowInfos, err := d.prepareChildWFInfosForWorkflowTxn(newWorkflow.ChildExecutionInfos)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this in create workflow operation?

if err != nil {
return nil, err
}
requestCancelInfoMap, err := d.prepareRequestCancelsForWorkflowTxn(newWorkflow.RequestCancelInfos)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this in create workflow operation?

Comment on lines 896 to 898
}
func (d *DataBlob) GetEncodingString() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: empty line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, thanks!

return err
}

err = db.updateActivityInfos(batch, shardID, domainID, workflowID, runID, activityInfoMap, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. Not sure for insert do we need this?

if err != nil {
return err
}
err = db.updateChildExecutionInfos(batch, shardID, domainID, workflowID, runID, childWorkflowInfoMap, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. Not sure for insert do we need this?

if err != nil {
return err
}
err = db.updateRequestCancelInfos(batch, shardID, domainID, workflowID, runID, requestCancelInfoMap, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. Not sure for insert do we need this?

Comment on lines 353 to 354
* cross_cluster_task is to store also background tasks that need to be processed right after the transaction, and only for
* but only for CrossDC(XDC) replication feature. Each record is a replication task generated for a target cluster.
* CrossCluster task stores information similar to TransferTask.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is "and only for but only for CrossDC(XDC) replication feature" under cross cluster task. I think it is just cross cluster execution feature. What do you think? @yycptt

Copy link
Contributor

@yycptt yycptt left a comment

Choose a reason for hiding this comment

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

It seems like the old code path is not deleted, do you think it makes sense to have a feature flag for controlling whether the new impl should be used?

@longquanzheng
Copy link
Collaborator Author

It seems like the old code path is not deleted, do you think it makes sense to have a feature flag for controlling whether the new impl should be used?

It's not being used at all. applyWorkflowSnapshotBatchAsNew is still being used by UpdateWorkflow and ConflictResolution API so they will be deleted in next PR.

I don't feel it's useful at all to have a feature flag. The refactoring goal is to get rid of it.

@github-actions github-actions bot merged commit ffe4e2f into master Jun 18, 2021
@github-actions github-actions bot deleted the qlong-nosql-wf-1 branch June 18, 2021 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants