From d32edb53290734b9ecef347f665d10b61a0a84c6 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 13 Apr 2017 14:45:05 -0600 Subject: [PATCH] Add cacheType to frame options. Previously the cache type (`lru` or `ranked`) was determined by checking the ending suffix of the frame. If it ended with a `.n` then it was ranked. Otherwise it was an LRU. This commit changes frames so that a `cacheType` option can be passed in during creation to set either `lru` or `ranked`. --- db.go | 9 +++- fragment.go | 22 ++++++---- fragment_test.go | 29 +++++++++++-- frame.go | 47 +++++++++++++++++---- handler.go | 4 -- internal/private.pb.go | 93 ++++++++++++++++++++++++++++++------------ internal/private.proto | 1 + internal/public.pb.go | 2 +- pilosa.go | 3 +- view.go | 3 ++ 10 files changed, 158 insertions(+), 55 deletions(-) diff --git a/db.go b/db.go index 6a4a956b6..ef95a54bf 100644 --- a/db.go +++ b/db.go @@ -358,9 +358,10 @@ func (db *DB) CreateFrameIfNotExists(name string, opt FrameOptions) (*Frame, err } func (db *DB) createFrame(name string, opt FrameOptions) (*Frame, error) { - if name == "" { return nil, errors.New("frame name required") + } else if opt.CacheType != "" && !IsValidCacheType(opt.CacheType) { + return nil, ErrInvalidCacheType } // Initialize frame. @@ -380,6 +381,12 @@ func (db *DB) createFrame(name string, opt FrameOptions) (*Frame, error) { return nil, err } + // Set cache type. + if opt.CacheType == "" { + opt.CacheType = DefaultCacheType + } + f.cacheType = opt.CacheType + // Set options. if opt.RowLabel != "" { f.rowLabel = opt.RowLabel diff --git a/fragment.go b/fragment.go index 5a3bcbd63..063b7e17c 100644 --- a/fragment.go +++ b/fragment.go @@ -16,7 +16,6 @@ import ( "log" "os" "sort" - "strings" "sync" "syscall" "time" @@ -69,7 +68,8 @@ type Fragment struct { opN int // number of ops since snapshot // Cache for bitmap counts. - cache Cache + cacheType string // passed in by frame + cache Cache // Cache containing full bitmaps (not just counts). bitmapCache BitmapCache @@ -95,11 +95,12 @@ type Fragment struct { // NewFragment returns a new instance of Fragment. func NewFragment(path, db, frame, view string, slice uint64) *Fragment { return &Fragment{ - path: path, - db: db, - frame: frame, - view: view, - slice: slice, + path: path, + db: db, + frame: frame, + view: view, + slice: slice, + cacheType: DefaultCacheType, LogOutput: ioutil.Discard, MaxOpN: DefaultFragmentMaxOpN, @@ -219,13 +220,16 @@ func (f *Fragment) openStorage() error { // openCache initializes the cache from bitmap ids persisted to disk. func (f *Fragment) openCache() error { // Determine cache type from frame name. - if strings.HasSuffix(f.frame, FrameSuffixRank) { + switch f.cacheType { + case CacheTypeRanked: c := NewRankCache() c.ThresholdLength = 50000 c.ThresholdIndex = 45000 f.cache = c - } else { + case CacheTypeLRU: f.cache = NewLRUCache(50000) + default: + return ErrInvalidCacheType } // Read cache data from disk. diff --git a/fragment_test.go b/fragment_test.go index 875b7c8bf..199ba0a06 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -386,8 +386,26 @@ func TestFragment_LRUCache_Persistence(t *testing.T) { // Ensure a fragment's cache can be persisted between restarts. func TestFragment_RankCache_Persistence(t *testing.T) { - f := MustOpenFragment("d", "f.n", pilosa.ViewStandard, 0) - defer f.Close() + db := MustOpenDB() + defer db.Close() + + // Create frame. + frame, err := db.CreateFrameIfNotExists("f", pilosa.FrameOptions{CacheType: pilosa.CacheTypeRanked}) + if err != nil { + t.Fatal(err) + } + + // Create view. + view, err := frame.CreateViewIfNotExists(pilosa.ViewStandard) + if err != nil { + t.Fatal(err) + } + + // Create fragment. + f, err := view.CreateFragmentIfNotExists(0) + if err != nil { + t.Fatal(err) + } // Set bits on the fragment. for i := uint64(0); i < 1000; i++ { @@ -403,11 +421,14 @@ func TestFragment_RankCache_Persistence(t *testing.T) { t.Fatalf("unexpected cache len: %d", cache.Len()) } - // Reopen the fragment. - if err := f.Reopen(); err != nil { + // Reopen the database. + if err := db.Reopen(); err != nil { t.Fatal(err) } + // Re-fetch fragment. + f = db.Frame("f").View(pilosa.ViewStandard).Fragment(0) + // Re-verify correct cache type and size. if cache, ok := f.Cache().(*pilosa.RankCache); !ok { t.Fatalf("unexpected cache: %T", f.Cache()) diff --git a/frame.go b/frame.go index 6709f4411..bd6f1218a 100644 --- a/frame.go +++ b/frame.go @@ -15,14 +15,10 @@ import ( "github.com/pilosa/pilosa/internal" ) -const ( - // FrameSuffixRank is the suffix used for rank-based frames. - FrameSuffixRank = ".n" -) - // Default frame settings. const ( DefaultRowLabel = "id" + DefaultCacheType = CacheTypeLRU DefaultInverseEnabled = false ) @@ -42,8 +38,9 @@ type Frame struct { stats StatsClient // Frame settings. - inverseEnabled bool rowLabel string + cacheType string + inverseEnabled bool LogOutput io.Writer } @@ -65,8 +62,9 @@ func NewFrame(path, db, name string) (*Frame, error) { stats: NopStatsClient, - inverseEnabled: DefaultInverseEnabled, rowLabel: DefaultRowLabel, + cacheType: DefaultCacheType, + inverseEnabled: DefaultInverseEnabled, LogOutput: ioutil.Discard, }, nil @@ -118,7 +116,6 @@ func (f *Frame) SetRowLabel(v string) error { return nil } - // Make sure rowLabel is valid name err := ValidateName(v) if err != nil { @@ -142,6 +139,11 @@ func (f *Frame) RowLabel() string { return v } +// CacheType returns the caching mode for the frame. +func (f *Frame) CacheType() string { + return f.cacheType +} + // InverseEnabled returns true if an inverse view is available. func (f *Frame) InverseEnabled() bool { return f.inverseEnabled @@ -151,8 +153,9 @@ func (f *Frame) InverseEnabled() bool { func (f *Frame) Options() FrameOptions { f.mu.Lock() opt := FrameOptions{ - InverseEnabled: f.inverseEnabled, RowLabel: f.rowLabel, + CacheType: f.cacheType, + InverseEnabled: f.inverseEnabled, } f.mu.Unlock() return opt @@ -230,6 +233,7 @@ func (f *Frame) loadMeta() error { if os.IsNotExist(err) { f.timeQuantum = "" f.rowLabel = DefaultRowLabel + f.cacheType = DefaultCacheType f.inverseEnabled = DefaultInverseEnabled return nil } else if err != nil { @@ -245,6 +249,12 @@ func (f *Frame) loadMeta() error { f.rowLabel = pb.RowLabel f.inverseEnabled = pb.InverseEnabled + // Copy cache type. + f.cacheType = pb.CacheType + if f.cacheType == "" { + f.cacheType = DefaultCacheType + } + return nil } @@ -254,6 +264,7 @@ func (f *Frame) saveMeta() error { buf, err := proto.Marshal(&internal.Frame{ TimeQuantum: string(f.timeQuantum), RowLabel: f.rowLabel, + CacheType: f.cacheType, InverseEnabled: f.inverseEnabled, }) if err != nil { @@ -366,6 +377,7 @@ func (f *Frame) CreateViewIfNotExists(name string) (*View, error) { func (f *Frame) newView(path, name string) *View { view := NewView(path, f.db, f.name, name) + view.cacheType = f.cacheType view.LogOutput = f.LogOutput view.BitmapAttrStore = f.bitmapAttrStore view.stats = f.stats.WithTags(fmt.Sprintf("slice:%s", name)) @@ -546,6 +558,7 @@ func (p frameInfoSlice) Less(i, j int) bool { return p[i].Name < p[j].Name } // FrameOptions represents options to set when initializing a frame. type FrameOptions struct { RowLabel string `json:"rowLabel,omitempty"` + CacheType string `json:"cacheType,omitempty"` InverseEnabled bool `json:"inverseEnabled,omitempty"` } @@ -561,3 +574,19 @@ func (p importBitSet) Swap(i, j int) { } func (p importBitSet) Len() int { return len(p.bitmapIDs) } func (p importBitSet) Less(i, j int) bool { return p.bitmapIDs[i] < p.bitmapIDs[j] } + +// Cache types. +const ( + CacheTypeLRU = "lru" + CacheTypeRanked = "ranked" +) + +// IsValidCacheType returns true if v is a valid cache type. +func IsValidCacheType(v string) bool { + switch v { + case CacheTypeLRU, CacheTypeRanked: + return true + default: + return false + } +} diff --git a/handler.go b/handler.go index fc14fc22f..5b44c51d7 100644 --- a/handler.go +++ b/handler.go @@ -1219,10 +1219,6 @@ func (h *Handler) handlePostFrameRestore(w http.ResponseWriter, r *http.Request) return } - for _, view := range views { - println("dbg/views", view) - } - // Loop over each slice and import it if this node owns it. //travis for slice := uint64(0); slice <= maxSlices[db]; slice++ { diff --git a/internal/private.pb.go b/internal/private.pb.go index 9a96165f3..ed2e6d41f 100644 --- a/internal/private.pb.go +++ b/internal/private.pb.go @@ -50,6 +50,7 @@ type Frame struct { TimeQuantum string `protobuf:"bytes,1,opt,name=TimeQuantum,proto3" json:"TimeQuantum,omitempty"` RowLabel string `protobuf:"bytes,2,opt,name=RowLabel,proto3" json:"RowLabel,omitempty"` InverseEnabled bool `protobuf:"varint,3,opt,name=InverseEnabled,proto3" json:"InverseEnabled,omitempty"` + CacheType string `protobuf:"bytes,4,opt,name=CacheType,proto3" json:"CacheType,omitempty"` } func (m *Frame) Reset() { *m = Frame{} } @@ -190,6 +191,12 @@ func (m *Frame) MarshalTo(dAtA []byte) (int, error) { } i++ } + if len(m.CacheType) > 0 { + dAtA[i] = 0x22 + i++ + i = encodeVarintPrivate(dAtA, i, uint64(len(m.CacheType))) + i += copy(dAtA[i:], m.CacheType) + } return i, nil } @@ -439,6 +446,10 @@ func (m *Frame) Size() (n int) { if m.InverseEnabled { n += 2 } + l = len(m.CacheType) + if l > 0 { + n += 1 + l + sovPrivate(uint64(l)) + } return n } @@ -751,6 +762,35 @@ func (m *Frame) Unmarshal(dAtA []byte) error { } } m.InverseEnabled = bool(v != 0) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CacheType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrivate + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CacheType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPrivate(dAtA[iNdEx:]) @@ -1576,30 +1616,31 @@ var ( func init() { proto.RegisterFile("private.proto", fileDescriptorPrivate) } var fileDescriptorPrivate = []byte{ - // 389 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x8b, 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x00, 0xff, 0xff, 0x5a, 0x1e, 0x5e, - 0x10, 0xa2, 0x02, 0x00, 0x00, + // 406 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xd1, 0x8a, 0xd3, 0x40, + 0x14, 0x86, 0x9d, 0x36, 0x95, 0xf6, 0x2c, 0x86, 0xee, 0xb0, 0x17, 0x61, 0x59, 0x42, 0x18, 0x50, + 0x8a, 0x17, 0xbd, 0xd0, 0x1b, 0x11, 0xaf, 0xb2, 0xad, 0x6c, 0x41, 0xc1, 0x1d, 0x17, 0xef, 0xa7, + 0xf5, 0x88, 0xa1, 0x93, 0x99, 0x38, 0x99, 0x74, 0x37, 0xcf, 0xe0, 0x0b, 0x08, 0xbe, 0x90, 0x97, + 0x3e, 0x82, 0xd4, 0x17, 0x91, 0x99, 0xa4, 0x4d, 0x54, 0x10, 0xef, 0xe6, 0x7c, 0x73, 0xce, 0x3f, + 0xff, 0xf9, 0x19, 0x78, 0x50, 0x98, 0x6c, 0x27, 0x2c, 0xce, 0x0b, 0xa3, 0xad, 0xa6, 0xe3, 0x4c, + 0x59, 0x34, 0x4a, 0x48, 0x76, 0x05, 0x83, 0x45, 0x4a, 0x13, 0x38, 0xb9, 0xc9, 0x72, 0xbc, 0xae, + 0x84, 0xb2, 0x55, 0x1e, 0x91, 0x84, 0xcc, 0x26, 0xbc, 0x8f, 0x5c, 0xc7, 0xa5, 0x96, 0x55, 0xae, + 0x5e, 0x89, 0x35, 0xca, 0x68, 0xd0, 0x74, 0xf4, 0x10, 0xfb, 0x4c, 0x60, 0xf4, 0xd2, 0x88, 0x1c, + 0xff, 0x43, 0xed, 0x1c, 0xc6, 0x5c, 0xdf, 0xf6, 0xa5, 0x8e, 0x35, 0x7d, 0x04, 0xe1, 0x4a, 0xed, + 0xd0, 0x94, 0xb8, 0x54, 0x62, 0x2d, 0xf1, 0x7d, 0x34, 0x4c, 0xc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0xfa, 0x90, 0xfb, 0x16, 0x6b, 0x97, 0xd3, 0x4e, 0xc8, 0xaa, 0xc9, 0x34, 0xe0, 0x4d, 0xf1, + 0x7c, 0xf0, 0x8c, 0xa4, 0xd3, 0x6f, 0xfb, 0x98, 0x7c, 0xdf, 0xc7, 0xe4, 0xc7, 0x3e, 0x26, 0x5f, + 0x7e, 0xc6, 0xf7, 0xd6, 0xf7, 0xfd, 0x87, 0x7d, 0xfa, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x99, 0x45, + 0xbe, 0x6d, 0xc1, 0x02, 0x00, 0x00, } diff --git a/internal/private.proto b/internal/private.proto index 6218a4b59..acd9ec43c 100644 --- a/internal/private.proto +++ b/internal/private.proto @@ -11,6 +11,7 @@ message Frame { string TimeQuantum = 1; string RowLabel = 2; bool InverseEnabled = 3; + string CacheType = 4; } message ImportResponse { diff --git a/internal/public.pb.go b/internal/public.pb.go index 77321bb5c..82645d9ee 100644 --- a/internal/public.pb.go +++ b/internal/public.pb.go @@ -2616,7 +2616,7 @@ func init() { proto.RegisterFile("public.proto", fileDescriptorPublic) } var fileDescriptorPublic = []byte{ // 572 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd4, 0x3c, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd4, 0x3c, 0x14, 0xfd, 0x3c, 0xc9, 0xfc, 0xdd, 0x69, 0xab, 0x7e, 0x16, 0xa0, 0x08, 0xa1, 0x51, 0x14, 0xb1, 0xc8, 0x86, 0xa9, 0x54, 0x1e, 0x00, 0x91, 0x4e, 0x2b, 0x8d, 0x10, 0x55, 0xeb, 0x16, 0x76, 0x2c, 0xd2, 0x62, 0x8a, 0xa5, 0xfc, 0x61, 0x3b, 0x8b, 0x59, 0xb2, 0xe0, 0x1d, 0x10, 0x6f, 0x00, 0x4f, diff --git a/pilosa.go b/pilosa.go index 814c69753..b754c0e48 100644 --- a/pilosa.go +++ b/pilosa.go @@ -21,7 +21,8 @@ var ( ErrFrameNotFound = errors.New("frame not found") ErrFrameInverseDisabled = errors.New("frame inverse disabled") - ErrInvalidView = errors.New("invalid view") + ErrInvalidView = errors.New("invalid view") + ErrInvalidCacheType = errors.New("invalid cache type") ErrName = errors.New("invalid database or frame's name, must match [a-z0-9_-]") diff --git a/view.go b/view.go index f113f22ca..54dda6f56 100644 --- a/view.go +++ b/view.go @@ -31,6 +31,7 @@ type View struct { name string // Fragments by slice. + cacheType string // passed in by frame fragments map[uint64]*Fragment stats StatsClient @@ -47,6 +48,7 @@ func NewView(path, db, frame, name string) *View { frame: frame, name: name, + cacheType: DefaultCacheType, fragments: make(map[uint64]*Fragment), stats: NopStatsClient, @@ -212,6 +214,7 @@ func (v *View) createFragmentIfNotExists(slice uint64) (*Fragment, error) { func (v *View) newFragment(path string, slice uint64) *Fragment { frag := NewFragment(path, v.db, v.frame, v.name, slice) + frag.cacheType = v.cacheType frag.LogOutput = v.LogOutput frag.stats = v.stats.WithTags(fmt.Sprintf("slice:%d", slice)) return frag