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

added create-snapshot/restore-snapshot on the sidecar CLI + readme #146

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

BrendanCoughlan5
Copy link
Contributor

@BrendanCoughlan5 BrendanCoughlan5 commented Dec 11, 2024

Copy link
Member

@seanmcgary seanmcgary left a comment

Choose a reason for hiding this comment

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

Start with these comments, most will apply to the restore command as well.

cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
cmd/snapshot-create.go Outdated Show resolved Hide resolved
@BrendanCoughlan5 BrendanCoughlan5 changed the title [wip] added create/restore and the readme [wip] added create-snapshot/restore-snapshot on the sidecar CLI + readme Dec 13, 2024
cmd/createSnapshot.go Fixed Show fixed Hide fixed
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
@BrendanCoughlan5 BrendanCoughlan5 changed the title [wip] added create-snapshot/restore-snapshot on the sidecar CLI + readme added create-snapshot/restore-snapshot on the sidecar CLI + readme Jan 3, 2025
@BrendanCoughlan5 BrendanCoughlan5 removed the request for review from 0xrajath January 3, 2025 11:11
README.md Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/restoreSnapshot.go Outdated Show resolved Hide resolved
cmd/restoreSnapshot.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/restoreSnapshot.go Outdated Show resolved Hide resolved
@BrendanCoughlan5 BrendanCoughlan5 force-pushed the add-shapshots-cli branch 2 times, most recently from e82ecf8 to 16e4fa0 Compare January 6, 2025 22:24
internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
cmd/root.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/postgres/postgres.go Outdated Show resolved Hide resolved
pkg/postgres/postgres.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Show resolved Hide resolved
return testDbName, pg, grm, nil
}

func GetTestPostgresDatabaseNoMigrations(cfg config.DatabaseConfig, l *zap.Logger) (
Copy link
Member

Choose a reason for hiding this comment

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

By more composable I meant:

GetTestPostgresDatabase() <-- get the database, but dont run the migrator
GetTestPostgresDatabaseWithMigrations() <-- should call GetTestPostgresDatabase and subsequently run the migrations.

But to do this without breaking things, youd first need to rename GetTestPostgresDatabase across the project to GetTestPostgresDatabaseWithMigrations then re-introduce GetTestPostgresDatabase

pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
@seanmcgary
Copy link
Member

Issue found with providing a output_file path of ~/snapshot-test

go run main.go create-snapshot \
    --ethereum.rpc-url="..." \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_testnet_holesky" \
    --ethereum.use_native_batch_call=false \
    --output_file=~/snapshot-test
{"level":"error","ts":"2025-01-10T10:44:02.338-0600","caller":"snapshot/snapshot.go:50","msg":"Failed to create database snapshot","error":"exit status 1","output":"pg_dump: error: could not open output file \"~/snapshot-test\": No such file or directory\n","stacktrace":"github.com/Layr-Labs/sidecar/pkg/snapshot.(*SnapshotService).CreateSnapshot\n\t/Users/seanmcgary/Code/sidecar/pkg/snapshot/snapshot.go:50\ngithub.com/Layr-Labs/sidecar/cmd.init.func1\n\t/Users/seanmcgary/Code/sidecar/cmd/createSnapshot.go:37\ngithub.com/spf13/cobra.(*Command).execute\n\t/Users/seanmcgary/Code/gocode/pkg/mod/github.com/spf13/[email protected]/command.go:985\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/seanmcgary/Code/gocode/pkg/mod/github.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\t/Users/seanmcgary/Code/gocode/pkg/mod/github.com/spf13/[email protected]/command.go:1041\ngithub.com/Layr-Labs/sidecar/cmd.Execute\n\t/Users/seanmcgary/Code/sidecar/cmd/root.go:19\nmain.main\n\t/Users/seanmcgary/Code/sidecar/main.go:8\nruntime.main\n\t/opt/homebrew/opt/go/libexec/src/runtime/proc.go:272"}
Error: failed to create snapshot: exit status 1

@seanmcgary
Copy link
Member

seanmcgary commented Jan 10, 2025

Restoring a snapshot that was dumped using a schema (e.g. public) to a different schema, doesnt work but gives me a success message. New schema I specified ends up as completely empty

# implicitly uses the public schema
go run main.go create-snapshot \
    --ethereum.rpc-url="..." \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_testnet_holesky" \
    --ethereum.use_native_batch_call=false \
    --input_file=/Users/seanmcgary/snapshot-test

# specifies a schema that is not public
go run main.go restore-snapshot \
    --ethereum.rpc-url="..." \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_testnet_holesky" \
    --ethereum.use_native_batch_call=false \
    --input_file=/Users/seanmcgary/snapshot-test \
    --database.schema_name=test

@BrendanCoughlan5
Copy link
Contributor Author

BrendanCoughlan5 commented Jan 13, 2025

Restoring a snapshot that was dumped using a schema (e.g. public) to a different schema, doesnt work but gives me a success message. New schema I specified ends up as completely empty

# implicitly uses the public schema
go run main.go create-snapshot \
    --ethereum.rpc-url="..." \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_testnet_holesky" \
    --ethereum.use_native_batch_call=false \
    --input_file=/Users/seanmcgary/snapshot-test

# specifies a schema that is not public
go run main.go restore-snapshot \
    --ethereum.rpc-url="..." \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_testnet_holesky" \
    --ethereum.use_native_batch_call=false \
    --input_file=/Users/seanmcgary/snapshot-test \
    --database.schema_name=test

More detail here:
https://www.notion.so/TDD-SideCar-Snapshots-14d13c11c3e0809c960cf1307d91d39e?d=17a13c11c3e0803c9ed6001cd067759d&pvs=4#17a13c11c3e0808e92a5e3800d1685bb

I thought about this case a fair bit,
I updated the CLI and docs accordingly and put in the docs how to convert the dump to a new schema.

pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
pkg/utils/helpers.go Outdated Show resolved Hide resolved
scripts/convertSnapshotSchema.sh Outdated Show resolved Hide resolved
scripts/convertSnapshotSchema.sh Outdated Show resolved Hide resolved
@@ -0,0 +1,58 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

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

If we're adding this, why is this not part of the cli directly as a flag that the user can pass?

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.

2 participants