• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang topo.NewShardInfo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.NewShardInfo函数的典型用法代码示例。如果您正苦于以下问题:Golang NewShardInfo函数的具体用法?Golang NewShardInfo怎么用?Golang NewShardInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewShardInfo函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: CreateShard

// CreateShard is part of the topo.Server interface
func (zkts *Server) CreateShard(ctx context.Context, keyspace, shard string, value *pb.Shard) error {
	shardPath := path.Join(globalKeyspacesPath, keyspace, "shards", shard)
	pathList := []string{
		shardPath,
		path.Join(shardPath, "action"),
		path.Join(shardPath, "actionlog"),
	}

	alreadyExists := false
	for i, zkPath := range pathList {
		c := ""
		if i == 0 {
			c = jscfg.ToJSON(value)
		}
		_, err := zk.CreateRecursive(zkts.zconn, zkPath, c, 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
		if err != nil {
			if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
				alreadyExists = true
			} else {
				return fmt.Errorf("error creating shard: %v %v", zkPath, err)
			}
		}
	}
	if alreadyExists {
		return topo.ErrNodeExists
	}

	event.Dispatch(&events.ShardChange{
		ShardInfo: *topo.NewShardInfo(keyspace, shard, value, -1),
		Status:    "created",
	})
	return nil
}
开发者ID:haoqoo,项目名称:vitess,代码行数:34,代码来源:shard.go


示例2: CreateShard

// CreateShard implements topo.Server.
func (s *Server) CreateShard(ctx context.Context, keyspace, shard string, value *topo.Shard) error {
	data := jscfg.ToJSON(value)
	global := s.getGlobal()

	resp, err := global.Create(shardFilePath(keyspace, shard), data, 0 /* ttl */)
	if err != nil {
		return convertError(err)
	}
	if err := initLockFile(global, shardDirPath(keyspace, shard)); err != nil {
		return err
	}

	// We don't return ErrBadResponse in this case because the Create() suceeeded
	// and we don't really need the version to satisfy our contract - we're only
	// logging it.
	version := int64(-1)
	if resp.Node != nil {
		version = int64(resp.Node.ModifiedIndex)
	}
	event.Dispatch(&events.ShardChange{
		ShardInfo: *topo.NewShardInfo(keyspace, shard, value, version),
		Status:    "created",
	})
	return nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:26,代码来源:shard.go


示例3: TestReparentSyslog

func TestReparentSyslog(t *testing.T) {
	wantSev, wantMsg := syslog.LOG_INFO, "keyspace-123/shard-123 [reparent cell-0000012345 -> cell-0000054321] status"
	tc := &Reparent{
		ShardInfo: *topo.NewShardInfo("keyspace-123", "shard-123", nil, -1),
		OldMaster: topo.Tablet{
			Alias: topo.TabletAlias{
				Cell: "cell",
				Uid:  12345,
			},
		},
		NewMaster: topo.Tablet{
			Alias: topo.TabletAlias{
				Cell: "cell",
				Uid:  54321,
			},
		},
		StatusUpdater: base.StatusUpdater{Status: "status"},
	}
	gotSev, gotMsg := tc.Syslog()

	if gotSev != wantSev {
		t.Errorf("wrong severity: got %v, want %v", gotSev, wantSev)
	}
	if gotMsg != wantMsg {
		t.Errorf("wrong message: got %v, want %v", gotMsg, wantMsg)
	}
}
开发者ID:chinna1986,项目名称:vitess,代码行数:27,代码来源:reparent_syslog_test.go


示例4: siBytes

func siBytes(start, end string) *topo.ShardInfo {
	return topo.NewShardInfo("keyspace", start+"-"+end, &topo.Shard{
		KeyRange: key.KeyRange{
			Start: key.KeyspaceId(start),
			End:   key.KeyspaceId(end),
		},
	}, 0)
}
开发者ID:nangong92t,项目名称:go_src,代码行数:8,代码来源:row_splitter_test.go


示例5: GetShard

func (topoServer *fakeTopo) GetShard(ctx context.Context, keyspace string, shard string) (*topo.ShardInfo, error) {
	value := &pb.Shard{
		MasterAlias: &pb.TabletAlias{
			Cell: "test_cell",
			Uid:  0,
		},
	}
	return topo.NewShardInfo(keyspace, shard, value, 0), nil
}
开发者ID:springlee,项目名称:vitess,代码行数:9,代码来源:schemamanager_test.go


示例6: TestMigrateServedFromSyslogReverse

func TestMigrateServedFromSyslogReverse(t *testing.T) {
	wantSev, wantMsg := syslog.LOG_INFO, "keyspace-1 [migrate served-from keyspace-2/source-shard <- keyspace-1/dest-shard] status"
	ev := &MigrateServedFrom{
		Keyspace:         *topo.NewKeyspaceInfo("keyspace-1", nil, -1),
		SourceShard:      *topo.NewShardInfo("keyspace-2", "source-shard", nil, -1),
		DestinationShard: *topo.NewShardInfo("keyspace-1", "dest-shard", nil, -1),
		Reverse:          true,
		StatusUpdater:    base.StatusUpdater{Status: "status"},
	}
	gotSev, gotMsg := ev.Syslog()

	if gotSev != wantSev {
		t.Errorf("wrong severity: got %v, want %v", gotSev, wantSev)
	}
	if gotMsg != wantMsg {
		t.Errorf("wrong message: got %v, want %v", gotMsg, wantMsg)
	}
}
开发者ID:chinna1986,项目名称:vitess,代码行数:18,代码来源:migrate_syslog_test.go


示例7: siBytes

func siBytes(start, end string) *topo.ShardInfo {
	s := hex.EncodeToString([]byte(start))
	e := hex.EncodeToString([]byte(end))
	return topo.NewShardInfo("keyspace", s+"-"+e, &topodatapb.Shard{
		KeyRange: &topodatapb.KeyRange{
			Start: []byte(start),
			End:   []byte(end),
		},
	}, 0)
}
开发者ID:littleyang,项目名称:vitess,代码行数:10,代码来源:row_splitter_test.go


示例8: si

func si(start, end string) *topo.ShardInfo {
	s := hki(start)
	e := hki((end))
	return topo.NewShardInfo("keyspace", s.String()+"-"+e.String(), &topo.Shard{
		KeyRange: key.KeyRange{
			Start: s,
			End:   e,
		},
	}, 0)
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:10,代码来源:split_test.go


示例9: si

func si(start, end string) *topo.ShardInfo {
	s := hki(start)
	e := hki(end)
	return topo.NewShardInfo("keyspace", start+"-"+end, &pb.Shard{
		KeyRange: &pb.KeyRange{
			Start: s,
			End:   e,
		},
	}, 0)
}
开发者ID:richarwu,项目名称:vitess,代码行数:10,代码来源:split_test.go


示例10: DeleteShard

// DeleteShard implements topo.Server.
func (s *Server) DeleteShard(ctx context.Context, keyspace, shard string) error {
	_, err := s.getGlobal().Delete(shardDirPath(keyspace, shard), true /* recursive */)
	if err != nil {
		return convertError(err)
	}

	event.Dispatch(&events.ShardChange{
		ShardInfo: *topo.NewShardInfo(keyspace, shard, nil, -1),
		Status:    "deleted",
	})
	return nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:13,代码来源:shard.go


示例11: TestMigrateServedTypesSyslogReverse

func TestMigrateServedTypesSyslogReverse(t *testing.T) {
	wantSev, wantMsg := syslog.LOG_INFO, "keyspace-1 [migrate served-types {src1, src2} <- {dst1, dst2}] status"
	ev := &MigrateServedTypes{
		Keyspace: *topo.NewKeyspaceInfo("keyspace-1", nil, -1),
		SourceShards: []*topo.ShardInfo{
			topo.NewShardInfo("keyspace-1", "src1", nil, -1),
			topo.NewShardInfo("keyspace-1", "src2", nil, -1),
		},
		DestinationShards: []*topo.ShardInfo{
			topo.NewShardInfo("keyspace-1", "dst1", nil, -1),
			topo.NewShardInfo("keyspace-1", "dst2", nil, -1),
		},
		Reverse:       true,
		StatusUpdater: base.StatusUpdater{Status: "status"},
	}
	gotSev, gotMsg := ev.Syslog()

	if gotSev != wantSev {
		t.Errorf("wrong severity: got %v, want %v", gotSev, wantSev)
	}
	if gotMsg != wantMsg {
		t.Errorf("wrong message: got %v, want %v", gotMsg, wantMsg)
	}
}
开发者ID:chinna1986,项目名称:vitess,代码行数:24,代码来源:migrate_syslog_test.go


示例12: TestShardChangeSyslog

func TestShardChangeSyslog(t *testing.T) {
	wantSev, wantMsg := syslog.LOG_INFO, "keyspace-123/shard-123 [shard] status"
	sc := &ShardChange{
		ShardInfo: *topo.NewShardInfo("keyspace-123", "shard-123", nil, -1),
		Status:    "status",
	}
	gotSev, gotMsg := sc.Syslog()

	if gotSev != wantSev {
		t.Errorf("wrong severity: got %v, want %v", gotSev, wantSev)
	}
	if gotMsg != wantMsg {
		t.Errorf("wrong message: got %v, want %v", gotMsg, wantMsg)
	}
}
开发者ID:chinna1986,项目名称:vitess,代码行数:15,代码来源:shard_change_syslog_test.go


示例13: GetShard

func (zkts *Server) GetShard(keyspace, shard string) (*topo.ShardInfo, error) {
	shardPath := path.Join(globalKeyspacesPath, keyspace, "shards", shard)
	data, _, err := zkts.zconn.Get(shardPath)
	if err != nil {
		if zookeeper.IsError(err, zookeeper.ZNONODE) {
			err = topo.ErrNoNode
		}
		return nil, err
	}

	shardInfo, err := topo.NewShardInfo(keyspace, shard, data)
	if err != nil {
		return nil, err
	}
	return shardInfo, nil
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:16,代码来源:global.go


示例14: DeleteShard

// DeleteShard is part of the topo.Server interface
func (zkts *Server) DeleteShard(ctx context.Context, keyspace, shard string) error {
	shardPath := path.Join(globalKeyspacesPath, keyspace, "shards", shard)
	err := zk.DeleteRecursive(zkts.zconn, shardPath, -1)
	if err != nil {
		if zookeeper.IsError(err, zookeeper.ZNONODE) {
			err = topo.ErrNoNode
		}
		return err
	}

	event.Dispatch(&events.ShardChange{
		ShardInfo: *topo.NewShardInfo(keyspace, shard, nil, -1),
		Status:    "deleted",
	})
	return nil
}
开发者ID:haoqoo,项目名称:vitess,代码行数:17,代码来源:shard.go


示例15: GetShard

// GetShard implements topo.Server.
func (s *Server) GetShard(ctx context.Context, keyspace, shard string) (*topo.ShardInfo, error) {
	resp, err := s.getGlobal().Get(shardFilePath(keyspace, shard), false /* sort */, false /* recursive */)
	if err != nil {
		return nil, convertError(err)
	}
	if resp.Node == nil {
		return nil, ErrBadResponse
	}

	value := &topo.Shard{}
	if err := json.Unmarshal([]byte(resp.Node.Value), value); err != nil {
		return nil, fmt.Errorf("bad shard data (%v): %q", err, resp.Node.Value)
	}

	return topo.NewShardInfo(keyspace, shard, value, int64(resp.Node.ModifiedIndex)), nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:17,代码来源:shard.go


示例16: GetShard

// GetShard is part of the topo.Server interface
func (zkts *Server) GetShard(ctx context.Context, keyspace, shard string) (*topo.ShardInfo, error) {
	shardPath := path.Join(globalKeyspacesPath, keyspace, "shards", shard)
	data, stat, err := zkts.zconn.Get(shardPath)
	if err != nil {
		if zookeeper.IsError(err, zookeeper.ZNONODE) {
			err = topo.ErrNoNode
		}
		return nil, err
	}

	s := &pb.Shard{}
	if err = json.Unmarshal([]byte(data), s); err != nil {
		return nil, fmt.Errorf("bad shard data %v", err)
	}

	return topo.NewShardInfo(keyspace, shard, s, int64(stat.Version())), nil
}
开发者ID:haoqoo,项目名称:vitess,代码行数:18,代码来源:shard.go


示例17: rebuildShard

// Update shard file with new master, replicas, etc.
//
// Re-read from TopologyServer to make sure we are using the side
// effects of all actions.
//
// This function should only be used with an action lock on the shard
// - otherwise the consistency of the serving graph data can't be
// guaranteed.
func (wr *Wrangler) rebuildShard(keyspace, shard string, cells []string) error {
	relog.Info("rebuildShard %v/%v", keyspace, shard)
	// NOTE(msolomon) nasty hack - pass non-empty string to bypass data check
	shardInfo, err := topo.NewShardInfo(keyspace, shard, "{}")
	if err != nil {
		return err
	}

	tabletMap, err := GetTabletMapForShard(wr.ts, keyspace, shard)
	if err != nil {
		return err
	}

	tablets := make([]*topo.TabletInfo, 0, len(tabletMap))
	for _, ti := range tabletMap {
		if ti.Keyspace != shardInfo.Keyspace() || ti.Shard != shardInfo.ShardName() {
			return fmt.Errorf("CRITICAL: tablet %v is in replication graph for shard %v/%v but belongs to shard %v:%v (maybe remove its replication path in shard %v/%v)", ti.Alias(), keyspace, shard, ti.Keyspace, ti.Shard, keyspace, shard)
		}
		if !ti.IsInReplicationGraph() {
			// only valid case is a scrapped master in the
			// catastrophic reparent case
			if ti.Parent.Uid != topo.NO_TABLET {
				relog.Warning("Tablet %v should not be in the replication graph, please investigate (it will be ignored in the rebuild)", ti.Alias())
			}
		}
		tablets = append(tablets, ti)
	}

	// Rebuild the rollup data in the replication graph.
	if err = shardInfo.Rebuild(tablets); err != nil {
		return err
	}
	if err = wr.ts.UpdateShard(shardInfo); err != nil {
		return err
	}
	return wr.rebuildShardSrvGraph(shardInfo, tablets, cells)
}
开发者ID:shrutip,项目名称:vitess,代码行数:45,代码来源:rebuild.go



注:本文中的github.com/youtube/vitess/go/vt/topo.NewShardInfo函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang topo.NewShardReplicationInfo函数代码示例发布时间:2022-05-28
下一篇:
Golang topo.NewKeyspaceInfo函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap