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

GetVersion implementation #182

Merged
merged 4 commits into from
Jul 12, 2017
Merged

GetVersion implementation #182

merged 4 commits into from
Jul 12, 2017

Conversation

yiminc-zz
Copy link
Contributor

This is based on #170, the only change is changing the map that attached to rootCtx from type map[string]*changeVersion to map[string]Version, as a result, also change the cadence.GetVersion() code a little bit.

@coveralls
Copy link

coveralls commented Jul 11, 2017

Coverage Status

Coverage remained the same at 92.086% when pulling 16abadc on yiminc:get_version into 855bbc8 on uber-go:master.

if attributes.GetMarkerName() != sideEffectMarkerName {
switch attributes.GetMarkerName() {
case sideEffectMarkerName:
dec := gob.NewDecoder(bytes.NewBuffer(attributes.GetDetails()))
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Could would be more readable if you extract the decoding into a helper method. (Same comment for decoding the "version marker"

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you not using encoding interface on hostEnv to decode, so we can switch easily with a different encoder.

markerID := fmt.Sprintf("%v_%v", versionMarkerName, changeID)
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
if err := enc.Encode(changeID); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you not going through encoding interface exposed through hostEnv.Encoder()? that would give us single place to switch different encoders.

if version > maxSupported {
panic(fmt.Sprintf("Workflow code is too old to support version %v "+
"for \"%v\" changeID. The maximum supported version is %v",
version, changeID, minSupported))
Copy link
Contributor

Choose a reason for hiding this comment

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

minSupported -> maxSupported

@@ -335,6 +335,40 @@ func (wc *workflowEnvironmentImpl) RequestCancelTimer(timerID string) {
wc.logger.Debug("RequestCancelTimer", zap.String(tagTimerID, timerID))
}

func validateVersion(changeID string, version, minSupported, maxSupported Version) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these methods return error message and panic at GetVersion() level? sometimes seeing too many panics in library code gives a feeling that panic is accepted pattern but we only do it in certain method calls, where error is not obvious choice.

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 helper method that has no much of logic inside. If we would return flag here and panic in GetVersion() level, then this method does not need to be exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can return error instead of flag. it is still good to have validation as a separate method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use error when invalid version is expected in legit case, and call site can handle that error accordingly. In this case, invalid version is not expected, and it is not recoverable. So I think panic is appropriate here.

Copy link
Contributor

Choose a reason for hiding this comment

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

instead of panic'ing here, panic inside GetVersion() if validateVersion() returns error. so it is very clear that method panics.

version = DefaultVersion
}
validateVersion(changeID, version, minSupported, maxSupported)
wc.logger.Debug("GetVersion return version from a marker",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you hide this logger under the verbose check?

version = maxSupported
wc.decisionsHelper.recordVersionMarker(changeID, version)

wc.logger.Debug("GetVersion return",
Copy link
Contributor

Choose a reason for hiding this comment

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

same here? the more it looks this flag of checking to log looks hacky all over place.

if attributes.GetMarkerName() != sideEffectMarkerName {
switch attributes.GetMarkerName() {
case sideEffectMarkerName:
dec := gob.NewDecoder(bytes.NewBuffer(attributes.GetDetails()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you not using encoding interface on hostEnv to decode, so we can switch easily with a different encoder.

@@ -53,6 +53,7 @@ type (
asyncActivityClient
workflowTimerClient
SideEffect(f func() ([]byte, error), callback resultHandler)
GetVersion(changeID string, maxSupported, minSupported Version) Version
Copy link
Contributor

Choose a reason for hiding this comment

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

The order of variables is inversed. minSupported, maxSupported. Can you add unit test for this layer as well?

@@ -327,6 +328,7 @@ func (d *syncWorkflowDefinition) Execute(env workflowEnvironment, input []byte)
d.rootCtx = WithValue(background, workflowEnvironmentContextKey, env)
var resultPtr *workflowResult
d.rootCtx = WithValue(d.rootCtx, workflowResultContextKey, &resultPtr)
d.rootCtx = WithValue(d.rootCtx, changeVersionsContextKey, make(map[string]Version))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the value if having this look up in this layer when you have the lookup already in task handler GetVersion()?

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 layer server as a cache so we always return same version for same changeID, only if the changeID is known ID. The lookup at workflowEnvironment layer serve lookup from marker result. If a changeID is not present at workflowEnvironment layer, we would return DefaultVersion, but if a changeID is not present at here, we won't return DefaultVersion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the 2 layer lookup can be combined, just updated.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.086% when pulling af4328c on yiminc:get_version into 855bbc8 on uber-go:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.086% when pulling af4328c on yiminc:get_version into 855bbc8 on uber-go:master.

@coveralls
Copy link

coveralls commented Jul 12, 2017

Coverage Status

Coverage remained the same at 92.086% when pulling 4c809ef on yiminc:get_version into 855bbc8 on uber-go:master.

@@ -335,6 +335,40 @@ func (wc *workflowEnvironmentImpl) RequestCancelTimer(timerID string) {
wc.logger.Debug("RequestCancelTimer", zap.String(tagTimerID, timerID))
}

func validateVersion(changeID string, version, minSupported, maxSupported Version) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can return error instead of flag. it is still good to have validation as a separate method.

@coveralls
Copy link

coveralls commented Jul 12, 2017

Coverage Status

Coverage remained the same at 92.086% when pulling 5edc877 on yiminc:get_version into 6efb266 on uber-go:master.

@yiminc-zz yiminc-zz merged commit 2263e84 into uber-go:master Jul 12, 2017
workflowFn := func(ctx Context) error {
ctx = WithActivityOptions(ctx, s.activityOptions)
var f Future
v := GetVersion(ctx, "test_change_id", DefaultVersion, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this we probably want to change DefaultVersion value to 1.

@yiminc-zz yiminc-zz deleted the get_version branch July 27, 2017 23:46
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.

None yet

6 participants