Commit b9346d07 authored by Jeromy's avatar Jeromy

betterify the everything

parent 6b0bf4f6
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
package measure package measure
import ( import (
"io"
"time" "time"
"github.com/jbenet/go-datastore" "github.com/jbenet/go-datastore"
...@@ -18,11 +19,6 @@ const ( ...@@ -18,11 +19,6 @@ const (
maxSize = int64(1 << 32) maxSize = int64(1 << 32)
) )
type DatastoreCloser interface {
datastore.Datastore
Close() error
}
// New wraps the datastore, providing metrics on the operations. The // New wraps the datastore, providing metrics on the operations. The
// metrics are registered with names starting with prefix and a dot. // metrics are registered with names starting with prefix and a dot.
// //
...@@ -84,7 +80,6 @@ type measure struct { ...@@ -84,7 +80,6 @@ type measure struct {
} }
var _ datastore.Datastore = (*measure)(nil) var _ datastore.Datastore = (*measure)(nil)
var _ DatastoreCloser = (*measure)(nil)
func recordLatency(h *metrics.Histogram, start time.Time) { func recordLatency(h *metrics.Histogram, start time.Time) {
elapsed := time.Now().Sub(start) / time.Microsecond elapsed := time.Now().Sub(start) / time.Microsecond
...@@ -159,7 +154,7 @@ type measuredBatch struct { ...@@ -159,7 +154,7 @@ type measuredBatch struct {
} }
func (m *measure) Batch() (datastore.Batch, error) { func (m *measure) Batch() (datastore.Batch, error) {
bds, ok := m.backend.(datastore.BatchingDatastore) bds, ok := m.backend.(datastore.Batching)
if !ok { if !ok {
return nil, datastore.ErrBatchUnsupported return nil, datastore.ErrBatchUnsupported
} }
...@@ -245,5 +240,9 @@ func (m *measure) Close() error { ...@@ -245,5 +240,9 @@ func (m *measure) Close() error {
m.queryNum.Remove() m.queryNum.Remove()
m.queryErr.Remove() m.queryErr.Remove()
m.queryLatency.Remove() m.queryLatency.Remove()
if c, ok := m.backend.(io.Closer); ok {
return c.Close()
}
return nil return nil
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment