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
Commits
1ca2d428
Commit
1ca2d428
authored
Nov 02, 2016
by
Jeromy Johnson
Committed by
GitHub
Nov 02, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3348 from ipfs/kevina/gclocker
Separate out the G.C. Locking from the Blockstore interface.
parents
9d132e70
ffe9d7da
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
15 deletions
+39
-15
blocks/blockstore/arc_cache_test.go
blocks/blockstore/arc_cache_test.go
+1
-1
blocks/blockstore/blockstore.go
blocks/blockstore/blockstore.go
+28
-6
blocks/blockstore/bloom_cache_test.go
blocks/blockstore/bloom_cache_test.go
+1
-1
blocks/blockstore/caching.go
blocks/blockstore/caching.go
+2
-2
blockservice/blockservice_test.go
blockservice/blockservice_test.go
+3
-3
core/builder.go
core/builder.go
+3
-1
unixfs/mod/dagmodifier_test.go
unixfs/mod/dagmodifier_test.go
+1
-1
No files found.
blocks/blockstore/arc_cache_test.go
View file @
1ca2d428
...
...
@@ -13,7 +13,7 @@ import (
var
exampleBlock
=
blocks
.
NewBlock
([]
byte
(
"foo"
))
func
testArcCached
(
bs
GC
Blockstore
,
ctx
context
.
Context
)
(
*
arccache
,
error
)
{
func
testArcCached
(
bs
Blockstore
,
ctx
context
.
Context
)
(
*
arccache
,
error
)
{
if
ctx
==
nil
{
ctx
=
context
.
TODO
()
}
...
...
blocks/blockstore/blockstore.go
View file @
1ca2d428
...
...
@@ -39,9 +39,7 @@ type Blockstore interface {
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
*
cid
.
Cid
,
error
)
}
type
GCBlockstore
interface
{
Blockstore
type
GCLocker
interface
{
// GCLock locks the blockstore for garbage collection. No operations
// that expect to finish with a pin should ocurr simultaneously.
// Reading during GC is safe, and requires no lock.
...
...
@@ -58,6 +56,20 @@ type GCBlockstore interface {
GCRequested
()
bool
}
type
GCBlockstore
interface
{
Blockstore
GCLocker
}
func
NewGCBlockstore
(
bs
Blockstore
,
gcl
GCLocker
)
GCBlockstore
{
return
gcBlockstore
{
bs
,
gcl
}
}
type
gcBlockstore
struct
{
Blockstore
GCLocker
}
func
NewBlockstore
(
d
ds
.
Batching
)
*
blockstore
{
var
dsb
ds
.
Batching
dd
:=
dsns
.
Wrap
(
d
,
BlockPrefix
)
...
...
@@ -223,6 +235,16 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
return
output
,
nil
}
func
NewGCLocker
()
*
gclocker
{
return
&
gclocker
{}
}
type
gclocker
struct
{
lk
sync
.
RWMutex
gcreq
int32
gcreqlk
sync
.
Mutex
}
type
Unlocker
interface
{
Unlock
()
}
...
...
@@ -236,18 +258,18 @@ func (u *unlocker) Unlock() {
u
.
unlock
=
nil
// ensure its not called twice
}
func
(
bs
*
b
lock
stor
e
)
GCLock
()
Unlocker
{
func
(
bs
*
gc
locke
r
)
GCLock
()
Unlocker
{
atomic
.
AddInt32
(
&
bs
.
gcreq
,
1
)
bs
.
lk
.
Lock
()
atomic
.
AddInt32
(
&
bs
.
gcreq
,
-
1
)
return
&
unlocker
{
bs
.
lk
.
Unlock
}
}
func
(
bs
*
b
lock
stor
e
)
PinLock
()
Unlocker
{
func
(
bs
*
gc
locke
r
)
PinLock
()
Unlocker
{
bs
.
lk
.
RLock
()
return
&
unlocker
{
bs
.
lk
.
RUnlock
}
}
func
(
bs
*
b
lock
stor
e
)
GCRequested
()
bool
{
func
(
bs
*
gc
locke
r
)
GCRequested
()
bool
{
return
atomic
.
LoadInt32
(
&
bs
.
gcreq
)
>
0
}
blocks/blockstore/bloom_cache_test.go
View file @
1ca2d428
...
...
@@ -14,7 +14,7 @@ import (
syncds
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync"
)
func
testBloomCached
(
bs
GC
Blockstore
,
ctx
context
.
Context
)
(
*
bloomcache
,
error
)
{
func
testBloomCached
(
bs
Blockstore
,
ctx
context
.
Context
)
(
*
bloomcache
,
error
)
{
if
ctx
==
nil
{
ctx
=
context
.
TODO
()
}
...
...
blocks/blockstore/caching.go
View file @
1ca2d428
...
...
@@ -22,8 +22,8 @@ func DefaultCacheOpts() CacheOpts {
}
}
func
CachedBlockstore
(
bs
GC
Blockstore
,
ctx
context
.
Context
,
opts
CacheOpts
)
(
cbs
GC
Blockstore
,
err
error
)
{
func
CachedBlockstore
(
bs
Blockstore
,
ctx
context
.
Context
,
opts
CacheOpts
)
(
cbs
Blockstore
,
err
error
)
{
cbs
=
bs
if
opts
.
HasBloomFilterSize
<
0
||
opts
.
HasBloomFilterHashes
<
0
||
...
...
blockservice/blockservice_test.go
View file @
1ca2d428
...
...
@@ -36,14 +36,14 @@ func TestWriteThroughWorks(t *testing.T) {
}
}
var
_
blockstore
.
GC
Blockstore
=
(
*
PutCountingBlockstore
)(
nil
)
var
_
blockstore
.
Blockstore
=
(
*
PutCountingBlockstore
)(
nil
)
type
PutCountingBlockstore
struct
{
blockstore
.
GC
Blockstore
blockstore
.
Blockstore
PutCounter
int
}
func
(
bs
*
PutCountingBlockstore
)
Put
(
block
blocks
.
Block
)
error
{
bs
.
PutCounter
++
return
bs
.
GC
Blockstore
.
Put
(
block
)
return
bs
.
Blockstore
.
Put
(
block
)
}
core/builder.go
View file @
1ca2d428
...
...
@@ -179,11 +179,13 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
opts
.
HasBloomFilterSize
=
0
}
n
.
Blockstore
,
err
=
bstore
.
CachedBlockstore
(
bs
,
ctx
,
opts
)
cbs
,
err
:
=
bstore
.
CachedBlockstore
(
bs
,
ctx
,
opts
)
if
err
!=
nil
{
return
err
}
n
.
Blockstore
=
bstore
.
NewGCBlockstore
(
cbs
,
bstore
.
NewGCLocker
())
rcfg
,
err
:=
n
.
Repo
.
Config
()
if
err
!=
nil
{
return
err
...
...
unixfs/mod/dagmodifier_test.go
View file @
1ca2d428
...
...
@@ -22,7 +22,7 @@ import (
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync"
)
func
getMockDagServAndBstore
(
t
testing
.
TB
)
(
mdag
.
DAGService
,
blockstore
.
GC
Blockstore
)
{
func
getMockDagServAndBstore
(
t
testing
.
TB
)
(
mdag
.
DAGService
,
blockstore
.
Blockstore
)
{
dstore
:=
ds
.
NewMapDatastore
()
tsds
:=
sync
.
MutexWrap
(
dstore
)
bstore
:=
blockstore
.
NewBlockstore
(
tsds
)
...
...
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