当前位置: 首页>>代码示例>>Golang>>正文


Golang topo.NewShardInfo函数代码示例

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


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


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