Search code examples
sql-serverpersistent-storageorleans

Orleans - how to implement storage sharding by Tenant with AdoNetStorageProvider


I am trying to find how we can implement storage sharding by tenant using the built in AdoNetStorageProvider. We are planning for SQL Server on-premises.

for example:

  • Grain that belong to tenant 1 should persist to shard A
  • Grain that belong to tenant 2 should persist to shard B
  • Grain that belong to tenant 3 should persist to shard A

Where our Sharding function will indicate which shard to use. For this purpose the sharding function gets its grain sharding from DB based on grain extended key. (so should not all be in configuration files, as number of shards rarely changes but new tenants added frequently). If this can be implemented by some built in framework then even better.

AS Per https://dotnet.github.io/orleans/Documentation/Core-Features/Grain-Persistence.html?q=sharded#shardedstorageprovider shardedstorageprovider will distribute (shard) the data equally across the shards based on hash function. which does not achieve this purpose. The shards may (or may not) be geo located.

The sharding example in github is referring to Elastic SQL Client on Azure which as per my understanding is not available for SQL server.

I know we can write our own storage provider. but whenever possible we try to stay with the core.


Solution

  • Based on the answer on the project Gitter, There is no built in ability to shard by tenant.

    The way to implement this is by deriving from https://github.com/dotnet/orleans/blob/master/src/OrleansProviders/Storage/ShardedStorageProvider.cs and overriding HashFunction method. Credit to @SebastianStehle