Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d39d9ed6
提交
d39d9ed6
authored
3月 20, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gc: address CR comments
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
f66ca2ff
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
23 行增加
和
13 行删除
+23
-13
repo.go
core/commands/repo.go
+1
-0
gc.go
core/corerepo/gc.go
+5
-0
gc.go
pin/gc/gc.go
+17
-13
没有找到文件。
core/commands/repo.go
浏览文件 @
d39d9ed6
...
...
@@ -40,6 +40,7 @@ var RepoCmd = &cmds.Command{
},
}
// GcResult is the result returned by "repo gc" command.
type
GcResult
struct
{
Key
*
cid
.
Cid
Error
string
`json:",omitempty"`
...
...
core/corerepo/gc.go
浏览文件 @
d39d9ed6
...
...
@@ -91,6 +91,9 @@ func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
return
CollectResult
(
ctx
,
rmed
,
nil
)
}
// CollectResult collects the output of a garbage collection run and calls the
// given callback for each object removed. It also collects all errors into a
// MultiError which is returned after the gc is completed.
func
CollectResult
(
ctx
context
.
Context
,
gcOut
<-
chan
gc
.
Result
,
cb
func
(
*
cid
.
Cid
))
error
{
var
errors
[]
error
loop
:
...
...
@@ -121,10 +124,12 @@ loop:
}
}
// NewMultiError creates a new MultiError object from a given slice of errors.
func
NewMultiError
(
errs
...
error
)
*
MultiError
{
return
&
MultiError
{
errs
[
:
len
(
errs
)
-
1
],
errs
[
len
(
errs
)
-
1
]}
}
// MultiError contains the results of multiple errors.
type
MultiError
struct
{
Errors
[]
error
Summary
error
...
...
pin/gc/gc.go
浏览文件 @
d39d9ed6
...
...
@@ -16,6 +16,8 @@ import (
var
log
=
logging
.
Logger
(
"gc"
)
// Result represents an incremental output from a garbage collection
// run. It contains either an error, or the cid of a removed object.
type
Result
struct
{
KeyRemoved
*
cid
.
Cid
Error
error
...
...
@@ -66,7 +68,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
err
:=
bs
.
DeleteBlock
(
k
)
if
err
!=
nil
{
errors
=
true
output
<-
Result
{
Error
:
&
C
ouldN
otDeleteBlockError
{
k
,
err
}}
output
<-
Result
{
Error
:
&
C
ann
otDeleteBlockError
{
k
,
err
}}
//log.Errorf("Error removing key from blockstore: %s", err)
// continue as error is non-fatal
continue
loop
...
...
@@ -82,7 +84,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
}
}
if
errors
{
output
<-
Result
{
Error
:
ErrC
ouldN
otDeleteSomeBlocks
}
output
<-
Result
{
Error
:
ErrC
ann
otDeleteSomeBlocks
}
}
}()
...
...
@@ -103,6 +105,8 @@ func Descendants(ctx context.Context, getLinks dag.GetLinks, set *cid.Set, roots
return
nil
}
// ColoredSet computes the set of nodes in the graph that are pinned by the
// pins in the given pinner.
func
ColoredSet
(
ctx
context
.
Context
,
pn
pin
.
Pinner
,
ls
dag
.
LinkService
,
bestEffortRoots
[]
*
cid
.
Cid
,
output
chan
<-
Result
)
(
*
cid
.
Set
,
error
)
{
// KeySet currently implemented in memory, in the future, may be bloom filter or
// disk backed to conserve memory.
...
...
@@ -112,7 +116,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo
links
,
err
:=
ls
.
GetLinks
(
ctx
,
cid
)
if
err
!=
nil
{
errors
=
true
output
<-
Result
{
Error
:
&
C
ouldN
otFetchLinksError
{
cid
,
err
}}
output
<-
Result
{
Error
:
&
C
ann
otFetchLinksError
{
cid
,
err
}}
}
return
links
,
nil
}
...
...
@@ -126,7 +130,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo
links
,
err
:=
ls
.
GetLinks
(
ctx
,
cid
)
if
err
!=
nil
&&
err
!=
dag
.
ErrNotFound
{
errors
=
true
output
<-
Result
{
Error
:
&
C
ouldN
otFetchLinksError
{
cid
,
err
}}
output
<-
Result
{
Error
:
&
C
ann
otFetchLinksError
{
cid
,
err
}}
}
return
links
,
nil
}
...
...
@@ -147,30 +151,30 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo
}
if
errors
{
return
nil
,
ErrCouldNotFetchAllLinks
}
else
{
return
gcs
,
nil
return
nil
,
ErrCannotFetchAllLinks
}
return
gcs
,
nil
}
var
ErrC
ouldN
otFetchAllLinks
=
errors
.
New
(
"garbage collection aborted: could not retrieve some links"
)
var
ErrC
ann
otFetchAllLinks
=
errors
.
New
(
"garbage collection aborted: could not retrieve some links"
)
var
ErrC
ouldN
otDeleteSomeBlocks
=
errors
.
New
(
"garbage collection incomplete: could not delete some blocks"
)
var
ErrC
ann
otDeleteSomeBlocks
=
errors
.
New
(
"garbage collection incomplete: could not delete some blocks"
)
type
C
ouldN
otFetchLinksError
struct
{
type
C
ann
otFetchLinksError
struct
{
Key
*
cid
.
Cid
Err
error
}
func
(
e
*
C
ouldN
otFetchLinksError
)
Error
()
string
{
func
(
e
*
C
ann
otFetchLinksError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"could not retrieve links for %s: %s"
,
e
.
Key
,
e
.
Err
)
}
type
C
ouldN
otDeleteBlockError
struct
{
type
C
ann
otDeleteBlockError
struct
{
Key
*
cid
.
Cid
Err
error
}
func
(
e
*
C
ouldN
otDeleteBlockError
)
Error
()
string
{
func
(
e
*
C
ann
otDeleteBlockError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"could not remove %s: %s"
,
e
.
Key
,
e
.
Err
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论