Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-pinner
Commits
9a4b4e93
Commit
9a4b4e93
authored
8 years ago
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc: address CR comments
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
8fab9b48
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
gc/gc.go
gc/gc.go
+17
-13
No files found.
gc/gc.go
View file @
9a4b4e93
...
...
@@ -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
)
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment