Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit e1c7308

Browse files
committed
feat: support sharded directories
For big directories we need to support HAMT sharded directories. Removes DAG traversal code and uses the importer/exporter from UnixFS exclusivley to do DAG manipulations. Transform directories into hamt-sharded directories when the number of DAGLinks reaches a certain point, otherwise reading them from the block store becomes too expensive. License: MIT Signed-off-by: achingbrain <[email protected]>
1 parent e0dceb6 commit e1c7308

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2072
-833
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"interface-datastore": "~0.6.0",
5656
"ipfs-multipart": "~0.1.0",
5757
"ipfs-unixfs": "~0.1.16",
58-
"ipfs-unixfs-engine": "~0.34.0",
58+
"ipfs-unixfs-importer": "~0.37.0",
59+
"ipfs-unixfs-exporter": "~0.35.0",
5960
"ipld-dag-pb": "~0.15.0",
6061
"is-pull-stream": "~0.0.0",
6162
"is-stream": "^1.1.0",

src/cli/cp.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ module.exports = {
2323
default: 'dag-pb',
2424
describe: 'If intermediate directories are created, use this format to create them (experimental)'
2525
},
26-
hash: {
26+
'hash-alg': {
2727
alias: 'h',
2828
type: 'string',
2929
default: 'sha2-256',
30-
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental)'
30+
describe: 'Hash function to use. Will set CID version to 1 if used'
31+
},
32+
'shard-split-threshold': {
33+
type: 'number',
34+
default: 1000,
35+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
3136
}
3237
},
3338

@@ -38,14 +43,16 @@ module.exports = {
3843
ipfs,
3944
parents,
4045
format,
41-
hash
46+
hashAlg,
47+
shardSplitThreshold
4248
} = argv
4349

4450
argv.resolve(
4551
ipfs.files.cp(source, dest, {
4652
parents,
4753
format,
48-
hashAlg: hash
54+
hashAlg,
55+
shardSplitThreshold
4956
})
5057
)
5158
}

src/cli/ls.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ module.exports = {
2828
coerce: asBoolean,
2929
describe: 'Do not sort; list entries in directory order.'
3030
},
31-
cidBase: {
32-
alias: 'cid-base',
31+
'cid-base': {
3332
default: 'base58btc',
3433
describe: 'CID base to use.'
3534
}

src/cli/mkdir.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ module.exports = {
1717
coerce: asBoolean,
1818
describe: 'No error if existing, make parent directories as needed.'
1919
},
20-
cidVersion: {
21-
alias: ['cid-ver', 'cid-version'],
20+
'cid-version': {
21+
alias: ['cid-ver'],
2222
type: 'number',
2323
default: 0,
2424
describe: 'Cid version to use. (experimental).'
2525
},
26-
hashAlg: {
26+
'hash-alg': {
2727
type: 'string',
2828
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental).'
2929
},
@@ -33,6 +33,11 @@ module.exports = {
3333
default: true,
3434
coerce: asBoolean,
3535
describe: 'Flush the changes to disk immediately'
36+
},
37+
'shard-split-threshold': {
38+
type: 'number',
39+
default: 1000,
40+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
3641
}
3742
},
3843

@@ -43,15 +48,17 @@ module.exports = {
4348
parents,
4449
cidVersion,
4550
hashAlg,
46-
flush
51+
flush,
52+
shardSplitThreshold
4753
} = argv
4854

4955
argv.resolve(
5056
ipfs.files.mkdir(path, {
5157
parents,
5258
cidVersion,
5359
hashAlg,
54-
flush
60+
flush,
61+
shardSplitThreshold
5562
})
5663
)
5764
}

src/cli/mv.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ module.exports = {
2323
default: false,
2424
coerce: asBoolean,
2525
describe: 'Remove directories recursively'
26+
},
27+
'shard-split-threshold': {
28+
type: 'number',
29+
default: 1000,
30+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
2631
}
2732
},
2833

@@ -32,13 +37,15 @@ module.exports = {
3237
dest,
3338
ipfs,
3439
parents,
35-
recursive
40+
recursive,
41+
shardSplitThreshold
3642
} = argv
3743

3844
argv.resolve(
3945
ipfs.files.mv(source, dest, {
4046
parents,
41-
recursive
47+
recursive,
48+
shardSplitThreshold
4249
})
4350
)
4451
}

src/cli/stat.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ Type: <type>`,
3535
coerce: asBoolean,
3636
describe: 'Print only size. Implies \'--format=<cumulsize>\'. Conflicts with other format options.'
3737
},
38-
withLocal: {
38+
'with-local': {
3939
alias: 'l',
4040
type: 'boolean',
4141
default: false,
4242
coerce: asBoolean,
4343
describe: 'Compute the amount of the dag that is local, and if possible the total size'
4444
},
45-
cidBase: {
46-
alias: 'cid-base',
45+
'cid-base': {
4746
default: 'base58btc',
4847
describe: 'CID base to use.'
4948
}

src/cli/write.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ module.exports = {
3939
coerce: asBoolean,
4040
describe: 'Truncate the file after writing'
4141
},
42-
rawLeaves: {
42+
'raw-leaves': {
4343
alias: 'r',
4444
type: 'boolean',
4545
default: false,
4646
coerce: asBoolean,
4747
describe: 'Whether to write leaf nodes as raw UnixFS nodes'
4848
},
49-
reduceSingleLeafToSelf: {
49+
'reduce-single-leaf-to-self': {
5050
type: 'boolean',
5151
default: false,
5252
coerce: asBoolean,
@@ -64,20 +64,25 @@ module.exports = {
6464
type: 'string',
6565
default: 'balanced'
6666
},
67-
cidVersion: {
68-
alias: ['cid-ver', 'cid-version'],
67+
'cid-version': {
68+
alias: ['cid-ver'],
6969
type: 'number',
7070
default: 0,
71-
describe: 'Cid version to use. (experimental).'
71+
describe: 'Cid version to use'
7272
},
73-
hashAlg: {
73+
'hash-alg': {
7474
alias: 'h',
7575
type: 'string',
7676
default: 'sha2-256'
7777
},
7878
format: {
7979
type: 'string',
8080
default: 'dag-pb'
81+
},
82+
'shard-split-threshold': {
83+
type: 'number',
84+
default: 1000,
85+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
8186
}
8287
},
8388

@@ -97,7 +102,8 @@ module.exports = {
97102
parents,
98103
progress,
99104
strategy,
100-
flush
105+
flush,
106+
shardSplitThreshold
101107
} = argv
102108

103109
argv.resolve(
@@ -114,7 +120,8 @@ module.exports = {
114120
parents,
115121
progress,
116122
strategy,
117-
flush
123+
flush,
124+
shardSplitThreshold
118125
})
119126
)
120127
}

0 commit comments

Comments
 (0)