Skip to content

Commit

Permalink
fixed DB to index conflicts after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
raskle committed Apr 25, 2017
1 parent 5a8c165 commit a543ba2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ default.etcd/
*.test
vendor
.protoc-gen-gofast

/datadog/.DS_Store
1 change: 0 additions & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pilosa
import (
"encoding/binary"
"hash/fnv"
"sync"

"github.com/pilosa/pilosa/internal"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ on the configured port.`,
flags.StringVarP(&Server.Config.Cluster.Type, "cluster.type", "", "static", "Determine how the cluster handles membership and state sharing. Choose from [static, http, gossip]")
flags.StringVarP(&Server.Config.Cluster.GossipSeed, "cluster.gossip-seed", "", "", "Host with which to seed the gossip membership.")
flags.StringVarP(&Server.Config.Cluster.InternalPort, "cluster.internal-port", "", "", "Port to which pilosa should bind for internal state sharing.")
flags.StringVarP(&Server.Config.Metric.Service, "metric.service", "", "noop", "Default URI on which pilosa should listen.")
flags.StringVarP(&Server.Config.Metric.Service, "metric.service", "", "nop", "Default URI on which pilosa should listen.")
flags.StringVarP(&Server.Config.Metric.Host, "metric.host", "", "", "Default URI to send metrics.")
flags.DurationVarP((*time.Duration)(&Server.Config.Metric.PollingInterval), "metric.poll-interval", "", time.Minute*0, "Polling interval metrics.")
return serveCmd
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
DefaultPort = "10101"
DefaultClusterType = "static"
DefaultInternalPort = "14000"
DefaultMetrics = "noop"
DefaultMetrics = "nop"
)

// Config represents the configuration for the command.
Expand Down
2 changes: 1 addition & 1 deletion executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func (e *Executor) executeSetColumnAttrs(ctx context.Context, index string, c *p
if err := idx.ColumnAttrStore().SetAttrs(id, attrs); err != nil {
return err
}
d.Stats.Count("SetProfileAttrs", 1)
idx.Stats.Count("SetProfileAttrs", 1)
// Do not forward call if this is already being forwarded.
if opt.Remote {
return nil
Expand Down
2 changes: 1 addition & 1 deletion holder.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (h *Holder) newIndex(path, name string) (*Index, error) {
return nil, err
}
index.LogOutput = h.LogOutput
index.stats = h.Stats.WithTags(fmt.Sprintf("index:%s", index.Name()))
index.Stats = h.Stats.WithTags(fmt.Sprintf("index:%s", index.Name()))
index.broadcaster = h.Broadcaster
return index, nil
}
Expand Down
12 changes: 6 additions & 6 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Index struct {
columnAttrStore *AttrStore

broadcaster Broadcaster
stats StatsClient
Stats StatsClient

LogOutput io.Writer
}
Expand All @@ -68,7 +68,7 @@ func NewIndex(path, name string) (*Index, error) {

columnLabel: DefaultColumnLabel,

stats: NopStatsClient,
Stats: NopStatsClient,
LogOutput: ioutil.Discard,
}, nil
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (i *Index) openFrames() error {
}
i.frames[fr.Name()] = fr

i.stats.Count("frameN", 1)
i.Stats.Count("frameN", 1)
}
return nil
}
Expand Down Expand Up @@ -405,7 +405,7 @@ func (i *Index) createFrame(name string, opt FrameOptions) (*Frame, error) {
// Add to index's frame lookup.
i.frames[name] = f

i.stats.Count("frameN", 1)
i.Stats.Count("frameN", 1)

return f, nil
}
Expand All @@ -416,7 +416,7 @@ func (i *Index) newFrame(path, name string) (*Frame, error) {
return nil, err
}
f.LogOutput = i.LogOutput
f.stats = i.stats.WithTags(fmt.Sprintf("frame:%s", name))
f.Stats = i.Stats.WithTags(fmt.Sprintf("frame:%s", name))
f.broadcaster = i.broadcaster
return f, nil
}
Expand Down Expand Up @@ -445,7 +445,7 @@ func (i *Index) DeleteFrame(name string) error {
// Remove reference.
delete(i.frames, name)

i.stats.Count("frameN", -1)
i.Stats.Count("frameN", -1)

return nil
}
Expand Down
9 changes: 2 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,13 @@ func (s *Server) ReceiveMessage(pb proto.Message) error {
// In a gossip implementation, memberlist.Delegate.LocalState() uses this.
func (s *Server) LocalStatus() (proto.Message, error) {
if s.Holder == nil {
return nil, errors.New("Server.Holder is nil.")
return nil, errors.New("Server.Holder is nil")
}
return &internal.NodeStatus{
Host: s.Host,
State: NodeStateUp,
Indexes: encodeIndexes(s.Holder.Indexes()),

ns := internal.NodeState{
}

s.Cluster.SetNodeState(&ns)
return &ns, nil
}, nil
}

// ClusterStatus returns the NodeState for all nodes in the cluster.
Expand Down
69 changes: 35 additions & 34 deletions stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@ package pilosa_test

import (
"context"
"github.com/pilosa/pilosa"
"testing"
"time"

"github.com/pilosa/pilosa"
)

func TestStatsCount_TopN(t *testing.T) {
idx := MustOpenIndex()
defer idx.Close()
hldr := MustOpenHolder()
defer hldr.Close()

idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 0)
idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 1)
idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 1).SetBit(0, SliceWidth)
idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 1).SetBit(0, SliceWidth+2)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 0)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 1)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 1).SetBit(0, SliceWidth)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 1).SetBit(0, SliceWidth+2)

// Execute query.
called := false
e := NewExecutor(idx.Index, NewCluster(1))
e.Index.Stats = &MockStats{
e := NewExecutor(hldr.Holder, NewCluster(1))
e.Holder.Stats = &MockStats{
mockCountWithTags: func(name string, value int64, tags []string) {
if name != "TopN" {
t.Errorf("Expected TopN, Results %s", name)
}

if tags[0] != "db:d" {
if tags[0] != "index:d" {
t.Errorf("Expected db, Results %s", tags[0])
}

Expand All @@ -42,20 +43,20 @@ func TestStatsCount_TopN(t *testing.T) {
}

func TestStatsCount_Bitmap(t *testing.T) {
idx := MustOpenIndex()
defer idx.Close()
hldr := MustOpenHolder()
defer hldr.Close()

idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 0)
idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 1)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 0)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(0, 1)
called := false
e := NewExecutor(idx.Index, NewCluster(1))
e.Index.Stats = &MockStats{
e := NewExecutor(hldr.Holder, NewCluster(1))
e.Holder.Stats = &MockStats{
mockCountWithTags: func(name string, value int64, tags []string) {
if name != "Bitmap" {
t.Errorf("Expected Bitmap, Results %s", name)
}

if tags[0] != "db:d" {
if tags[0] != "index:d" {
t.Errorf("Expected db, Results %s", tags[0])
}

Expand All @@ -72,15 +73,15 @@ func TestStatsCount_Bitmap(t *testing.T) {
}

func TestStatsCount_SetBitmapAttrs(t *testing.T) {
idx := MustOpenIndex()
defer idx.Close()
hldr := MustOpenHolder()
defer hldr.Close()

idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 0)
idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 1)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 0)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 1)

called := false
e := NewExecutor(idx.Index, NewCluster(1))
frame := e.Index.Frame("d", "f")
e := NewExecutor(hldr.Holder, NewCluster(1))
frame := e.Holder.Frame("d", "f")
if frame == nil {
t.Fatal("frame not found")
}
Expand All @@ -94,7 +95,7 @@ func TestStatsCount_SetBitmapAttrs(t *testing.T) {
return
},
}
if _, err := e.Execute(context.Background(), "d", MustParse(`SetBitmapAttrs(id=10, frame=f, foo="bar")`), nil, nil); err != nil {
if _, err := e.Execute(context.Background(), "d", MustParse(`SetRowAttrs(id=10, frame=f, foo="bar")`), nil, nil); err != nil {
t.Fatal(err)
}
if !called {
Expand All @@ -103,20 +104,20 @@ func TestStatsCount_SetBitmapAttrs(t *testing.T) {
}

func TestStatsCount_SetProfileAttrs(t *testing.T) {
idx := MustOpenIndex()
defer idx.Close()
hldr := MustOpenHolder()
defer hldr.Close()

idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 0)
idx.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 1)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 0)
hldr.MustCreateFragmentIfNotExists("d", "f", pilosa.ViewStandard, 0).SetBit(10, 1)

called := false
e := NewExecutor(idx.Index, NewCluster(1))
db := e.Index.DB("d")
if db == nil {
t.Fatal("db not found")
e := NewExecutor(hldr.Holder, NewCluster(1))
idx := e.Holder.Index("d")
if idx == nil {
t.Fatal("idex not found")
}

db.Stats = &MockStats{
idx.Stats = &MockStats{
mockCount: func(name string, value int64) {
if name != "SetProfileAttrs" {
t.Errorf("Expected SetProfilepAttrs, Results %s", name)
Expand All @@ -126,7 +127,7 @@ func TestStatsCount_SetProfileAttrs(t *testing.T) {
return
},
}
if _, err := e.Execute(context.Background(), "d", MustParse(`SetProfileAttrs(id=10, frame=f, foo="bar")`), nil, nil); err != nil {
if _, err := e.Execute(context.Background(), "d", MustParse(`SetColumnAttrs(id=10, frame=f, foo="bar")`), nil, nil); err != nil {
t.Fatal(err)
}
if !called {
Expand Down

0 comments on commit a543ba2

Please sign in to comment.