Skip to content

Commit

Permalink
feat metadata reading at storeSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
hyemmie committed Aug 3, 2023
1 parent bde853c commit 757fa42
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions server/packs/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,34 @@ func storeSnapshot(
minSyncedTicket *time.Ticket,
) error {
// 01. get the closest snapshot of this docInfo
// TODO: For performance issue, we only need to read the snapshot's metadata.
snapshotInfo, err := be.DB.FindClosestSnapshotInfo(ctx, docInfo.ID, docInfo.ServerSeq)
snapshotMetadata, err := be.DB.FindClosestSnapshotMetadata(ctx, docInfo.ID, docInfo.ServerSeq)
if err != nil {
return err
}
if snapshotInfo.ServerSeq == docInfo.ServerSeq {
if snapshotMetadata.ServerSeq == docInfo.ServerSeq {
return nil
}
if docInfo.ServerSeq-snapshotInfo.ServerSeq < be.Config.SnapshotInterval {
if docInfo.ServerSeq-snapshotMetadata.ServerSeq < be.Config.SnapshotInterval {
return nil
}

// 02. retrieve the changes between last snapshot and current docInfo
changes, err := be.DB.FindChangesBetweenServerSeqs(
ctx,
docInfo.ID,
snapshotInfo.ServerSeq+1,
snapshotMetadata.ServerSeq+1,
docInfo.ServerSeq,
)
if err != nil {
return err
}

// 03. create document instance of the docInfo
// TODO: check policy to guarantee atomicity
snapshotInfo, err := be.DB.FindClosestSnapshotFullData(ctx, docInfo.ID, docInfo.ServerSeq)
if err != nil {
return err
}
doc, err := document.NewInternalDocumentFromSnapshot(
docInfo.Key,
snapshotInfo.ServerSeq,
Expand Down

0 comments on commit 757fa42

Please sign in to comment.