Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 24 additions & 9 deletions src/DurableTask.Core/Entities/ClientEntityHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,36 @@ public static EventToSend EmitUnlockForOrphanedLock(OrchestrationInstance target
};

var jmessage = JToken.FromObject(message, Serializer.InternalSerializer);

return new EventToSend(EntityMessageEventNames.ReleaseMessageEventName, jmessage, targetInstance);
}

/// <summary>
/// Extracts the user-defined entity state (as a serialized string) from the scheduler state (also a serialized string).
/// Extracts the user-defined entity state from the serialized scheduler state. The result is the serialized state,
/// or null if the entity has no state.
/// </summary>
/// <param name="serializedSchedulerState">The state of the scheduler, as a serialized string.</param>
/// <param name="entityState">The entity state</param>
/// <returns>True if the entity exists, or false otherwise</returns>
public static bool TryGetEntityStateFromSerializedSchedulerState(string serializedSchedulerState, out string? entityState)
public static string? GetEntityState(string? serializedSchedulerState)
{
var schedulerState = JsonConvert.DeserializeObject<SchedulerState>(serializedSchedulerState, Serializer.InternalSerializerSettings);
entityState = schedulerState!.EntityState;
return schedulerState.EntityExists;
if (serializedSchedulerState == null)
{
return null;
}

var schedulerState = JsonConvert.DeserializeObject<SchedulerState>(serializedSchedulerState, Serializer.InternalSerializerSettings)!;
return schedulerState.EntityState;
}

/// <summary>
/// Gets the entity status from the serialized custom status of the orchestration.
/// or null if the entity has no state.
/// </summary>
public static EntityStatus? GetEntityStatus(string? orchestrationCustomStatus)
{
if (orchestrationCustomStatus == null)
{
return null;
}

return JsonConvert.DeserializeObject<EntityStatus>(orchestrationCustomStatus, Serializer.InternalSerializerSettings)!;
}
}
}
17 changes: 16 additions & 1 deletion src/DurableTask.Core/Entities/StateFormat/EntityStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,25 @@ namespace DurableTask.Core.Entities
[DataContract]
public class EntityStatus
{
/// <summary>
/// The JSON property name for the entityExists property.
/// </summary>
const string EntityExistsProperyName = "entityExists";

/// <summary>
/// A fast shortcut for checking whether an entity exists, looking at the serialized json string directly. Used by queries.
/// </summary>
/// <param name="serializedJson"></param>
/// <returns></returns>
public static bool TestEntityExists(string serializedJson)
{
return serializedJson.Contains(EntityExistsProperyName);
}

/// <summary>
/// Whether this entity exists or not.
/// </summary>
[DataMember(Name = "entityExists", EmitDefaultValue = false)]
[DataMember(Name = EntityExistsProperyName, EmitDefaultValue = false)]
public bool EntityExists { get; set; }

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions src/DurableTask.Core/Entities/StateFormat/SchedulerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ namespace DurableTask.Core.Entities
[DataContract]
internal class SchedulerState
{
/// <summary>
/// Whether this entity exists or not.
/// </summary>
[DataMember(Name = "exists", EmitDefaultValue = false)]
public bool EntityExists { get; set; }
[IgnoreDataMember]
public bool EntityExists => this.EntityState != null;
Comment on lines -27 to +28
Copy link
Collaborator

@davidmrdavid davidmrdavid Sep 7, 2023

Choose a reason for hiding this comment

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

Is this change (changing DataMember to IgnoreDataMember) backwards compatible? Not immediately sure who's consuming this.

Copy link
Member

Choose a reason for hiding this comment

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

This change should be backwards compatible since it should always (in theory) return the same value as before. But entities haven't been shipped/announced as a public feature of DTFx, so I assume we don't need to worry about backwards compatibility yet?

Copy link
Collaborator

@davidmrdavid davidmrdavid Sep 7, 2023

Choose a reason for hiding this comment

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

entities haven't been shipped/announced as a public feature of DTFx

ah, good call out

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so I assume we don't need to worry about backwards compatibility yet?

I actually did design the core-entities with compatibility in mind - I was planning to switch the old entity implementation in DF to the new implementation of entities in DT core, so non-isolated users can benefit from it as well. However, that is not currently our priority - for now we just care about getting Isolated working.


/// <summary>
/// The last serialized entity state.
Expand Down
1 change: 0 additions & 1 deletion src/DurableTask.Core/TaskEntityDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ protected async Task<bool> OnProcessWorkItemAsync(TaskOrchestrationWorkItem work

// update the entity state based on the result
schedulerState.EntityState = result.EntityState;
schedulerState.EntityExists = result.EntityState != null;

// perform the actions
foreach (var action in result.Actions!)
Expand Down