Skip to content

Commit

Permalink
Doesn't use the contact directly and constructs the error message dep…
Browse files Browse the repository at this point in the history
…ending on the persistent projection contract id
  • Loading branch information
Kali-Sh committed Nov 6, 2024
1 parent 47cc030 commit 133761b
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/Elders.Cronus/Projections/LatestVersionProjectionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class LatestVersionProjectionFinder : IProjectionVersionFinder
private readonly ICronusContextAccessor _cronusContextAccessor;
private readonly ILogger<LatestVersionProjectionFinder> _logger;

private const string MasterProjectionMissingMessage = "table f1469a8e9fc847f5b057d5394ed33b4c_1_ver does not exist";
private const char Dash = '-';

private readonly ProjectionVersion persistentVersion;

Expand Down Expand Up @@ -55,9 +55,11 @@ public async Task<ProjectionVersion> GetCurrentLiveVersionOrTheDefaultOne(Type p
ProjectionVersionManagerId versionId = new ProjectionVersionManagerId(projectionName, _cronusContextAccessor.CronusContext.Tenant);
ProjectionVersion initialVersion = new ProjectionVersion(projectionName, ProjectionStatus.NotPresent, 1, _hasher.CalculateHash(projectionType));

string error = $"table {GetPersistantProjectionColumnFamilyName()} does not exist";

try
{
var loadResultFromF1 = await GetProjectionVersionsFromStoreAsync(projectionName, _cronusContextAccessor.CronusContext.Tenant);
var loadResultFromF1 = await GetProjectionVersionsFromStoreAsync(projectionName, _cronusContextAccessor.CronusContext.Tenant).ConfigureAwait(false);

if (loadResultFromF1.IsSuccess)
{
Expand All @@ -76,7 +78,7 @@ public async Task<ProjectionVersion> GetCurrentLiveVersionOrTheDefaultOne(Type p
return initialVersion;
}
}
catch (Exception ex) when (ex.Message.Contains(MasterProjectionMissingMessage)) // we might come here if we are in the initial state (we have no data and f1 projection is missing), because we are trying to load from tables that don't exist yet
catch (Exception ex) when (ex.Message.Contains(error)) // we might come here if we are in the initial state (we have no data and f1 projection is missing), because we are trying to load from tables that don't exist yet
{
return initialVersion;
}
Expand All @@ -97,7 +99,6 @@ private async Task<ReadResult<ProjectionVersionsHandler>> GetProjectionVersionsF
return new ReadResult<ProjectionVersionsHandler>(projectionInstance);
}


private async Task<ProjectionStream> LoadProjectionStreamAsync(IBlobId projectionId, ProjectionVersion version)
{
List<ProjectionCommit> projectionCommits = new List<ProjectionCommit>();
Expand All @@ -118,4 +119,32 @@ private async Task<ProjectionStream> LoadProjectionStreamAsync(IBlobId projectio

return stream;
}

private string GetPersistantProjectionColumnFamilyName()
{
string projectionName = persistentVersion.ProjectionName;
Span<char> result = stackalloc char[projectionName.Length];

int theIndex = 0;
for (int i = 0; i < projectionName.Length; i++)
{
char character = projectionName[i];

if (character.Equals(Dash))
continue;

if (char.IsUpper(character))
{
result[theIndex] = char.ToLower(character);
}
else
{
result[theIndex] = character;
}
theIndex++;
}
Span<char> trimmed = result.Slice(0, theIndex);
return $"{trimmed}_{persistentVersion.Revision}_{persistentVersion.Hash}";
}

}

0 comments on commit 133761b

Please sign in to comment.