本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.TabletType函数的典型用法代码示例。如果您正苦于以下问题:Golang TabletType函数的具体用法?Golang TabletType怎么用?Golang TabletType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TabletType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestQueryShard
func TestQueryShard(t *testing.T) {
reflected, err := bson.Marshal(&reflectQueryShard{
Sql: "query",
BindVariables: map[string]interface{}{"val": int64(1)},
Keyspace: "keyspace",
Shards: []string{"shard1", "shard2"},
TabletType: topo.TabletType("replica"),
Session: &commonSession,
})
if err != nil {
t.Error(err)
}
want := string(reflected)
custom := QueryShard{
Sql: "query",
BindVariables: map[string]interface{}{"val": int64(1)},
Keyspace: "keyspace",
Shards: []string{"shard1", "shard2"},
TabletType: topo.TabletType("replica"),
Session: &commonSession,
}
encoded, err := bson.Marshal(&custom)
if err != nil {
t.Error(err)
}
got := string(encoded)
if want != got {
t.Errorf("want\n%#v, got\n%#v", want, got)
}
var unmarshalled QueryShard
err = bson.Unmarshal(encoded, &unmarshalled)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(custom, unmarshalled) {
t.Errorf("want \n%#v, got \n%#v", custom, unmarshalled)
}
unexpected, err := bson.Marshal(&badQueryShard{})
if err != nil {
t.Error(err)
}
err = bson.Unmarshal(unexpected, &unmarshalled)
want = "Unrecognized tag Extra"
if err == nil || want != err.Error() {
t.Errorf("want %v, got %v", want, err)
}
}
示例2: TestSession
func TestSession(t *testing.T) {
reflected, err := bson.Marshal(&reflectSession{
InTransaction: true,
ShardSessions: []*ShardSession{{
Keyspace: "a",
Shard: "0",
TabletType: topo.TabletType("replica"),
TransactionId: 1,
}, {
Keyspace: "b",
Shard: "1",
TabletType: topo.TabletType("master"),
TransactionId: 2,
}},
})
if err != nil {
t.Error(err)
}
want := string(reflected)
custom := commonSession
encoded, err := bson.Marshal(&custom)
if err != nil {
t.Error(err)
}
got := string(encoded)
if want != got {
t.Errorf("want\n%#v, got\n%#v", want, got)
}
var unmarshalled Session
err = bson.Unmarshal(encoded, &unmarshalled)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(custom, unmarshalled) {
t.Errorf("want \n%#v, got \n%#v", custom, unmarshalled)
}
unexpected, err := bson.Marshal(&badSession{})
if err != nil {
t.Error(err)
}
err = bson.Unmarshal(unexpected, &unmarshalled)
want = "Unrecognized tag Extra"
if err == nil || want != err.Error() {
t.Errorf("want %v, got %v", want, err)
}
}
示例3: getSrvKeyspace
func getSrvKeyspace(rpcClient *rpcplus.Client, cell, keyspace string, verbose bool) {
req := &topo.GetSrvKeyspaceArgs{
Cell: cell,
Keyspace: keyspace,
}
reply := &topo.SrvKeyspace{}
if err := rpcClient.Call("TopoReader.GetSrvKeyspace", req, reply); err != nil {
log.Fatalf("TopoReader.GetSrvKeyspace error: %v", err)
}
if verbose {
tabletTypes := make([]string, 0, len(reply.Partitions))
for t, _ := range reply.Partitions {
tabletTypes = append(tabletTypes, string(t))
}
sort.Strings(tabletTypes)
for _, t := range tabletTypes {
println(fmt.Sprintf("Partitions[%v] =", t))
for i, s := range reply.Partitions[topo.TabletType(t)].Shards {
println(fmt.Sprintf(" Shards[%v]=%v", i, s.KeyRange.String()))
}
}
for i, s := range reply.Shards {
println(fmt.Sprintf("Shards[%v]=%v", i, s.KeyRange.String()))
}
for i, t := range reply.TabletTypes {
println(fmt.Sprintf("TabletTypes[%v] = %v", i, t))
}
}
}
示例4: UnmarshalBson
// UnmarshalBson unmarshals QueryShard from buf.
func (qrs *QueryShard) UnmarshalBson(buf *bytes.Buffer) {
bson.Next(buf, 4)
kind := bson.NextByte(buf)
for kind != bson.EOO {
key := bson.ReadCString(buf)
switch key {
case "Sql":
qrs.Sql = bson.DecodeString(buf, kind)
case "BindVariables":
qrs.BindVariables = tproto.DecodeBindVariablesBson(buf, kind)
case "Keyspace":
qrs.Keyspace = bson.DecodeString(buf, kind)
case "TabletType":
qrs.TabletType = topo.TabletType(bson.DecodeString(buf, kind))
case "Shards":
qrs.Shards = bson.DecodeStringArray(buf, kind)
case "Session":
qrs.Session = new(Session)
qrs.Session.UnmarshalBson(buf)
default:
panic(bson.NewBsonError("Unrecognized tag %s", key))
}
kind = bson.NextByte(buf)
}
}
示例5: UnmarshalBson
func (sqs *StreamQueryKeyRange) UnmarshalBson(buf *bytes.Buffer) {
bson.Next(buf, 4)
kind := bson.NextByte(buf)
for kind != bson.EOO {
keyName := bson.ReadCString(buf)
switch keyName {
case "Sql":
sqs.Sql = bson.DecodeString(buf, kind)
case "BindVariables":
sqs.BindVariables = tproto.DecodeBindVariablesBson(buf, kind)
case "Keyspace":
sqs.Keyspace = bson.DecodeString(buf, kind)
case "KeyRange":
sqs.KeyRange = bson.DecodeString(buf, kind)
case "TabletType":
sqs.TabletType = topo.TabletType(bson.DecodeString(buf, kind))
case "Session":
sqs.Session = new(Session)
sqs.Session.UnmarshalBson(buf)
default:
panic(bson.NewBsonError("Unrecognized tag %s", keyName))
}
kind = bson.NextByte(buf)
}
}
示例6: Open
// for direct zk connection: vtzk://host:port/cell/keyspace/tabletType
// we always use a MetaConn, host and port are ignored.
// the driver name dictates if we use zk or zkocc, and streaming or not
//
// if user and password are specified in the URL, they will be used
// for each DB connection to the tablet's vttablet processes
func (driver *sDriver) Open(name string) (sc db.Conn, err error) {
if !strings.HasPrefix(name, "vtzk://") {
// add a default protocol talking to zk
name = "vtzk://" + name
}
u, err := url.Parse(name)
if err != nil {
return nil, err
}
dbi, tabletType := path.Split(u.Path)
dbi = strings.Trim(dbi, "/")
tabletType = strings.Trim(tabletType, "/")
cell, keyspace := path.Split(dbi)
cell = strings.Trim(cell, "/")
keyspace = strings.Trim(keyspace, "/")
var user, password string
if u.User != nil {
user = u.User.Username()
var ok bool
password, ok = u.User.Password()
if !ok {
return nil, fmt.Errorf("vt: need a password if a user is specified")
}
}
return Dial(driver.ts, cell, keyspace, topo.TabletType(tabletType), driver.stream, tablet.DefaultTimeout, user, password)
}
示例7: UnmarshalBson
// UnmarshalBson unmarshals BatchQueryShard from buf.
func (bqs *BatchQueryShard) UnmarshalBson(buf *bytes.Buffer, kind byte) {
bson.VerifyObject(kind)
bson.Next(buf, 4)
kind = bson.NextByte(buf)
for kind != bson.EOO {
keyName := bson.ReadCString(buf)
switch keyName {
case "Queries":
bqs.Queries = tproto.DecodeQueriesBson(buf, kind)
case "Keyspace":
bqs.Keyspace = bson.DecodeString(buf, kind)
case "Shards":
bqs.Shards = bson.DecodeStringArray(buf, kind)
case "TabletType":
bqs.TabletType = topo.TabletType(bson.DecodeString(buf, kind))
case "Session":
if kind != bson.Null {
bqs.Session = new(Session)
bqs.Session.UnmarshalBson(buf, kind)
}
default:
bson.Skip(buf, kind)
}
kind = bson.NextByte(buf)
}
}
示例8: TestHashResolve
func TestHashResolve(t *testing.T) {
hind := NewHashIndex(TEST_SHARDED, new(sandboxTopo), "")
nn, _ := sqltypes.BuildNumeric("11")
ks, shards, err := hind.Resolve(topo.TabletType("master"), []interface{}{1, int32(2), int64(3), uint(4), uint32(5), uint64(6), nn})
if err != nil {
t.Error(err)
}
want := []string{"-20", "-20", "40-60", "c0-e0", "60-80", "e0-", "a0-c0"}
if !reflect.DeepEqual(shards, want) {
t.Errorf("got\n%#v, want\n%#v", shards, want)
}
if ks != TEST_SHARDED {
t.Errorf("got %v, want TEST_SHARDED", ks)
}
_, _, err = hind.Resolve(topo.TabletType("master"), []interface{}{"aa"})
wantErr := "unexpected type for aa: string"
if err == nil || err.Error() != wantErr {
t.Errorf("got %v, want %v", err, wantErr)
}
}
示例9: initHeathCheck
func (agent *ActionAgent) initHeathCheck() {
if !agent.IsRunningHealthCheck() {
log.Infof("No target_tablet_type specified, disabling any health check")
return
}
log.Infof("Starting periodic health check every %v with target_tablet_type=%v", *healthCheckInterval, *targetTabletType)
t := timer.NewTimer(*healthCheckInterval)
servenv.OnTerm(func() {
// When we enter lameduck mode, we want to not call
// the health check any more. After this returns, we
// are guaranteed to not call it.
log.Info("Stopping periodic health check timer")
t.Stop()
// Now we can finish up and force ourselves to not healthy.
agent.terminateHealthChecks(topo.TabletType(*targetTabletType))
})
t.Start(func() {
agent.runHealthCheck(topo.TabletType(*targetTabletType))
})
}
示例10: handleExplorerRedirect
// handleExplorerRedirect returns the redirect target URL.
func handleExplorerRedirect(r *http.Request) (string, error) {
keyspace := r.FormValue("keyspace")
shard := r.FormValue("shard")
cell := r.FormValue("cell")
switch r.FormValue("type") {
case "keyspace":
if keyspace == "" {
return "", errors.New("keyspace is required for this redirect")
}
return explorer.GetKeyspacePath(keyspace), nil
case "shard":
if keyspace == "" || shard == "" {
return "", errors.New("keyspace and shard are required for this redirect")
}
return explorer.GetShardPath(keyspace, shard), nil
case "srv_keyspace":
if keyspace == "" || cell == "" {
return "", errors.New("keyspace and cell are required for this redirect")
}
return explorer.GetSrvKeyspacePath(cell, keyspace), nil
case "srv_shard":
if keyspace == "" || shard == "" || cell == "" {
return "", errors.New("keyspace, shard, and cell are required for this redirect")
}
return explorer.GetSrvShardPath(cell, keyspace, shard), nil
case "srv_type":
tabletType := r.FormValue("tablet_type")
if keyspace == "" || shard == "" || cell == "" || tabletType == "" {
return "", errors.New("keyspace, shard, cell, and tablet_type are required for this redirect")
}
return explorer.GetSrvTypePath(cell, keyspace, shard, topo.TabletType(tabletType)), nil
case "tablet":
alias := r.FormValue("alias")
if alias == "" {
return "", errors.New("alias is required for this redirect")
}
tabletAlias, err := topo.ParseTabletAliasString(alias)
if err != nil {
return "", fmt.Errorf("bad tablet alias %q: %v", alias, err)
}
return explorer.GetTabletPath(tabletAlias), nil
case "replication":
if keyspace == "" || shard == "" || cell == "" {
return "", errors.New("keyspace, shard, and cell are required for this redirect")
}
return explorer.GetReplicationSlaves(cell, keyspace, shard), nil
default:
return "", errors.New("bad redirect type")
}
}
示例11: initHeathCheck
func initHeathCheck(agent *tabletmanager.ActionAgent) {
if *targetTabletType == "" {
log.Infof("No target_tablet_type specified, disabling any health check")
return
}
log.Infof("Starting up periodic health check every %v with target_tablet_type=%v", *healthCheckInterval, *targetTabletType)
go func() {
t := time.NewTicker(*healthCheckInterval)
for _ = range t.C {
agent.RunHealthCheck(topo.TabletType(*targetTabletType))
}
}()
}
示例12: GetSrvTabletTypesPerShard
func (zkts *Server) GetSrvTabletTypesPerShard(cell, keyspace, shard string) ([]topo.TabletType, error) {
zkSgShardPath := zkPathForVtShard(cell, keyspace, shard)
children, _, err := zkts.zconn.Children(zkSgShardPath)
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNONODE) {
err = topo.ErrNoNode
}
return nil, err
}
result := make([]topo.TabletType, len(children))
for i, tt := range children {
result[i] = topo.TabletType(tt)
}
return result, nil
}
示例13: UnmarshalBson
func (spm *SessionParams) UnmarshalBson(buf *bytes.Buffer) {
bson.Next(buf, 4)
kind := bson.NextByte(buf)
for kind != bson.EOO {
key := bson.ReadCString(buf)
switch key {
case "TabletType":
spm.TabletType = topo.TabletType(bson.DecodeString(buf, kind))
default:
panic(bson.NewBsonError("Unrecognized tag %s", key))
}
kind = bson.NextByte(buf)
}
}
示例14: TestSessionParams
func TestSessionParams(t *testing.T) {
reflected, err := bson.Marshal(&reflectSessionParams{topo.TabletType("master")})
if err != nil {
t.Error(err)
}
want := string(reflected)
custom := SessionParams{topo.TabletType("master")}
encoded, err := bson.Marshal(&custom)
if err != nil {
t.Error(err)
}
got := string(encoded)
if want != got {
t.Errorf("want\n%#v, got\n%#v", want, got)
}
var unmarshalled SessionParams
err = bson.Unmarshal(encoded, &unmarshalled)
if err != nil {
t.Error(err)
}
if custom != unmarshalled {
t.Errorf("want %v, got %#v", custom, unmarshalled)
}
unexpected, err := bson.Marshal(&badSessionParams{})
if err != nil {
t.Error(err)
}
err = bson.Unmarshal(unexpected, &unmarshalled)
want = "Unrecognized tag Extra"
if err == nil || want != err.Error() {
t.Errorf("want %v, got %v", want, err)
}
}
示例15: getEndPoints
func getEndPoints(rpcClient *rpcplus.Client, cell, keyspace, shard, tabletType string, verbose bool) {
req := &topo.GetEndPointsArgs{
Cell: cell,
Keyspace: keyspace,
Shard: shard,
TabletType: topo.TabletType(tabletType),
}
reply := &topo.EndPoints{}
if err := rpcClient.Call("TopoReader.GetEndPoints", req, reply); err != nil {
log.Fatalf("TopoReader.GetEndPoints error: %v", err)
}
if verbose {
for i, e := range reply.Entries {
println(fmt.Sprintf("Entries[%v] = %v %v", i, e.Uid, e.Host))
}
}
}