-
Notifications
You must be signed in to change notification settings - Fork 50
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
Rename stores #136
Rename stores #136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ const MountStore = core.MountDatastore | |
const ShardingStore = core.ShardingDatastore | ||
|
||
const Key = require('interface-datastore').Key | ||
const LevelStore = require('datastore-level') | ||
const waterfall = require('async/waterfall') | ||
const series = require('async/series') | ||
const parallel = require('async/parallel') | ||
|
@@ -22,8 +21,8 @@ const blockstore = require('./blockstore') | |
const log = debug('repo') | ||
|
||
const apiFile = new Key('api') | ||
const flatfsDirectory = 'blocks' | ||
const levelDirectory = 'datastore' | ||
const blockStoreDirectory = 'blocks' | ||
const dataStoreDirectory = 'datastore' | ||
const repoVersion = 5 | ||
|
||
/** | ||
|
@@ -34,33 +33,25 @@ class IpfsRepo { | |
/** | ||
* @param {string} repoPath - path where the repo is stored | ||
* @param {object} options - Configuration | ||
* @param {Datastore} options.fs | ||
* @param {Leveldown} options.level | ||
* @param {object} [options.fsOptions={}] | ||
* @param {datastore} options.blockStore | ||
* @param {datastore} options.dataStore | ||
* @param {object} [options.blockStoreOptions={}] | ||
* @param {object} [options.dataStoreOptions={}] | ||
* @param {bool} [options.sharding=true] - Enable sharding (flatfs on disk), not needed in the browser. | ||
* @param {string} [options.lock='fs'] - Either `fs` or `memory`. | ||
*/ | ||
constructor (repoPath, options) { | ||
assert.equal(typeof repoPath, 'string', 'missing repoPath') | ||
|
||
if (options == null) { | ||
options = require('./default-options') | ||
} | ||
|
||
const defaultOptions = require('./default-options') | ||
this.closed = true | ||
this.path = repoPath | ||
this.options = Object.assign({ | ||
sharding: true, | ||
lock: 'fs' | ||
}, options) | ||
this._fsOptions = Object.assign({}, options.fsOptions) | ||
const FsStore = this.options.fs | ||
this._fsStore = new FsStore(this.path, Object.assign({}, this._fsOptions, { | ||
extension: '' | ||
})) | ||
this.options = Object.assign({ lock: 'memory', sharding: true }, options || defaultOptions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question about this. The Is its purpose to prevent other apps from writing the same files and if so shouldn't the lock actually be in the one of the stores? |
||
const BlockStore = this.options.blockStore | ||
this._blockStore = new BlockStore(this.path, this.options.blockStoreOptions) | ||
|
||
this.version = version(this._fsStore) | ||
this.config = config(this._fsStore) | ||
this.version = version(this._blockStore) | ||
this.config = config(this._blockStore) | ||
|
||
if (this.options.lock === 'memory') { | ||
this._locker = require('./lock-memory') | ||
|
@@ -82,7 +73,7 @@ class IpfsRepo { | |
log('initializing at: %s', this.path) | ||
|
||
series([ | ||
(cb) => this._fsStore.open((err) => { | ||
(cb) => this._blockStore.open((err) => { | ||
if (err && err.message === 'Already open') { | ||
return cb() | ||
} | ||
|
@@ -108,7 +99,7 @@ class IpfsRepo { | |
|
||
// check if the repo is already initialized | ||
waterfall([ | ||
(cb) => this._fsStore.open((err) => { | ||
(cb) => this._blockStore.open((err) => { | ||
if (err && err.message === 'Already open') { | ||
return cb() | ||
} | ||
|
@@ -121,8 +112,8 @@ class IpfsRepo { | |
this.lockfile = lck | ||
|
||
log('creating flatfs') | ||
const FsStore = this.options.fs | ||
const s = new FsStore(path.join(this.path, flatfsDirectory), this._fsOptions) | ||
const BlockStore = this.options.blockStore | ||
const s = new BlockStore(path.join(this.path, blockStoreDirectory), this.options.blockStoreOptions) | ||
|
||
if (this.options.sharding) { | ||
const shard = new core.shard.NextToLast(2) | ||
|
@@ -131,17 +122,21 @@ class IpfsRepo { | |
cb(null, s) | ||
} | ||
}, | ||
(flatfs, cb) => { | ||
(blockStore, cb) => { | ||
log('Flatfs store opened') | ||
this.store = new MountStore([{ | ||
prefix: new Key(flatfsDirectory), | ||
datastore: flatfs | ||
}, { | ||
prefix: new Key('/'), | ||
datastore: new LevelStore(path.join(this.path, levelDirectory), { | ||
db: this.options.level | ||
}) | ||
}]) | ||
const DataStore = this.options.dataStore | ||
const dataStore = new DataStore(path.join(this.path, dataStoreDirectory), this.options.dataStoreOptions) | ||
log(dataStore) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
this.store = new MountStore([ | ||
{ | ||
prefix: new Key(blockStoreDirectory), | ||
datastore: blockStore | ||
}, | ||
{ | ||
prefix: new Key('/'), | ||
datastore: dataStore | ||
} | ||
]) | ||
|
||
this.blockstore = blockstore(this) | ||
this.closed = false | ||
|
@@ -197,14 +192,14 @@ class IpfsRepo { | |
|
||
log('closing at: %s', this.path) | ||
series([ | ||
(cb) => this._fsStore.delete(apiFile, (err) => { | ||
(cb) => this._blockStore.delete(apiFile, (err) => { | ||
if (err && err.message.startsWith('ENOENT')) { | ||
return cb() | ||
} | ||
cb(err) | ||
}), | ||
(cb) => this.store.close(cb), | ||
(cb) => this._fsStore.close(cb), | ||
(cb) => this._blockStore.close(cb), | ||
(cb) => { | ||
log('unlocking') | ||
this.closed = true | ||
|
@@ -235,7 +230,7 @@ class IpfsRepo { | |
* @returns {void} | ||
*/ | ||
setApiAddress (addr, callback) { | ||
this._fsStore.put(apiFile, Buffer.from(addr.toString()), callback) | ||
this._blockStore.put(apiFile, Buffer.from(addr.toString()), callback) | ||
} | ||
|
||
/** | ||
|
@@ -245,7 +240,7 @@ class IpfsRepo { | |
* @returns {void} | ||
*/ | ||
apiAddress (callback) { | ||
this._fsStore.get(apiFile, (err, rawAddr) => { | ||
this._blockStore.get(apiFile, (err, rawAddr) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,35 +13,28 @@ const expect = chai.expect | |
const IPFSRepo = require('../src') | ||
|
||
describe('IPFS Repo Tests on on Node.js', () => { | ||
const repos = [{ | ||
name: 'default', | ||
opts: undefined, | ||
init: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this removed? |
||
}, { | ||
name: 'memory', | ||
opts: { | ||
fs: require('interface-datastore').MemoryDatastore, | ||
level: require('memdown'), | ||
lock: 'memory' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this removed? |
||
const repos = [ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't change code style, this makes it hard to read the diff |
||
name: 'default', | ||
opts: undefined | ||
}, | ||
init: true | ||
}] | ||
{ | ||
name: 'memory', | ||
opts: { | ||
blockStore: require('interface-datastore').MemoryDatastore, | ||
dataStore: require('interface-datastore').MemoryDatastore | ||
} | ||
} | ||
] | ||
repos.forEach((r) => describe(r.name, () => { | ||
const testRepoPath = path.join(__dirname, 'test-repo') | ||
const date = Date.now().toString() | ||
const repoPath = testRepoPath + '-for-' + date | ||
|
||
const repo = new IPFSRepo(repoPath, r.opts) | ||
|
||
before((done) => { | ||
series([ | ||
(cb) => { | ||
if (r.init) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you removing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a bad reason. Basically I thought it was an inconsistency in the way the stores were getting created and a bug in this test but now I see that the tests were failing because I dropped the |
||
repo.init({}, cb) | ||
} else { | ||
ncp(testRepoPath, repoPath, cb) | ||
} | ||
}, | ||
(cb) => ncp(testRepoPath, repoPath, cb), | ||
(cb) => repo.init({}, cb), | ||
(cb) => repo.open(cb) | ||
], done) | ||
}) | ||
|
@@ -73,7 +66,7 @@ describe('IPFS Repo Tests on on Node.js', () => { | |
require('./repo-test')(repo) | ||
require('./blockstore-test')(repo) | ||
require('./datastore-test')(repo) | ||
if (!r.init) { | ||
if (r.name === 'default') { | ||
require('./interop-test')(repo) | ||
} | ||
})) | ||
|
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.
you can't just remove options that are important
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.
I fixed this in #138
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.
Yup, that was missed when moving options into default options objects.