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

Add versioning support in durabletask-dotnet(phase1) #295

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
380c622
Add a new constructor that sets the version expected by the client
skyao Apr 22, 2024
1976de6
Add new abstract method to get instance version
skyao Apr 22, 2024
4e1f8cb
Implemented new added abstract method to get instance version
skyao Apr 22, 2024
f6162ff
change to get instance version from this.innerContext.Version
skyao Apr 23, 2024
d564c79
Merge branch 'main' into versioning-phase1
skyao Apr 26, 2024
d9298d0
change InstanceVersion to virtual and return null be default to avoid…
skyao Apr 26, 2024
60c1341
Merge branch 'versioning-phase1' of github.com:skyao/durabletask-dotn…
skyao Apr 26, 2024
fc44a4a
Merge branch 'main' into versioning-phase1
skyao Apr 29, 2024
5b1b2b2
Merge branch 'main' into versioning-phase1
skyao May 7, 2024
cb86ecd
Merge branch 'main' into versioning-phase1
skyao May 21, 2024
83bc227
update constructor to handle null correctly
skyao May 21, 2024
f1619b1
Merge branch 'main' into versioning-phase1
skyao Jul 5, 2024
0045ced
update Equals/GetHashCode method to include version field
skyao Jul 10, 2024
2172e96
use value.ToString() to include version field
skyao Jul 10, 2024
5c3ad58
rollback file formator to use 4 space indentation
skyao Jul 16, 2024
7912d46
use Microsoft.Bcl.HashCode to do hash
skyao Jul 16, 2024
d015d3e
fix typo
skyao Jul 16, 2024
87b15e1
udpate documents for version
skyao Jul 18, 2024
6ecfde1
add static FromString() method and update the string conversion opera…
skyao Jul 18, 2024
220fb2d
Merge branch 'main' into versioning-phase1
skyao Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Abstractions/Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.DurableTask.Core" Version="2.17.1" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
Expand Down
77 changes: 69 additions & 8 deletions src/Abstractions/TaskName.cs
skyao marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,41 @@ public TaskName(string name)
}
}

/// <summary>
/// Initializes a new instance of the <see cref="TaskName"/> struct.
/// </summary>
/// <param name="name">The name of the task. Providing <c>null</c> will yield the default struct.</param>
/// <param name="version">The version of the task.</param>
public TaskName(string name, string version)
{
if (name is null)
skyao marked this conversation as resolved.
Show resolved Hide resolved
{
if (version is null)
{
// Force the default struct when null is passed in.
this.Name = null!;
this.Version = null!;
}
else
{
throw new ArgumentException("name must not be null when version is non-null");
}
}
else
{
if (version is null)
{
this.Name = name;
this.Version = string.Empty; // fallback to the constructor without version parameter
}
else
{
this.Name = name;
this.Version = version;
}
}
}

/// <summary>
/// Gets the name of the task without the version.
/// </summary>
Expand All @@ -40,23 +75,22 @@ public TaskName(string name)
/// <summary>
/// Gets the version of the task.
/// </summary>
/// <remarks>
/// Task versions is currently locked to <see cref="string.Empty" /> as it is not yet integrated into task
/// identification. This is being left here as we intend to support it soon.
/// </remarks>
/// <value>
/// The version of the activity task.
/// </value>
public string Version { get; }

/// <summary>
/// Implicitly converts a <see cref="TaskName"/> into a <see cref="string"/> of the <see cref="Name"/> property value.
/// </summary>
/// <param name="value">The <see cref="TaskName"/> to be converted into a string.</param>
public static implicit operator string(TaskName value) => value.Name;
public static implicit operator string(TaskName value) => value.ToString();

/// <summary>
/// Implicitly converts a <see cref="string"/> into a <see cref="TaskName"/> value.
/// </summary>
/// <param name="value">The string to convert into a <see cref="TaskName"/>.</param>
public static implicit operator TaskName(string value) => string.IsNullOrEmpty(value) ? default : new(value);
public static implicit operator TaskName(string value) => FromString(value);

/// <summary>
/// Compares two <see cref="TaskName"/> objects for equality.
Expand All @@ -80,6 +114,32 @@ public TaskName(string name)
return !a.Equals(b);
}

/// <summary>
/// Parses the taskname string and initializes a new instance of the <see cref="TaskName"/> struct.
/// </summary>
/// <param name="taskname">The taskname string in format of "Name:Version" or "Name".</param>
/// <returns>New <see cref="TaskName"/> instance parsed from taskname string.</returns>
public static TaskName FromString(string taskname)
{
if (string.IsNullOrEmpty(taskname))
{
return default;
}

string[] parts = taskname.Split(':');
if (parts.Length == 1)
{
return new TaskName(parts[0]);
}

if (parts.Length == 2)
{
return new TaskName(parts[0], parts[1]);
}

throw new ArgumentException("Invalid task name format: taskname=" + taskname);
}

/// <summary>
/// Gets a value indicating whether to <see cref="TaskName"/> objects
/// are equal using value semantics.
Expand All @@ -88,7 +148,8 @@ public TaskName(string name)
/// <returns><c>true</c> if the two objects are equal using value semantics; otherwise <c>false</c>.</returns>
public bool Equals(TaskName other)
{
return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase);
return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(this.Version, other.Version, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
Expand All @@ -113,7 +174,7 @@ public override bool Equals(object? obj)
/// <returns>A 32-bit hash code value.</returns>
public override int GetHashCode()
{
return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name);
return HashCode.Combine(this.Name, this.Version);
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Abstractions/TaskOrchestrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public abstract class TaskOrchestrationContext
/// </summary>
public abstract string InstanceId { get; }

/// <summary>
/// Gets the version of the current orchestration instance.
/// </summary>
public virtual string? InstanceVersion => null;

/// <summary>
/// Gets the parent instance or <c>null</c> if there is no parent orchestration.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public TaskOrchestrationContextWrapper(
/// <inheritdoc/>
public override string InstanceId => this.innerContext.OrchestrationInstance.InstanceId;

/// <inheritdoc/>
public override string InstanceVersion => this.innerContext.Version;

/// <inheritdoc/>
public override ParentOrchestrationInstance? Parent => this.invocationContext.Parent;

Expand Down