-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat(interface) ThreadSafeDatastoreCloser #9
Conversation
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
@jbenet need to merge ipfs/go-datastore#9 and re-vendor License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
// interface | ||
type ThreadSafeDatastoreCloser interface { | ||
ThreadSafeDatastore | ||
io.Closer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to keep the Closer
interface outside of the Datastore*
interfaces. I think the leveldb instance (or whatever you want the Close
func in) can just conform to io.Closer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LevelDB returns a ThreadSafeDatastore. Prefer to expose the concrete struct?
@maybebtc i think the |
I'll have the LevelDB constructor return a concrete instance then. |
@maybebtc yeah that makes sense. feel free to break up |
// Datastore wraps a levelDB instance with a Datastore interface
type Datastore interface {
ds.ThreadSafeDatastore
io.Closer
DB() *leveldb.DB
}
// datastore uses a standard Go map for internal storage.
type datastore struct {
db *leveldb.DB
} |
closed in favor of #10 |
One minor note... Since the datastore interfaces to not expose Close(), the client is left to implement her own wrapper. This is perfectly fine, but it might be nice for the library to anticipate this need and provide this behavior just as it does with the mutex wrapper. Example: // ClientAppStore returns a Datastore that may need to be closed in Production
func ClientAppStore(in_test_env bool) MyThreadSafeDatastoreCloser {
if in_test_env {
return ds.NewMapDatastore() // compiler error
}
return leveldb.NewDatastore()
} To fix this, each go-datastore client must implement a trivial Wrapper around datastores. type ThreadSafeDatastoreCloserWrapper struct {
ds.ThreadSafeDatastore
}
func (w *ThreadSafeDatastoreCloserWrapper) Close() error {
return nil // no-op
} For now, I'll implement a wrapper for my specific use case. |
@maybebtc i hear you. It's a tough call. A few things to bear in mind:
So i think for now let's keep as is? We can revisit this if a better strategy is found. |
I agree with all points. There's no harm in being careful about over-extending the library. as an aside, here's a link to the wrapper: https://github.com/jbenet/go-ipfs/blob/feat/daemon-init/util/datastore_closer.go |
Expose
Close()
to make it possible to clean up LevelDB instances.License: MIT
Signed-off-by: Brian Tiger Chow brian@perfmode.com