imranmomin/Hangfire.AzureDocumentDB

Hangfire.Storage.JobStorageConnection.GetFirstByLowestScoreFromSet method not supported

Closed this issue · 10 comments

Current Nuget package versions:
Hangfire.Core 1.7.3
Hangfire.AzureDocumentDB 3.0.2
Microsoft.Azure.DocumentDB 2.8.1

We get the following error when trying to run our hangfire instance.

Specified method is not supported.
   at Hangfire.Storage.JobStorageConnection.GetFirstByLowestScoreFromSet(String key, Double fromScore, Double toScore, Int32 count)

We set it up as follows (Sif is our internal project name):

GlobalConfiguration.Configuration.UseAzureDocumentDbStorage($"https://{cosmosAccount}.documents.azure.com/", $"{cosmosAuthKey}", "Sif", "Hangfire");

This worked previously when we were on:
Hangfire.Core 1.7.3
Hangfire.AzureDocumentDB 2.1.0
Microsoft.Azure.DocumentDB 1.22.0

I also noticed some issues where it complained it could not connect to Cosmos stating that I should check my firewall or authorisation token. However, another application using the same auth token from the same maching works without a problem.

@NoMercy82 - Yeah I think a new overload was introduce which is not implemented. I can fix this. But will need your help to test this

Let me know if u will do the test

@imranmomin I forked the project and it is now local for me. So if you wish for me to simply change one method we can test very quickly without rolling out pre-release packages etc.

@NoMercy82 I have fixed the issue under branch - https://github.com/imranmomin/Hangfire.AzureDocumentDB/tree/bug-fixes

Can you pull down and check if its works fine.

I am getting a few errors:

System.ArgumentNullException: 'Value cannot be null.
Parameter name: key'

At line 288 of DocumentDbConnection.cs

if (key == null) throw new ArgumentNullException(nameof(key));

I also get a few others:

Line 106 of ClientHelper.cs

return await query.ExecuteNextAsync<T>();
Microsoft.Azure.Documents.DocumentClientException: 'The provided cross partition query can not be directly served by the gateway. This is a first chance (internal) exception that all newer clients will know how to handle gracefully. This exception is traced, but unless you see it bubble up as an exception (which only happens on older SDK clients), then you can safely ignore this message.'

Technically you should not get error on Line#288 on DocumentDbConnection. Then same exception is in place on Hangfire Sql Service library.

For Line#106 of ClientHelper can you provide me context. i.e which query or call stack.

I think the problem is in the Acquiring of a distributed lock, perhaps.

Line 60 of DocumentDbDistributedLock.cs

Message: {"Errors":["Resource Not Found"]}
ActivityId: 4d042c60-042f-4257-b6e4-306c09eb4b86, Request URI: /apps/ee8e3283-942e-44a0-96e9-191267efb4ff/services/3fa9a280-d363-4ae9-a745-0be6488b80b6/partitions/70518734-f2a1-4374-a4b9-b2374bf9ea81/replicas/132155879663156628p/, RequestStats: 
RequestStartTime: 2019-10-30T07:53:59.5301038Z, RequestEndTime: 2019-10-30T07:53:59.6656249Z,  Number of regions attempted:1
ResponseTime: 2019-10-30T07:53:59.6656249Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-northeurope1-fd19.documents.azure.com:16836/apps/ee8e3283-942e-44a0-96e9-191267efb4ff/services/3fa9a280-d363-4ae9-a745-0be6488b80b6/partitions/70518734-f2a1-4374-a4b9-b2374bf9ea81/replicas/132155879663156628p/, LSN: 1299872, GlobalCommittedLsn: 1299872, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#1299872, UsingLocalLSN: True, TransportException: null, ResourceType: Document, OperationType: Read
, SDK: documentdb-dotnet-sdk/2.8.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0

I am getting this error bubble up:

The provided cross partition query can not be directly served by the gateway. This is a first chance (internal) exception that all newer clients will know how to handle gracefully. This exception is traced, but unless you see it bubble up as an exception (which only happens on older SDK clients), then you can safely ignore this message., documentdb-dotnet-sdk/2.8.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0
at Microsoft.Azure.Documents.Routing.PartitionRoutingHelper.GetProvidedPartitionKeyRanges(SqlQuerySpec querySpec, Boolean enableCrossPartitionQuery, Boolean parallelizeCrossPartitionQuery, Boolean isContinuationExpected, Boolean hasLogicalPartitionKey, PartitionKeyDefinition partitionKeyDefinition, QueryPartitionProvider queryPartitionProvider, String clientApiVersion, QueryInfo& queryInfo)

The query string that caused it is:
{{"query":"SELECT DISTINCT VALUE doc['name'] FROM doc WHERE doc.type = @type","parameters":[{"name":"@type","value":3}]}}

Under DocumentDbDistributedLock we don't use any queries. I think that is not the issue.

Any based on the document, we should be avoiding DISTINCT queries when using gateway. Luckily there was only one query which used DISTINCT. I have updated the query.

Let me know if it works fine.

https://docs.microsoft.com/en-us/rest/api/cosmos-db/querying-cosmosdb-resources-using-the-rest-api#queries-that-cannot-be-served-by-gateway

This does seem to be working much better now yes.

I will leave the app running in our dev environment for a day or so and see if all is good. If so I'll report back and let you know. Thanks

Fixed and released under v3.0.3