vtcombo now also supports vttest topology param.

This commit is contained in:
Alain Jobart 2016-05-25 10:36:28 -07:00
Родитель 508ff06dcc
Коммит a8731c5ce1
6 изменённых файлов: 193 добавлений и 28 удалений

Просмотреть файл

@ -38,10 +38,15 @@ const (
)
var (
// old-style parameters, will go away soon
topology = flag.String("topology", "", "Define which shards exist in the test topology in the form <keyspace>/<shardrange>:<dbname>,... The dbname must be unique among all shards, since they share a MySQL instance in the test environment.")
shardingColumnName = flag.String("sharding_column_name", "", "Specifies the column to use for sharding operations")
shardingColumnType = flag.String("sharding_column_type", "", "Specifies the type of the column to use for sharding operations")
vschemaFile = flag.String("vschema", "", "vschema file")
// new-style parameter
protoTopo = flag.String("proto_topo", "", "vttest proto definition of the topology, encoded in compact text format. See vttest.proto for more information.")
vschemaFile = flag.String("vschema", "", "vschema file")
ts topo.Server
)
@ -98,7 +103,11 @@ func main() {
log.Infof("v3 is enabled: loaded vschema from file")
// tablets configuration and init
initTabletMap(ts, *topology, mysqld, dbcfgs, formal, mycnf)
if *protoTopo != "" {
initTabletMapProto(ts, *protoTopo, mysqld, dbcfgs, formal, mycnf)
} else {
initTabletMap(ts, *topology, mysqld, dbcfgs, formal, mycnf)
}
// vtgate configuration and init
resilientSrvTopoServer := vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer")

Просмотреть файл

@ -8,6 +8,7 @@ import (
"time"
log "github.com/golang/glog"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"github.com/youtube/vitess/go/sqltypes"
@ -31,6 +32,7 @@ import (
replicationdatapb "github.com/youtube/vitess/go/vt/proto/replicationdata"
tabletmanagerdatapb "github.com/youtube/vitess/go/vt/proto/tabletmanagerdata"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
vttestpb "github.com/youtube/vitess/go/vt/proto/vttest"
)
// tablet contains all the data for an individual tablet.
@ -193,6 +195,160 @@ func initTabletMap(ts topo.Server, topology string, mysqld mysqlctl.MysqlDaemon,
}
}
// initTabletMapProto creates the action agents and associated data structures
// for all tablets, based on the vttest proto parameter.
func initTabletMapProto(ts topo.Server, topoProto string, mysqld mysqlctl.MysqlDaemon, dbcfgs dbconfigs.DBConfigs, formal *vindexes.VSchemaFormal, mycnf *mysqlctl.Mycnf) {
// parse the input topology
var tpb *vttestpb.VTTestTopology
if err := proto.UnmarshalText(topoProto, tpb); err != nil {
log.Fatalf("cannot parse topology: %v", err)
}
tabletMap = make(map[uint32]*tablet)
ctx := context.Background()
// disable publishing of stats from query service
flag.Lookup("queryserver-config-enable-publish-stats").Value.Set("false")
// iterate through the keyspaces
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil)
var uid uint32 = 1
for _, kpb := range tpb.Keyspaces {
keyspace := kpb.Name
// if we have a redirect, create a completely redirected
// keyspace and move on
if kpb.ServedFrom != "" {
if err := ts.CreateKeyspace(ctx, keyspace, &topodatapb.Keyspace{
ServedFroms: []*topodatapb.Keyspace_ServedFrom{
{
TabletType: topodatapb.TabletType_MASTER,
Keyspace: kpb.ServedFrom,
},
{
TabletType: topodatapb.TabletType_REPLICA,
Keyspace: kpb.ServedFrom,
},
{
TabletType: topodatapb.TabletType_RDONLY,
Keyspace: kpb.ServedFrom,
},
},
}); err != nil {
log.Fatalf("CreateKeyspace(%v) failed: %v", keyspace, err)
}
continue
}
// create a regular keyspace
sct, err := key.ParseKeyspaceIDType(kpb.ShardingColumnType)
if err != nil {
log.Fatalf("parseKeyspaceIDType(%v) failed: %v", kpb.ShardingColumnType, err)
}
if err := ts.CreateKeyspace(ctx, keyspace, &topodatapb.Keyspace{
ShardingColumnName: kpb.ShardingColumnName,
ShardingColumnType: sct,
}); err != nil {
log.Fatalf("CreateKeyspace(%v) failed: %v", keyspace, err)
}
// iterate through the shards
for _, spb := range kpb.Shards {
shard := spb.Name
dbname := spb.DbName
dbcfgs.App.DbName = dbname
// create the master
alias := &topodatapb.TabletAlias{
Cell: cell,
Uid: uid,
}
log.Infof("Creating master tablet %v for %v/%v", topoproto.TabletAliasString(alias), keyspace, shard)
flag.Lookup("debug-url-prefix").Value.Set(fmt.Sprintf("/debug-%d", uid))
masterController := tabletserver.NewServer()
masterAgent := tabletmanager.NewComboActionAgent(ctx, ts, alias, int32(8000+uid), int32(9000+uid), masterController, dbcfgs, mysqld, keyspace, shard, dbname, "replica")
if err := masterAgent.TabletExternallyReparented(ctx, ""); err != nil {
log.Fatalf("TabletExternallyReparented failed on master: %v", err)
}
tabletMap[uid] = &tablet{
keyspace: keyspace,
shard: shard,
tabletType: topodatapb.TabletType_MASTER,
dbname: dbname,
qsc: masterController,
agent: masterAgent,
}
uid++
// create a replica slave
alias = &topodatapb.TabletAlias{
Cell: cell,
Uid: uid,
}
log.Infof("Creating replica tablet %v for %v/%v", topoproto.TabletAliasString(alias), keyspace, shard)
flag.Lookup("debug-url-prefix").Value.Set(fmt.Sprintf("/debug-%d", uid))
replicaController := tabletserver.NewServer()
tabletMap[uid] = &tablet{
keyspace: keyspace,
shard: shard,
tabletType: topodatapb.TabletType_REPLICA,
dbname: dbname,
qsc: replicaController,
agent: tabletmanager.NewComboActionAgent(ctx, ts, alias, int32(8000+uid), int32(9000+uid), replicaController, dbcfgs, mysqld, keyspace, shard, dbname, "replica"),
}
uid++
// create a rdonly slave
alias = &topodatapb.TabletAlias{
Cell: cell,
Uid: uid,
}
log.Infof("Creating rdonly tablet %v for %v/%v", topoproto.TabletAliasString(alias), keyspace, shard)
flag.Lookup("debug-url-prefix").Value.Set(fmt.Sprintf("/debug-%d", uid))
rdonlyController := tabletserver.NewServer()
tabletMap[uid] = &tablet{
keyspace: keyspace,
shard: shard,
tabletType: topodatapb.TabletType_RDONLY,
dbname: dbname,
qsc: rdonlyController,
agent: tabletmanager.NewComboActionAgent(ctx, ts, alias, int32(8000+uid), int32(9000+uid), rdonlyController, dbcfgs, mysqld, keyspace, shard, dbname, "rdonly"),
}
uid++
}
// Rebuild the SrvKeyspace object, we we can support
// range-based sharding queries.
if err := wr.RebuildKeyspaceGraph(ctx, keyspace, nil); err != nil {
log.Fatalf("cannot rebuild %v: %v", keyspace, err)
}
}
// Register the tablet dialer for tablet server
tabletconn.RegisterDialer("internal", dialer)
*tabletconn.TabletProtocol = "internal"
// Register the tablet manager client factory for tablet manager
tmclient.RegisterTabletManagerClientFactory("internal", func() tmclient.TabletManagerClient {
return &internalTabletManagerClient{}
})
*tmclient.TabletManagerProtocol = "internal"
// run healthcheck on all vttablets
tmc := tmclient.NewTabletManagerClient()
for _, tablet := range tabletMap {
tabletInfo, err := ts.GetTablet(ctx, tablet.agent.TabletAlias)
if err != nil {
log.Fatalf("cannot find tablet: %+v", tablet.agent.TabletAlias)
}
tmc.RunHealthCheck(ctx, tabletInfo.Tablet)
}
}
//
// TabletConn implementation
//

Просмотреть файл

@ -52,7 +52,7 @@ type Keyspace struct {
// sharding_column_type for this keyspace. Used for v2 calls, but not for v3.
ShardingColumnType string `protobuf:"bytes,4,opt,name=sharding_column_type,json=shardingColumnType" json:"sharding_column_type,omitempty"`
// redirects all traffic to another keyspace. If set, shards is ignored.
Redirect string `protobuf:"bytes,5,opt,name=redirect" json:"redirect,omitempty"`
ServedFrom string `protobuf:"bytes,5,opt,name=served_from,json=servedFrom" json:"served_from,omitempty"`
}
func (m *Keyspace) Reset() { *m = Keyspace{} }
@ -92,20 +92,20 @@ func init() {
}
var fileDescriptor0 = []byte{
// 227 bytes of a gzipped FileDescriptorProto
// 234 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x2b, 0x29, 0x49,
0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x4c, 0xb8, 0x58,
0x83, 0x33, 0x12, 0x8b, 0x52, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, 0x18, 0x15,
0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x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0x00, 0x00,
0x25, 0x58, 0xb0, 0xe9, 0x08, 0x01, 0xca, 0x08, 0xc9, 0x73, 0x71, 0x17, 0xa7, 0x16, 0x95, 0xa5,
0xa6, 0xc4, 0xa7, 0x15, 0xe5, 0xe7, 0x4a, 0xb0, 0x82, 0x15, 0x72, 0x41, 0x84, 0xdc, 0x80, 0x22,
0x4a, 0x0e, 0x5c, 0x7c, 0x61, 0x21, 0x21, 0x40, 0xc7, 0x85, 0xe4, 0x17, 0xe4, 0xe7, 0xe4, 0xa7,
0x57, 0x0a, 0xe9, 0x71, 0x71, 0x66, 0x43, 0x7d, 0x57, 0x0c, 0xf4, 0x16, 0xc8, 0x03, 0x02, 0x30,
0x0f, 0xc0, 0xbc, 0x1d, 0x84, 0x50, 0x92, 0xc4, 0x06, 0x0e, 0x53, 0x63, 0x40, 0x00, 0x00, 0x00,
0xff, 0xff, 0xad, 0x70, 0x4f, 0xdd, 0x63, 0x01, 0x00, 0x00,
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace Vitess\Proto\Vttest {
public $sharding_column_type = null;
/** @var string */
public $redirect = null;
public $served_from = null;
/** @var \Closure[] */
@ -62,10 +62,10 @@ namespace Vitess\Proto\Vttest {
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f);
// OPTIONAL STRING redirect = 5
// OPTIONAL STRING served_from = 5
$f = new \DrSlump\Protobuf\Field();
$f->number = 5;
$f->name = "redirect";
$f->name = "served_from";
$f->type = \DrSlump\Protobuf::TYPE_STRING;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f);
@ -246,39 +246,39 @@ namespace Vitess\Proto\Vttest {
}
/**
* Check if <redirect> has a value
* Check if <served_from> has a value
*
* @return boolean
*/
public function hasRedirect(){
public function hasServedFrom(){
return $this->_has(5);
}
/**
* Clear <redirect> value
* Clear <served_from> value
*
* @return \Vitess\Proto\Vttest\Keyspace
*/
public function clearRedirect(){
public function clearServedFrom(){
return $this->_clear(5);
}
/**
* Get <redirect> value
* Get <served_from> value
*
* @return string
*/
public function getRedirect(){
public function getServedFrom(){
return $this->_get(5);
}
/**
* Set <redirect> value
* Set <served_from> value
*
* @param string $value
* @return \Vitess\Proto\Vttest\Keyspace
*/
public function setRedirect( $value){
public function setServedFrom( $value){
return $this->_set(5, $value);
}
}

Просмотреть файл

@ -37,7 +37,7 @@ message Keyspace {
string sharding_column_type = 4;
// redirects all traffic to another keyspace. If set, shards is ignored.
string redirect = 5;
string served_from = 5;
}
// VTTestTopology describes the keyspaces in the topology.

Просмотреть файл

@ -19,7 +19,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
name='vttest.proto',
package='vttest',
syntax='proto3',
serialized_pb=_b('\n\x0cvttest.proto\x12\x06vttest\"&\n\x05Shard\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07\x64\x62_name\x18\x02 \x01(\t\"\x85\x01\n\x08Keyspace\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1d\n\x06shards\x18\x02 \x03(\x0b\x32\r.vttest.Shard\x12\x1c\n\x14sharding_column_name\x18\x03 \x01(\t\x12\x1c\n\x14sharding_column_type\x18\x04 \x01(\t\x12\x10\n\x08redirect\x18\x05 \x01(\t\"5\n\x0eVTTestTopology\x12#\n\tkeyspaces\x18\x01 \x03(\x0b\x32\x10.vttest.Keyspaceb\x06proto3')
serialized_pb=_b('\n\x0cvttest.proto\x12\x06vttest\"&\n\x05Shard\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07\x64\x62_name\x18\x02 \x01(\t\"\x88\x01\n\x08Keyspace\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1d\n\x06shards\x18\x02 \x03(\x0b\x32\r.vttest.Shard\x12\x1c\n\x14sharding_column_name\x18\x03 \x01(\t\x12\x1c\n\x14sharding_column_type\x18\x04 \x01(\t\x12\x13\n\x0bserved_from\x18\x05 \x01(\t\"5\n\x0eVTTestTopology\x12#\n\tkeyspaces\x18\x01 \x03(\x0b\x32\x10.vttest.Keyspaceb\x06proto3')
)
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
@ -100,7 +100,7 @@ _KEYSPACE = _descriptor.Descriptor(
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='redirect', full_name='vttest.Keyspace.redirect', index=4,
name='served_from', full_name='vttest.Keyspace.served_from', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
@ -119,7 +119,7 @@ _KEYSPACE = _descriptor.Descriptor(
oneofs=[
],
serialized_start=65,
serialized_end=198,
serialized_end=201,
)
@ -149,8 +149,8 @@ _VTTESTTOPOLOGY = _descriptor.Descriptor(
extension_ranges=[],
oneofs=[
],
serialized_start=200,
serialized_end=253,
serialized_start=203,
serialized_end=256,
)
_KEYSPACE.fields_by_name['shards'].message_type = _SHARD