diff --git a/attr.go b/attr.go index 7e025ea5b..03ea4f43f 100644 --- a/attr.go +++ b/attr.go @@ -30,11 +30,6 @@ const ( AttrTypeFloat = 4 ) -// AttrStoreGenerator represents an interface for generating an AttrStore. -type AttrStoreGenerator interface { - New(string) AttrStore -} - // AttrStore represents an interface for handling row/column attributes. type AttrStore interface { Path() string @@ -48,25 +43,13 @@ type AttrStore interface { } func init() { - NopAttrStoreGenerator = &nopAttrStoreGenerator{ - Name: "NooP", - } NopAttrStore = &nopAttrStore{} } -// NopAttrStoreGenerator represents an AttrStoreGenerator that return a no-op AttrStore. -var NopAttrStoreGenerator AttrStoreGenerator - // NopAttrStore represents an AttrStore that doesn't do anything. var NopAttrStore AttrStore -// nopAttrStoreGenerator represents a no-op implementation of the AttrStoreGenerator interface. -type nopAttrStoreGenerator struct { - Name string -} - -// New is a no-op implementation of AttrStoreGenerator New method. -func (g *nopAttrStoreGenerator) New(string) AttrStore { +func NewNopAttrStore(string) AttrStore { return &nopAttrStore{} } diff --git a/boltdb/attrstore.go b/boltdb/attrstore.go index 0ea35e663..ebb539903 100644 --- a/boltdb/attrstore.go +++ b/boltdb/attrstore.go @@ -62,14 +62,6 @@ func (c *AttrCache) Set(id uint64, attrs map[string]interface{}) { c.attrs[id] = attrs } -// AttrStoreGenerator represents a bolt implementation of the AttrStoreGenerator interface. -type AttrStoreGenerator struct{} - -// New is a bolt implementation of AttrStoreGenerator New method. -func (g *AttrStoreGenerator) New(path string) pilosa.AttrStore { - return NewAttrStore(path) -} - // AttrStore represents a storage layer for attributes. type AttrStore struct { mu sync.RWMutex @@ -78,11 +70,6 @@ type AttrStore struct { attrCache *AttrCache } -// NewAttrStoreGenerator returns a new instance of AttrStoreGenerator. -func NewAttrStoreGenerator() *AttrStoreGenerator { - return &AttrStoreGenerator{} -} - // NewAttrCache returns a new instance of AttrCache. func NewAttrCache() *AttrCache { return &AttrCache{ @@ -91,7 +78,7 @@ func NewAttrCache() *AttrCache { } // NewAttrStore returns a new instance of AttrStore. -func NewAttrStore(path string) *AttrStore { +func NewAttrStore(path string) pilosa.AttrStore { return &AttrStore{ path: path, attrCache: NewAttrCache(), diff --git a/fragment_test.go b/fragment_test.go index 8a54d3b07..b86c10e3f 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -702,7 +702,7 @@ func TestFragment_TopN_CacheSize(t *testing.T) { Fragment: frag, RowAttrStore: test.MustOpenAttrStore(), } - f.Fragment.RowAttrStore = f.RowAttrStore.AttrStore + f.Fragment.RowAttrStore = f.RowAttrStore if err := f.Open(); err != nil { panic(err) } diff --git a/holder.go b/holder.go index 2ebc1a639..63bbbbc86 100644 --- a/holder.go +++ b/holder.go @@ -56,7 +56,7 @@ type Holder struct { Broadcaster Broadcaster - AttrStoreGenerator AttrStoreGenerator + NewAttrStore func(string) AttrStore // Close management wg sync.WaitGroup @@ -85,7 +85,7 @@ func NewHolder() *Holder { Broadcaster: NopBroadcaster, Stats: NopStatsClient, - AttrStoreGenerator: NopAttrStoreGenerator, + NewAttrStore: NewNopAttrStore, CacheFlushInterval: DefaultCacheFlushInterval, @@ -377,8 +377,8 @@ func (h *Holder) newIndex(path, name string) (*Index, error) { index.LogOutput = h.LogOutput index.Stats = h.Stats.WithTags(fmt.Sprintf("index:%s", index.Name())) index.broadcaster = h.Broadcaster - index.AttrStoreGenerator = h.AttrStoreGenerator - index.columnAttrStore = h.AttrStoreGenerator.New(filepath.Join(index.path, ".data")) + index.NewAttrStore = h.NewAttrStore + index.columnAttrStore = h.NewAttrStore(filepath.Join(index.path, ".data")) return index, nil } diff --git a/index.go b/index.go index ba50f47e1..707b87213 100644 --- a/index.go +++ b/index.go @@ -55,7 +55,7 @@ type Index struct { remoteMaxSlice uint64 remoteMaxInverseSlice uint64 - AttrStoreGenerator AttrStoreGenerator + NewAttrStore func(string) AttrStore // Column attribute storage and cache. columnAttrStore AttrStore @@ -85,8 +85,8 @@ func NewIndex(path, name string) (*Index, error) { remoteMaxSlice: 0, remoteMaxInverseSlice: 0, - AttrStoreGenerator: NopAttrStoreGenerator, - columnAttrStore: NopAttrStore, + NewAttrStore: NewNopAttrStore, + columnAttrStore: NopAttrStore, columnLabel: DefaultColumnLabel, @@ -531,7 +531,7 @@ func (i *Index) newFrame(path, name string) (*Frame, error) { f.LogOutput = i.LogOutput f.Stats = i.Stats.WithTags(fmt.Sprintf("frame:%s", name)) f.broadcaster = i.broadcaster - f.rowAttrStore = i.AttrStoreGenerator.New(filepath.Join(f.path, ".data")) + f.rowAttrStore = i.NewAttrStore(filepath.Join(f.path, ".data")) return f, nil } diff --git a/server.go b/server.go index c939b5ba1..7f6eeb6cb 100644 --- a/server.go +++ b/server.go @@ -74,7 +74,7 @@ type Server struct { GCNotifier GCNotifier - AttrStoreGenerator AttrStoreGenerator + NewAttrStore func(string) AttrStore // Background monitoring intervals. AntiEntropyInterval time.Duration @@ -109,7 +109,7 @@ func NewServer() *Server { GCNotifier: NopGCNotifier, - AttrStoreGenerator: NopAttrStoreGenerator, + NewAttrStore: NewNopAttrStore, AntiEntropyInterval: DefaultAntiEntropyInterval, MetricInterval: 0, diff --git a/server/server.go b/server/server.go index 976e277c4..8e1bb6b97 100644 --- a/server/server.go +++ b/server/server.go @@ -147,8 +147,8 @@ func (m *Command) SetupServer() error { // Configure data directory (for Cluster .topology) m.Server.Cluster.Path = m.Config.DataDir - m.Server.AttrStoreGenerator = boltdb.NewAttrStoreGenerator() - m.Server.Holder.AttrStoreGenerator = m.Server.AttrStoreGenerator + m.Server.NewAttrStore = boltdb.NewAttrStore + m.Server.Holder.NewAttrStore = boltdb.NewAttrStore // Configure holder. m.Server.Logger().Printf("Using data from: %s\n", m.Config.DataDir) diff --git a/test/attr.go b/test/attr.go index de87144af..16e8ff334 100644 --- a/test/attr.go +++ b/test/attr.go @@ -21,17 +21,17 @@ import ( "sync" "testing" + "github.com/pilosa/pilosa" "github.com/pilosa/pilosa/boltdb" ) // AttrStore represents a test wrapper for pilosa.AttrStore. type AttrStore struct { - //*pilosa.AttrStore - *boltdb.AttrStore + pilosa.AttrStore } // NewAttrStore returns a new instance of AttrStore. -func NewAttrStore() *AttrStore { +func NewAttrStore(string) pilosa.AttrStore { f, err := ioutil.TempFile("", "pilosa-attr-") if err != nil { panic(err) @@ -39,7 +39,7 @@ func NewAttrStore() *AttrStore { f.Close() os.Remove(f.Name()) - return &AttrStore{AttrStore: boltdb.NewAttrStore(f.Name())} + return &AttrStore{boltdb.NewAttrStore(f.Name())} } func BenchmarkAttrStore_Duplicate(b *testing.B) { @@ -75,8 +75,8 @@ func BenchmarkAttrStore_Duplicate(b *testing.B) { } // MustOpenAttrStore returns a new, opened attribute store at a temporary path. Panic on error. -func MustOpenAttrStore() *AttrStore { - s := NewAttrStore() +func MustOpenAttrStore() pilosa.AttrStore { + s := NewAttrStore("") if err := s.Open(); err != nil { panic(err) } diff --git a/test/fragment.go b/test/fragment.go index b208e7a3a..39caa8db2 100644 --- a/test/fragment.go +++ b/test/fragment.go @@ -27,7 +27,7 @@ const SliceWidth = pilosa.SliceWidth // Fragment is a test wrapper for pilosa.Fragment. type Fragment struct { *pilosa.Fragment - RowAttrStore *AttrStore + RowAttrStore pilosa.AttrStore } // NewFragment returns a new instance of Fragment with a temporary path. @@ -43,7 +43,7 @@ func NewFragment(index, frame, view string, slice uint64, cacheType string) *Fra RowAttrStore: MustOpenAttrStore(), } f.Fragment.CacheType = cacheType - f.Fragment.RowAttrStore = f.RowAttrStore.AttrStore + f.Fragment.RowAttrStore = f.RowAttrStore return f } @@ -78,7 +78,7 @@ func (f *Fragment) Reopen() error { f.Fragment = pilosa.NewFragment(path, f.Index(), f.Frame(), f.View(), f.Slice()) f.Fragment.CacheType = cacheType - f.Fragment.RowAttrStore = f.RowAttrStore.AttrStore + f.Fragment.RowAttrStore = f.RowAttrStore if err := f.Open(); err != nil { return err } diff --git a/test/holder.go b/test/holder.go index 2778cf8c2..59402cea0 100644 --- a/test/holder.go +++ b/test/holder.go @@ -39,7 +39,7 @@ func NewHolder() *Holder { h := &Holder{Holder: pilosa.NewHolder()} h.Path = path h.Holder.LogOutput = &h.LogOutput - h.Holder.AttrStoreGenerator = boltdb.NewAttrStoreGenerator() + h.Holder.NewAttrStore = boltdb.NewAttrStore return h } @@ -66,7 +66,7 @@ func (h *Holder) Reopen() error { h.Holder = pilosa.NewHolder() h.Holder.Path = path h.Holder.LogOutput = logOutput - h.Holder.AttrStoreGenerator = boltdb.NewAttrStoreGenerator() + h.Holder.NewAttrStore = boltdb.NewAttrStore if err := h.Holder.Open(); err != nil { return err } diff --git a/test/pilosa.go b/test/pilosa.go index f798e4a85..86623c239 100644 --- a/test/pilosa.go +++ b/test/pilosa.go @@ -50,8 +50,8 @@ func NewMain() *Main { m := &Main{Command: server.NewCommand(os.Stdin, os.Stdout, os.Stderr)} m.Server.Network = *Network - m.Server.AttrStoreGenerator = boltdb.NewAttrStoreGenerator() - m.Server.Holder.AttrStoreGenerator = m.Server.AttrStoreGenerator + m.Server.NewAttrStore = NewAttrStore + m.Server.Holder.NewAttrStore = NewAttrStore m.Config.DataDir = path m.Config.Bind = "http://localhost:0" m.Config.Cluster.Disabled = true @@ -139,8 +139,8 @@ func (m *Main) Reopen() error { config := m.Config m.Command = server.NewCommand(os.Stdin, os.Stdout, os.Stderr) m.Server.Network = *Network - m.Server.AttrStoreGenerator = boltdb.NewAttrStoreGenerator() - m.Server.Holder.AttrStoreGenerator = m.Server.AttrStoreGenerator + m.Server.NewAttrStore = boltdb.NewAttrStore + m.Server.Holder.NewAttrStore = m.Server.NewAttrStore m.Config = config // Run new program. diff --git a/view_test.go b/view_test.go index 64041aea0..87ed8e628 100644 --- a/view_test.go +++ b/view_test.go @@ -26,7 +26,7 @@ import ( // View is a test wrapper for pilosa.View. type View struct { *pilosa.View - RowAttrStore *test.AttrStore + RowAttrStore pilosa.AttrStore } // NewView returns a new instance of View with a temporary path. @@ -40,7 +40,7 @@ func NewView(index, frame, name string) *View { View: pilosa.NewView(path, index, frame, name, pilosa.DefaultCacheSize), RowAttrStore: test.MustOpenAttrStore(), } - v.View.RowAttrStore = v.RowAttrStore.AttrStore + v.View.RowAttrStore = v.RowAttrStore return v } @@ -68,7 +68,7 @@ func (v *View) Reopen() error { } v.View = pilosa.NewView(path, v.Index(), v.Frame(), v.Name(), pilosa.DefaultCacheSize) - v.View.RowAttrStore = v.RowAttrStore.AttrStore + v.View.RowAttrStore = v.RowAttrStore if err := v.Open(); err != nil { return err }