From 6bba2e5c8c09794883b97f9e8711708ec66d25d8 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 22 Nov 2021 19:21:00 -0500 Subject: [PATCH 1/2] fix: make NullDatastore satisfy the Batching interface again --- basic_ds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basic_ds.go b/basic_ds.go index fb03137..b7950f4 100644 --- a/basic_ds.go +++ b/basic_ds.go @@ -131,7 +131,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 } From 933404091e7323790c1945b338822b08b5bf8d54 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 22 Nov 2021 19:46:00 -0500 Subject: [PATCH 2/2] chore: add lots of interface assertions --- autobatch/autobatch.go | 3 +++ basic_ds.go | 16 ++++++++++++++++ batch.go | 2 ++ delayed/delayed.go | 2 ++ examples/fs.go | 4 ++++ failstore/failstore.go | 6 ++++++ keytransform/keytransform.go | 16 ++++++++++------ mount/mount.go | 7 +++++++ retrystore/retrystore.go | 4 ++++ sync/sync.go | 10 ++++++++++ 10 files changed, 64 insertions(+), 6 deletions(-) diff --git a/autobatch/autobatch.go b/autobatch/autobatch.go index a864b6e..4a19d90 100644 --- a/autobatch/autobatch.go +++ b/autobatch/autobatch.go @@ -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 diff --git a/basic_ds.go b/basic_ds.go index b7950f4..95f03fe 100644 --- a/basic_ds.go +++ b/basic_ds.go @@ -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). @@ -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{} @@ -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 @@ -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 { diff --git a/batch.go b/batch.go index ad4f990..7dbd27f 100644 --- a/batch.go +++ b/batch.go @@ -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), diff --git a/delayed/delayed.go b/delayed/delayed.go index 8ddaa96..a06c130 100644 --- a/delayed/delayed.go +++ b/delayed/delayed.go @@ -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. diff --git a/examples/fs.go b/examples/fs.go index 0f87125..53f370a 100644 --- a/examples/fs.go +++ b/examples/fs.go @@ -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) { diff --git a/failstore/failstore.go b/failstore/failstore.go index a1d7ea7..906f337 100644 --- a/failstore/failstore.go +++ b/failstore/failstore.go @@ -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, @@ -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 { diff --git a/keytransform/keytransform.go b/keytransform/keytransform.go index 9498c94..c1c7414 100644 --- a/keytransform/keytransform.go +++ b/keytransform/keytransform.go @@ -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} @@ -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) } @@ -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) diff --git a/mount/mount.go b/mount/mount.go index 769a7e7..8885358 100644 --- a/mount/mount.go +++ b/mount/mount.go @@ -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) { @@ -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{ diff --git a/retrystore/retrystore.go b/retrystore/retrystore.go index 507d199..feac4d5 100644 --- a/retrystore/retrystore.go +++ b/retrystore/retrystore.go @@ -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 { diff --git a/sync/sync.go b/sync/sync.go index 8679c7c..2cefa3f 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -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 { @@ -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()