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

Support Storage Migration #89

Merged
merged 5 commits into from
Dec 6, 2024
Merged

Conversation

loreanvictor
Copy link
Contributor

@loreanvictor loreanvictor commented Aug 12, 2024

This PR adds support for migrating diagram storage from one storage backend to another in a slow and gradual manner, by using an intermediary storage driver that moves diagrams from the old storage to the new one upon load:

  • When a diagram is loaded that is not present in the new (target) storage, it will be loaded from the old (source) storage, and also stored in the target storage.
  • Updates to diagrams will only be stored in target storage.
  • Newly created diagrams will be stored in the target storage only.

Which will look like the following:

storage = new MigratingStorageService({ sourceStorage, targetStorage })

This PR also adds support for environment variable APOLLON_REDIS_MIGRATE_FROM_FILE, which if set, instructs Apollon Standalone to use a migrating storage, and migrate from file storage to redis storage.

Why Not a Migration Script?

A migration script will be tightly coupled with storage logic (how a storage stores its keys, what metadata it uses for storing diagrams, etc.), while being kept separated and designed for independent execution. Subsequently, it will be deprecated over time as storage logic is updated but migration scripts are not kept in sync.

The migrating storage driver provides a storage-agnostic solution that is usable for any potential future migration as well (e.g. from Redis to Postgres). Considering the fact that stored diagrams have a limited time span (30 days), after this time any old diagram would have been deleted regardless, so using a migrating storage driver (through an environment variable, for example) for the diagram retention period will be sufficient for a clean migration.

Copy link
Contributor

@egenerse egenerse left a comment

Choose a reason for hiding this comment

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

I tested this pr and it works as expected.
but during the migration these two env values must be there otherwise it breaks the server.
APOLLON_REDIS_URL="redis://localhost:6379" APOLLON_REDIS_MIGRATE_FROM_FILE="true" // this key can be anything then undefined.

there is also crash when apollon_standalone tries to patch with non existed diagram in anywhere something like https://apollon.ase.in.tum.de/xxxxxxxxxxxxxxxxxxx?view=COLLABORATOR
but it has nothing to do with this pr

@loreanvictor loreanvictor requested review from FelixTJDietrich and removed request for matthiaslehnertum and krusche October 23, 2024 10:57
@loreanvictor
Copy link
Contributor Author

loreanvictor commented Oct 23, 2024

@egenerse thanks a lot for review and testing!

@FelixTJDietrich since this PR affects deployment and future migrations as well, I'd appreciate if you could also take a look. I should note that this is not urgent by any means. Whenever this is merged we can migrate the main apollon standalone instance to use redis as storage instead of files.

@FelixTJDietrich
Copy link
Contributor

We will first need to update the deployment side. I how to do that in the next two weeks.

Copy link
Contributor

@FelixTJDietrich FelixTJDietrich left a comment

Choose a reason for hiding this comment

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

I could finally test it on the test server, it worked as expected and successfully migrated an old diagram. Thanks for this! I will soon deploy Redis in prod 🎉

@FelixTJDietrich FelixTJDietrich merged commit 14e381c into main Dec 6, 2024
5 checks passed
@FelixTJDietrich FelixTJDietrich deleted the feature/storage-migration branch December 6, 2024 21:05
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.

3 participants