From 10d90f742ab1215c12b070d405972c8a5e0e0769 Mon Sep 17 00:00:00 2001 From: jaffee Date: Wed, 18 Jan 2017 09:28:05 -0600 Subject: [PATCH 1/2] thread logoutput index -> db -> frame -> fragment also stop extra output to stderr from tests --- db.go | 9 +++++++-- db_test.go | 4 ++-- fragment.go | 6 +++--- fragment_test.go | 6 +++--- frame.go | 9 +++++++-- frame_test.go | 4 ++-- handler_test.go | 1 + index.go | 2 +- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/db.go b/db.go index f2a5740bc..cb672559b 100644 --- a/db.go +++ b/db.go @@ -3,6 +3,7 @@ package pilosa import ( "errors" "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -34,10 +35,12 @@ type DB struct { profileAttrStore *AttrStore stats StatsClient + + LogOutput io.Writer } // NewDB returns a new instance of DB. -func NewDB(path, name string) *DB { +func NewDB(path, name string, logOutput io.Writer) *DB { return &DB{ path: path, name: name, @@ -47,6 +50,8 @@ func NewDB(path, name string) *DB { profileAttrStore: NewAttrStore(filepath.Join(path, "data")), stats: NopStatsClient, + + LogOutput: logOutput, } } @@ -270,7 +275,7 @@ func (db *DB) createFrameIfNotExists(name string) (*Frame, error) { } func (db *DB) newFrame(path, name string) *Frame { - f := NewFrame(path, db.name, name) + f := NewFrame(path, db.name, name, db.LogOutput) f.stats = db.stats.WithTags(fmt.Sprintf("frame:%s", name)) return f } diff --git a/db_test.go b/db_test.go index 46a138c87..2018b488a 100644 --- a/db_test.go +++ b/db_test.go @@ -90,7 +90,7 @@ func NewDB() *DB { panic(err) } - return &DB{DB: pilosa.NewDB(path, "d")} + return &DB{DB: pilosa.NewDB(path, "d", ioutil.Discard)} } // MustOpenDB returns a new, opened database at a temporary path. Panic on error. @@ -115,7 +115,7 @@ func (db *DB) Reopen() error { } path, name := db.Path(), db.Name() - db.DB = pilosa.NewDB(path, name) + db.DB = pilosa.NewDB(path, name, ioutil.Discard) if err := db.Open(); err != nil { return err diff --git a/fragment.go b/fragment.go index 4d0586952..90c1d9678 100644 --- a/fragment.go +++ b/fragment.go @@ -90,14 +90,14 @@ type Fragment struct { } // NewFragment returns a new instance of Fragment. -func NewFragment(path, db, frame string, slice uint64) *Fragment { +func NewFragment(path, db, frame string, slice uint64, logOutput io.Writer) *Fragment { return &Fragment{ path: path, db: db, frame: frame, slice: slice, - LogOutput: os.Stderr, + LogOutput: logOutput, MaxOpN: DefaultFragmentMaxOpN, stats: NopStatsClient, @@ -861,7 +861,7 @@ func (f *Fragment) Import(bitmapIDs, profileIDs []uint64) error { // no real danger if i == 0 || bitmapID != lastID { lastID = bitmapID - set[bitmapID] = struct{}{} + set[bitmapID] = struct{}{} } if changed { bmCounter += 1 diff --git a/fragment_test.go b/fragment_test.go index da2edac6c..d28deee55 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -505,7 +505,7 @@ func BenchmarkFragment_Blocks(b *testing.B) { } // Open the fragment specified by the path. - f := pilosa.NewFragment(*FragmentPath, "d", "f", 0) + f := pilosa.NewFragment(*FragmentPath, "d", "f", 0, ioutil.Discard) if err := f.Open(); err != nil { b.Fatal(err) } @@ -566,7 +566,7 @@ func NewFragment(db, frame string, slice uint64) *Fragment { file.Close() f := &Fragment{ - Fragment: pilosa.NewFragment(file.Name(), db, frame, slice), + Fragment: pilosa.NewFragment(file.Name(), db, frame, slice, ioutil.Discard), BitmapAttrStore: MustOpenAttrStore(), } f.Fragment.BitmapAttrStore = f.BitmapAttrStore.AttrStore @@ -597,7 +597,7 @@ func (f *Fragment) Reopen() error { return err } - f.Fragment = pilosa.NewFragment(path, f.DB(), f.Frame(), f.Slice()) + f.Fragment = pilosa.NewFragment(path, f.DB(), f.Frame(), f.Slice(), ioutil.Discard) f.Fragment.BitmapAttrStore = f.BitmapAttrStore.AttrStore if err := f.Open(); err != nil { return err diff --git a/frame.go b/frame.go index 0456488a3..787577996 100644 --- a/frame.go +++ b/frame.go @@ -2,6 +2,7 @@ package pilosa import ( "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -32,10 +33,12 @@ type Frame struct { bitmapAttrStore *AttrStore stats StatsClient + + LogOutput io.Writer } // NewFrame returns a new instance of frame. -func NewFrame(path, db, name string) *Frame { +func NewFrame(path, db, name string, logOutput io.Writer) *Frame { return &Frame{ path: path, db: db, @@ -45,6 +48,8 @@ func NewFrame(path, db, name string) *Frame { bitmapAttrStore: NewAttrStore(filepath.Join(path, "data")), stats: NopStatsClient, + + LogOutput: logOutput, } } @@ -281,7 +286,7 @@ func (f *Frame) createFragmentIfNotExists(slice uint64) (*Fragment, error) { } func (f *Frame) newFragment(path string, slice uint64) *Fragment { - frag := NewFragment(path, f.db, f.name, slice) + frag := NewFragment(path, f.db, f.name, slice, f.LogOutput) frag.stats = f.stats.WithTags(fmt.Sprintf("slice:%d", slice)) return frag } diff --git a/frame_test.go b/frame_test.go index 186db0c62..0dcb07ddc 100644 --- a/frame_test.go +++ b/frame_test.go @@ -66,7 +66,7 @@ func NewFrame() *Frame { panic(err) } - return &Frame{Frame: pilosa.NewFrame(path, "d", "f")} + return &Frame{Frame: pilosa.NewFrame(path, "d", "f", ioutil.Discard)} } // MustOpenFrame returns a new, opened frame at a temporary path. Panic on error. @@ -91,7 +91,7 @@ func (f *Frame) Reopen() error { } path, db, name := f.Path(), f.DB(), f.Name() - f.Frame = pilosa.NewFrame(path, db, name) + f.Frame = pilosa.NewFrame(path, db, name, ioutil.Discard) if err := f.Open(); err != nil { return err diff --git a/handler_test.go b/handler_test.go index 6e998191a..cc86df4b8 100644 --- a/handler_test.go +++ b/handler_test.go @@ -730,6 +730,7 @@ func NewHandler() *Handler { Handler: pilosa.NewHandler(), } h.Handler.Executor = &h.Executor + h.Handler.LogOutput = ioutil.Discard return h } diff --git a/index.go b/index.go index 6b5de11d5..f8935ddbc 100644 --- a/index.go +++ b/index.go @@ -187,7 +187,7 @@ func (i *Index) createDBIfNotExists(name string) (*DB, error) { } func (i *Index) newDB(path, name string) *DB { - db := NewDB(path, name) + db := NewDB(path, name, i.LogOutput) db.stats = i.Stats.WithTags(fmt.Sprintf("db:%s", db.Name())) return db } From da82cdcb6ab8d86cbb5694fb2982538688bc54b8 Mon Sep 17 00:00:00 2001 From: jaffee Date: Wed, 18 Jan 2017 12:28:09 -0600 Subject: [PATCH 2/2] remove LogOutput arg from New* funcs default to ioutil.Discard --- db.go | 10 +++++----- db_test.go | 5 ++--- fragment.go | 4 ++-- fragment_test.go | 6 +++--- frame.go | 7 ++++--- frame_test.go | 4 ++-- index.go | 3 ++- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/db.go b/db.go index cb672559b..2a4f1d6e0 100644 --- a/db.go +++ b/db.go @@ -40,7 +40,7 @@ type DB struct { } // NewDB returns a new instance of DB. -func NewDB(path, name string, logOutput io.Writer) *DB { +func NewDB(path, name string) *DB { return &DB{ path: path, name: name, @@ -49,9 +49,8 @@ func NewDB(path, name string, logOutput io.Writer) *DB { profileAttrStore: NewAttrStore(filepath.Join(path, "data")), - stats: NopStatsClient, - - LogOutput: logOutput, + stats: NopStatsClient, + LogOutput: ioutil.Discard, } } @@ -275,7 +274,8 @@ func (db *DB) createFrameIfNotExists(name string) (*Frame, error) { } func (db *DB) newFrame(path, name string) *Frame { - f := NewFrame(path, db.name, name, db.LogOutput) + f := NewFrame(path, db.name, name) + f.LogOutput = db.LogOutput f.stats = db.stats.WithTags(fmt.Sprintf("frame:%s", name)) return f } diff --git a/db_test.go b/db_test.go index 2018b488a..db017dcd4 100644 --- a/db_test.go +++ b/db_test.go @@ -89,8 +89,7 @@ func NewDB() *DB { if err != nil { panic(err) } - - return &DB{DB: pilosa.NewDB(path, "d", ioutil.Discard)} + return &DB{DB: pilosa.NewDB(path, "d")} } // MustOpenDB returns a new, opened database at a temporary path. Panic on error. @@ -115,7 +114,7 @@ func (db *DB) Reopen() error { } path, name := db.Path(), db.Name() - db.DB = pilosa.NewDB(path, name, ioutil.Discard) + db.DB = pilosa.NewDB(path, name) if err := db.Open(); err != nil { return err diff --git a/fragment.go b/fragment.go index 90c1d9678..1181f1739 100644 --- a/fragment.go +++ b/fragment.go @@ -90,14 +90,14 @@ type Fragment struct { } // NewFragment returns a new instance of Fragment. -func NewFragment(path, db, frame string, slice uint64, logOutput io.Writer) *Fragment { +func NewFragment(path, db, frame string, slice uint64) *Fragment { return &Fragment{ path: path, db: db, frame: frame, slice: slice, - LogOutput: logOutput, + LogOutput: ioutil.Discard, MaxOpN: DefaultFragmentMaxOpN, stats: NopStatsClient, diff --git a/fragment_test.go b/fragment_test.go index d28deee55..da2edac6c 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -505,7 +505,7 @@ func BenchmarkFragment_Blocks(b *testing.B) { } // Open the fragment specified by the path. - f := pilosa.NewFragment(*FragmentPath, "d", "f", 0, ioutil.Discard) + f := pilosa.NewFragment(*FragmentPath, "d", "f", 0) if err := f.Open(); err != nil { b.Fatal(err) } @@ -566,7 +566,7 @@ func NewFragment(db, frame string, slice uint64) *Fragment { file.Close() f := &Fragment{ - Fragment: pilosa.NewFragment(file.Name(), db, frame, slice, ioutil.Discard), + Fragment: pilosa.NewFragment(file.Name(), db, frame, slice), BitmapAttrStore: MustOpenAttrStore(), } f.Fragment.BitmapAttrStore = f.BitmapAttrStore.AttrStore @@ -597,7 +597,7 @@ func (f *Fragment) Reopen() error { return err } - f.Fragment = pilosa.NewFragment(path, f.DB(), f.Frame(), f.Slice(), ioutil.Discard) + f.Fragment = pilosa.NewFragment(path, f.DB(), f.Frame(), f.Slice()) f.Fragment.BitmapAttrStore = f.BitmapAttrStore.AttrStore if err := f.Open(); err != nil { return err diff --git a/frame.go b/frame.go index 787577996..9cdb4c707 100644 --- a/frame.go +++ b/frame.go @@ -38,7 +38,7 @@ type Frame struct { } // NewFrame returns a new instance of frame. -func NewFrame(path, db, name string, logOutput io.Writer) *Frame { +func NewFrame(path, db, name string) *Frame { return &Frame{ path: path, db: db, @@ -49,7 +49,7 @@ func NewFrame(path, db, name string, logOutput io.Writer) *Frame { stats: NopStatsClient, - LogOutput: logOutput, + LogOutput: ioutil.Discard, } } @@ -286,7 +286,8 @@ func (f *Frame) createFragmentIfNotExists(slice uint64) (*Fragment, error) { } func (f *Frame) newFragment(path string, slice uint64) *Fragment { - frag := NewFragment(path, f.db, f.name, slice, f.LogOutput) + frag := NewFragment(path, f.db, f.name, slice) + frag.LogOutput = f.LogOutput frag.stats = f.stats.WithTags(fmt.Sprintf("slice:%d", slice)) return frag } diff --git a/frame_test.go b/frame_test.go index 0dcb07ddc..186db0c62 100644 --- a/frame_test.go +++ b/frame_test.go @@ -66,7 +66,7 @@ func NewFrame() *Frame { panic(err) } - return &Frame{Frame: pilosa.NewFrame(path, "d", "f", ioutil.Discard)} + return &Frame{Frame: pilosa.NewFrame(path, "d", "f")} } // MustOpenFrame returns a new, opened frame at a temporary path. Panic on error. @@ -91,7 +91,7 @@ func (f *Frame) Reopen() error { } path, db, name := f.Path(), f.DB(), f.Name() - f.Frame = pilosa.NewFrame(path, db, name, ioutil.Discard) + f.Frame = pilosa.NewFrame(path, db, name) if err := f.Open(); err != nil { return err diff --git a/index.go b/index.go index f8935ddbc..12e3ca9bb 100644 --- a/index.go +++ b/index.go @@ -187,7 +187,8 @@ func (i *Index) createDBIfNotExists(name string) (*DB, error) { } func (i *Index) newDB(path, name string) *DB { - db := NewDB(path, name, i.LogOutput) + db := NewDB(path, name) + db.LogOutput = i.LogOutput db.stats = i.Stats.WithTags(fmt.Sprintf("db:%s", db.Name())) return db }