-
Notifications
You must be signed in to change notification settings - Fork 142
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
Make GetVersion more deterministic #1807
Merged
Quinn-With-Two-Ns
merged 3 commits into
temporalio:master
from
Quinn-With-Two-Ns:sdk-versioning
Jul 17, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
temporal-sdk/src/main/java/io/temporal/internal/common/SdkFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.internal.common; | ||
|
||
/** | ||
* SdkFlag represents a flag used to help version the sdk internally to make breaking changes in | ||
* workflow logic. | ||
*/ | ||
public enum SdkFlag { | ||
UNSET(0), | ||
/* | ||
* Changes behavior of GetVersion to not yield if no previous call existed in history. | ||
*/ | ||
SKIP_YIELD_ON_DEFAULT_VERSION(1), | ||
UNKNOWN(Integer.MAX_VALUE); | ||
|
||
private final int value; | ||
|
||
SdkFlag(int value) { | ||
this.value = value; | ||
} | ||
|
||
public boolean compare(int i) { | ||
return value == i; | ||
} | ||
|
||
public static SdkFlag getValue(int id) { | ||
SdkFlag[] as = SdkFlag.values(); | ||
for (int i = 0; i < as.length; i++) { | ||
if (as[i].compare(id)) return as[i]; | ||
} | ||
return SdkFlag.UNKNOWN; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
Quinn-With-Two-Ns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
79 changes: 79 additions & 0 deletions
79
temporal-sdk/src/main/java/io/temporal/internal/common/SdkFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.internal.common; | ||
|
||
import io.temporal.workflow.Functions; | ||
import java.util.EnumSet; | ||
|
||
/** Represents all the flags that are currently set in a workflow execution. */ | ||
public final class SdkFlags { | ||
private final boolean supportSdkMetadata; | ||
private final Functions.Func<Boolean> replaying; | ||
// Flags that have been received from the server or have not been sent yet. | ||
private final EnumSet<SdkFlag> sdkFlags = EnumSet.noneOf(SdkFlag.class); | ||
// Flags that have been set this WFT that have not been sent to the server. | ||
// Keep track of them separately, so we know what to send to the server. | ||
private final EnumSet<SdkFlag> unsentSdkFlags = EnumSet.noneOf(SdkFlag.class); | ||
|
||
public SdkFlags(boolean supportSdkMetadata, Functions.Func<Boolean> replaying) { | ||
this.supportSdkMetadata = supportSdkMetadata; | ||
this.replaying = replaying; | ||
} | ||
|
||
/** | ||
* Marks a flag as usable regardless of replay status. | ||
* | ||
* @return True, as long as the server supports SDK flags | ||
*/ | ||
public boolean setSdkFlag(SdkFlag flag) { | ||
if (!supportSdkMetadata) { | ||
return false; | ||
} | ||
sdkFlags.add(flag); | ||
return true; | ||
} | ||
|
||
/** | ||
* @return True if this flag may currently be used. | ||
*/ | ||
public boolean tryUseSdkFlag(SdkFlag flag) { | ||
if (!supportSdkMetadata) { | ||
return false; | ||
} | ||
|
||
if (!replaying.apply()) { | ||
sdkFlags.add(flag); | ||
unsentSdkFlags.add(flag); | ||
return true; | ||
} else { | ||
return sdkFlags.contains(flag); | ||
} | ||
} | ||
|
||
/** | ||
* @return All flags set since the last call to takeNewSdkFlags. | ||
*/ | ||
public EnumSet<SdkFlag> takeNewSdkFlags() { | ||
EnumSet<SdkFlag> result = unsentSdkFlags.clone(); | ||
unsentSdkFlags.clear(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have an unknown flag? Just make the return from
GetValue
(sic) asOptional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UNKNOWN
is not the same as an empty optionalThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm saying is it shouldn't be the same. You should only have enumerates for real flags IMO. There's no reason to have all but one enumerate be a real flag IMO. Make it clear to the caller that the flag is unknown, not just that it happens to have another name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think returning
UNKNOWN
is clear to the caller that the flags meaning is not know. This is how we handle it in the other SDKs that implement flags as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eek. I hope we at least don't in TS, Python, and .NET. All those languages have a good way of representing an absent enum without having to work around that some values of the enum are representable in history and some aren't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it was an absent enum I would use optional, but it really is the lack of knowledge about how to handle a value. I would rather leave it as is in Java since I think it is clearer and more consistent with other SDKs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree, but y'all's design choice here. At least it's internal.