-
Notifications
You must be signed in to change notification settings - Fork 608
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1497d05
migration
dholms 432d53c
wip
dholms 68bff2a
migraiton test
dholms d66751f
Merge branch 'repo-mutation-diffs' into repo-storage-migration
dholms f03605c
sql repo storage tests
dholms 3ad85db
fix up some diff code
dholms 11241b2
Merge branch 'repo-mutation-diffs' into repo-storage-migration
dholms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/pds/tests/migrations/repo-sync-data/expected-data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"repoData":{"com.example.posts":{"3jks3gib5622x":{"name":"6iNxhasFMmadjASg2FpfPH4NfQ44zTQQkSZnLoMH4gLdXuQ8tYsY1o74gHeaX2svzWKckFSDpRVANy3mAkVj1yoGBn23p3vLJjds"},"3jks3gib5632x":{"name":"mVA1o5LSgC9ePvuretNJo6uhA5yqMAJAxqXAmEobTxNmCTgkYWFGGFwQpY74ZLZeyUD57iJ7uXhibBwvPYVHQR13jn4YEdM7N7JS"},"3jks3gib5642x":{"name":"rzRdoEhdv1Q6aZDQEDK9rc6ZQjrKgEZoCYGc9oSq676zGgN2UprKQ52Qt3LrbFh2TntVPH967ecpYRK8PQypo8oHc6exwRUEzufp"},"3jks3gib65e2x":{"name":"aFqx5794xq8ab6Xfd3atpW498QtNDCiYRBLJZ9DTT8p57f3BLCu1Nh2ZSm5mTjumWu7Fhi3EzfdocR8n8BpQoHbwESAyE7aXvpEk"},"3jks3gib65f2x":{"name":"YPkwuUT1q8JRokdm2fNGe8DVrcUVD1HvQgzETBeHbnGGdU8hFASSNzsjk7jV7oXtEi788q1QvChdVHzc9PZXxbhQfqLeiWWXL4GW"},"3jks3gib65g2x":{"name":"Kq2ZiiLH14BHPngQ6x19CZdicvqnPqjtnwCy6S34sNDKLLCYvr3QteuW8QJDW9XnRYJWJ5dCXm5SFD4s7bvMEbJrXcdBGtejBX3E"},"3jks3gib65h2x":{"name":"vahSKmUoajxbKttaA2nx8Aeuoh9SSMvG79joH6dkeEX6Aafm7ZnvCv1iqt1xK5Y9X1YBjSBJfN3JrT8vyDHAgNVTpqF3863B112y"},"3jks3gib65i2x":{"name":"nNBv2oFmpMmmLNoaCDh1ERTzgrR7VGvbGNV1EnaHjup52f75BCxWnd7KnxueqyZPep1MdPCAD6jpDWrHFYBY4QAS6xKhH1wdU1FQ"},"3jks3gib65j2x":{"name":"iotWfn9vsQ682fuz1z2zg1tuujmkNnnkSNjtoFqK5ydfhDcgypP2URqSwhM4GLc3bqmhUvb4XsRrueB1EWuDcvQ8aVzS1PnnuRrD"},"3jks3gib65k2x":{"name":"Fwoy8DgbJNaWxo2F4N7CXodTNxNVP7M57JWp13KRUVbMWobDomWGpYs3UL8ik8u6nKjbLLcWUiab2ccSQPMzftiK5KxEuumKcNZc"},"3jks3gibb3m2x":{"name":"BGLARtQNMayNVb61St3oVZbUxwKmDe2XouYhR7ujgJ6FxB3WJ7Qbjv5LdLMPnKdTnZKd5fWZVhNDRvCEtdUF9cxdpsiCxT8zqKCn"},"3jks3gibb3n2x":{"name":"bUs9qNwp5hpF2GYKvcbfCaGv1Pyszwty5rBkBTFvaLhdFS2f1kw4R5p1DaawBbiDoD9hPSaagaJoWyHwjqgHY53E2dURGKLru4R6"},"3jks3gibb3o2x":{"name":"oumukY1UVkd3Twoc1G4Nv7xkFJF3kEHhzm7Pt9CjJJGEoLD4kUCEFC3C7haiHUmaASkycpoHxQYpiNRm4mv2JoHFhEPqVaCPK9n7"},"3jks3gibb3p2x":{"name":"yF78rrq3RDf5PizXVPxFEc97HNv5jBnPF7RqVsSKXBc9K7M6M8KfM1tSSeCivq6yE5kaMe71gxrK86H8FCJEJevXxBn1QmUtMSKX"},"3jks3gibb3q2x":{"name":"AB2J4KsQq8FTqVsXzbejX1ZXJEyedH6GuSH59uFr7C8wP1TqVqRzPNW65Rpd5WtWoHUhEDaUccJRgWKJbDqb6uvBDrpe2BSRHsb8"}},"com.example.likes":{"3jks3gib65l2x":{"name":"99rYFFmorU83gn1UgmyTLuGHfTmgBbGj1hqAoSwMTCDb5Yyk7pUZin8Wc7H7HuRzWTsrziYHKuYWrmGatmcdSpnhB96BovxWfQ9B"},"3jks3gib65m2x":{"name":"e5GfS1ZgenSKWP34KrCurykMigqJvooEAqgzXnppA74QprfuEdrbtwZMAijhTCifMzGXWRYRD6smKA6kVU5tZk8ZVjZJ1N7sc1MX"},"3jks3gib65n2x":{"name":"tnzAvrhCJddmsym2dzUcc4cdpLMVqrHx6vYjLj9Yj2g8RXFVumgZctYy7yx395zthTRdZrzFijDnuRTJe9jGfvemVc77NaWazcJ3"},"3jks3gib65o2x":{"name":"dKHLaYHKu5H3PnFRtuQvEotXqeY7He86AtP6E1rdBkYxVEJ2M4o5gHJuPk6azwP3MM27wnmMMhMJavL4dUCHBjmdJ7UtSeb6Azu2"},"3jks3gib65p2x":{"name":"wM1pv9iUnXEdpsRBKGHX4DMsS4PSun55fYEKEDxeYUU8gscVuigLiEwwHqW5dsETuFQUayuBQYrh3m6FSzDokcvG8PFmtN7o5uky"},"3jks3gib65q2x":{"name":"nVzbGDBiPF87uD7oUoFMrkJm7d1y64m9ANZ299NtUHLcT5wAnYjp5NFsmjCkFHkCo4UHwjhVinwKfCecmayz4j4hhTeDxc9zdRq7"},"3jks3gib65r2x":{"name":"xwcJa1jcTDqcKfTZawpGeBFW4f9zqFGG4oVEfezAQ2FB8jEPk8gd5cA8QHUA5adg1hbgeHBhXiM1o1V5uBYuoCccRJjzi9yYd8xy"},"3jks3gib65s2x":{"name":"qM4gBR58feygtT5Ghvud67JGoZaakWNmMovfaQySEVYuHxkZe5DQsmqsMa5yjSZ7UXbGj5yDaz4P5yRnZ3U2RR4xJ4381BerAqrx"},"3jks3gib65t2x":{"name":"D3VQ6wDGY5WsBeQv8aoaiiGFmXXbZ2QEnNjF4BVww6u7qb6ZPk2QnS7EjSSBzdZs7siE1CcKABaQNKuzGUV5vV7JNC9RubJFw2p8"},"3jks3gib65u2x":{"name":"BEXjK5hdsP9HSjELCrhU8NFNXtfJy52aMZutY2WEanAFS4eePZ2WPCCtEDNCt9pRq2Ah3YDyU2zs8D5wXigKnZUKNTRQX8tF3mub"},"3jks3gibc2y2x":{"name":"cZoEJ1QsEP9UCg5vAkrEhnjYm4FSKcgqk9d4Vo9ZE9hx5gVNSH9M6CFdW8TQsFG7VCjm2Jr38DnNQtn3SRWFkeaZAWV9Qm831eJ4"},"3jks3gibc2z2x":{"name":"BCNX7hEYb1W2XPhGnFuodR5Rdv7kHnwBBvnftaCQVUcyd6GBThCLb9tKaz8GRyCBJTy4emwu6Qu8LMaYdhDdRVTNQXfpeg8KUq9m"},"3jks3gibc322x":{"name":"EJQRfPSkbw2xzJwznzYMeCy4QSMki2jMG8anvrFriRjRHbFafyR6JuxkHWr8hTXcHroJZRzV3imqKcw6g97RdakLMwvmTzLHQBBh"},"3jks3gibc332x":{"name":"63xdcVPSvzZpzFHxoRacdFxq2EEKjX4EkHsLS1mtxkBhjdJhXhtjJsgQRhBXb1J1AVgHKSwrjHfqBaejLiEeCfbwUKJu7RmN3MRQ"},"3jks3gibc342x":{"name":"C5pUg3XXKhKdCmTfHmX74K3REx1bxBM8DBe9JtaPwH2bLY3FAn8RyTB432MXVEn7n3xtYssN3Nacyk2KisJrAXBiZm22CDGvsvjw"}}},"commitPath":["bafyreifuzhgzo6udzsgctl4wvp7ixninvpwnjvimiy7udrmggnboz2ozky","bafyreibhji7ousajscnaktajwje7wbatwky3lnmgknbih772azeksb6e2a","bafyreifmjipk3n3zfrnw25iz7ryd2d2fuah45vvqe3as7kalgggtsh74eq"]} |
73 changes: 73 additions & 0 deletions
73
packages/pds/tests/migrations/repo-sync-data/migration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { MemoryBlockstore, Repo } from '@atproto/repo' | ||
import BlockMap from '@atproto/repo/src/block-map' | ||
import fs from 'fs/promises' | ||
import { CID } from 'multiformats/cid' | ||
import { Database } from '../../../src' | ||
import SqlRepoStorage from '../../../src/sql-repo-storage' | ||
|
||
type TestData = { | ||
repoData: Record<string, Record<string, unknown>> | ||
commitPath: string[] | ||
} | ||
|
||
describe('repo sync data migration', () => { | ||
let db: Database | ||
const did = 'did:key:zDnaegoVtoy9Na3arc4QAu7Su2ZCaNQVsZNqqnCR8fjVgBrFQ' | ||
let data: TestData | ||
|
||
beforeAll(async () => { | ||
await fs.copyFile( | ||
'tests/migrations/repo-sync-data/pre-migration.sqlite', | ||
'tests/migrations/repo-sync-data/test.sqlite', | ||
) | ||
db = Database.sqlite('tests/migrations/repo-sync-data/test.sqlite') | ||
await db.migrator.migrateTo('_20221221T013010374Z') | ||
const readData = await fs.readFile( | ||
'tests/migrations/repo-sync-data/expected-data.json', | ||
) | ||
if (!readData) { | ||
throw new Error('could not read test data') | ||
} | ||
data = JSON.parse(readData.toString()) | ||
}) | ||
|
||
afterAll(async () => { | ||
await db.close() | ||
await fs.rm('tests/migrations/repo-sync-data/test.sqlite') | ||
}) | ||
|
||
it('migrated correctly', async () => { | ||
const storage = new SqlRepoStorage(db, did) | ||
const root = await storage.getHead() | ||
if (!root) { | ||
throw new Error('could not get repo root') | ||
} | ||
const commitLog = await storage.getCommitPath(root, null) | ||
if (!commitLog) { | ||
throw new Error('could not get commit log') | ||
} | ||
const commitLogStr = commitLog.map((cid) => cid.toString()) | ||
expect(commitLogStr).toEqual(data.commitPath) | ||
|
||
const res = await db.db | ||
.selectFrom('repo_commit_block') | ||
.innerJoin('ipld_block', 'ipld_block.cid', 'repo_commit_block.block') | ||
.where('repo_commit_block.commit', 'in', commitLogStr) | ||
.select(['ipld_block.cid as cid', 'ipld_block.content as content']) | ||
.execute() | ||
const blockmap = new BlockMap() | ||
res.forEach((row) => { | ||
blockmap.set(CID.parse(row.cid), row.content) | ||
}) | ||
const blockstore = new MemoryBlockstore() | ||
blockstore.putMany(blockmap) | ||
const repo = await Repo.load(blockstore, root) | ||
for (const collName of Object.keys(data.repoData)) { | ||
const collData = data.repoData[collName] | ||
for (const rkey of Object.keys(collData)) { | ||
const record = await repo.getRecord(collName, rkey) | ||
expect(record).toEqual(collData[rkey]) | ||
} | ||
} | ||
}) | ||
}) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()
)?There was a problem hiding this comment.
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 likeBlockMap
being a relatively dumb class. Almost didn't want to putadd
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