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

Implement describeMutableState #805

Merged
merged 7 commits into from
Jun 5, 2018

Conversation

longquanzheng
Copy link
Contributor

Initial PR, I will implement unit test for HistoryCache if there is no major issue in the code change.

thriftCache map[string]historyserviceclient.Interface
rpcFactory common.RPCFactory
// TODO: consider refactor InquireCache into a separate struct
InquireCacheLock sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these intentionally Upper case?

c.thriftCacheLock.RLock()
client, ok := c.thriftCache[hostPort]
c.thriftCacheLock.RUnlock()
c.InquireCacheLock.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

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

If you just do:
c.InquireCacheLock.RLock()
defer c.InquireCacheLock.Unlock()
here, you won't have to acquire the lock again and the lock is cleaner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, I mistakenly changed the naming and this is not part of my scope. But we can open another issue to optimize the locking mechanism.
One reason I can see that why they did this, is they want to release the lock earlier? But I can see that they did that on purpose to improve the performance, as the trade off, it will sacrify some readability

Copy link
Contributor

Choose a reason for hiding this comment

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

ok got it.

thriftCache map[string]historyserviceclient.Interface
rpcFactory common.RPCFactory
// TODO: consider refactor InquireCache into a separate struct
InquireCacheLock sync.RWMutex

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a mistake when I refactor the naming. I will change it back. Thanks for reminding.

10: optional string shardId
20: optional string historyAddr
30: optional string otherInfo

Choose a reason for hiding this comment

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

what is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wxing1292 said he need more information in mutableStateBuilder like update/deleteActivityInfos, making sure that they are empty.

Copy link
Contributor

@wxing1292 wxing1292 Jun 3, 2018

Choose a reason for hiding this comment

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

but not called otherInfo, as a string, the idea is to dump all things from mutable state (cache version and persistence version).
the original type is preferable

moreover, shardId is a int64, i believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked offline, I will get rid of otherInfo

contextFromCache, cacheHit := c.Get(key).(*workflowExecutionContext)
releaseFunc := func(error) {}
// If cache hit, we need to lock the cache to prevent race condition
if cacheHit {

Choose a reason for hiding this comment

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

this feels complicated, it would be simpler if we just return from whatever in the cache, and provide another API to force unload the cache, which is also needed as an admin command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This s about requirement of the task. I will talk to you in uChat

retResp.MutableStateInCache, retError = e.toMutableStateJSON(msb)
otherInfo := ""
if len(msb.updateActivityInfos) > 0 {
otherInfo += "updateActivityInfos is not empty;"

Choose a reason for hiding this comment

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

why do we need this otherInfo? The toMutableStateJSON should already include everything, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like above. there are still someother information like updateActivityInfos. @wxing1292 you guys can discuss if they are really needed. I don't have too much context of how we are going to use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, i still prefer dumping everything as original type, not string

@@ -169,6 +169,22 @@ func newMutableStateBuilderWithReplicationState(config *Config, logger bark.Logg
return s
}

func (e *mutableStateBuilder) Unload() *persistence.WorkflowMutableState {

Choose a reason for hiding this comment

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

The function name is unclear. Maybe name it as CopyTo...

Copy link
Contributor Author

@longquanzheng longquanzheng Jun 1, 2018

Choose a reason for hiding this comment

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

I felt so too. did that because we already have

func (e *mutableStateBuilder) Load(state *persistence.WorkflowMutableState)" 

doing the opposite.

CopyTo might not be a better name because mutableStateBuilder and mutabeState struct are not exactly the same.
To be more clear, we probably can call it loadFromMutableState and unloadToMutableState.

Choose a reason for hiding this comment

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

Unload give false impression that you are resetting the mutable state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense. How about rename it to "copyTo"?

Copy link
Contributor

@arthurgan arthurgan left a comment

Choose a reason for hiding this comment

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

Approved because all my comments are addressed.

However, maybe wait for another approval(like from Yimin) before merging.

**/
InquiryWorkflowExecutionResponse InquiryWorkflowExecution(1: shared.DescribeWorkflowExecutionRequest inquiryRequest)
InquireWorkflowExecutionResponse InquireWorkflowExecution(1: InquireWorkflowExecutionRequest inquireRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

let us use simple words here, try describe or get.

Choose a reason for hiding this comment

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

+1 for Describe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will rename them to DescribeXX

Copy link

@yiminc-zz yiminc-zz left a comment

Choose a reason for hiding this comment

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

Looks good. With 2 minor naming suggestion.

**/
InquiryWorkflowExecutionResponse InquiryWorkflowExecution(1: shared.DescribeWorkflowExecutionRequest inquiryRequest)
InquireWorkflowExecutionResponse InquireWorkflowExecution(1: InquireWorkflowExecutionRequest inquireRequest)

Choose a reason for hiding this comment

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

+1 for Describe

@@ -169,6 +169,22 @@ func newMutableStateBuilderWithReplicationState(config *Config, logger bark.Logg
return s
}

func (e *mutableStateBuilder) Unload() *persistence.WorkflowMutableState {

Choose a reason for hiding this comment

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

Unload give false impression that you are resetting the mutable state.

@longquanzheng longquanzheng merged commit 772d653 into cadence-workflow:master Jun 5, 2018
@longquanzheng longquanzheng changed the title Implement inquireMutableState Implement describeMutableState Jun 5, 2018
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