@cryptotaxi247 / kubo / commits / 02fb0a4ad

cmds/dag/import: pin roots by default (#9966)

This is a partial revert of b685355ca8ceaaf55619ee3b8cffa612a4106569. Closes #9765 with compromise agreed in https://github.com/ipfs/kubo/issues/9765#issuecomment-1593117410

Jorropo committed Jun 15, 2023 at 16:41 UTC 02fb0a4ad427c8993f2be77ae9db6bab3bd9dbb4
5 files changed +16 -44
core/commands/dag/dag.go
+5 -8
@@ -176,16 +176,13 @@ var DagImportCmd = &cmds.Command{
176 Tagline: "Import the contents of .car files",
177 ShortDescription: `
178 'ipfs dag import' imports all blocks present in supplied .car
179 -( Content Address aRchive ) files, optionally recursively pinning any
180 -roots specified in the CAR file headers if --pin-roots is set.
179 +( Content Address aRchive ) files, recursively pinning any roots
180 +specified in the CAR file headers, unless --pin-roots is set to false.
181
182 Note:
183 This command will import all blocks in the CAR file, not just those
184 - reachable from the specified roots. However, when using --pin-roots,
185 - these other blocks will not be pinned and may be garbage collected
186 - later. When not using --pin-roots, all blocks imported may be garbage
187 - collected if no other pin operation is performed on them, or a root
188 - that references them.
184 + reachable from the specified roots. However, these other blocks will
185 + not be pinned and may be garbage collected later.
186
187 The pinning of the roots happens after all car files are processed,
188 permitting import of DAGs spanning multiple files.
@@ -203,7 +200,7 @@ Specification of CAR formats: https://ipld.io/specs/transport/car/
200 cmds.FileArg("path", true, true, "The path of a .car file.").EnableStdin(),
201 },
202 Options: []cmds.Option{
206 - cmds.BoolOption(pinRootsOptionName, "Pin optional roots listed in the .car headers after importing."),
203 + cmds.BoolOption(pinRootsOptionName, "Pin optional roots listed in the .car headers after importing.").WithDefault(true),
204 cmds.BoolOption(silentOptionName, "No output."),
205 cmds.BoolOption(statsOptionName, "Output stats."),
206 cmdutils.AllowBigBlockOption,
docs/changelogs/v0.22.md
-22
@@ -6,7 +6,6 @@
6
7 - [Overview](#overview)
8 - [🔦 Highlights](#-highlights)
9 - - [`ipfs dag import` no longer pins by default](#ipfs-dag-import-no-longer-pins-by-default)
9 - [📝 Changelog](#-changelog)
10 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
11
@@ -14,27 +13,6 @@
13
14 ### 🔦 Highlights
15
17 -#### `ipfs dag import` no longer pins by default
18 -
19 -With the gateway now capable of handling partial CAR exports
20 -([IPIP-402](https://github.com/ipfs/specs/pull/402)) and incomplete DAG CARs
21 -becoming more prevalent, there have been changes to the pinning mode when using
22 -`ipfs dag import`.
23 -
24 -Recursive pinning of the entire DAG within an imported CAR is now optional. To
25 -explicitly attempt pinning the DAG referenced by any roots present in the CAR,
26 -you can opt in by using the `--pin-roots` option.
27 -
28 -Pinning incomplete DAG will produce an error:
29 -
30 -```console
31 -$ curl 'http://127.0.0.1:8080/ipns/docs.ipfs.tech?format=car&dag-scope=entity' > ./partial-entity.car # Kubo 0.21.0 with IPIP-402 (only root block of unixfs dir)
32 -$ ipfs dag import --stats --pin-roots=true ./partial-entity.car
33 -Error pinning QmPDC11yLAbVw3dX5jMeEuSdk4BiVjSd9X87zaYRdVjzW3 FAILED: block was not found locally (offline): ipld: could not find QmPDvrDAz2aHeLjPVQ4uh1neyknUmDpf1GsBzAbpFhS8ro
34 -Imported 1 blocks (1618 bytes)
35 -[exit code 1]
36 -```
37 -
16 ### 📝 Changelog
17
18 ### 👨‍👩‍👧‍👦 Contributors
test/sharness/t0054-dag-car-import-export.sh
+9 -12
@@ -41,7 +41,7 @@ do_import() {
41 while [[ -e spin.gc ]]; do ipfsi "$node" repo gc &>/dev/null; done &
42 while [[ -e spin.gc ]]; do ipfsi "$node" repo gc &>/dev/null; done &
43
44 - ipfsi "$node" dag import --pin-roots "$@" 2>&1 && ipfsi "$node" repo verify &>/dev/null
44 + ipfsi "$node" dag import "$@" 2>&1 && ipfsi "$node" repo verify &>/dev/null
45 result=$?
46
47 rm -f spin.gc &>/dev/null
@@ -117,7 +117,7 @@ EOE
117 '
118
119 test_expect_success "import/pin naked roots only, relying on local blockstore having all the data" '
120 - ipfsi 1 dag import --stats --enc=json --pin-roots ../t0054-dag-car-import-export-data/combined_naked_roots_genesis_and_128.car \
120 + ipfsi 1 dag import --stats --enc=json ../t0054-dag-car-import-export-data/combined_naked_roots_genesis_and_128.car \
121 > naked_import_result_json_actual
122 '
123
@@ -197,14 +197,14 @@ EOE
197 head -3 multiroot_import_json_stats_expected > multiroot_import_json_expected
198
199 test_expect_success "multiroot import works (--enc=json)" '
200 - ipfs dag import --enc=json --pin-roots ../t0054-dag-car-import-export-data/lotus_testnet_export_256_multiroot.car > multiroot_import_json_actual
200 + ipfs dag import --enc=json ../t0054-dag-car-import-export-data/lotus_testnet_export_256_multiroot.car > multiroot_import_json_actual
201 '
202 test_expect_success "multiroot import expected output" '
203 test_cmp_sorted multiroot_import_json_expected multiroot_import_json_actual
204 '
205
206 test_expect_success "multiroot import works with --stats" '
207 - ipfs dag import --stats --enc=json --pin-roots ../t0054-dag-car-import-export-data/lotus_testnet_export_256_multiroot.car > multiroot_import_json_actual
207 + ipfs dag import --stats --enc=json ../t0054-dag-car-import-export-data/lotus_testnet_export_256_multiroot.car > multiroot_import_json_actual
208 '
209 test_expect_success "multiroot import expected output" '
210 test_cmp_sorted multiroot_import_json_stats_expected multiroot_import_json_actual
@@ -215,18 +215,18 @@ cat >pin_import_expected << EOE
215 {"Stats":{"BlockCount":1198,"BlockBytesCount":468513}}
216 EOE
217 test_expect_success "pin-less import works" '
218 - ipfs dag import --stats --enc=json \
218 + ipfs dag import --stats --enc=json --pin-roots=false \
219 ../t0054-dag-car-import-export-data/lotus_devnet_genesis.car \
220 ../t0054-dag-car-import-export-data/lotus_testnet_export_128.car \
221 > no-pin_import_actual
222 '
223 -test_expect_success "expected no pins on" '
223 +test_expect_success "expected no pins on --pin-roots=false" '
224 test_cmp pin_import_expected no-pin_import_actual
225 '
226
227
228 test_expect_success "naked root import works" '
229 - ipfs dag import --stats --enc=json --pin-roots ../t0054-dag-car-import-export-data/combined_naked_roots_genesis_and_128.car \
229 + ipfs dag import --stats --enc=json ../t0054-dag-car-import-export-data/combined_naked_roots_genesis_and_128.car \
230 > naked_root_import_json_actual
231 '
232 test_expect_success "naked root import expected output" '
@@ -253,7 +253,7 @@ cat > version_2_import_expected << EOE
253 EOE
254
255 test_expect_success "version 2 import" '
256 - ipfs dag import --stats --enc=json --pin-roots \
256 + ipfs dag import --stats --enc=json \
257 ../t0054-dag-car-import-export-data/lotus_testnet_export_128_v2.car \
258 ../t0054-dag-car-import-export-data/lotus_devnet_genesis_v2.car \
259 > version_2_import_actual
@@ -299,9 +299,6 @@ test_expect_success "'ipfs dag import' without pinning works fine with incomplet
299 ipfs dag import --stats --enc=json --pin-roots=false ../t0054-dag-car-import-export-data/partial-dag-scope-entity.car >partial_nopin_import_out 2>&1 &&
300 test_cmp partial_nopin_import_expected partial_nopin_import_out
301 '
302 -test_expect_success "'ipfs dag import' with no params in CLI mode produces exit code 0 (unixfs dir exported as dag-scope=entity from IPIP-402)" '
303 - test_expect_code 0 ipfs dag import ../t0054-dag-car-import-export-data/partial-dag-scope-entity.car
304 -'
302
303 test_expect_success "'ipfs dag import' with pinning errors due to incomplete DAG (unixfs dir exported as dag-scope=entity from IPIP-402)" '
304 ipfs dag import --stats --enc=json --pin-roots=true ../t0054-dag-car-import-export-data/partial-dag-scope-entity.car >partial_pin_import_out 2>&1 &&
@@ -309,7 +306,7 @@ test_expect_success "'ipfs dag import' with pinning errors due to incomplete DAG
306 '
307
308 test_expect_success "'ipfs dag import' pin error in default CLI mode produces exit code 1 (unixfs dir exported as dag-scope=entity from IPIP-402)" '
312 - test_expect_code 1 ipfs dag import --pin-roots ../t0054-dag-car-import-export-data/partial-dag-scope-entity.car >partial_pin_import_out 2>&1 &&
309 + test_expect_code 1 ipfs dag import ../t0054-dag-car-import-export-data/partial-dag-scope-entity.car >partial_pin_import_out 2>&1 &&
310 test_should_contain "Error: pinning root \"QmPDC11yLAbVw3dX5jMeEuSdk4BiVjSd9X87zaYRdVjzW3\" FAILED: block was not found locally" partial_pin_import_out
311 '
312
test/sharness/t0124-gateway-ipns-record.sh
+1 -1
@@ -12,7 +12,7 @@ test_launch_ipfs_daemon
12 IPNS_KEY=k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab
13 FILE_CID=bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244 # A file containing Hello IPFS
14 test_expect_success "Add the test directory & IPNS records" '
15 - ipfs dag import --pin-roots ../t0124-gateway-ipns-record/fixtures.car &&
15 + ipfs dag import ../t0124-gateway-ipns-record/fixtures.car &&
16 ipfs routing put /ipns/${IPNS_KEY} ../t0124-gateway-ipns-record/${IPNS_KEY}.ipns-record
17 '
18
test/sharness/t0400-api-no-gateway.sh
+1 -1
@@ -13,7 +13,7 @@ test_init_ipfs
13 # Import test case
14 # See the static fixtures in ./t0400-api-no-gateway/
15 test_expect_success "Add the test directory" '
16 - ipfs dag import --pin-roots ../t0400-api-no-gateway/fixtures.car
16 + ipfs dag import ../t0400-api-no-gateway/fixtures.car
17 '
18 HASH=QmNYERzV2LfD2kkfahtfv44ocHzEFK1sLBaE7zdcYT2GAZ # a file containing the string "testing"
19