配置文件
"Datastore": {
"StorageMax": "10GB", // 最大存儲(chǔ)空間, 實(shí)際上, 存儲(chǔ)量超過該值仍可以繼續(xù)存儲(chǔ)
"StorageGCWatermark": 90, // 存儲(chǔ)空間警戒線, 只有 已使用存儲(chǔ)空間/最大存儲(chǔ)空間 超過該值, 定時(shí)自動(dòng) GC 才會(huì)生效, 否則不會(huì) GC
"GCPeriod": "1h", // 每過 1h, 檢查是否需要 GC
"Spec": {
"mounts": [
{
"child": {
"path": "blocks",
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
"sync": true,
"type": "flatfs"
},
"mountpoint": "/blocks", // 文件塊存儲(chǔ)路徑(相對(duì)于 ~/.ipfs)
"prefix": "flatfs.datastore",
"type": "measure"
},
{
"child": {
"compression": "none",
"path": "datastore",
"type": "levelds"
},
"mountpoint": "/",
"prefix": "leveldb.datastore",
"type": "measure"
}
],
"type": "mount"
},
...
},
ipfs 定時(shí) GC 功能
如配置所示残家,StorageMax
表明 ipfs 的最大存儲(chǔ)空間榆俺,StorageGCWatermark
表明存儲(chǔ)空間警戒線坞淮,GCPeriod
為檢查是否 GC 的間隔時(shí)間茴晋。
當(dāng)?shù)竭_(dá)檢查時(shí)間時(shí)回窘,如果已用存儲(chǔ)空間 > StorageMax * StorageGCWatermark
,則會(huì)發(fā)生 GC啡直。
注意: 使用 ipfs daemon
啟動(dòng) ipfs苍碟,并不會(huì)自動(dòng)啟動(dòng) ipfs 的定時(shí)GC功能。
需要開啟相應(yīng)的參數(shù), 即 ipfs daemon --enable-gc
, 才會(huì)啟動(dòng) ipfs 的定時(shí)GC功能驰怎。
ipfs 數(shù)據(jù)持久化
Spec
是 ipfs 數(shù)據(jù)持久化的規(guī)格說明書,說明了 ipfs 有哪些存儲(chǔ)結(jié)構(gòu)县忌。下圖是 ipfs 的 Spec
對(duì)應(yīng)生成的 datastore 結(jié)構(gòu)。
measure datastore
用于統(tǒng)計(jì)信息症杏,如 GC 次數(shù)等。
mount datastore
用于存儲(chǔ)有實(shí)際存儲(chǔ)功能的 datastore厉颤。
flatfs datastore
用于存儲(chǔ) Block。
leveldb datastore
用于存儲(chǔ) KV 信息逼友。