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

Repo storage migration #443

Merged
merged 7 commits into from
Dec 29, 2022
Merged

Repo storage migration #443

merged 7 commits into from
Dec 29, 2022

Conversation

dholms
Copy link
Collaborator

@dholms dholms commented Dec 26, 2022

Writing the migration & migration test for the repo storage changes.

The migration test is working off of a sqlite file that I generated using the old code.

Also snuck in a new method (that helped on the migration, but we want anyway): getCommits which returns all data relevant to some commits in a range

@dholms dholms marked this pull request as ready for review December 26, 2022 21:16
Comment on lines +59 to +61
if (!uint8arrays.equals(entry.bytes, otherBytes)) {
return false
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

At first glance it struck me that this check wasn't needed. But I think I follow— is the idea that the block-map itself doesn't enforce how bytes map to cid, so its usage allows different bytes to be behind the same cid in two different block-maps (therefore we need to check the bytes in equals())?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah that was my thinking.

Another line of thought is that we prevent this from happening in the first place (with an integrity check on set). But I kind've like BlockMap being a relatively dumb class. Almost didn't want to put add on it (which serializes some data & calculates a CID), but it made all the consuming code so much simpler that I did.

Relatedly, I've actually realized that we don't enforce integrity checks correctly on our blockstore (I guess I'd assumed that the car reader does this, but it doesn't). So have been putting some thinking today into ensuring that blockstores have correct CID mappings

@@ -262,34 +261,15 @@ export class Repo {
latest: CID,
earliest: CID | null,
): Promise<void> {
const commitPath = await this.storage.getCommitPath(latest, earliest)
if (commitPath === null) {
const commits = await this.storage.getCommits(latest, earliest)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 nice simplification in here.

Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

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

Having this test in here brings some nice peace of mind 💎 I am sure you had this in your mind while you worked on it, but the only lingering question for me is whether you feel the sqlite test brings good confidence running the same migration with postgres.

It seems to me like it does as long as the queries in the migration are all valid in postgres. In other words, I could imagine a world in which the migration totally fails on postgres for some reason and succeeds on sqlite. But it's hard for me to see a case in which the migration is incorrect on postgres but still runs without failing. So that seems pretty safe 👍

@dholms
Copy link
Collaborator Author

dholms commented Dec 28, 2022

That was essentially my thought re: migrations, especially with relatively straightforward queries like these. I was interested to get your read on it. I bailed out of testing postgres, because to do so involved keeping around old code paths, which we can do if necessary, but it seemed like overkill.

Actually, I guess one option would be to just run some repo operations, migrateDown & then migrate back up 🤔

Base automatically changed from repo-mutation-diffs to sync-revamp December 29, 2022 21:16
@dholms dholms merged commit f9fd8a2 into sync-revamp Dec 29, 2022
@dholms dholms deleted the repo-storage-migration branch December 29, 2022 21:16
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