-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make GetVersion more deterministic (#1807)
Make GetVersion more deterministic
- Loading branch information
1 parent
3be060b
commit 6054c31
Showing
22 changed files
with
1,609 additions
and
71 deletions.
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; | ||
} | ||
} |
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.