This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate mfs root to datastore (#126)
We've been storing the mfs root in the repo's 'root' datastore since forever which means it's a block on the filesystem. It should have been stored in the datastore instead so add migration 11 which moves the key to the datastore. BREAKING CHANGE: adds a new migration, should go out as a major
- Loading branch information
1 parent
d3c0056
commit 540a077
Showing
13 changed files
with
142 additions
and
18 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict' | ||
|
||
const { Key } = require('interface-datastore') | ||
|
||
const MFS_ROOT_KEY = new Key('/local/filesroot') | ||
|
||
/** | ||
* @param {import('../../src/types').Backends} backends | ||
* @param {import('../../src/types').MigrationProgressCallback} onProgress | ||
*/ | ||
async function storeMfsRootInDatastore (backends, onProgress = () => {}) { | ||
onProgress(100, 'Migrating MFS root to repo datastore') | ||
|
||
await backends.root.open() | ||
await backends.datastore.open() | ||
|
||
const root = await backends.root.get(MFS_ROOT_KEY) | ||
await backends.datastore.put(MFS_ROOT_KEY, root) | ||
await backends.root.delete(MFS_ROOT_KEY) | ||
|
||
await backends.datastore.close() | ||
await backends.root.close() | ||
|
||
onProgress(100, 'Stored MFS root in repo datastore') | ||
} | ||
|
||
/** | ||
* @param {import('../../src/types').Backends} backends | ||
* @param {import('../../src/types').MigrationProgressCallback} onProgress | ||
*/ | ||
async function storeMfsRootInRoot (backends, onProgress = () => {}) { | ||
onProgress(100, 'Migrating MFS root to repo root datastore') | ||
|
||
await backends.root.open() | ||
await backends.datastore.open() | ||
|
||
const root = await backends.datastore.get(MFS_ROOT_KEY) | ||
await backends.root.put(MFS_ROOT_KEY, root) | ||
await backends.datastore.delete(MFS_ROOT_KEY) | ||
|
||
await backends.datastore.close() | ||
await backends.root.close() | ||
|
||
onProgress(100, 'Stored MFS root in repo root datastore') | ||
} | ||
|
||
/** @type {import('../../src/types').Migration} */ | ||
module.exports = { | ||
version: 11, | ||
description: 'Store mfs root in the datastore', | ||
migrate: storeMfsRootInDatastore, | ||
revert: storeMfsRootInRoot | ||
} |
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
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
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,69 @@ | ||
/* eslint-env mocha */ | ||
/* eslint-disable max-nested-callbacks */ | ||
'use strict' | ||
|
||
const { expect } = require('aegir/utils/chai') | ||
const { CID } = require('multiformats/cid') | ||
const migration = require('../../migrations/migration-11') | ||
const { Key } = require('interface-datastore') | ||
|
||
const MFS_ROOT_KEY = new Key('/local/filesroot') | ||
const MFS_ROOT = CID.parse('Qmc42sn2WBHYeAShU3nx8mYkhKVq4sRLapawTaGh4XH4iE') | ||
|
||
module.exports = (setup, cleanup) => { | ||
describe('migration 11', function () { | ||
this.timeout(240 * 1000) | ||
let dir | ||
let backends | ||
|
||
beforeEach(async () => { | ||
({ dir, backends } = await setup()) | ||
}) | ||
|
||
afterEach(async () => { | ||
await cleanup(dir) | ||
}) | ||
|
||
describe('forwards', () => { | ||
beforeEach(async () => { | ||
await backends.root.open() | ||
await backends.root.put(MFS_ROOT_KEY, MFS_ROOT.bytes) | ||
await backends.root.close() | ||
}) | ||
|
||
it('should migrate MFS root forward', async () => { | ||
await migration.migrate(backends, () => {}) | ||
|
||
await backends.root.open() | ||
await backends.datastore.open() | ||
|
||
await expect(backends.root.has(MFS_ROOT_KEY)).to.eventually.be.false() | ||
await expect(backends.datastore.has(MFS_ROOT_KEY)).to.eventually.be.true() | ||
|
||
await backends.datastore.close() | ||
await backends.root.close() | ||
}) | ||
}) | ||
|
||
describe('backwards', () => { | ||
beforeEach(async () => { | ||
await backends.datastore.open() | ||
await backends.datastore.put(MFS_ROOT_KEY, MFS_ROOT.bytes) | ||
await backends.datastore.close() | ||
}) | ||
|
||
it('should migrate MFS root backward', async () => { | ||
await migration.revert(backends, () => {}) | ||
|
||
await backends.root.open() | ||
await backends.datastore.open() | ||
|
||
await expect(backends.root.has(MFS_ROOT_KEY)).to.eventually.be.true() | ||
await expect(backends.datastore.has(MFS_ROOT_KEY)).to.eventually.be.false() | ||
|
||
await backends.datastore.close() | ||
await backends.root.close() | ||
}) | ||
}) | ||
}) | ||
} |
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