Skip to content

Commit

Permalink
Merge branch 'master' into gtid
Browse files Browse the repository at this point in the history
  • Loading branch information
enisoc committed Jul 28, 2014
2 parents 150d8da + 2205f4e commit 8206436
Show file tree
Hide file tree
Showing 54 changed files with 2,637 additions and 1,714 deletions.
77 changes: 64 additions & 13 deletions data/test/sqlparser_test/ddl_cases.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
create table a(abcd)#{"Action": "create", "NewName": "a"}
drop table b#{"Action": "drop", "TableName": "b"}
alter table c alter foo#{"Action": "alter", "TableName": "c", "NewTable": "c"}
alter table c comment 'aa'#{"Action": "alter", "TableName": "c", "NewTable": "c"}
drop index a on b#{"Action": "alter", "TableName": "b", "NewName": "b"}
rename table a to b#{"Action": "rename", "TableName": "a", "NewTable": "b"}
alter table a rename b#{"Action": "rename", "TableName": "a", "NewTable": "b"}
alter table a rename to b#{"Action": "rename", "TableName": "a", "NewTable": "b"}
create view a asdasd#{"Action": "create", "NewName": "a"}
alter view c alter foo#{"Action": "alter", "TableName": "c", "NewTable": "c"}
drop view b#{"Action": "drop", "TableName": "b"}
select * from a#{"Action": ""}
syntax error#{"Action": ""}
"create table a(abcd)"
{
"Action": "create", "NewName": "a"
}

"drop table b"
{
"Action": "drop", "TableName": "b"
}

"alter table c alter foo"
{
"Action": "alter", "TableName": "c", "NewTable": "c"
}

"alter table c comment 'aa'"
{
"Action": "alter", "TableName": "c", "NewTable": "c"
}

"drop index a on b"
{
"Action": "alter", "TableName": "b", "NewName": "b"
}

"rename table a to b"
{
"Action": "rename", "TableName": "a", "NewTable": "b"
}

"alter table a rename b"
{
"Action": "rename", "TableName": "a", "NewTable": "b"
}

"alter table a rename to b"
{
"Action": "rename", "TableName": "a", "NewTable": "b"
}

"create view a asdasd"
{
"Action": "create", "NewName": "a"
}

"alter view c alter foo"
{
"Action": "alter", "TableName": "c", "NewTable": "c"
}

"drop view b"
{
"Action": "drop", "TableName": "b"
}

"select * from a"
{
"Action": ""
}

"syntax error"
{
"Action": ""
}
8 changes: 4 additions & 4 deletions data/test/sqlparser_test/exec_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@
{
"PlanId":"DDL",
"Reason":"DEFAULT",
"TableName":"",
"TableName":"a",
"FieldQuery":null,
"FullQuery":null,
"OuterQuery":null,
Expand All @@ -2076,7 +2076,7 @@
{
"PlanId":"DDL",
"Reason":"DEFAULT",
"TableName":"",
"TableName":"a",
"FieldQuery":null,
"FullQuery":null,
"OuterQuery":null,
Expand All @@ -2095,7 +2095,7 @@
{
"PlanId":"DDL",
"Reason":"DEFAULT",
"TableName":"",
"TableName":"a",
"FieldQuery":null,
"FullQuery":null,
"OuterQuery":null,
Expand All @@ -2114,7 +2114,7 @@
{
"PlanId":"DDL",
"Reason":"DEFAULT",
"TableName":"",
"TableName":"a",
"FieldQuery":null,
"FullQuery":null,
"OuterQuery":null,
Expand Down
49 changes: 47 additions & 2 deletions data/test/sqlparser_test/stream_cases.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
# select
"select * from a"
{
"FullQuery": "select * from a"
"PlanId":"PASS_SELECT",
"Reason":"DEFAULT",
"TableName":"a",
"FieldQuery":null,
"FullQuery":"select * from a",
"OuterQuery":null,
"Subquery":null,
"IndexUsed":"",
"ColumnNumbers":null,
"PKValues":null,
"SecondaryPKValues":null,
"SubqueryPKColumns":null,
"SetKey":"",
"SetValue":null
}

# select join
"select * from a join b"
{
"PlanId":"PASS_SELECT",
"Reason":"DEFAULT",
"TableName":"",
"FieldQuery":null,
"FullQuery":"select * from a join b",
"OuterQuery":null,
"Subquery":null,
"IndexUsed":"",
"ColumnNumbers":null,
"PKValues":null,
"SecondaryPKValues":null,
"SubqueryPKColumns":null,
"SetKey":"",
"SetValue":null
}

# select for update
Expand All @@ -11,7 +43,20 @@
# union
"select * from a union select * from b"
{
"FullQuery": "select * from a union select * from b"
"PlanId":"PASS_SELECT",
"Reason":"DEFAULT",
"TableName":"",
"FieldQuery":null,
"FullQuery": "select * from a union select * from b",
"OuterQuery":null,
"Subquery":null,
"IndexUsed":"",
"ColumnNumbers":null,
"PKValues":null,
"SecondaryPKValues":null,
"SubqueryPKColumns":null,
"SetKey":"",
"SetValue":null
}

# dml
Expand Down
5 changes: 5 additions & 0 deletions go/cmd/vtocc/vtocc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/youtube/vitess/go/vt/dbconfigs"
"github.com/youtube/vitess/go/vt/mysqlctl"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/tableacl"
"github.com/youtube/vitess/go/vt/tabletserver"
)

Expand All @@ -21,6 +22,7 @@ var (
enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche")
enableInvalidator = flag.Bool("enable-invalidator", false, "enable rowcache invalidator")
binlogPath = flag.String("binlog-path", "", "binlog path used by rowcache invalidator")
tableAclConfig = flag.String("table-acl-config", "", "path to table access checker config file")
)

var schemaOverrides []tabletserver.SchemaOverride
Expand Down Expand Up @@ -55,6 +57,9 @@ func main() {
data, _ := json.MarshalIndent(schemaOverrides, "", " ")
log.Infof("schemaOverrides: %s\n", data)

if *tableAclConfig != "" {
tableacl.Init(*tableAclConfig)
}
tabletserver.InitQueryService()

err = tabletserver.AllowQueries(&dbConfigs.App, schemaOverrides, tabletserver.LoadCustomRules(), mysqld, true)
Expand Down
5 changes: 5 additions & 0 deletions go/cmd/vttablet/vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/youtube/vitess/go/vt/dbconfigs"
"github.com/youtube/vitess/go/vt/mysqlctl"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/tableacl"
"github.com/youtube/vitess/go/vt/tabletmanager"
"github.com/youtube/vitess/go/vt/tabletserver"
"github.com/youtube/vitess/go/vt/topo"
Expand All @@ -23,6 +24,7 @@ var (
tabletPath = flag.String("tablet-path", "", "tablet alias or path to zk node representing the tablet")
enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche")
overridesFile = flag.String("schema-override", "", "schema overrides file")
tableAclConfig = flag.String("table-acl-config", "", "path to table access checker config file")

agent *tabletmanager.ActionAgent
)
Expand Down Expand Up @@ -77,6 +79,9 @@ func main() {
}
dbcfgs.App.EnableRowcache = *enableRowcache

if *tableAclConfig != "" {
tableacl.Init(*tableAclConfig)
}
tabletserver.InitQueryService()
binlog.RegisterUpdateStreamService(mycnf)

Expand Down
16 changes: 13 additions & 3 deletions go/stats/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ type Histogram struct {
// NewHistogram creates a histogram with auto-generated labels
// based on the cutoffs. The buckets are categorized using the
// following criterion: cutoff[i-1] < value <= cutoff[i]. Anything
// higher than the highest cutoff is labeled as "Max".
// higher than the highest cutoff is labeled as "inf".
func NewHistogram(name string, cutoffs []int64) *Histogram {
labels := make([]string, len(cutoffs)+1)
for i, v := range cutoffs {
labels[i] = fmt.Sprintf("%d", v)
}
labels[len(labels)-1] = "Max"
labels[len(labels)-1] = "inf"
return NewGenericHistogram(name, cutoffs, labels, "Count", "Total")
}

Expand Down Expand Up @@ -85,8 +85,8 @@ func (h *Histogram) MarshalJSON() ([]byte, error) {
fmt.Fprintf(b, "{")
totalCount := int64(0)
for i, label := range h.labels {
fmt.Fprintf(b, "\"%v\": %v, ", label, h.buckets[i])
totalCount += h.buckets[i]
fmt.Fprintf(b, "\"%v\": %v, ", label, totalCount)
}
fmt.Fprintf(b, "\"%s\": %v, ", h.countLabel, totalCount)
fmt.Fprintf(b, "\"%s\": %v", h.totalLabel, h.total)
Expand Down Expand Up @@ -128,3 +128,13 @@ func (h *Histogram) Total() (total int64) {
defer h.mu.Unlock()
return h.total
}

func (h *Histogram) Labels() []string {
return h.labels
}

func (h *Histogram) Buckets() []int64 {
h.mu.Lock()
defer h.mu.Unlock()
return h.buckets
}
6 changes: 3 additions & 3 deletions go/stats/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestHistogram(t *testing.T) {
for i := 0; i < 10; i++ {
h.Add(int64(i))
}
want := `{"1": 2, "5": 4, "Max": 4, "Count": 10, "Total": 45}`
want := `{"1": 2, "5": 6, "inf": 10, "Count": 10, "Total": 45}`
if h.String() != want {
t.Errorf("want %s, got %s", want, h.String())
}
Expand All @@ -26,8 +26,8 @@ func TestHistogram(t *testing.T) {
if counts["5"] != 4 {
t.Errorf("want 4, got %d", counts["2"])
}
if counts["Max"] != 4 {
t.Errorf("want 4, got %d", counts["Max"])
if counts["inf"] != 4 {
t.Errorf("want 4, got %d", counts["inf"])
}
if h.Count() != 10 {
t.Errorf("want 10, got %d", h.Count())
Expand Down
4 changes: 2 additions & 2 deletions go/stats/timings.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ var bucketLabels []string
func init() {
bucketLabels = make([]string, len(bucketCutoffs)+1)
for i, v := range bucketCutoffs {
bucketLabels[i] = fmt.Sprintf("%.4f", float64(v)/1e9)
bucketLabels[i] = fmt.Sprintf("%d", v)
}
bucketLabels[len(bucketLabels)-1] = "Max"
bucketLabels[len(bucketLabels)-1] = "inf"
}

// MultiTimings is meant to tracks timing data by categories as well
Expand Down
4 changes: 2 additions & 2 deletions go/stats/timings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestTimings(t *testing.T) {
tm.Add("tag1", 500*time.Microsecond)
tm.Add("tag1", 1*time.Millisecond)
tm.Add("tag2", 1*time.Millisecond)
want := `{"TotalCount":3,"TotalTime":2500000,"Histograms":{"tag1":{"0.0005":1,"0.0010":1,"0.0050":0,"0.0100":0,"0.0500":0,"0.1000":0,"0.5000":0,"1.0000":0,"5.0000":0,"10.0000":0,"Max":0,"Count":2,"Time":1500000},"tag2":{"0.0005":0,"0.0010":1,"0.0050":0,"0.0100":0,"0.0500":0,"0.1000":0,"0.5000":0,"1.0000":0,"5.0000":0,"10.0000":0,"Max":0,"Count":1,"Time":1000000}}}`
want := `{"TotalCount":3,"TotalTime":2500000,"Histograms":{"tag1":{"500000":1,"1000000":2,"5000000":2,"10000000":2,"50000000":2,"100000000":2,"500000000":2,"1000000000":2,"5000000000":2,"10000000000":2,"inf":2,"Count":2,"Time":1500000},"tag2":{"500000":0,"1000000":1,"5000000":1,"10000000":1,"50000000":1,"100000000":1,"500000000":1,"1000000000":1,"5000000000":1,"10000000000":1,"inf":1,"Count":1,"Time":1000000}}}`
if tm.String() != want {
t.Errorf("want %s, got %s", want, tm.String())
}
Expand All @@ -28,7 +28,7 @@ func TestMultiTimings(t *testing.T) {
mtm.Add([]string{"tag1a", "tag1b"}, 500*time.Microsecond)
mtm.Add([]string{"tag1a", "tag1b"}, 1*time.Millisecond)
mtm.Add([]string{"tag2a", "tag2b"}, 1*time.Millisecond)
want := `{"TotalCount":3,"TotalTime":2500000,"Histograms":{"tag1a.tag1b":{"0.0005":1,"0.0010":1,"0.0050":0,"0.0100":0,"0.0500":0,"0.1000":0,"0.5000":0,"1.0000":0,"5.0000":0,"10.0000":0,"Max":0,"Count":2,"Time":1500000},"tag2a.tag2b":{"0.0005":0,"0.0010":1,"0.0050":0,"0.0100":0,"0.0500":0,"0.1000":0,"0.5000":0,"1.0000":0,"5.0000":0,"10.0000":0,"Max":0,"Count":1,"Time":1000000}}}`
want := `{"TotalCount":3,"TotalTime":2500000,"Histograms":{"tag1a.tag1b":{"500000":1,"1000000":2,"5000000":2,"10000000":2,"50000000":2,"100000000":2,"500000000":2,"1000000000":2,"5000000000":2,"10000000000":2,"inf":2,"Count":2,"Time":1500000},"tag2a.tag2b":{"500000":0,"1000000":1,"5000000":1,"10000000":1,"50000000":1,"100000000":1,"500000000":1,"1000000000":1,"5000000000":1,"10000000000":1,"inf":1,"Count":1,"Time":1000000}}}`
if mtm.String() != want {
t.Errorf("want %s, got %s", want, mtm.String())
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/client2/sharded.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
mproto "github.com/youtube/vitess/go/mysql/proto"
"github.com/youtube/vitess/go/vt/client2/tablet"
"github.com/youtube/vitess/go/vt/key"
"github.com/youtube/vitess/go/vt/sqlparser"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/vtgate"
"github.com/youtube/vitess/go/vt/zktopo"
"github.com/youtube/vitess/go/zk"
)
Expand Down Expand Up @@ -233,7 +233,7 @@ func (sc *ShardedConn) Exec(query string, bindVars map[string]interface{}) (db.R
if sc.srvKeyspace == nil {
return nil, ErrNotConnected
}
shards, err := sqlparser.GetShardList(query, bindVars, sc.shardMaxKeys)
shards, err := vtgate.GetShardList(query, bindVars, sc.shardMaxKeys)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 8206436

Please sign in to comment.