Skip to content

Commit 1485d43

Browse files
committed
🎉 feat(event): 添加GenerateSerializer和IdAttribute
1 parent dbb8115 commit 1485d43

15 files changed

Lines changed: 171 additions & 29 deletions

File tree

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
using Vertex.Abstractions.Serialization;
1+
using Orleans;
2+
using Vertex.Abstractions.Serialization;
23
using Vertex.Transaction.Abstractions.Snapshot;
34

45
namespace Transfer.Grains.Snapshot
56
{
7+
/// <summary>
8+
/// 账户快照类
9+
/// </summary>
10+
[GenerateSerializer]
611
public class AccountSnapshot : ITxSnapshot<AccountSnapshot>
712
{
13+
/// <summary>
14+
/// 账户余额
15+
/// </summary>
16+
[Id(0)]
817
public decimal Balance { get; set; }
918

19+
/// <summary>
20+
/// 克隆当前快照
21+
/// </summary>
22+
/// <param name="serializer">序列化器</param>
23+
/// <returns>克隆的账户快照</returns>
1024
public AccountSnapshot Clone(ISerializer serializer)
1125
{
1226
return new AccountSnapshot
@@ -15,4 +29,4 @@ public AccountSnapshot Clone(ISerializer serializer)
1529
};
1630
}
1731
}
18-
}
32+
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
namespace Vertex.Abstractions.Event
1+
using Orleans;
2+
3+
namespace Vertex.Abstractions.Event
24
{
5+
[GenerateSerializer]
36
public class EventDocument<TPrimaryKey>
47
{
8+
[Id(0)]
59
public string FlowId { get; set; }
610

11+
[Id(1)]
712
public TPrimaryKey ActorId { get; set; }
813

14+
[Id(2)]
915
public string Name { get; set; }
1016

17+
[Id(3)]
1118
public string Data { get; set; }
1219

20+
[Id(4)]
1321
public long Timestamp { get; set; }
1422

23+
[Id(5)]
1524
public long Version { get; set; }
1625
}
17-
}
26+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
namespace Vertex.Abstractions.Event
1+
using Orleans;
2+
3+
namespace Vertex.Abstractions.Event
24
{
5+
[GenerateSerializer]
36
public class EventDocumentDto
47
{
8+
[Id(0)]
59
public string Name { get; set; }
610

11+
[Id(1)]
712
public string Data { get; set; }
813

14+
[Id(2)]
915
public string FlowId { get; set; }
1016

17+
[Id(3)]
1118
public long Timestamp { get; set; }
1219

20+
[Id(4)]
1321
public long Version { get; set; }
1422
}
1523
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
using Orleans.Concurrency;
1+
using Orleans;
22

33
namespace Vertex.Abstractions.Event
44
{
55
/// <summary>
6-
/// Record the meta information of the event
6+
/// 记录事件的元信息
77
/// </summary>
8-
[Orleans.Immutable]
9-
public record EventMeta
8+
[GenerateSerializer]
9+
public class EventMeta
1010
{
11+
/// <summary>
12+
/// 流程ID
13+
/// </summary>
14+
[Id(0)]
1115
public string FlowId { get; set; }
1216

1317
/// <summary>
14-
/// Used to describe the sequence of events produced by an actor
18+
/// 用于描述由演员生成的事件序列
1519
/// </summary>
20+
[Id(1)]
1621
public long Version { get; init; }
1722

1823
/// <summary>
19-
/// Records the timestamp generated by the event, accurate to seconds
24+
/// 记录事件生成的时间戳,精确到秒
2025
/// </summary>
26+
[Id(2)]
2127
public long Timestamp { get; init; }
2228
}
23-
}
29+
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
namespace Vertex.Abstractions.Event
1+
using Orleans;
2+
3+
namespace Vertex.Abstractions.Event
24
{
35
/// <summary>
46
/// A typed wrapper for an event that contains details about the event.
57
/// </summary>
68
/// <typeparam name="TPrimaryKey">The type of the entity's key.</typeparam>
9+
[GenerateSerializer]
710
public class EventUnit<TPrimaryKey>
811
{
9-
public IEvent Event { get; set; }
12+
[Id(0)]
13+
public TPrimaryKey ActorId { get; set; }
1014

15+
[Id(1)]
1116
public EventMeta Meta { get; set; }
12-
13-
public TPrimaryKey ActorId { get; set; }
17+
18+
public IEvent Event { get; set; }
1419
}
1520
}
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
1-
namespace Vertex.Abstractions.Snapshot
1+
using Orleans;
2+
3+
namespace Vertex.Abstractions.Snapshot
24
{
5+
/// <summary>
6+
/// 快照元数据类
7+
/// </summary>
8+
[GenerateSerializer]
39
public record SnapshotMeta<TPrimaryKey>
410
{
11+
/// <summary>
12+
/// 演员ID
13+
/// </summary>
14+
[Id(0)]
515
public TPrimaryKey ActorId { get; set; }
616

17+
/// <summary>
18+
/// 正在处理的版本
19+
/// </summary>
20+
[Id(1)]
721
public long DoingVersion { get; set; }
822

23+
/// <summary>
24+
/// 版本
25+
/// </summary>
26+
[Id(2)]
927
public long Version { get; set; }
1028

29+
/// <summary>
30+
/// 最小事件时间戳
31+
/// </summary>
32+
[Id(3)]
1133
public long MinEventTimestamp { get; set; }
1234

35+
/// <summary>
36+
/// 最小事件版本
37+
/// </summary>
38+
[Id(4)]
1339
public long MinEventVersion { get; set; }
1440

41+
/// <summary>
42+
/// 是否是最新的
43+
/// </summary>
44+
[Id(5)]
1545
public bool IsLatest { get; set; }
1646
}
17-
}
47+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
namespace Vertex.Abstractions.Snapshot
1+
using Orleans;
2+
3+
namespace Vertex.Abstractions.Snapshot
24
{
5+
[GenerateSerializer]
36
public record SnapshotUnit<TPrimaryKey, T>
47
where T : ISnapshot
58
{
9+
[Id(0)]
610
public SnapshotMeta<TPrimaryKey> Meta { get; set; }
711

12+
[Id(1)]
813
public T Data { get; set; }
914
}
1015
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
namespace Vertex.Abstractions.Snapshot
1+
using Orleans;
2+
3+
namespace Vertex.Abstractions.Snapshot
24
{
5+
/// <summary>
6+
/// 子快照类
7+
/// </summary>
8+
[GenerateSerializer]
39
public record SubSnapshot<TPrimaryKey>
410
{
11+
[Id(0)]
512
public TPrimaryKey ActorId { get; set; }
613

14+
/// <summary>
15+
/// 正在处理的版本
16+
/// </summary>
17+
[Id(1)]
718
public long DoingVersion { get; set; }
819

20+
/// <summary>
21+
/// 版本
22+
/// </summary>
23+
[Id(2)]
924
public long Version { get; set; }
1025
}
11-
}
26+
}

src/Vertex.Abstractions/Vertex.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Sdk Name="Microsoft.Build.CentralPackageVersions" />
33
<ItemGroup>
44
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" />
5+
<PackageReference Include="Microsoft.Orleans.CodeGenerator" />
56
</ItemGroup>
67

78
</Project>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
namespace Vertex.Runtime.Options
1+
using Orleans;
2+
3+
namespace Vertex.Runtime.Options
24
{
5+
[GenerateSerializer]
36
public class ActorOptions
47
{
58
/// <summary>
69
/// Event Version interval of RayGrain saving snapshot
710
/// </summary>
11+
[Id(0)]
812
public int SnapshotVersionInterval { get; set; } = 500;
913

1014
/// <summary>
1115
/// The minimum event Version interval for saving snapshots when RayGrain is deactivated
1216
/// </summary>
17+
[Id(1)]
1318
public int MinSnapshotVersionInterval { get; set; } = 1;
1419

1520
/// <summary>
1621
/// The amount of data read each time when reading events in batches
1722
/// </summary>
23+
[Id(2)]
1824
public int EventPageSize { get; set; } = 2000;
1925
}
2026
}

0 commit comments

Comments
 (0)