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

Support rewinding orchestrations #96

Merged
merged 9 commits into from
Jun 1, 2022
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

### New

* Support for orchestration rewind ([#96](https://github.com/microsoft/durabletask-mssql/pull/96)) - contributed by [@Greybird](https://github.com/Greybird)

### Updates

None

### Breaking changes

None

## v1.0.0-rc2

### New

* Support for purging data with filters ([#80](https://github.com/microsoft/durabletask-mssql/pull/80)) - contributed by [@usemam](https://github.com/usemam)
* Support for new multi-instance query interface ([#88](https://github.com/microsoft/durabletask-mssql/pull/80)) - contributed by [@usemam](https://github.com/usemam)

Expand All @@ -12,7 +26,9 @@
* Removed unnecessary .NET Standard 2.1 target ([#82](https://github.com/microsoft/durabletask-mssql/pull/82))
* Fixed problem terminating orchestration with running activity ([#83](https://github.com/microsoft/durabletask-mssql/pull/83))
* Fixed payload data leak for completed activities (same PR as above)
* Fixed NewEvents leak for completed or continued-as-new instances ([#97](https://github.com/microsoft/durabletask-mssql/pull/97))
* Activity payload IDs are now consistently saved to the history table ([#90](https://github.com/microsoft/durabletask-mssql/issues/90))
* Remove Microsoft.SqlServer.SqlManagementObjects dependency ([#92](https://github.com/microsoft/durabletask-mssql/pull/92)) - contributed by [@IGx89](https://github.com/IGx89)

### Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ steps:
vsVersion: 'latest'
logFileVerbosity: minimal
configuration: Release
msbuildArgs: /p:GITHUB_RUN_NUMBER=$(Build.BuildId) /p:ContinuousIntegrationBuild=true
msbuildArgs: /p:FileVersionRevision=$(Build.BuildId) /p:ContinuousIntegrationBuild=true

# Authenticode sign all the DLLs with the Microsoft certificate.
# This appears to be an in-place signing job, which is convenient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public override async Task<int> PurgeHistoryByFilters(DateTime createdTimeFrom,
return purgeResult.DeletedInstanceCount;
}

public override async Task RewindAsync(string instanceId, string reason)
{
await this.service.RewindTaskOrchestrationAsync(instanceId, reason);
}

public override bool TryGetScaleMonitor(
string functionId,
string functionName,
Expand Down
16 changes: 16 additions & 0 deletions src/DurableTask.SqlServer/LogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ public void CreatedDatabase(string databaseName)
this.WriteLog(logEvent);
}

public void DiscardingEvent(string instanceId, string eventType, int taskEventId, string details)
{
var logEvent = new LogEvents.DiscardingEventEvent(
instanceId,
eventType,
taskEventId,
details);
this.WriteLog(logEvent);
}

public void GenericInfoEvent(string details, string? instanceId)
{
var logEvent = new LogEvents.GenericInfo(details, instanceId);
this.WriteLog(logEvent);
}

void WriteLog(ILogEvent logEvent)
{
// LogDurableEvent is an extension method defined in DurableTask.Core
Expand Down
34 changes: 33 additions & 1 deletion src/DurableTask.SqlServer/Logging/DefaultEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ internal void PurgedInstances(
}

[Event(EventIds.CommandCompleted, Level = EventLevel.Verbose)]
public void CommandCompleted(
internal void CommandCompleted(
string? InstanceId,
string CommandText,
long LatencyMs,
Expand Down Expand Up @@ -266,5 +266,37 @@ internal void CreatedDatabase(
AppName,
ExtensionVersion);
}

[Event(EventIds.DiscardingEvent, Level = EventLevel.Warning, Version = 1)]
internal void DiscardingEvent(
string InstanceId,
string EventType,
int TaskEventId,
string Details,
string AppName,
string ExtensionVersion)
{
// TODO: Use WriteEventCore for better performance
this.WriteEvent(
EventIds.DiscardingEvent,
InstanceId,
EventType,
TaskEventId,
Details,
AppName,
ExtensionVersion);
}

[Event(EventIds.GenericInfo, Level = EventLevel.Informational, Version = 1)]
internal void GenericInfo(string Details, string InstanceId, string AppName, string ExtensionVersion)
{
// TODO: Use WriteEventCore for better performance
this.WriteEvent(
EventIds.GenericInfo,
InstanceId,
Details,
AppName,
ExtensionVersion);
}
}
}
2 changes: 2 additions & 0 deletions src/DurableTask.SqlServer/Logging/EventIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ static class EventIds
public const int PurgedInstances = 310;
public const int CommandCompleted = 311;
public const int CreatedDatabase = 312;
public const int DiscardingEvent = 313;
public const int GenericInfo = 314;
}
}
73 changes: 73 additions & 0 deletions src/DurableTask.SqlServer/Logging/LogEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,78 @@ void IEventSourceEvent.WriteEventSource() =>
DTUtils.AppName,
DTUtils.ExtensionVersionString);
}

internal class DiscardingEventEvent : StructuredLogEvent, IEventSourceEvent
{
public DiscardingEventEvent(string instanceId, string eventType, int taskEventId, string details)
{
this.InstanceId = instanceId;
this.EventType = eventType;
this.TaskEventId = taskEventId;
this.Details = details;
}

[StructuredLogField]
public string InstanceId { get; }

[StructuredLogField]
public string EventType { get; }

[StructuredLogField]
public int TaskEventId { get; }

[StructuredLogField]
public string Details { get; }

public override EventId EventId => new EventId(
EventIds.DiscardingEvent,
nameof(EventIds.DiscardingEvent));

public override LogLevel Level => LogLevel.Warning;

protected override string CreateLogMessage() =>
$"{this.InstanceId}: Discarding {GetEventDescription(this.EventType, this.TaskEventId)}: {this.Details}";

void IEventSourceEvent.WriteEventSource() =>
DefaultEventSource.Log.DiscardingEvent(
this.InstanceId,
this.EventType,
this.TaskEventId,
this.Details,
DTUtils.AppName,
DTUtils.ExtensionVersionString);
}

internal class GenericInfo : StructuredLogEvent, IEventSourceEvent
{
public GenericInfo(string details, string? instanceId)
{
this.Details = details;
this.InstanceId = instanceId;
}

[StructuredLogField]
public string Details { get; }

[StructuredLogField]
public string? InstanceId { get; }

public override EventId EventId => new EventId(
EventIds.GenericInfo,
nameof(EventIds.GenericInfo));

public override LogLevel Level => LogLevel.Information;

protected override string CreateLogMessage() => string.IsNullOrEmpty(this.InstanceId) ?
this.Details :
$"{this.InstanceId}: {this.Details}";

void IEventSourceEvent.WriteEventSource() =>
DefaultEventSource.Log.GenericInfo(
this.Details,
this.InstanceId ?? string.Empty,
DTUtils.AppName,
DTUtils.ExtensionVersionString);
}
}
}
3 changes: 3 additions & 0 deletions src/DurableTask.SqlServer/Scripts/drop-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ DROP PROCEDURE IF EXISTS dt.PurgeInstanceStateByTime
DROP PROCEDURE IF EXISTS dt._AddOrchestrationEvents
DROP PROCEDURE IF EXISTS dt._CheckpointOrchestration
DROP PROCEDURE IF EXISTS dt._CompleteTasks
DROP PROCEDURE IF EXISTS dt._DiscardEventsAndUnlockInstance
DROP PROCEDURE IF EXISTS dt._GetVersions
DROP PROCEDURE IF EXISTS dt._LockNextOrchestration
DROP PROCEDURE IF EXISTS dt._LockNextTask
DROP PROCEDURE IF EXISTS dt._QueryManyOrchestrations
DROP PROCEDURE IF EXISTS dt._RenewOrchestrationLocks
DROP PROCEDURE IF EXISTS dt._RenewTaskLocks
DROP PROCEDURE IF EXISTS dt._UpdateVersion
DROP PROCEDURE IF EXISTS dt._RewindInstance
DROP PROCEDURE IF EXISTS dt._RewindInstanceRecursive

-- Tables
DROP TABLE IF EXISTS dt.Versions
Expand Down
Loading