Skip to content

Commit

Permalink
Merge pull request #120 from ipfs/feat/no-thread-safe
Browse files Browse the repository at this point in the history
remove ThreadSafeDatastore
  • Loading branch information
Stebalien authored Mar 16, 2019
2 parents 1b37198 + 9f529bc commit 6de025e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
4 changes: 3 additions & 1 deletion basic_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type MapDatastore struct {
values map[Key][]byte
}

// NewMapDatastore constructs a MapDatastore
// 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).
func NewMapDatastore() (d *MapDatastore) {
return &MapDatastore{
values: make(map[Key][]byte),
Expand Down
8 changes: 0 additions & 8 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ type Batching interface {
// actually support batching.
var ErrBatchUnsupported = errors.New("this datastore does not support batching")

// ThreadSafeDatastore is an interface that all threadsafe datastore should
// implement to leverage type safety checks.
type ThreadSafeDatastore interface {
Datastore

IsThreadSafe()
}

// CheckedDatastore is an interface that should be implemented by datastores
// which may need checking on-disk data integrity.
type CheckedDatastore interface {
Expand Down
2 changes: 0 additions & 2 deletions mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
}), nil
}

func (d *Datastore) IsThreadSafe() {}

func (d *Datastore) Close() error {
for _, d := range d.mounts {
err := d.Datastore.Close()
Expand Down
7 changes: 2 additions & 5 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type MutexDatastore struct {
child ds.Datastore
}

// MutexWrap constructs a datastore with a coarse lock around
// the entire datastore, for every single operation
// MutexWrap constructs a datastore with a coarse lock around the entire
// datastore, for every single operation.
func MutexWrap(d ds.Datastore) *MutexDatastore {
return &MutexDatastore{child: d}
}
Expand All @@ -26,9 +26,6 @@ func (d *MutexDatastore) Children() []ds.Datastore {
return []ds.Datastore{d.child}
}

// IsThreadSafe implements ThreadSafeDatastore
func (d *MutexDatastore) IsThreadSafe() {}

// Put implements Datastore.Put
func (d *MutexDatastore) Put(key ds.Key, value []byte) (err error) {
d.Lock()
Expand Down

0 comments on commit 6de025e

Please sign in to comment.