Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockstore/blockservice: change option to WriteThrough(enabled bool) #749

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The following emojis are used to highlight certain changes:

### Changed

* 🛠 `blockstore` and `blockservice`'s `WriteThrough()` option now takes an "enabled" parameter: `WriteThrough(enabled bool)`.

### Removed

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions blockservice/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ type blockService struct {
type Option func(*blockService)

// WriteThrough disable cache checks for writes and make them go straight to
// the blockstore.
func WriteThrough() Option {
// the blockstore, when enabled.
func WriteThrough(enabled bool) Option {
return func(bs *blockService) {
bs.checkFirst = false
bs.checkFirst = !enabled
}
}

Expand Down
8 changes: 4 additions & 4 deletions blockservice/blockservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestWriteThroughWorks(t *testing.T) {
}
exchbstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
exch := offline.Exchange(exchbstore)
bserv := New(bstore, exch, WriteThrough())
bserv := New(bstore, exch, WriteThrough(true))

block := random.BlocksOfSize(1, blockSize)[0]

Expand Down Expand Up @@ -63,7 +63,7 @@ func TestExchangeWrite(t *testing.T) {
offline.Exchange(exchbstore),
0,
}
bserv := New(bstore, exch, WriteThrough())
bserv := New(bstore, exch, WriteThrough(true))

for name, fetcher := range map[string]BlockGetter{
"blockservice": bserv,
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestLazySessionInitialization(t *testing.T) {
session := offline.Exchange(bstore2)
exch := offline.Exchange(bstore3)
sessionExch := &fakeSessionExchange{Interface: exch, session: session}
bservSessEx := New(bstore, sessionExch, WriteThrough())
bservSessEx := New(bstore, sessionExch, WriteThrough(true))
blks := random.BlocksOfSize(2, blockSize)

block := blks[0]
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestNilExchange(t *testing.T) {
block := random.BlocksOfSize(1, blockSize)[0]

bs := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
bserv := New(bs, nil, WriteThrough())
bserv := New(bs, nil, WriteThrough(true))
sess := NewSession(ctx, bserv)
_, err := sess.GetBlock(ctx, block.Cid())
if !ipld.IsNotFound(err) {
Expand Down
6 changes: 3 additions & 3 deletions blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
}

// WriteThrough skips checking if the blockstore already has a block before
// writing it.
func WriteThrough() Option {
// writing it, when enabled.
func WriteThrough(enabled bool) Option {

Check warning on line 126 in blockstore/blockstore.go

View check run for this annotation

Codecov / codecov/patch

blockstore/blockstore.go#L126

Added line #L126 was not covered by tests
return Option{
func(bs *blockstore) {
bs.writeThrough = true
bs.writeThrough = enabled

Check warning on line 129 in blockstore/blockstore.go

View check run for this annotation

Codecov / codecov/patch

blockstore/blockstore.go#L129

Added line #L129 was not covered by tests
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion exchange/providing/providing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestExchange(t *testing.T) {
provExchange := New(i.Exchange, prov)
// write-through so that we notify when re-adding block
bs := blockservice.New(i.Blockstore, provExchange,
blockservice.WriteThrough())
blockservice.WriteThrough(true))
block := random.BlocksOfSize(1, 10)[0]
// put it on the blockstore of the first instance
err = i.Blockstore.Put(ctx, block)
Expand Down
Loading