From 920b9d01e2d27e72e9aa501dfde0222ba7eb86bd Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Tue, 7 Mar 2017 15:37:00 -0600 Subject: [PATCH 1/4] add . before meta frame --- db.go | 7 ++++--- frame_test.go | 4 ++-- pilosa.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/db.go b/db.go index 9348c97b6..528369787 100644 --- a/db.go +++ b/db.go @@ -60,7 +60,7 @@ func NewDB(path, name string) (*DB, error) { frames: make(map[string]*Frame), remoteMaxSlice: 0, - profileAttrStore: NewAttrStore(filepath.Join(path, "data")), + profileAttrStore: NewAttrStore(filepath.Join(path, ".data")), columnLabel: DefaultColumnLabel, @@ -165,7 +165,7 @@ func (db *DB) loadMeta() error { var pb internal.DB // Read data from meta file. - buf, err := ioutil.ReadFile(filepath.Join(db.path, "meta")) + buf, err := ioutil.ReadFile(filepath.Join(db.path, ".meta")) if os.IsNotExist(err) { db.timeQuantum = "" db.columnLabel = DefaultColumnLabel @@ -188,6 +188,7 @@ func (db *DB) loadMeta() error { // saveMeta writes meta data for the database. func (db *DB) saveMeta() error { // Marshal metadata. + buf, err := proto.Marshal(&internal.DB{ TimeQuantum: string(db.timeQuantum), ColumnLabel: db.columnLabel, @@ -197,7 +198,7 @@ func (db *DB) saveMeta() error { } // Write to meta file. - if err := ioutil.WriteFile(filepath.Join(db.path, "meta"), buf, 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(db.path, ".meta"), buf, 0666); err != nil { return err } diff --git a/frame_test.go b/frame_test.go index 042bd751e..891ff203a 100644 --- a/frame_test.go +++ b/frame_test.go @@ -106,13 +106,13 @@ func (f *Frame) Reopen() error { return nil } -// NewFrame returns a new instance of Frame d/0. +// NewFrame doesnot return with invalid name func TestFrame_NameRestriction(t *testing.T) { path, err := ioutil.TempDir("", "pilosa-frame-") if err != nil { panic(err) } - frame, err := pilosa.NewFrame(path, "d", "ABC") + frame, err := pilosa.NewFrame(path, "d", ".meta") if frame != nil { t.Fatalf("unexpected frame name %s", err) } diff --git a/pilosa.go b/pilosa.go index d2df7c5ed..16434b04e 100644 --- a/pilosa.go +++ b/pilosa.go @@ -29,7 +29,7 @@ var ( // Regular expression to valuate db and frame's name // Todo: remove . when frame doesn't require . for topN -var nameRegexp = regexp.MustCompile(`^([a-z0-9._-]{1,64}$)`) +var nameRegexp = regexp.MustCompile(`^([^.][a-z0-9._-]{1,64}$)`) // Profile represents vertical column in a database. // A profile can have a set of attributes attached to it. From 34b8f30c0db38cb480473573d0ecd96f8cc7c9fd Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Wed, 8 Mar 2017 12:07:14 -0600 Subject: [PATCH 2/4] invalid name start with dot --- pilosa.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pilosa.go b/pilosa.go index 16434b04e..d7e61e46b 100644 --- a/pilosa.go +++ b/pilosa.go @@ -29,7 +29,7 @@ var ( // Regular expression to valuate db and frame's name // Todo: remove . when frame doesn't require . for topN -var nameRegexp = regexp.MustCompile(`^([^.][a-z0-9._-]{1,64}$)`) +var nameRegexp = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,64}$`) // Profile represents vertical column in a database. // A profile can have a set of attributes attached to it. From 3ab1d34d9abf805a2387e5d39e0d57f30a5134ed Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Wed, 8 Mar 2017 13:10:25 -0600 Subject: [PATCH 3/4] change frame name to meta for testing --- handler_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handler_test.go b/handler_test.go index 3a3ad3047..099d85074 100644 --- a/handler_test.go +++ b/handler_test.go @@ -605,7 +605,7 @@ func TestHandler_Frame_AttrStore_Diff(t *testing.T) { // Set attributes on the database. d := idx.MustCreateDBIfNotExists("d", pilosa.DBOptions{}) - f, err := d.CreateFrameIfNotExists("f", pilosa.FrameOptions{}) + f, err := d.CreateFrameIfNotExists("meta", pilosa.FrameOptions{}) if err != nil { t.Fatal(err) } @@ -631,7 +631,7 @@ func TestHandler_Frame_AttrStore_Diff(t *testing.T) { resp, err := http.Post( s.URL+"/frame/attr/diff?db=d", "application/json", - strings.NewReader(`{"db":"d", "frame":"f", "blocks":`+string(MustMarshalJSON(blks))+`}`), + strings.NewReader(`{"db":"d", "frame":"meta", "blocks":`+string(MustMarshalJSON(blks))+`}`), ) if err != nil { t.Fatal(err) From 3649a52c00fe77ba8cf7e5dac2b1987c4c08802e Mon Sep 17 00:00:00 2001 From: Travis Date: Fri, 10 Mar 2017 15:47:17 -0600 Subject: [PATCH 4/4] Change frame `meta` and `data` to `.meta` and `.data` to be consistent with the DB dot files. --- db.go | 1 - frame.go | 6 +++--- frame_test.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/db.go b/db.go index 528369787..fef92e755 100644 --- a/db.go +++ b/db.go @@ -188,7 +188,6 @@ func (db *DB) loadMeta() error { // saveMeta writes meta data for the database. func (db *DB) saveMeta() error { // Marshal metadata. - buf, err := proto.Marshal(&internal.DB{ TimeQuantum: string(db.timeQuantum), ColumnLabel: db.columnLabel, diff --git a/frame.go b/frame.go index fa47517c5..8ff32f761 100644 --- a/frame.go +++ b/frame.go @@ -58,7 +58,7 @@ func NewFrame(path, db, name string) (*Frame, error) { name: name, fragments: make(map[uint64]*Fragment), - bitmapAttrStore: NewAttrStore(filepath.Join(path, "data")), + bitmapAttrStore: NewAttrStore(filepath.Join(path, ".data")), stats: NopStatsClient, @@ -202,7 +202,7 @@ func (f *Frame) loadMeta() error { var pb internal.Frame // Read data from meta file. - buf, err := ioutil.ReadFile(filepath.Join(f.path, "meta")) + buf, err := ioutil.ReadFile(filepath.Join(f.path, ".meta")) if os.IsNotExist(err) { f.timeQuantum = "" f.rowLabel = DefaultRowLabel @@ -234,7 +234,7 @@ func (f *Frame) saveMeta() error { } // Write to meta file. - if err := ioutil.WriteFile(filepath.Join(f.path, "meta"), buf, 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(f.path, ".meta"), buf, 0666); err != nil { return err } diff --git a/frame_test.go b/frame_test.go index 891ff203a..5b03cfb3e 100644 --- a/frame_test.go +++ b/frame_test.go @@ -106,7 +106,7 @@ func (f *Frame) Reopen() error { return nil } -// NewFrame doesnot return with invalid name +// NewFrame does not return a frame when name is invalid. func TestFrame_NameRestriction(t *testing.T) { path, err := ioutil.TempDir("", "pilosa-frame-") if err != nil {