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

fix NullDatastore Batch to take a Context #184

Merged
merged 2 commits into from
Nov 29, 2021
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
3 changes: 3 additions & 0 deletions autobatch/autobatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type Datastore struct {
maxBufferEntries int
}

var _ ds.Datastore = (*Datastore)(nil)
var _ ds.PersistentDatastore = (*Datastore)(nil)

type op struct {
delete bool
value []byte
Expand Down
18 changes: 17 additions & 1 deletion basic_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type MapDatastore struct {
values map[Key][]byte
}

var _ Datastore = (*MapDatastore)(nil)
var _ Batching = (*MapDatastore)(nil)

// NewMapDatastore constructs a MapDatastore. It is _not_ thread-safe by
// default, wrap using sync.MutexWrap if you need thread safety (the answer here
// is usually yes).
Expand Down Expand Up @@ -91,6 +94,9 @@ func (d *MapDatastore) Close() error {
type NullDatastore struct {
}

var _ Datastore = (*NullDatastore)(nil)
var _ Batching = (*NullDatastore)(nil)

// NewNullDatastore constructs a null datastoe
func NewNullDatastore() *NullDatastore {
return &NullDatastore{}
Expand Down Expand Up @@ -131,7 +137,7 @@ func (d *NullDatastore) Query(ctx context.Context, q dsq.Query) (dsq.Results, er
return dsq.ResultsWithEntries(q, nil), nil
}

func (d *NullDatastore) Batch() (Batch, error) {
func (d *NullDatastore) Batch(ctx context.Context) (Batch, error) {
return NewBasicBatch(d), nil
}

Expand All @@ -145,6 +151,14 @@ type LogDatastore struct {
child Datastore
}

var _ Datastore = (*LogDatastore)(nil)
var _ Batching = (*LogDatastore)(nil)
var _ GCDatastore = (*LogDatastore)(nil)
var _ PersistentDatastore = (*LogDatastore)(nil)
var _ ScrubbedDatastore = (*LogDatastore)(nil)
var _ CheckedDatastore = (*LogDatastore)(nil)
var _ Shim = (*LogDatastore)(nil)

// Shim is a datastore which has a child.
type Shim interface {
Datastore
Expand Down Expand Up @@ -226,6 +240,8 @@ type LogBatch struct {
child Batch
}

var _ Batch = (*LogBatch)(nil)

func (d *LogDatastore) Batch(ctx context.Context) (Batch, error) {
log.Printf("%s: Batch\n", d.Name)
if bds, ok := d.child.(Batching); ok {
Expand Down
2 changes: 2 additions & 0 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type basicBatch struct {
target Datastore
}

var _ Batch = (*basicBatch)(nil)

func NewBasicBatch(ds Datastore) Batch {
return &basicBatch{
ops: make(map[Key]op),
Expand Down
2 changes: 2 additions & 0 deletions delayed/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ type Delayed struct {
delay delay.D
}

var _ ds.Datastore = (*Delayed)(nil)
var _ ds.Batching = (*Delayed)(nil)
var _ ds.PersistentDatastore = (*Delayed)(nil)
var _ io.Closer = (*Delayed)(nil)

// Put implements the ds.Datastore interface.
Expand Down
4 changes: 4 additions & 0 deletions examples/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Datastore struct {
path string
}

var _ ds.Datastore = (*Datastore)(nil)
var _ ds.Batching = (*Datastore)(nil)
var _ ds.PersistentDatastore = (*Datastore)(nil)

// NewDatastore returns a new fs Datastore at given `path`
func NewDatastore(path string) (ds.Datastore, error) {
if !isDir(path) {
Expand Down
6 changes: 6 additions & 0 deletions failstore/failstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type Failstore struct {
errfunc func(string) error
}

var _ ds.Datastore = (*Failstore)(nil)
var _ ds.Batching = (*Failstore)(nil)
var _ ds.PersistentDatastore = (*Failstore)(nil)

// NewFailstore creates a new datastore with the given error function.
// The efunc will be called with different strings depending on the
// datastore function: put, get, has, delete, query, batch, batch-put,
Expand Down Expand Up @@ -117,6 +121,8 @@ type FailBatch struct {
dstore *Failstore
}

var _ ds.Batch = (*FailBatch)(nil)

// Batch returns a new Batch Failstore.
func (d *Failstore) Batch(ctx context.Context) (ds.Batch, error) {
if err := d.errfunc("batch"); err != nil {
Expand Down
16 changes: 10 additions & 6 deletions keytransform/keytransform.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ type Datastore struct {
KeyTransform
}

var _ ds.Datastore = (*Datastore)(nil)
var _ ds.Batching = (*Datastore)(nil)
var _ ds.Shim = (*Datastore)(nil)
var _ ds.PersistentDatastore = (*Datastore)(nil)
var _ ds.CheckedDatastore = (*Datastore)(nil)
var _ ds.ScrubbedDatastore = (*Datastore)(nil)
var _ ds.GCDatastore = (*Datastore)(nil)

// Children implements ds.Shim
func (d *Datastore) Children() []ds.Datastore {
return []ds.Datastore{d.child}
Expand Down Expand Up @@ -222,6 +230,8 @@ type transformBatch struct {
f KeyMapping
}

var _ ds.Batch = (*transformBatch)(nil)

func (t *transformBatch) Put(ctx context.Context, key ds.Key, val []byte) error {
return t.dst.Put(ctx, t.f(key), val)
}
Expand Down Expand Up @@ -254,9 +264,3 @@ func (d *Datastore) CollectGarbage(ctx context.Context) error {
}
return nil
}

var _ ds.Datastore = (*Datastore)(nil)
var _ ds.GCDatastore = (*Datastore)(nil)
var _ ds.Batching = (*Datastore)(nil)
var _ ds.PersistentDatastore = (*Datastore)(nil)
var _ ds.ScrubbedDatastore = (*Datastore)(nil)
7 changes: 7 additions & 0 deletions mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ type Datastore struct {
}

var _ ds.Datastore = (*Datastore)(nil)
var _ ds.Batching = (*Datastore)(nil)
var _ ds.PersistentDatastore = (*Datastore)(nil)
var _ ds.CheckedDatastore = (*Datastore)(nil)
var _ ds.ScrubbedDatastore = (*Datastore)(nil)
var _ ds.GCDatastore = (*Datastore)(nil)

// lookup looks up the datastore in which the given key lives.
func (d *Datastore) lookup(key ds.Key) (ds.Datastore, ds.Key, ds.Key) {
Expand Down Expand Up @@ -406,6 +411,8 @@ type mountBatch struct {
d *Datastore
}

var _ ds.Batch = (*mountBatch)(nil)

// Batch returns a batch that operates over all mounted datastores.
func (d *Datastore) Batch(ctx context.Context) (ds.Batch, error) {
return &mountBatch{
Expand Down
4 changes: 4 additions & 0 deletions retrystore/retrystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type Datastore struct {
ds.Batching
}

var _ ds.Datastore = (*Datastore)(nil)
var _ ds.Batching = (*Datastore)(nil)
var _ ds.PersistentDatastore = (*Datastore)(nil)

var errFmtString = "ran out of retries trying to get past temporary error: %w"

func (d *Datastore) runOp(op func() error) error {
Expand Down
10 changes: 10 additions & 0 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type MutexDatastore struct {
child ds.Datastore
}

var _ ds.Datastore = (*MutexDatastore)(nil)
var _ ds.Batching = (*MutexDatastore)(nil)
var _ ds.Shim = (*MutexDatastore)(nil)
var _ ds.PersistentDatastore = (*MutexDatastore)(nil)
var _ ds.CheckedDatastore = (*MutexDatastore)(nil)
var _ ds.ScrubbedDatastore = (*MutexDatastore)(nil)
var _ ds.GCDatastore = (*MutexDatastore)(nil)

// MutexWrap constructs a datastore with a coarse lock around the entire
// datastore, for every single operation.
func MutexWrap(d ds.Datastore) *MutexDatastore {
Expand Down Expand Up @@ -129,6 +137,8 @@ type syncBatch struct {
mds *MutexDatastore
}

var _ ds.Batch = (*syncBatch)(nil)

func (b *syncBatch) Put(ctx context.Context, key ds.Key, val []byte) error {
b.mds.Lock()
defer b.mds.Unlock()
Expand Down