0

I have stateful service that uses uniform int64 partitioning with 5 partitions

<UniformInt64Partition PartitionCount="5" LowKey="-9223372036854775808" HighKey="9223372036854775807" />

This results in partitions as below

[
  {
    "lowKey": -5534023222112865000,
    "highKey": -1844674407370955300,
    "id": "92b4c32e-cb3c-432f-aea0-4579fc72850c",
    "kind": 2
  },
  {
    "lowKey": 5534023222112865000,
    "highKey": 9223372036854776000,
    "id": "dd9b084d-88fa-4773-94d9-f634d22a2c03",
    "kind": 2
  },
  {
    "lowKey": -9223372036854776000,
    "highKey": -5534023222112865000,
    "id": "d7322e52-cf1e-47c2-b713-e983f443b533",
    "kind": 2
  },
  {
    "lowKey": -1844674407370955300,
    "highKey": 1844674407370955300,
    "id": "dfe2f994-bdc7-4b32-b54f-78a0245e4c4c",
    "kind": 2
  },
  {
    "lowKey": 1844674407370955300,
    "highKey": 5534023222112865000,
    "id": "6ad81ffb-5f3c-48ba-91d9-e65b23c528a4",
    "kind": 2
  }
]

So if I have a request using the partition key 55340232221128650067

Why has this been resolved by the 92b4c32e-cb3c-432f-aea0-4579fc72850c partition?

I am using the logic below to find the partition

public static long MapUlongToLong(ulong ulongValue)
{
    return unchecked((long)ulongValue + long.MinValue);
}

protected override async Task<ResolvedServicePartition> FindPartition(ulong key = 0)
{
    var longValue = MapUlongToLong(key);
    var partitionKey = new ServicePartitionKey(longValue);
    var resolver = ServicePartitionResolver.GetDefault();
    var result = await resolver.ResolveAsync(FullServiceName, partitionKey, CancellationToken.None).ConfigureAwait(false);
    return result;
}

I have to map ulong to long because when I tried using the big value in code it classed this as a ulong value

Is this causing the problem?

Are there alternatives?

Paul

Paul
  • 2,773
  • 7
  • 41
  • 96
  • I think you mean partition `92b4c32e-cb3c-432f-aea0-4579fc72850c`. Also, your input value does not compile (too big). What is the output of `longValue` in your code for the given input? – Peter Bons Jul 29 '18 at 13:48
  • This was a value I typed directly into the URL. Maybe I dont need to worry about ulong at all? – Paul Jul 29 '18 at 14:14
  • Well, let me put it this way. Given an input of 5534023222112865006 I get -3689348814741910802 as output using `MapUlongToLong` which maps to partition 92b4c32e-cb3c-432f-aea0-4579fc72850c. – Peter Bons Jul 29 '18 at 14:16
  • Just use a long, not ulong and you'll be fine. – Peter Bons Jul 29 '18 at 14:18
  • ok I am using FNV-1 to generate my key. https://stackoverflow.com/questions/51226000/create-key-via-sql-and-c-sharp-for-partition-key#51239370. This does a cast to long at the end. Im now worried about this i I do get a big value thats bigger than long? I obviously cannot control the key generated here – Paul Jul 29 '18 at 14:20
  • ok I have removed ulong stuff – Paul Jul 29 '18 at 14:20
  • to ignore overflow checking errors, use `unchecked`. – LoekD Jul 30 '18 at 06:29

0 Answers0