Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new method for vacuuming a c1z db. #79

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/dotc1z/sync_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ func (c *C1File) Cleanup(ctx context.Context) error {
l.Info("Removed old sync data.", zap.String("sync_date", ret[i].EndedAt.Format(time.RFC3339)), zap.String("sync_id", ret[i].ID))
}

err = c.Vacuum(ctx)
if err != nil {
return err
}

c.dbUpdated = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to set this to true here, when it is already set from the vacuum call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice no, but i think it is probably good to set it in any method that changes the database. This flag being set to true is what tells the c1z manager that it should write the c1z back to the origin. There isn't really a way to run this method without invoking other things that change the database, but for completeness sake I'm setting it.


return nil
}

Expand Down Expand Up @@ -457,3 +464,20 @@ func (c *C1File) DeleteSyncRun(ctx context.Context, syncID string) error {

return nil
}

// Vacuum runs a VACUUM on the database to reclaim space.
func (c *C1File) Vacuum(ctx context.Context) error {
err := c.validateDb(ctx)
if err != nil {
return err
}

_, err = c.rawDb.ExecContext(ctx, "VACUUM")
if err != nil {
return err
}

c.dbUpdated = true

return nil
}