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

feat: sqlite vacuum and optional migrations #633

Merged
merged 3 commits into from
Aug 10, 2023
Merged

feat: sqlite vacuum and optional migrations #633

merged 3 commits into from
Aug 10, 2023

Conversation

richard-ramos
Copy link
Member

@richard-ramos richard-ramos commented Aug 8, 2023

Description

This adds new flags already available in nwaku to allow users to execute the vacuum procedure on sqlite databases and choose whether they want to execute migrations or not

cc: @apentori

Changes

  • Adds new flags --store-message-db-vacuum and --store-message-db-migrate
  • Introduces a struct DBSettings that can be used to pass settings required for different RDBMS (might be refactored away in the future)
  • DB instantiation requires a logger

@status-im-auto
Copy link

status-im-auto commented Aug 8, 2023

Jenkins Builds

Click to see older builds (17)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 9b4a438 #1 2023-08-08 15:52:45 ~1 min linux 📦deb
✔️ 9b4a438 #1 2023-08-08 15:53:24 ~1 min nix-flake 📄log
✔️ 9b4a438 #1 2023-08-08 15:54:12 ~2 min tests 📄log
✔️ 9b4a438 #1 2023-08-08 15:55:29 ~4 min android 📦tgz
✔️ 9b4a438 #1 2023-08-08 15:57:24 ~5 min ios 📦tgz
✔️ e2b2662 #2 2023-08-08 15:55:40 ~1 min linux 📦deb
✔️ e2b2662 #2 2023-08-08 15:56:29 ~1 min nix-flake 📄log
✔️ e2b2662 #2 2023-08-08 15:57:15 ~2 min tests 📄log
✔️ e2b2662 #2 2023-08-08 15:58:36 ~3 min android 📦tgz
✔️ e2b2662 #2 2023-08-08 15:58:40 ~4 min ios 📦tgz
✔️ e2b2662 #1 2023-08-09 08:00:43 ~3 min tests 📄log
✔️ 7bdbaf1 #3 2023-08-09 17:19:35 ~32 sec linux 📦deb
✔️ 7bdbaf1 #3 2023-08-09 17:20:51 ~1 min tests 📄log
✔️ 7bdbaf1 #3 2023-08-09 17:20:56 ~1 min nix-flake 📄log
✔️ 7bdbaf1 #2 2023-08-09 17:21:52 ~2 min tests 📄log
✔️ 7bdbaf1 #3 2023-08-09 17:22:59 ~3 min ios 📦tgz
✔️ 7bdbaf1 #3 2023-08-09 17:23:55 ~4 min android 📦tgz
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 6414dcc #4 2023-08-10 13:41:09 ~31 sec linux 📦deb
✔️ 6414dcc #4 2023-08-10 13:42:15 ~1 min tests 📄log
✔️ 6414dcc #4 2023-08-10 13:42:33 ~1 min nix-flake 📄log
✔️ 6414dcc #3 2023-08-10 13:43:17 ~2 min tests 📄log
✔️ 6414dcc #4 2023-08-10 13:43:33 ~2 min android 📦tgz
✔️ 6414dcc #4 2023-08-10 13:44:45 ~4 min ios 📦tgz
✔️ d794146 #5 2023-08-10 13:57:15 ~1 min linux 📦deb
✔️ d794146 #4 2023-08-10 13:57:58 ~1 min tests 📄log
✔️ d794146 #5 2023-08-10 13:58:19 ~2 min nix-flake 📄log
✔️ d794146 #5 2023-08-10 13:58:52 ~2 min tests 📄log
✔️ d794146 #5 2023-08-10 13:59:42 ~3 min ios 📦tgz
✔️ d794146 #5 2023-08-10 13:59:52 ~3 min android 📦tgz

@@ -298,6 +298,19 @@ var (
Destination: &options.Store.DatabaseURL,
EnvVars: []string{"WAKUNODE2_STORE_MESSAGE_DB_URL"},
})
StoreMessageDBVacuum = altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "store-message-db-vacuum",
Usage: "Enable database vacuuming at start. Only supported by SQLite database engine.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like postgres also supports vacuum https://www.postgresql.org/docs/current/sql-vacuum.html.
Maybe we should allow this for postgres as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it could be good to have it also on Postgres.

db, err := sql.Open("pgx", dburl)
if err != nil {
return nil, nil, err
}

if shouldVacuum {
err := executeVacuum(db, logger)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering, since vacuuming of db can take time upto minutes.
Should this be a bocking call or should we start this process in a go-routine and report the result back in async way?
Do we have any test indicating how much time a vacuum takes for our store db?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reading how SQLite VACUUM documentation, it will prevent writes to be executed, so it should be a blocking call.
No tests, but this command works by creating a temporary copy of the db, so the time it will take depends on the amount of data stored in the DB.

For postgresql, I modified the PR to use VACUUM FULL, just so the behavior of the command is the same as SQLite, but I think we shouldnt expect people to use vacuum with PostgreSQL since it is possible to setup routine vacuuming in it https://www.postgresql.org/docs/current/routine-vacuuming.html#AUTOVACUUM

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, maybe the caller can do an async status to the user then. Rather than us doing it.
I am just concerned since this is an API call by the user, blocking it for soo long may not be a good idea.

But its ok for now, we can change it if we get user feedback.

Copy link
Collaborator

@chaitanyaprem chaitanyaprem left a comment

Choose a reason for hiding this comment

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

LGTM

@richard-ramos richard-ramos merged commit e56f542 into master Aug 10, 2023
2 checks passed
@richard-ramos richard-ramos deleted the vacuum branch August 10, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants