Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Add locking for concurrent pin operations #2174

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ddae854
feat: implement ipfs refs
dirkmc Apr 22, 2019
95a360f
feat: refs support in http api
dirkmc Apr 24, 2019
22232e5
feat: use ipld instead of unix-fs-exporter for refs
dirkmc Apr 28, 2019
2dc9265
feat: refs local
dirkmc Apr 30, 2019
659bb5c
feat: add refs.localPullStream && refs.localReadableStream
dirkmc May 1, 2019
1f40f7a
feat: make object.links work with CBOR
dirkmc May 3, 2019
7be9725
feat: handle multiple refs. Better param handling
dirkmc May 3, 2019
6c9ae7d
feat: GC
dirkmc May 8, 2019
9aae8b4
chore: add comment to explain cli param parsing
dirkmc May 8, 2019
ee8edb3
refactor: move links retrieval from object to refs
dirkmc May 9, 2019
40ae451
feat: expose GC to http api
dirkmc May 10, 2019
072ddfd
test: unskip repo gc test
dirkmc May 10, 2019
732a02c
fix: refactor and fix some bugs with GC
dirkmc May 10, 2019
ff28923
feat: GC locking
dirkmc May 20, 2019
eae37e1
test: add gc locking tests
dirkmc May 21, 2019
730a96d
refactor: rebase
dirkmc May 21, 2019
bdaaed9
fix: gc use uppercase dag.Links
dirkmc May 21, 2019
72fc905
chore: update package.json deps
dirkmc May 21, 2019
a4bffb2
chore: rebase
dirkmc May 21, 2019
b27e7a2
chore: add joi to package.json
dirkmc May 22, 2019
e2f68a8
refactor: pin/gc common code
dirkmc May 22, 2019
13d3801
fix: browser gc tests
dirkmc May 22, 2019
64a1566
fix: gc parsing of block cid in browser
dirkmc May 22, 2019
088041d
test: add gc-lock tests
dirkmc May 23, 2019
d772ed7
fix: gc lock error handling
dirkmc May 23, 2019
45db74d
fix: gc - take pin lock after resolve
dirkmc May 23, 2019
f6f9a72
fix: make sure each GCLock instance uses distinct mutex
dirkmc May 23, 2019
3a185d5
fix: choose non-overlapping port for GC test
dirkmc May 24, 2019
0af694a
fix: better gc test port config
dirkmc May 24, 2019
ffb4eb3
test: increase timeout for repo gc test
dirkmc May 24, 2019
9dd1402
fix: webworkers + mortice
dirkmc May 28, 2019
f35f492
chore: refactor mortice options
dirkmc May 28, 2019
b76737c
fix: gc rm test on Windows
dirkmc May 28, 2019
e31650c
fix: ensure gc filters all internal pins
dirkmc Jun 7, 2019
830b9a1
test: enable gc tests over ipfs-http-client
dirkmc Jun 7, 2019
280f987
chore: better gc logging
dirkmc Jun 10, 2019
232fc39
fix: pin walking
dirkmc Jun 14, 2019
6b45fea
refactor: pin set walking
dirkmc Jun 21, 2019
fbbba1d
feat: add locking for concurrent pin operations
dirkmc Jun 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.103.0",
"interface-ipfs-core": "ipfs/interface-js-ipfs-core#feat/gc",
"ipfsd-ctl": "~0.42.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
Expand All @@ -87,7 +87,7 @@
"@hapi/joi": "^15.0.1",
"async": "^2.6.1",
"async-iterator-all": "0.0.2",
"async-iterator-to-pull-stream": "^1.1.0",
"async-iterator-to-pull-stream": "^1.3.0",
"async-iterator-to-stream": "^1.1.0",
"base32.js": "~0.1.0",
"bignumber.js": "^8.0.2",
Expand Down Expand Up @@ -117,7 +117,7 @@
"ipfs-bitswap": "~0.24.0",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^32.0.0",
"ipfs-http-client": "ipfs/js-ipfs-http-client#feat/gc",
"ipfs-http-response": "~0.3.0",
"ipfs-mfs": "~0.11.2",
"ipfs-multipart": "~0.1.0",
Expand All @@ -139,6 +139,7 @@
"is-pull-stream": "~0.0.0",
"is-stream": "^2.0.0",
"iso-url": "~0.4.6",
"joi": "^14.3.1",
"just-flatten-it": "^2.1.0",
"just-safe-set": "^2.1.0",
"kind-of": "^6.0.2",
Expand All @@ -159,13 +160,15 @@
"merge-options": "^1.0.1",
"mime-types": "^2.1.21",
"mkdirp": "~0.5.1",
"mortice": "dirkmc/mortice#fix/read-then-write",
"multiaddr": "^6.0.5",
"multiaddr-to-uri": "^4.0.1",
"multibase": "~0.6.0",
"multicodec": "~0.5.1",
"multihashes": "~0.4.14",
"multihashing-async": "~0.6.0",
"node-fetch": "^2.3.0",
"p-event": "^4.1.0",
"peer-book": "~0.9.0",
"peer-id": "~0.12.0",
"peer-info": "~0.15.0",
Expand Down
31 changes: 26 additions & 5 deletions src/cli/commands/repo/gc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
'use strict'

const { print } = require('../../utils')

module.exports = {
command: 'gc',

describe: 'Perform a garbage collection sweep on the repo.',

builder: {},
builder: {
quiet: {
alias: 'q',
desc: 'Write minimal output',
type: 'boolean',
default: false
},
'stream-errors': {
desc: 'Output individual errors thrown when deleting blocks.',
type: 'boolean',
default: false
}
},

handler (argv) {
argv.resolve((async () => {
const ipfs = await argv.getIpfs()
await ipfs.repo.gc()
handler ({ getIpfs, quiet, streamErrors, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const res = await ipfs.repo.gc()
for (const r of res) {
if (r.err) {
streamErrors && print(r.err, true, true)
} else {
print((quiet ? '' : 'Removed ') + r.cid)
}
}
})())
}
}
23 changes: 13 additions & 10 deletions src/core/components/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,19 @@ module.exports = function block (self) {
cb(null, new Block(block, cid))
})
},
(block, cb) => self._blockService.put(block, (err) => {
if (err) {
return cb(err)
}
(block, cb) => self._gcLock.readLock((_cb) => {
self._blockService.put(block, (err) => {
if (err) {
return _cb(err)
}

if (options.preload !== false) {
self._preload(block.cid)
}
if (options.preload !== false) {
self._preload(block.cid)
}

cb(null, block)
})
_cb(null, block)
})
}, cb)
], callback)
}),
rm: promisify((cid, callback) => {
Expand All @@ -100,7 +102,8 @@ module.exports = function block (self) {
} catch (err) {
return setImmediate(() => callback(errCode(err, 'ERR_INVALID_CID')))
}
self._blockService.delete(cid, callback)

self._gcLock.writeLock((cb) => self._blockService.delete(cid, cb), callback)
}),
stat: promisify((cid, options, callback) => {
if (typeof options === 'function') {
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/files-regular/add-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function pinFile (file, self, opts, cb) {
const isRootDir = !file.path.includes('/')
const shouldPin = pin && isRootDir && !opts.onlyHash && !opts.hashAlg
if (shouldPin) {
return self.pin.add(file.hash, { preload: false }, err => cb(err, file))
return self.pin.add(file.hash, { preload: false, lock: false }, err => cb(err, file))
} else {
cb(null, file)
}
Expand Down Expand Up @@ -152,7 +152,7 @@ module.exports = function (self) {
}

opts.progress = progress
return pull(
return self._gcLock.pullReadLock(() => pull(
pullMap(content => normalizeContent(content, opts)),
pullFlatten(),
pullMap(file => ({
Expand All @@ -163,6 +163,6 @@ module.exports = function (self) {
pullAsyncMap((file, cb) => prepareFile(file, self, opts, cb)),
pullMap(file => preloadFile(file, self, opts)),
pullAsyncMap((file, cb) => pinFile(file, self, opts, cb))
)
))
}
}
28 changes: 15 additions & 13 deletions src/core/components/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,21 @@ module.exports = function object (self) {
}

function next () {
self._ipld.put(node, multicodec.DAG_PB, {
cidVersion: 0,
hashAlg: multicodec.SHA2_256
}).then(
(cid) => {
if (options.preload !== false) {
self._preload(cid)
}

callback(null, cid)
},
(error) => callback(error)
)
self._gcLock.readLock((cb) => {
self._ipld.put(node, multicodec.DAG_PB, {
cidVersion: 0,
hashAlg: multicodec.SHA2_256
}).then(
(cid) => {
if (options.preload !== false) {
self._preload(cid)
}

cb(null, cid)
},
cb
)
}, callback)
}
}),

Expand Down
Loading