Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from youtube/master
Browse files Browse the repository at this point in the history
pull
  • Loading branch information
yangxuanjia authored Nov 28, 2017
2 parents 925e14a + c36dd99 commit 1095e58
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 516 deletions.
12 changes: 0 additions & 12 deletions go/vt/topo/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ func IsSlaveType(tt topodatapb.TabletType) bool {
return true
}

// TabletComplete validates and normalizes the tablet. If the shard name
// contains a '-' it is going to try to infer the keyrange from it.
func TabletComplete(tablet *topodatapb.Tablet) error {
shard, kr, err := ValidateShardName(tablet.Shard)
if err != nil {
return err
}
tablet.Shard = shard
tablet.KeyRange = kr
return nil
}

// NewTablet create a new Tablet record with the given id, cell, and hostname.
func NewTablet(uid uint32, cell, host string) *topodatapb.Tablet {
return &topodatapb.Tablet{
Expand Down
294 changes: 192 additions & 102 deletions go/vt/vtgate/vtgateservice/vtgateservice_testing/mock_vtgateservice.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions go/vt/vttablet/endtoend/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestCommit(t *testing.T) {
tag: "Transactions/TotalCount",
diff: 2,
}, {
tag: "Transactions/Histograms/Completed/Count",
tag: "Transactions/Histograms/commit/Count",
diff: 2,
}, {
tag: "Queries/TotalCount",
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestRollback(t *testing.T) {
tag: "Transactions/TotalCount",
diff: 1,
}, {
tag: "Transactions/Histograms/Aborted/Count",
tag: "Transactions/Histograms/rollback/Count",
diff: 1,
}, {
tag: "Queries/Histograms/BEGIN/Count",
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestAutoCommit(t *testing.T) {
tag: "Transactions/TotalCount",
diff: 2,
}, {
tag: "Transactions/Histograms/Completed/Count",
tag: "Transactions/Histograms/commit/Count",
diff: 2,
}, {
tag: "Queries/TotalCount",
Expand Down
8 changes: 3 additions & 5 deletions go/vt/vttablet/tabletmanager/init_tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
}

// parse and validate shard name
shard, _, err := topo.ValidateShardName(*initShard)
shard, keyRange, err := topo.ValidateShardName(*initShard)
if err != nil {
return fmt.Errorf("cannot validate shard name %v: %v", *initShard, err)
}
Expand Down Expand Up @@ -155,7 +155,8 @@ func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
Hostname: hostname,
PortMap: make(map[string]int32),
Keyspace: *initKeyspace,
Shard: *initShard,
Shard: shard,
KeyRange: keyRange,
Type: tabletType,
DbNameOverride: *initDbNameOverride,
Tags: initTags,
Expand All @@ -166,9 +167,6 @@ func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
if gRPCPort != 0 {
tablet.PortMap["grpc"] = gRPCPort
}
if err := topo.TabletComplete(tablet); err != nil {
return fmt.Errorf("InitTablet TabletComplete failed: %v", err)
}

// Now try to create the record (it will also fix up the
// ShardReplication record if necessary).
Expand Down
15 changes: 12 additions & 3 deletions go/vt/vttablet/tabletmanager/init_tablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ func TestInitTablet(t *testing.T) {

// 1. Initialize the tablet as REPLICA.
// This will create the respective topology records.
// We use a capitalized shard name here, to make sure the
// Keyrange computation works, fills in the KeyRange, and converts
// it to lower case.
*tabletHostname = "localhost"
*initKeyspace = "test_keyspace"
*initShard = "-80"
*initShard = "-C0"
*initTabletType = "replica"
tabletAlias = &topodatapb.TabletAlias{
Cell: "cell1",
Expand All @@ -71,7 +74,7 @@ func TestInitTablet(t *testing.T) {
if err := agent.InitTablet(port, gRPCPort); err != nil {
t.Fatalf("InitTablet(type) failed: %v", err)
}
si, err := ts.GetShard(ctx, "test_keyspace", "-80")
si, err := ts.GetShard(ctx, "test_keyspace", "-c0")
if err != nil {
t.Fatalf("GetShard failed: %v", err)
}
Expand All @@ -94,6 +97,12 @@ func TestInitTablet(t *testing.T) {
if ti.PortMap["grpc"] != gRPCPort {
t.Errorf("wrong gRPC port for tablet: %v", ti.PortMap["grpc"])
}
if ti.Shard != "-c0" {
t.Errorf("wrong shard for tablet: %v", ti.Shard)
}
if string(ti.KeyRange.Start) != "" || string(ti.KeyRange.End) != "\xc0" {
t.Errorf("wrong KeyRange for tablet: %v", ti.KeyRange)
}
if got := agent._tabletExternallyReparentedTime; !got.IsZero() {
t.Fatalf("REPLICA tablet should not have an ExternallyReparentedTimestamp set: %v", got)
}
Expand All @@ -102,7 +111,7 @@ func TestInitTablet(t *testing.T) {
// (This simulates the case where the MasterAlias in the shard record says
// that we are the master but the tablet record says otherwise. In that case,
// we assume we are not the MASTER.)
si, err = agent.TopoServer.UpdateShardFields(ctx, "test_keyspace", "-80", func(si *topo.ShardInfo) error {
si, err = agent.TopoServer.UpdateShardFields(ctx, "test_keyspace", "-c0", func(si *topo.ShardInfo) error {
si.MasterAlias = tabletAlias
return nil
})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions go/vt/vttablet/tabletserver/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func (axp *TxPool) LocalBegin(ctx context.Context, useFoundRows bool, txIsolatio
func (axp *TxPool) LocalCommit(ctx context.Context, conn *TxConnection, messager *messager.Engine) error {
defer conn.conclude(TxCommit)
defer messager.LockDB(conn.NewMessages, conn.ChangedMessages)()
txStats.Add("Completed", time.Now().Sub(conn.StartTime))
if _, err := conn.Exec(ctx, "commit", 1, false); err != nil {
conn.Close()
return err
Expand All @@ -277,7 +276,6 @@ func (axp *TxPool) LocalConclude(ctx context.Context, conn *TxConnection) {

func (axp *TxPool) localRollback(ctx context.Context, conn *TxConnection) error {
defer conn.conclude(TxRollback)
txStats.Add("Aborted", time.Now().Sub(conn.StartTime))
if _, err := conn.Exec(ctx, "rollback", 1, false); err != nil {
conn.Close()
return err
Expand Down Expand Up @@ -404,6 +402,7 @@ func (txc *TxConnection) log(conclusion string) {
duration := txc.EndTime.Sub(txc.StartTime)
tabletenv.UserTransactionCount.Add([]string{username, conclusion}, 1)
tabletenv.UserTransactionTimesNs.Add([]string{username, conclusion}, int64(duration))
txStats.Add(conclusion, duration)
if txc.LogToFile.Get() != 0 {
log.Infof("Logged transaction: %s", txc.Format(nil))
}
Expand Down
Loading

0 comments on commit 1095e58

Please sign in to comment.