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 docs & logging information for Leases table info #756

Merged
merged 1 commit into from
Mar 23, 2023
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
28 changes: 28 additions & 0 deletions docs/BindingsOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ This table stores information about each function being executed, what table tha

A `Leases_*` table is created for every unique instance of a function and table. The full name will be in the format `Leases_<FunctionId>_<TableId>` where `<FunctionId>` is generated from the function ID and `<TableId>` is the object ID of the table being tracked. Such as `Leases_7d12c06c6ddff24c_1845581613`.

To find the name of the leases table associated with your function, look in the log output for a line such as this which is emitted when the trigger is started.

`SQL trigger Leases table: [az_func].[Leases_84d975fca0f7441a_901578250]`

This log message is at the `Information` level, so make sure your log level is set correctly.

NOTE: `FunctionId` is generated from a couple of inputs:
- The HostId, which is a hash of the assembly name containing the function
- The full class and method name of the function
Expand Down Expand Up @@ -194,3 +200,25 @@ Note that these retries are outside the built in idle connection retry logic tha
If an exception occurs in the user function when processing changes then those rows will be retried again in 60 seconds. Other changes will be processed as normal during this time, but the rows that caused the exception will be ignored until the timeout period has elapsed.

If the function execution fails 5 times in a row for a given row then that row is completely ignored for all future changes.

You can run this query to see what rows have failed 5 times and are currently ignored, see [Leases table](#az_funcleases_) documentation for how to get the correct Leases table to query for your function.

```sql
SELECT * FROM [az_func].[Leases_<FunctionId>_<TableId>] WHERE _az_func_AttemptCount = 5
```

To reset a row and enable functions to try processing it again set the `_az_func_AttemptCount` value to 0.

e.g.

```sql
UPDATE [Products].[az_func].[Leases_<FunctionId>_<TableId>] SET _az_func_AttemptCount = 0 WHERE _az_func_AttemptCount = 5
```

> Note: This will reset ALL ignored rows. To reset only a specific row change the WHERE clause to select only the row you want to update.

e.g.

```sql
UPDATE [Products].[az_func].[Leases_<FunctionId>_<TableId>] SET _az_func_AttemptCount = 0 WHERE ProductId = 123
```
5 changes: 3 additions & 2 deletions src/TriggerBinding/SqlTriggerListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
transaction.Commit();
}

this._logger.LogInformation($"Starting SQL trigger listener for table: '{this._userTable.FullName}', function ID: '{this._userFunctionId}'.");
this._logger.LogInformation($"Starting SQL trigger listener for table: '{this._userTable.FullName}' (object ID: {userTableId}), function ID: {this._userFunctionId}");

this._changeMonitor = new SqlTableChangeMonitor<T>(
this._connectionString,
Expand All @@ -155,7 +155,8 @@ public async Task StartAsync(CancellationToken cancellationToken)
this._telemetryProps);

this._listenerState = ListenerStarted;
this._logger.LogInformation($"Started SQL trigger listener for table: '{this._userTable.FullName}', function ID: '{this._userFunctionId}'.");
this._logger.LogInformation($"Started SQL trigger listener for table: '{this._userTable.FullName}' (object ID: {userTableId}), function ID: {this._userFunctionId}");
this._logger.LogInformation($"SQL trigger Leases table: {leasesTableName}");

var measures = new Dictionary<TelemetryMeasureName, double>
{
Expand Down