Skip to content

Commit 247b58f

Browse files
committed
归档逻辑优化
1 parent 7a9b5f4 commit 247b58f

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/Vertex.Runtime/Actor/VertexActor.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,25 +419,30 @@ protected ValueTask Archive()
419419
[MethodImpl(MethodImplOptions.AggressiveInlining)]
420420
protected async Task Archive(long endTimestamp)
421421
{
422-
var takes = 0;
422+
var skip = 0;
423423
while (true)
424424
{
425-
var events = await this.EventStorage.GetList(this.ActorId, endTimestamp, takes, this.ArchiveOptions.EventPageSize);
425+
var events = await this.EventStorage.GetList(this.ActorId, endTimestamp, skip, this.ArchiveOptions.EventPageSize);
426426
if (events.Count > 0)
427427
{
428-
await this.EventArchive.Arichive(events);
429-
this.Snapshot.Meta.MinEventTimestamp = events.Max(o => o.Timestamp);
430-
this.Snapshot.Meta.MinEventVersion += events.Count;
428+
var validEvents = events.Where(v => v.Version >= this.Snapshot.Meta.MinEventVersion).ToList();
429+
430+
await this.EventArchive.Arichive(validEvents);
431+
this.Snapshot.Meta.MinEventTimestamp = validEvents.Max(o => o.Timestamp);
432+
this.Snapshot.Meta.MinEventVersion = validEvents.Max(o => o.Version) + 1;
431433
}
434+
432435
if (events.Count < this.ArchiveOptions.EventPageSize)
433436
{
434437
break;
435438
}
436439

437-
takes += events.Count;
440+
skip += events.Count;
438441
}
442+
439443
this.Snapshot.Meta.MinEventTimestamp = endTimestamp;
440-
var isLatest = this.Snapshot.Meta.Version - this.Snapshot.Meta.MinEventVersion == -1;
444+
445+
var isLatest = this.Snapshot.Meta.Version - this.Snapshot.Meta.MinEventVersion < 0;
441446
await this.SaveSnapshotAsync(true, isLatest);
442447

443448
await this.EventStorage.DeletePrevious(this.ActorId, this.Snapshot.Meta.MinEventVersion);

0 commit comments

Comments
 (0)