Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit faa278e

Browse files
committed
Merge branch '605-physical-branch-metadata' into 'master'
fix: verify branch metadata after snapshot creation (#646) Closes #605 See merge request postgres-ai/database-lab!1051
2 parents 507b7e1 + f6044dc commit faa278e

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

‎engine/internal/provision/thinclones/zfs/branching.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,33 @@ func (m *Manager) VerifyBranchMetadata() error {
126126
return nil
127127
}
128128

129-
latest := snapshots[0]
129+
branchHeads := make(map[string]string)
130130

131-
brName, err := m.getProperty(branchProp, latest.ID)
132-
if err != nil {
133-
log.Dbg("cannot find branch for snapshot", latest.ID, err.Error())
134-
}
131+
for i := numberSnapshots; i > 0; i-- {
132+
sn := snapshots[i-1]
133+
log.Dbg(sn)
135134

136-
for i := numberSnapshots; i > 1; i-- {
137-
if err := m.SetRelation(snapshots[i-1].ID, snapshots[i-2].ID); err != nil {
138-
return fmt.Errorf("failed to set snapshot relations: %w", err)
135+
if err := m.DeleteBranchProp(sn.Branch, sn.ID); err != nil {
136+
return fmt.Errorf("failed to clean branch property: %w", err)
139137
}
140138

141-
if brName == "" {
142-
brName, err = m.getProperty(branchProp, snapshots[i-1].ID)
143-
if err != nil {
144-
log.Dbg("cannot find branch for snapshot", snapshots[i-1].ID, err.Error())
145-
}
139+
head, ok := branchHeads[sn.Branch]
140+
if !ok {
141+
branchHeads[sn.Branch] = sn.ID
142+
continue
143+
}
144+
145+
if err := m.SetRelation(head, sn.ID); err != nil {
146+
return fmt.Errorf("failed to set snapshot relations: %w", err)
146147
}
147-
}
148148

149-
if brName == "" {
150-
brName = branching.DefaultBranch
149+
branchHeads[sn.Branch] = sn.ID
151150
}
152151

153-
if err := m.AddBranchProp(brName, latest.ID); err != nil {
154-
return fmt.Errorf("failed to add branch property: %w", err)
152+
for brName, latestID := range branchHeads {
153+
if err := m.AddBranchProp(brName, latestID); err != nil {
154+
return fmt.Errorf("failed to add branch property: %w", err)
155+
}
155156
}
156157

157158
log.Msg("data branching has been verified")

‎engine/internal/provision/thinclones/zfs/zfs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,17 @@ func (m *Manager) CreateSnapshot(poolSuffix, dataStateAt string) (string, error)
373373
return "", fmt.Errorf("failed to parse dataStateAt: %w", err)
374374
}
375375

376+
branch := branching.ParseBranchNameFromSnapshot(snapshotName, poolName)
377+
if branch == "" {
378+
branch = branching.DefaultBranch
379+
}
380+
376381
newSnapshot := resources.Snapshot{
377382
ID: snapshotName,
378383
CreatedAt: time.Now(),
379384
DataStateAt: dataStateTime,
380385
Pool: m.config.Pool.Name,
386+
Branch: branch,
381387
}
382388

383389
if !strings.HasSuffix(snapshotName, m.config.PreSnapshotSuffix) {

‎engine/internal/retrieval/engine/postgres/snapshot/physical.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ func (p *PhysicalInitial) run(ctx context.Context) (err error) {
402402

403403
p.tm.SendEvent(ctx, telemetry.SnapshotCreatedEvent, telemetry.SnapshotCreated{})
404404

405+
if err := p.cloneManager.VerifyBranchMetadata(); err != nil {
406+
log.Warn("cannot verify branch metadata", err.Error())
407+
}
408+
405409
if err := p.cleanupOldLogs(); err != nil {
406410
log.Warn("cannot clean up old logs", err.Error())
407411
}

‎engine/internal/srv/routes.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *Server) retrievalState(w http.ResponseWriter, r *http.Request) {
5555
retrieving.NextRefresh = models.NewLocalTime(spec.Next(time.Now()))
5656
}
5757

58-
retrieving.Activity = s.jobActivity(r.Context())
58+
retrieving.Activity = s.jobActivity(context.Background())
5959

6060
if err := api.WriteJSON(w, http.StatusOK, retrieving); err != nil {
6161
api.SendError(w, r, err)
@@ -182,7 +182,9 @@ func (s *Server) createSnapshot(w http.ResponseWriter, r *http.Request) {
182182
return
183183
}
184184

185-
// TODO: set branching metadata.
185+
if err := fsManager.VerifyBranchMetadata(); err != nil {
186+
log.Warn("cannot verify branch metadata", err.Error())
187+
}
186188

187189
latestSnapshot := snapshotList[0]
188190

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /