Skip to content

Commit 50a5d31

Browse files
committed
Replace Tuple<StoredId, long> with StoredIdAndPosition record
Introduces a named StoredIdAndPosition record (in Storage/Types.cs) for the GetCrashedReplicaMessages result instead of the anonymous Tuple<StoredId, long>, giving the (flow, position) pair meaningful member names.
1 parent 5afe25e commit 50a5d31

10 files changed

Lines changed: 21 additions & 21 deletions

File tree

Core/Cleipnir.ResilientFunctions.Tests/Messaging/TestTemplates/MessageStoreTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,8 @@ protected async Task CrashedReplicaMessagesAreFetched(Task<IFunctionStore> funct
12321232
var crashed = await messageStore.GetCrashedReplicaMessages([liveReplica]);
12331233

12341234
crashed.Count.ShouldBe(2);
1235-
crashed.ShouldContain(t => t.Item1 == flow1 && t.Item2 == bPosition);
1236-
crashed.ShouldContain(t => t.Item1 == flow2 && t.Item2 == cPosition);
1235+
crashed.ShouldContain(t => t.StoredId == flow1 && t.Position == bPosition);
1236+
crashed.ShouldContain(t => t.StoredId == flow2 && t.Position == cPosition);
12371237
}
12381238

12391239
public abstract Task MessageReplicaCanBeReassigned();

Core/Cleipnir.ResilientFunctions/Messaging/IMessageStore.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Threading.Tasks;
43
using Cleipnir.ResilientFunctions.Domain;
54
using Cleipnir.ResilientFunctions.Storage;
@@ -38,7 +37,7 @@ public interface IMessageStore
3837
/// longer alive (its replica is not contained in <paramref name="liveReplicas"/>).
3938
/// Used to detect messages stranded by crashed replicas so they can be re-assigned to a live replica via <see cref="SetReplica"/>.
4039
/// </summary>
41-
Task<List<Tuple<StoredId, long>>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas);
40+
Task<List<StoredIdAndPosition>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas);
4241

4342
/// <summary>
4443
/// Re-assigns the messages at the provided positions to <paramref name="newReplica"/>,

Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,16 @@ public Task<Dictionary<StoredId, List<StoredMessage>>> GetMessagesForReplica(Rep
688688
}
689689
}
690690

691-
public Task<List<Tuple<StoredId, long>>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
691+
public Task<List<StoredIdAndPosition>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
692692
{
693693
var live = liveReplicas.ToHashSet();
694694
lock (_sync)
695695
{
696-
var result = new List<Tuple<StoredId, long>>();
696+
var result = new List<StoredIdAndPosition>();
697697
foreach (var (storedId, messages) in _messages)
698698
foreach (var (position, message) in messages.OrderBy(kv => kv.Key))
699699
if (!live.Contains(message.Replica))
700-
result.Add(Tuple.Create(storedId, position));
700+
result.Add(new StoredIdAndPosition(storedId, position));
701701

702702
return result.ToTask();
703703
}

Core/Cleipnir.ResilientFunctions/Storage/Types.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public record StoredException(string ExceptionMessage, string? ExceptionStackTra
113113

114114
public record StatusAndId(StoredId StoredId, Status Status, long Expiry);
115115

116+
public record StoredIdAndPosition(StoredId StoredId, long Position);
117+
116118
public record StoredEffectChange(
117119
StoredId StoredId,
118120
EffectId EffectId,

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbMessageStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public async Task<Dictionary<StoredId, List<StoredMessage>>> GetMessagesForRepli
212212
return storedMessages;
213213
}
214214

215-
public async Task<List<Tuple<StoredId, long>>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
215+
public async Task<List<StoredIdAndPosition>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
216216
{
217217
await using var conn = await DatabaseHelper.CreateOpenConnection(_connectionString);
218218
await using var command = _sqlGenerator

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Runtime.Serialization;
32
using System.Text.Json;
43
using Cleipnir.ResilientFunctions.Domain;
@@ -687,14 +686,14 @@ WHERE replica IS NOT NULL{notInClause}
687686
return StoreCommand.Create(sql);
688687
}
689688

690-
public async Task<List<Tuple<StoredId, long>>> ReadStoredIdAndPositions(MySqlDataReader reader)
689+
public async Task<List<StoredIdAndPosition>> ReadStoredIdAndPositions(MySqlDataReader reader)
691690
{
692-
var result = new List<Tuple<StoredId, long>>();
691+
var result = new List<StoredIdAndPosition>();
693692
while (await reader.ReadAsync())
694693
{
695694
var id = reader.GetString(0).ToGuid().ToStoredId();
696695
var position = reader.GetInt64(1);
697-
result.Add(Tuple.Create(id, position));
696+
result.Add(new StoredIdAndPosition(id, position));
698697
}
699698

700699
return result;

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlMessageStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public async Task<Dictionary<StoredId, List<StoredMessage>>> GetMessagesForRepli
211211
return storedMessages;
212212
}
213213

214-
public async Task<List<Tuple<StoredId, long>>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
214+
public async Task<List<StoredIdAndPosition>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
215215
{
216216
await using var conn = await CreateConnection();
217217
await using var command = sqlGenerator.GetCrashedReplicaMessages(liveReplicas).ToNpgsqlCommand(conn);

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,14 @@ public StoreCommand GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplica
606606
return StoreCommand.Create(sql, values: [ liveReplicas.Select(r => r.AsGuid).ToArray() ]);
607607
}
608608

609-
public async Task<List<Tuple<StoredId, long>>> ReadStoredIdAndPositions(NpgsqlDataReader reader)
609+
public async Task<List<StoredIdAndPosition>> ReadStoredIdAndPositions(NpgsqlDataReader reader)
610610
{
611-
var result = new List<Tuple<StoredId, long>>();
611+
var result = new List<StoredIdAndPosition>();
612612
while (await reader.ReadAsync())
613613
{
614614
var id = reader.GetGuid(0).ToStoredId();
615615
var position = reader.GetInt64(1);
616-
result.Add(Tuple.Create(id, position));
616+
result.Add(new StoredIdAndPosition(id, position));
617617
}
618618

619619
return result;

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,14 @@ WHERE Replica IS NOT NULL{notInClause}
693693
return command;
694694
}
695695

696-
public async Task<List<Tuple<StoredId, long>>> ReadStoredIdAndPositions(SqlDataReader reader)
696+
public async Task<List<StoredIdAndPosition>> ReadStoredIdAndPositions(SqlDataReader reader)
697697
{
698-
var result = new List<Tuple<StoredId, long>>();
698+
var result = new List<StoredIdAndPosition>();
699699
while (await reader.ReadAsync())
700700
{
701701
var id = reader.GetGuid(0).ToStoredId();
702702
var position = reader.GetInt64(1);
703-
result.Add(Tuple.Create(id, position));
703+
result.Add(new StoredIdAndPosition(id, position));
704704
}
705705

706706
return result;

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerMessageStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public async Task<Dictionary<StoredId, List<StoredMessage>>> GetMessagesForRepli
221221
return storedMessages;
222222
}
223223

224-
public async Task<List<Tuple<StoredId, long>>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
224+
public async Task<List<StoredIdAndPosition>> GetCrashedReplicaMessages(IEnumerable<ReplicaId> liveReplicas)
225225
{
226226
await using var conn = await CreateConnection();
227227
await using var cmd = _sqlGenerator.GetCrashedReplicaMessages(liveReplicas).ToSqlCommand(conn);

0 commit comments

Comments
 (0)