Skip to content

Commit

Permalink
Minor updates to finding storage locations for grains
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJoPages committed Jan 30, 2024
1 parent 2fbde87 commit ad2fe1b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
9 changes: 7 additions & 2 deletions OrleansShardedStorageProvider/AzureShardedGrainBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AzureShardedGrainBase(string serviceId, AzureShardedStorageOptions option
_options = options;
}

protected int GetShardNumberFromKey(string pk)
public int GetShardNumberFromKey(string pk)
{
var hash = GetStableHashCode(pk);
var storageNum = Math.Abs(hash % this._options.ConnectionStrings.Count());
Expand Down Expand Up @@ -51,7 +51,12 @@ protected int GetStableHashCode(string str)
}


private const string KeyStringSeparator = "__";
protected const string KeyStringSeparator = "__";

public string GetKeyStringSeparator()
{
return KeyStringSeparator;
}

protected string GetKeyString(GrainId grainId)
{
Expand Down
28 changes: 27 additions & 1 deletion ZDataFinder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@
options.ConnectionStrings.AddRange(blobGrainStores);



var serviceId = "OrleansBasics";
var grainName = "smalldata";
var grainId = "1F";
AzureShardedGrainBase agb = new AzureShardedGrainBase(serviceId, options);

var key = $"{serviceId}{agb.GetKeyStringSeparator()}{grainName}_{grainId}";
var storageNumberFromKey = agb.GetShardNumberFromKey(key);
Console.WriteLine($"storage location from key = {storageNumberFromKey}");

















StorageDataFinder finder = new StorageDataFinder();
await finder.Init(options);

Expand All @@ -49,7 +75,7 @@

do
{
Console.WriteLine("Enter the guid you wish to find the data location of");
Console.WriteLine("Enter the all (or part of) the guid you wish to find the data location of");
input = Console.ReadLine();
}
while (String.IsNullOrWhiteSpace(input));
Expand Down
10 changes: 3 additions & 7 deletions ZDataFinder/StorageDataFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Azure.Storage.Blobs.Models;
using System.Collections.Concurrent;
using Microsoft.Identity.Client;
using System.Xml;

namespace ZDataFinder
{
Expand Down Expand Up @@ -105,7 +106,7 @@ await Parallel.ForEachAsync(this._blobClients, options, async (blobClient, ct) =
{
retVal.Add($"{blobClient.AccountName} / {blobItem.Name}");

if(exitAtFirstResult)
if (exitAtFirstResult)
{
Console.WriteLine("Found something. Exiting parallel foreach...");
source.Cancel();
Expand All @@ -122,16 +123,11 @@ await Parallel.ForEachAsync(this._blobClients, options, async (blobClient, ct) =
{
// ... (the cts was cancelled)
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine(e.ToString());
}






return retVal;
}
}
Expand Down

0 comments on commit ad2fe1b

Please sign in to comment.