From 2202bf467b32d23dc718b2b4d930aeb089ef9801 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 2 Jul 2018 17:18:00 -0500 Subject: [PATCH] unexport view stuff --- api.go | 12 +++--- executor.go | 6 +-- field.go | 54 +++++++++++++------------- field_internal_test.go | 2 +- fragment_internal_test.go | 76 ++++++++++++++++++------------------- holder.go | 4 +- holder_internal_test.go | 8 ++-- view.go | 80 +++++++++++++++++++-------------------- view_internal_test.go | 6 +-- 9 files changed, 124 insertions(+), 124 deletions(-) diff --git a/api.go b/api.go index c745b2a0b..33fff083d 100644 --- a/api.go +++ b/api.go @@ -337,7 +337,7 @@ func (api *API) ExportCSV(ctx context.Context, indexName string, fieldName strin } // Find the fragment. - f := api.holder.fragment(indexName, fieldName, ViewStandard, shard) + f := api.holder.fragment(indexName, fieldName, viewStandard, shard) if f == nil { return ErrFragmentNotFound } @@ -379,7 +379,7 @@ func (api *API) MarshalFragment(ctx context.Context, indexName string, fieldName } // Retrieve fragment from holder. - f := api.holder.fragment(indexName, fieldName, ViewStandard, shard) + f := api.holder.fragment(indexName, fieldName, viewStandard, shard) if f == nil { return nil, ErrFragmentNotFound } @@ -401,7 +401,7 @@ func (api *API) UnmarshalFragment(ctx context.Context, indexName string, fieldNa } // Retrieve view. - view, err := f.createViewIfNotExists(ViewStandard) + view, err := f.createViewIfNotExists(viewStandard) if err != nil { return errors.Wrap(err, "creating view") } @@ -437,7 +437,7 @@ func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, } // Retrieve fragment from holder. - f := api.holder.fragment(req.Index, req.Field, ViewStandard, req.Shard) + f := api.holder.fragment(req.Index, req.Field, viewStandard, req.Shard) if f == nil { return nil, ErrFragmentNotFound } @@ -461,7 +461,7 @@ func (api *API) FragmentBlocks(ctx context.Context, indexName string, fieldName } // Retrieve fragment from holder. - f := api.holder.fragment(indexName, fieldName, ViewStandard, shard) + f := api.holder.fragment(indexName, fieldName, viewStandard, shard) if f == nil { return nil, ErrFragmentNotFound } @@ -529,7 +529,7 @@ func (api *API) Schema(ctx context.Context) []*IndexInfo { } // Views returns the views in the given field. -func (api *API) Views(ctx context.Context, indexName string, fieldName string) ([]*View, error) { +func (api *API) Views(ctx context.Context, indexName string, fieldName string) ([]*view, error) { if err := api.validate(apiViews); err != nil { return nil, errors.Wrap(err, "validating api method") } diff --git a/executor.go b/executor.go index f8a5d6a46..b8a7713a7 100644 --- a/executor.go +++ b/executor.go @@ -623,7 +623,7 @@ func (e *executor) executeTopNShard(ctx context.Context, index string, c *pql.Ca field = defaultField } - f := e.Holder.fragment(index, field, ViewStandard, shard) + f := e.Holder.fragment(index, field, viewStandard, shard) if f == nil { return nil, nil } @@ -693,7 +693,7 @@ func (e *executor) executeBitmapShard(ctx context.Context, index string, c *pql. return nil, fmt.Errorf("Row() must specify %v", rowLabel) } - frag := e.Holder.fragment(index, fieldName, ViewStandard, shard) + frag := e.Holder.fragment(index, fieldName, viewStandard, shard) if frag == nil { return NewRow(), nil } @@ -784,7 +784,7 @@ func (e *executor) executeRangeShard(ctx context.Context, index string, c *pql.C // Union bitmaps across all time-based views. row := &Row{} - for _, view := range viewsByTimeRange(ViewStandard, startTime, endTime, q) { + for _, view := range viewsByTimeRange(viewStandard, startTime, endTime, q) { f := e.Holder.fragment(index, fieldName, view, shard) if f == nil { continue diff --git a/field.go b/field.go index 93901dda1..f39c8946f 100644 --- a/field.go +++ b/field.go @@ -59,7 +59,7 @@ type Field struct { index string name string - viewMap map[string]*View + viewMap map[string]*view // Row attribute storage and cache rowAttrStore AttrStore @@ -131,7 +131,7 @@ func NewField(path, index, name string, options FieldOptions) (*Field, error) { index: index, name: name, - viewMap: make(map[string]*View), + viewMap: make(map[string]*view), rowAttrStore: nopStore, @@ -279,7 +279,7 @@ func (f *Field) openViews() error { if err := view.open(); err != nil { return fmt.Errorf("opening view: view=%s, err=%s", view.name, err) } - view.RowAttrStore = f.rowAttrStore + view.rowAttrStore = f.rowAttrStore f.viewMap[view.name] = view } @@ -404,7 +404,7 @@ func (f *Field) Close() error { return err } } - f.viewMap = make(map[string]*View) + f.viewMap = make(map[string]*view) return nil } @@ -541,7 +541,7 @@ func (f *Field) RowTime(rowID uint64, time time.Time, quantum string) (*Row, err if !TimeQuantum(quantum).Valid() { return nil, ErrInvalidTimeQuantum } - viewname := viewsByTime(ViewStandard, time, TimeQuantum(quantum[len(quantum)-1:]))[0] + viewname := viewsByTime(viewStandard, time, TimeQuantum(quantum[len(quantum)-1:]))[0] view := f.view(viewname) if view == nil { return nil, errors.Errorf("view with quantum %v not found.", quantum) @@ -555,20 +555,20 @@ func (f *Field) ViewPath(name string) string { } // view returns a view in the field by name. -func (f *Field) view(name string) *View { +func (f *Field) view(name string) *view { f.mu.RLock() defer f.mu.RUnlock() return f.unprotectedView(name) } -func (f *Field) unprotectedView(name string) *View { return f.viewMap[name] } +func (f *Field) unprotectedView(name string) *view { return f.viewMap[name] } // views returns a list of all views in the field. -func (f *Field) views() []*View { +func (f *Field) views() []*view { f.mu.RLock() defer f.mu.RUnlock() - other := make([]*View, 0, len(f.viewMap)) + other := make([]*view, 0, len(f.viewMap)) for _, view := range f.viewMap { other = append(other, view) } @@ -596,7 +596,7 @@ func (f *Field) RecalculateCaches() { // createViewIfNotExists returns the named view, creating it if necessary. // Additionally, a CreateViewMessage is sent to the cluster. -func (f *Field) createViewIfNotExists(name string) (*View, error) { +func (f *Field) createViewIfNotExists(name string) (*view, error) { view, created, err := f.createViewIfNotExistsBase(name) if err != nil { return nil, err @@ -620,7 +620,7 @@ func (f *Field) createViewIfNotExists(name string) (*View, error) { // createViewIfNotExistsBase returns the named view, creating it if necessary. // The returned bool indicates whether the view was created or not. -func (f *Field) createViewIfNotExistsBase(name string) (*View, bool, error) { +func (f *Field) createViewIfNotExistsBase(name string) (*view, bool, error) { f.mu.Lock() defer f.mu.Unlock() @@ -632,17 +632,17 @@ func (f *Field) createViewIfNotExistsBase(name string) (*View, bool, error) { if err := view.open(); err != nil { return nil, false, errors.Wrap(err, "opening view") } - view.RowAttrStore = f.rowAttrStore + view.rowAttrStore = f.rowAttrStore f.viewMap[view.name] = view return view, true, nil } -func (f *Field) newView(path, name string) *View { - view := NewView(path, f.index, f.name, name, f.options.CacheSize) +func (f *Field) newView(path, name string) *view { + view := newView(path, f.index, f.name, name, f.options.CacheSize) view.cacheType = f.options.CacheType - view.Logger = f.Logger - view.RowAttrStore = f.rowAttrStore + view.logger = f.Logger + view.rowAttrStore = f.rowAttrStore view.stats = f.Stats.WithTags(fmt.Sprintf("view:%s", name)) view.broadcaster = f.broadcaster return view @@ -675,7 +675,7 @@ func (f *Field) Row(rowID uint64) (*Row, error) { if f.Type() != FieldTypeSet { return nil, errors.Errorf("row method unsupported for field type: %s", f.Type()) } - view := f.view(ViewStandard) + view := f.view(viewStandard) if view == nil { return nil, ErrInvalidView } @@ -684,7 +684,7 @@ func (f *Field) Row(rowID uint64) (*Row, error) { // SetBit sets a bit on a view within the field. func (f *Field) SetBit(rowID, colID uint64, t *time.Time) (changed bool, err error) { - viewName := ViewStandard + viewName := viewStandard // Retrieve view. Exit if it doesn't exist. view, err := f.createViewIfNotExists(viewName) @@ -723,7 +723,7 @@ func (f *Field) SetBit(rowID, colID uint64, t *time.Time) (changed bool, err err // ClearBit clears a bit within the field. func (f *Field) ClearBit(rowID, colID uint64) (changed bool, err error) { - viewName := ViewStandard + viewName := viewStandard // Retrieve view. Exit if it doesn't exist. view, present := f.viewMap[viewName] @@ -777,10 +777,10 @@ func groupCompare(a, b string, offset int) (lt, eq bool) { return v < 0, v == 0 } -func (f *Field) allTimeViewsSortedByQuantum() (me []*View) { - me = make([]*View, len(f.viewMap), len(f.viewMap)) - prefix := ViewStandard + "_" - offset := len(ViewStandard) + 1 +func (f *Field) allTimeViewsSortedByQuantum() (me []*view) { + me = make([]*view, len(f.viewMap), len(f.viewMap)) + prefix := viewStandard + "_" + offset := len(viewStandard) + 1 i := 0 for _, v := range f.viewMap { if len(v.name) > offset && strings.Compare(v.name[:offset], prefix) == 0 { // skip non-time views @@ -978,12 +978,12 @@ func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time) erro var standard []string if timestamp == nil { - standard = []string{ViewStandard} + standard = []string{viewStandard} } else { - standard = viewsByTime(ViewStandard, *timestamp, q) + standard = viewsByTime(viewStandard, *timestamp, q) // In order to match the logic of `SetBit()`, we want bits // with timestamps to write to both time and standard views. - standard = append(standard, ViewStandard) + standard = append(standard, viewStandard) } // Attach bit to each standard view. @@ -1102,7 +1102,7 @@ func (p fieldSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } type FieldInfo struct { Name string `json:"name"` Options FieldOptions `json:"options"` - Views []*ViewInfo `json:"views,omitempty"` + Views []*viewInfo `json:"views,omitempty"` } type fieldInfoSlice []*FieldInfo diff --git a/field_internal_test.go b/field_internal_test.go index 15a81077c..3a43909c3 100644 --- a/field_internal_test.go +++ b/field_internal_test.go @@ -156,7 +156,7 @@ func TestField_DeleteView(t *testing.T) { f := MustOpenField(FieldOptions{}) defer f.Close() - viewName := ViewStandard + "_v" + viewName := viewStandard + "_v" // Create view. view, err := f.createViewIfNotExists(viewName) diff --git a/fragment_internal_test.go b/fragment_internal_test.go index 4f7f91637..eda4cbbdc 100644 --- a/fragment_internal_test.go +++ b/fragment_internal_test.go @@ -36,7 +36,7 @@ var ( // Ensure a fragment can set a bit and retrieve it. func TestFragment_SetBit(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set bits on the fragment. @@ -67,7 +67,7 @@ func TestFragment_SetBit(t *testing.T) { // Ensure a fragment can clear a set bit. func TestFragment_ClearBit(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set and then clear bits on the fragment. @@ -95,7 +95,7 @@ func TestFragment_ClearBit(t *testing.T) { // Ensure a fragment can set & read a value. func TestFragment_SetValue(t *testing.T) { t.Run("OK", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set value. @@ -123,7 +123,7 @@ func TestFragment_SetValue(t *testing.T) { }) t.Run("Overwrite", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set value. @@ -151,7 +151,7 @@ func TestFragment_SetValue(t *testing.T) { }) t.Run("NotExists", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set value. @@ -181,7 +181,7 @@ func TestFragment_SetValue(t *testing.T) { values[i] = values[i] % (1 << bitDepth) } - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -219,7 +219,7 @@ func TestFragment_SetValue(t *testing.T) { func TestFragment_Sum(t *testing.T) { const bitDepth = 16 - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -258,7 +258,7 @@ func TestFragment_Sum(t *testing.T) { func TestFragment_MinMax(t *testing.T) { const bitDepth = 16 - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -332,7 +332,7 @@ func TestFragment_Range(t *testing.T) { const bitDepth = 16 t.Run("EQ", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -355,7 +355,7 @@ func TestFragment_Range(t *testing.T) { }) t.Run("NEQ", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -378,7 +378,7 @@ func TestFragment_Range(t *testing.T) { }) t.Run("LT", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -426,7 +426,7 @@ func TestFragment_Range(t *testing.T) { }) t.Run("GT", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -474,7 +474,7 @@ func TestFragment_Range(t *testing.T) { }) t.Run("BETWEEN", func(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set values. @@ -524,7 +524,7 @@ func TestFragment_Range(t *testing.T) { // Ensure a fragment can snapshot correctly. func TestFragment_Snapshot(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set and then clear bits on the fragment. @@ -553,7 +553,7 @@ func TestFragment_Snapshot(t *testing.T) { // Ensure a fragment can iterate over all bits in order. func TestFragment_ForEachBit(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set bits on the fragment. @@ -582,7 +582,7 @@ func TestFragment_ForEachBit(t *testing.T) { // Ensure a fragment can return the top n results. func TestFragment_Top(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() // Set bits on the rows 100, 101, & 102. f.mustSetBits(100, 1, 3, 200) @@ -604,7 +604,7 @@ func TestFragment_Top(t *testing.T) { // Ensure a fragment can filter rows when retrieving the top n rows. func TestFragment_Top_Filter(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() // Set bits on the rows 100, 101, & 102. @@ -634,7 +634,7 @@ func TestFragment_Top_Filter(t *testing.T) { // Ensure a fragment can return top rows that intersect with an input row. func TestFragment_TopN_Intersect(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() // Create an intersecting input row. @@ -665,7 +665,7 @@ func TestFragment_TopN_Intersect_Large(t *testing.T) { t.Skip("short mode") } - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() // Create an intersecting input row. @@ -703,7 +703,7 @@ func TestFragment_TopN_Intersect_Large(t *testing.T) { // Ensure a fragment can return top rows when specified by ID. func TestFragment_TopN_IDs(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() // Set bits on various rows. @@ -724,7 +724,7 @@ func TestFragment_TopN_IDs(t *testing.T) { // Ensure a fragment return none if CacheTypeNone is set func TestFragment_TopN_NopCache(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeNone) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeNone) defer f.Close() // Set bits on various rows. @@ -756,7 +756,7 @@ func TestFragment_TopN_CacheSize(t *testing.T) { } // Create view. - view, err := field.createViewIfNotExists(ViewStandard) + view, err := field.createViewIfNotExists(viewStandard) if err != nil { t.Fatal(err) } @@ -805,7 +805,7 @@ func TestFragment_TopN_CacheSize(t *testing.T) { // Ensure fragment can return a checksum for its blocks. func TestFragment_Checksum(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Retrieve checksum and set bits. @@ -824,7 +824,7 @@ func TestFragment_Checksum(t *testing.T) { // Ensure fragment can return a checksum for a given block. func TestFragment_Blocks(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Retrieve initial checksum. @@ -862,7 +862,7 @@ func TestFragment_Blocks(t *testing.T) { // Ensure fragment returns an empty checksum if no data exists for a block. func TestFragment_Blocks_Empty(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set bits on a different block. @@ -880,7 +880,7 @@ func TestFragment_Blocks_Empty(t *testing.T) { // Ensure a fragment's cache can be persisted between restarts. func TestFragment_LRUCache_Persistence(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeLRU) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeLRU) defer f.Close() // Set bits on the fragment. @@ -922,7 +922,7 @@ func TestFragment_RankCache_Persistence(t *testing.T) { } // Create view. - view, err := field.createViewIfNotExists(ViewStandard) + view, err := field.createViewIfNotExists(viewStandard) if err != nil { t.Fatal(err) } @@ -953,7 +953,7 @@ func TestFragment_RankCache_Persistence(t *testing.T) { } // Re-fetch fragment. - f = index.Field("f").view(ViewStandard).Fragment(0) + f = index.Field("f").view(viewStandard).Fragment(0) // Re-verify correct cache type and size. if cache, ok := f.cache.(*rankCache); !ok { @@ -965,7 +965,7 @@ func TestFragment_RankCache_Persistence(t *testing.T) { // Ensure a fragment can be copied to another fragment. func TestFragment_WriteTo_ReadFrom(t *testing.T) { - f0 := mustOpenFragment("i", "f", ViewStandard, 0, "") + f0 := mustOpenFragment("i", "f", viewStandard, 0, "") defer f0.Close() // Set and then clear bits on the fragment. @@ -990,7 +990,7 @@ func TestFragment_WriteTo_ReadFrom(t *testing.T) { } // Read into another fragment. - f1 := mustOpenFragment("i", "f", ViewStandard, 0, "") + f1 := mustOpenFragment("i", "f", viewStandard, 0, "") if rn, err := f1.ReadFrom(&buf); err != nil { t.Fatal(err) } else if wn != rn { @@ -1023,7 +1023,7 @@ func BenchmarkFragment_Blocks(b *testing.B) { } // Open the fragment specified by the path. - f := newFragment(*FragmentPath, "i", "f", ViewStandard, 0) + f := newFragment(*FragmentPath, "i", "f", viewStandard, 0) if err := f.Open(); err != nil { b.Fatal(err) } @@ -1039,7 +1039,7 @@ func BenchmarkFragment_Blocks(b *testing.B) { } func BenchmarkFragment_IntersectionCount(b *testing.B) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() f.MaxOpN = math.MaxInt32 @@ -1070,7 +1070,7 @@ func BenchmarkFragment_IntersectionCount(b *testing.B) { } func TestFragment_Tanimoto(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() src := NewRow(1, 2, 3) @@ -1093,7 +1093,7 @@ func TestFragment_Tanimoto(t *testing.T) { } func TestFragment_Zero_Tanimoto(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, CacheTypeRanked) + f := mustOpenFragment("i", "f", viewStandard, 0, CacheTypeRanked) defer f.Close() src := NewRow(1, 2, 3) @@ -1118,7 +1118,7 @@ func TestFragment_Zero_Tanimoto(t *testing.T) { } func TestFragment_Snapshot_Run(t *testing.T) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Set bits on the fragment. @@ -1150,7 +1150,7 @@ func BenchmarkFragment_Snapshot(b *testing.B) { b.ReportAllocs() // Open the fragment specified by the path. - f := newFragment(*FragmentPath, "i", "f", ViewStandard, 0) + f := newFragment(*FragmentPath, "i", "f", viewStandard, 0) if err := f.Open(); err != nil { b.Fatal(err) } @@ -1169,7 +1169,7 @@ func BenchmarkFragment_Snapshot(b *testing.B) { } func BenchmarkFragment_FullSnapshot(b *testing.B) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() // Generate some intersecting data. maxX := 1048576 / 2 @@ -1206,7 +1206,7 @@ func BenchmarkFragment_FullSnapshot(b *testing.B) { } func BenchmarkFragment_Import(b *testing.B) { - f := mustOpenFragment("i", "f", ViewStandard, 0, "") + f := mustOpenFragment("i", "f", viewStandard, 0, "") defer f.Close() maxX := 1048576 * 5 * 2 sz := maxX diff --git a/holder.go b/holder.go index 1f4c88c23..4fb84aefc 100644 --- a/holder.go +++ b/holder.go @@ -217,7 +217,7 @@ func (h *Holder) Schema() []*IndexInfo { for _, field := range index.Fields() { fi := &FieldInfo{Name: field.Name(), Options: field.Options()} for _, view := range field.views() { - fi.Views = append(fi.Views, &ViewInfo{Name: view.name}) + fi.Views = append(fi.Views, &viewInfo{Name: view.name}) } sort.Sort(viewInfoSlice(fi.Views)) di.Fields = append(di.Fields, fi) @@ -403,7 +403,7 @@ func (h *Holder) Field(index, name string) *Field { } // view returns the view for an index, field, and name. -func (h *Holder) view(index, field, name string) *View { +func (h *Holder) view(index, field, name string) *view { f := h.Field(index, field) if f == nil { return nil diff --git a/holder_internal_test.go b/holder_internal_test.go index d7953b9ee..95ce55be4 100644 --- a/holder_internal_test.go +++ b/holder_internal_test.go @@ -107,7 +107,7 @@ func TestHolder_Optn(t *testing.T) { t.Fatal(err) } else if field, err := idx.CreateField("bar", FieldOptions{}); err != nil { t.Fatal(err) - } else if _, err := field.createViewIfNotExists(ViewStandard); err != nil { + } else if _, err := field.createViewIfNotExists(viewStandard); err != nil { t.Fatal(err) } else if err := h.Holder.Close(); err != nil { t.Fatal(err) @@ -131,7 +131,7 @@ func TestHolder_Optn(t *testing.T) { t.Fatal(err) } else if field, err := idx.CreateField("bar", FieldOptions{}); err != nil { t.Fatal(err) - } else if _, err := field.createViewIfNotExists(ViewStandard); err != nil { + } else if _, err := field.createViewIfNotExists(viewStandard); err != nil { t.Fatal(err) } else if err := h.Holder.Close(); err != nil { t.Fatal(err) @@ -156,7 +156,7 @@ func TestHolder_Optn(t *testing.T) { t.Fatal(err) } else if field, err := idx.CreateField("bar", FieldOptions{}); err != nil { t.Fatal(err) - } else if view, err := field.createViewIfNotExists(ViewStandard); err != nil { + } else if view, err := field.createViewIfNotExists(viewStandard); err != nil { t.Fatal(err) } else if _, err := field.SetBit(0, 0, nil); err != nil { t.Fatal(err) @@ -279,7 +279,7 @@ func TestHolderCleaner_CleanHolder(t *testing.T) { t.Fatalf("unexpected columns(%d/200): %+v", i, a) } - f := hldr.fragment("i", "f0", ViewStandard, 1) + f := hldr.fragment("i", "f0", viewStandard, 1) if f != nil { t.Fatalf("expected fragment to be deleted: (%d/i/f0): %+v", i, f) } diff --git a/view.go b/view.go index 0f3deaa7f..fd5306b85 100644 --- a/view.go +++ b/view.go @@ -29,13 +29,13 @@ import ( // View layout modes. const ( - ViewStandard = "standard" + viewStandard = "standard" viewBSIGroupPrefix = "bsig_" ) -// View represents a container for field data. -type View struct { +// view represents a container for field data. +type view struct { mu sync.RWMutex path string index string @@ -54,13 +54,13 @@ type View struct { broadcaster broadcaster stats StatsClient - RowAttrStore AttrStore - Logger Logger + rowAttrStore AttrStore + logger Logger } -// NewView returns a new instance of View. -func NewView(path, index, field, name string, cacheSize uint32) *View { - return &View{ +// newView returns a new instance of View. +func newView(path, index, field, name string, cacheSize uint32) *view { + return &view{ path: path, index: index, field: field, @@ -72,12 +72,12 @@ func NewView(path, index, field, name string, cacheSize uint32) *View { broadcaster: NopBroadcaster, stats: NopStatsClient, - Logger: NopLogger, + logger: NopLogger, } } // open opens and initializes the view. -func (v *View) open() error { +func (v *view) open() error { // Never keep a cache for field views. if strings.HasPrefix(v.name, viewBSIGroupPrefix) { @@ -106,7 +106,7 @@ func (v *View) open() error { } // openFragments opens and initializes the fragments inside the view. -func (v *View) openFragments() error { +func (v *view) openFragments() error { file, err := os.Open(filepath.Join(v.path, "fragments")) if os.IsNotExist(err) { return nil @@ -135,7 +135,7 @@ func (v *View) openFragments() error { if err := frag.Open(); err != nil { return fmt.Errorf("open fragment: shard=%d, err=%s", frag.shard, err) } - frag.RowAttrStore = v.RowAttrStore + frag.RowAttrStore = v.rowAttrStore v.fragments[frag.shard] = frag } @@ -143,7 +143,7 @@ func (v *View) openFragments() error { } // close closes the view and its fragments. -func (v *View) close() error { +func (v *view) close() error { v.mu.Lock() defer v.mu.Unlock() @@ -159,7 +159,7 @@ func (v *View) close() error { } // calculateMaxShard returns the max shard in the view. -func (v *View) calculateMaxShard() uint64 { +func (v *view) calculateMaxShard() uint64 { v.mu.RLock() defer v.mu.RUnlock() @@ -174,21 +174,21 @@ func (v *View) calculateMaxShard() uint64 { } // fragmentPath returns the path to a fragment in the view. -func (v *View) fragmentPath(shard uint64) string { +func (v *view) fragmentPath(shard uint64) string { return filepath.Join(v.path, "fragments", strconv.FormatUint(shard, 10)) } // Fragment returns a fragment in the view by shard. -func (v *View) Fragment(shard uint64) *fragment { +func (v *view) Fragment(shard uint64) *fragment { v.mu.RLock() defer v.mu.RUnlock() return v.fragment(shard) } -func (v *View) fragment(shard uint64) *fragment { return v.fragments[shard] } +func (v *view) fragment(shard uint64) *fragment { return v.fragments[shard] } // allFragments returns a list of all fragments in the view. -func (v *View) allFragments() []*fragment { +func (v *view) allFragments() []*fragment { v.mu.Lock() defer v.mu.Unlock() @@ -200,20 +200,20 @@ func (v *View) allFragments() []*fragment { } // recalculateCaches recalculates the cache on every fragment in the view. -func (v *View) recalculateCaches() { +func (v *view) recalculateCaches() { for _, fragment := range v.allFragments() { fragment.RecalculateCache() } } // CreateFragmentIfNotExists returns a fragment in the view by shard. -func (v *View) CreateFragmentIfNotExists(shard uint64) (*fragment, error) { +func (v *view) CreateFragmentIfNotExists(shard uint64) (*fragment, error) { v.mu.Lock() defer v.mu.Unlock() return v.createFragmentIfNotExists(shard) } -func (v *View) createFragmentIfNotExists(shard uint64) (*fragment, error) { +func (v *view) createFragmentIfNotExists(shard uint64) (*fragment, error) { // Find fragment in cache first. if frag := v.fragments[shard]; frag != nil { return frag, nil @@ -224,7 +224,7 @@ func (v *View) createFragmentIfNotExists(shard uint64) (*fragment, error) { if err := frag.Open(); err != nil { return nil, errors.Wrap(err, "opening fragment") } - frag.RowAttrStore = v.RowAttrStore + frag.RowAttrStore = v.rowAttrStore // Broadcast a message that a new max shard was just created. if shard > v.maxShard { @@ -246,24 +246,24 @@ func (v *View) createFragmentIfNotExists(shard uint64) (*fragment, error) { return frag, nil } -func (v *View) newFragment(path string, shard uint64) *fragment { +func (v *view) newFragment(path string, shard uint64) *fragment { frag := newFragment(path, v.index, v.field, v.name, shard) frag.CacheType = v.cacheType frag.CacheSize = v.cacheSize - frag.Logger = v.Logger + frag.Logger = v.logger frag.stats = v.stats.WithTags(fmt.Sprintf("shard:%d", shard)) return frag } // deleteFragment removes the fragment from the view. -func (v *View) deleteFragment(shard uint64) error { +func (v *view) deleteFragment(shard uint64) error { fragment := v.fragments[shard] if fragment == nil { return ErrFragmentNotFound } - v.Logger.Printf("delete fragment: (%s/%s/%s) %d", v.index, v.field, v.name, shard) + v.logger.Printf("delete fragment: (%s/%s/%s) %d", v.index, v.field, v.name, shard) // Close data files before deletion. if err := fragment.Close(); err != nil { @@ -277,7 +277,7 @@ func (v *View) deleteFragment(shard uint64) error { // Delete fragment cache file. if err := os.Remove(fragment.cachePath()); err != nil { - v.Logger.Printf("no cache file to delete for shard %d", shard) + v.logger.Printf("no cache file to delete for shard %d", shard) } delete(v.fragments, shard) @@ -286,7 +286,7 @@ func (v *View) deleteFragment(shard uint64) error { } // row returns a row for a shard of the view. -func (v *View) row(rowID uint64) *Row { +func (v *view) row(rowID uint64) *Row { row := NewRow() for _, frag := range v.allFragments() { fr := frag.row(rowID) @@ -300,7 +300,7 @@ func (v *View) row(rowID uint64) *Row { } // setBit sets a bit within the view. -func (v *View) setBit(rowID, columnID uint64) (changed bool, err error) { +func (v *view) setBit(rowID, columnID uint64) (changed bool, err error) { shard := columnID / ShardWidth frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { @@ -310,7 +310,7 @@ func (v *View) setBit(rowID, columnID uint64) (changed bool, err error) { } // clearBit clears a bit within the view. -func (v *View) clearBit(rowID, columnID uint64) (changed bool, err error) { +func (v *view) clearBit(rowID, columnID uint64) (changed bool, err error) { shard := columnID / ShardWidth frag, found := v.fragments[shard] if !found { @@ -320,7 +320,7 @@ func (v *View) clearBit(rowID, columnID uint64) (changed bool, err error) { } // value uses a column of bits to read a multi-bit value. -func (v *View) value(columnID uint64, bitDepth uint) (value uint64, exists bool, err error) { +func (v *view) value(columnID uint64, bitDepth uint) (value uint64, exists bool, err error) { shard := columnID / ShardWidth frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { @@ -330,7 +330,7 @@ func (v *View) value(columnID uint64, bitDepth uint) (value uint64, exists bool, } // setValue uses a column of bits to set a multi-bit value. -func (v *View) setValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { +func (v *view) setValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { shard := columnID / ShardWidth frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { @@ -340,7 +340,7 @@ func (v *View) setValue(columnID uint64, bitDepth uint, value uint64) (changed b } // sum returns the sum & count of a field. -func (v *View) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { +func (v *view) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { for _, f := range v.allFragments() { fsum, fcount, err := f.sum(filter, bitDepth) if err != nil { @@ -353,7 +353,7 @@ func (v *View) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { } // min returns the min and count of a field. -func (v *View) min(filter *Row, bitDepth uint) (min, count uint64, err error) { +func (v *view) min(filter *Row, bitDepth uint) (min, count uint64, err error) { var minHasValue bool for _, f := range v.allFragments() { fmin, fcount, err := f.min(filter, bitDepth) @@ -381,7 +381,7 @@ func (v *View) min(filter *Row, bitDepth uint) (min, count uint64, err error) { } // max returns the max and count of a field. -func (v *View) max(filter *Row, bitDepth uint) (max, count uint64, err error) { +func (v *view) max(filter *Row, bitDepth uint) (max, count uint64, err error) { for _, f := range v.allFragments() { fmax, fcount, err := f.max(filter, bitDepth) if err != nil { @@ -396,7 +396,7 @@ func (v *View) max(filter *Row, bitDepth uint) (max, count uint64, err error) { } // rangeOp returns rows with a field value encoding matching the predicate. -func (v *View) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { +func (v *view) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { r := NewRow() for _, frag := range v.allFragments() { other, err := frag.rangeOp(op, bitDepth, predicate) @@ -410,7 +410,7 @@ func (v *View) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, err // rangeBetween returns bitmaps with a field value encoding matching any // value between predicateMin and predicateMax. -func (v *View) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { +func (v *view) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { r := NewRow() for _, frag := range v.allFragments() { other, err := frag.rangeBetween(bitDepth, predicateMin, predicateMax) @@ -422,12 +422,12 @@ func (v *View) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (* return r, nil } -// ViewInfo represents schema information for a view. -type ViewInfo struct { +// viewInfo represents schema information for a view. +type viewInfo struct { Name string `json:"name"` } -type viewInfoSlice []*ViewInfo +type viewInfoSlice []*viewInfo func (p viewInfoSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p viewInfoSlice) Len() int { return len(p) } diff --git a/view_internal_test.go b/view_internal_test.go index a592330cb..6fe0b0e33 100644 --- a/view_internal_test.go +++ b/view_internal_test.go @@ -20,17 +20,17 @@ import ( ) // mustOpenView returns a new instance of View with a temporary path. -func mustOpenView(index, field, name string) *View { +func mustOpenView(index, field, name string) *view { path, err := ioutil.TempDir("", "pilosa-view-") if err != nil { panic(err) } - v := NewView(path, index, field, name, DefaultCacheSize) + v := newView(path, index, field, name, DefaultCacheSize) if err := v.open(); err != nil { panic(err) } - v.RowAttrStore = newMemAttrStore() + v.rowAttrStore = newMemAttrStore() return v }