本文整理汇总了Golang中github.com/youtube/vitess/go/zk.CreateRecursive函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateRecursive函数的具体用法?Golang CreateRecursive怎么用?Golang CreateRecursive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateRecursive函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPruneActionLogs
// TestPruneActionLogs is a ZK specific unit test
func TestPruneActionLogs(t *testing.T) {
ctx := context.Background()
ts := NewTestServer(t, []string{"test"})
defer ts.Close()
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topo.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
actionLogPath := path.Join(globalKeyspacesPath, "test_keyspace", "actionlog")
zkts := ts.Server.(*Server)
if _, err := zk.CreateRecursive(zkts.zconn, actionLogPath+"/0", "first", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(stale): %v", err)
}
if _, err := zk.CreateRecursive(zkts.zconn, actionLogPath+"/1", "second", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(fresh): %v", err)
}
if count, err := zkts.PruneActionLogs(actionLogPath, 1); err != nil || count != 1 {
t.Fatalf("PruneActionLogs: %v %v", err, count)
}
actionLogs, _, err := zkts.zconn.Children(actionLogPath)
if err != nil || len(actionLogs) != 1 || actionLogs[0] != "1" {
t.Errorf("PruneActionLogs kept the wrong things: %v %v", err, actionLogs)
}
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:29,代码来源:zktopo_test.go
示例2: TestPurgeActions
// TestPurgeActions is a ZK specific unit test
func TestPurgeActions(t *testing.T) {
ctx := context.Background()
ts := NewTestServer(t, []string{"test"})
defer ts.Close()
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topo.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
actionPath := path.Join(globalKeyspacesPath, "test_keyspace", "action")
zkts := ts.Server.(*Server)
if _, err := zk.CreateRecursive(zkts.zconn, actionPath+"/topurge", "purgeme", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(topurge): %v", err)
}
if _, err := zk.CreateRecursive(zkts.zconn, actionPath+"/tokeep", "keepme", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(tokeep): %v", err)
}
if err := zkts.PurgeActions(actionPath, func(data string) bool {
return data == "purgeme"
}); err != nil {
t.Fatalf("PurgeActions(tokeep): %v", err)
}
actions, _, err := zkts.zconn.Children(actionPath)
if err != nil || len(actions) != 1 || actions[0] != "tokeep" {
t.Errorf("PurgeActions kept the wrong things: %v %v", err, actions)
}
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:31,代码来源:zktopo_test.go
示例3: TestPurgeActions
// TestPurgeActions is a ZK specific unit test
func TestPurgeActions(t *testing.T) {
ctx := context.Background()
ts := newTestServer(t, []string{"test"})
defer ts.Close()
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
actionPath := path.Join(zktopo.GlobalKeyspacesPath, "test_keyspace", "action")
zkts := ts.(*TestServer).Impl.(*zktopo.Server)
if _, err := zk.CreateRecursive(zkts.GetZConn(), actionPath+"/topurge", []byte("purgeme"), 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil {
t.Fatalf("CreateRecursive(topurge): %v", err)
}
if _, err := zk.CreateRecursive(zkts.GetZConn(), actionPath+"/tokeep", []byte("keepme"), 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil {
t.Fatalf("CreateRecursive(tokeep): %v", err)
}
if err := zkts.PurgeActions(actionPath, func(data []byte) bool {
return string(data) == "purgeme"
}); err != nil {
t.Fatalf("PurgeActions(tokeep): %v", err)
}
actions, _, err := zkts.GetZConn().Children(actionPath)
if err != nil || len(actions) != 1 || actions[0] != "tokeep" {
t.Errorf("PurgeActions kept the wrong things: %v %v", err, actions)
}
}
开发者ID:erzel,项目名称:vitess,代码行数:31,代码来源:zktopo_test.go
示例4: newTestServer
// newTestServer returns a new TestServer (with the required paths created)
func newTestServer(t *testing.T, cells []string) topo.Impl {
zconn := fakezk.NewConn()
// create the toplevel zk paths
if _, err := zk.CreateRecursive(zconn, "/zk/global/vt", nil, 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil {
t.Fatalf("cannot init ZooKeeper: %v", err)
}
for _, cell := range cells {
if _, err := zk.CreateRecursive(zconn, fmt.Sprintf("/zk/%v/vt", cell), nil, 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil {
t.Fatalf("cannot init ZooKeeper: %v", err)
}
}
return &TestServer{Impl: zktopo.NewServer(zconn), localCells: cells}
}
开发者ID:erzel,项目名称:vitess,代码行数:15,代码来源:testserver.go
示例5: CreateKeyspace
func (zkts *Server) CreateKeyspace(keyspace string) error {
keyspacePath := path.Join(globalKeyspacesPath, keyspace)
pathList := []string{
keyspacePath,
path.Join(keyspacePath, "action"),
path.Join(keyspacePath, "actionlog"),
path.Join(keyspacePath, "shards"),
}
alreadyExists := false
for _, zkPath := range pathList {
_, err := zk.CreateRecursive(zkts.zconn, zkPath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
alreadyExists = true
} else {
return fmt.Errorf("error creating keyspace: %v %v", zkPath, err)
}
}
}
if alreadyExists {
return topo.ErrNodeExists
}
return nil
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:25,代码来源:global.go
示例6: CreateTablet
func (zkts *Server) CreateTablet(tablet *topo.Tablet) error {
zkTabletPath := TabletPathForAlias(tablet.Alias())
// Create /zk/<cell>/vt/tablets/<uid>
_, err := zk.CreateRecursive(zkts.zconn, zkTabletPath, tablet.Json(), 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
err = topo.ErrNodeExists
}
return err
}
// Create /zk/<cell>/vt/tablets/<uid>/action
tap := path.Join(zkTabletPath, "action")
_, err = zkts.zconn.Create(tap, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
return err
}
// Create /zk/<cell>/vt/tablets/<uid>/actionlog
talp := path.Join(zkTabletPath, "actionlog")
_, err = zkts.zconn.Create(talp, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
return err
}
return nil
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:28,代码来源:cell.go
示例7: 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
示例8: CreateKeyspace
func (zkts *Server) CreateKeyspace(keyspace string, value *topo.Keyspace) error {
keyspacePath := path.Join(globalKeyspacesPath, keyspace)
pathList := []string{
keyspacePath,
path.Join(keyspacePath, "action"),
path.Join(keyspacePath, "actionlog"),
path.Join(keyspacePath, "shards"),
}
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 keyspace: %v %v", zkPath, err)
}
}
}
if alreadyExists {
return topo.ErrNodeExists
}
event.Dispatch(&events.KeyspaceChange{
KeyspaceInfo: *topo.NewKeyspaceInfo(keyspace, value),
Status: "created",
})
return nil
}
开发者ID:ninqing,项目名称:vitess,代码行数:34,代码来源:keyspace.go
示例9: UpdateShardReplicationFields
// UpdateShardReplicationFields is part of the topo.Server interface
func (zkts *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, update func(*topodatapb.ShardReplication) error) error {
// create the parent directory to be sure it's here
zkDir := path.Join("/zk", cell, "vt", "replication", keyspace)
if _, err := zk.CreateRecursive(zkts.zconn, zkDir, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil && !zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
return convertError(err)
}
// now update the data
zkPath := shardReplicationPath(cell, keyspace, shard)
f := func(oldValue string, oldStat zk.Stat) (string, error) {
sr := &topodatapb.ShardReplication{}
if oldValue != "" {
if err := json.Unmarshal([]byte(oldValue), sr); err != nil {
return "", err
}
}
if err := update(sr); err != nil {
return "", err
}
data, err := json.MarshalIndent(sr, "", " ")
if err != nil {
return "", err
}
return string(data), nil
}
err := zkts.zconn.RetryChange(zkPath, 0, zookeeper.WorldACL(zookeeper.PERM_ALL), f)
if err != nil {
return convertError(err)
}
return nil
}
开发者ID:CowLeo,项目名称:vitess,代码行数:33,代码来源:replication_graph.go
示例10: CreateShard
// CreateShard is part of the topo.Server interface
func (zkts *Server) CreateShard(ctx context.Context, keyspace, shard string, value *topodatapb.Shard) error {
shardPath := path.Join(globalKeyspacesPath, keyspace, "shards", shard)
pathList := []string{
shardPath,
path.Join(shardPath, "action"),
path.Join(shardPath, "actionlog"),
}
data, err := json.MarshalIndent(value, "", " ")
if err != nil {
return err
}
alreadyExists := false
for i, zkPath := range pathList {
c := ""
if i == 0 {
c = string(data)
}
_, 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
}
return nil
}
开发者ID:BobbWu,项目名称:vitess,代码行数:34,代码来源:shard.go
示例11: CreateKeyspace
// CreateKeyspace is part of the topo.Server interface
func (zkts *Server) CreateKeyspace(ctx context.Context, keyspace string, value *topodatapb.Keyspace) error {
keyspacePath := path.Join(GlobalKeyspacesPath, keyspace)
pathList := []string{
keyspacePath,
path.Join(keyspacePath, "action"),
path.Join(keyspacePath, "actionlog"),
path.Join(keyspacePath, "shards"),
}
data, err := json.MarshalIndent(value, "", " ")
if err != nil {
return err
}
alreadyExists := false
for i, zkPath := range pathList {
var c []byte
if i == 0 {
c = data
}
_, err := zk.CreateRecursive(zkts.zconn, zkPath, c, 0, zookeeper.WorldACL(zookeeper.PermAll))
switch err {
case nil:
// nothing here
case zookeeper.ErrNodeExists:
alreadyExists = true
default:
return convertError(err)
}
}
if alreadyExists {
return topo.ErrNodeExists
}
return nil
}
开发者ID:erzel,项目名称:vitess,代码行数:36,代码来源:keyspace.go
示例12: NewConnFromFile
// NewConnFromFile returns a fake zk.Conn implementation, that is seeded
// with the json data extracted from the input file.
func NewConnFromFile(filename string) zk.Conn {
result := &zconn{
root: &node{
_stat: _stat{name: "/"},
children: make(map[string]*node),
},
existWatches: make(map[string][]chan zookeeper.Event)}
data, err := ioutil.ReadFile(filename)
if err != nil {
panic(fmt.Errorf("NewConnFromFile failed to read file %v: %v", filename, err))
}
values := make(map[string]interface{})
if err := json.Unmarshal(data, &values); err != nil {
panic(fmt.Errorf("NewConnFromFile failed to json.Unmarshal file %v: %v", filename, err))
}
for k, v := range values {
jv, err := json.Marshal(v)
if err != nil {
panic(fmt.Errorf("NewConnFromFile failed to json.Marshal value %v: %v", k, err))
}
// CreateRecursive will work for a leaf node where the parent
// doesn't exist, but not for a node in the middle of a tree
// that already exists. So have to use 'Set' as a backup.
if _, err := zk.CreateRecursive(result, k, string(jv), 0, nil); err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
_, err = result.Set(k, string(jv), -1)
}
if err != nil {
panic(fmt.Errorf("NewConnFromFile failed to zk.CreateRecursive value %v: %v", k, err))
}
}
}
return result
}
开发者ID:CowLeo,项目名称:vitess,代码行数:37,代码来源:fakezk.go
示例13: UpdateEndPoints
// UpdateEndPoints is part of the topo.Server interface
func (zkts *Server) UpdateEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType, addrs *topodatapb.EndPoints, existingVersion int64) error {
path := zkPathForVtName(cell, keyspace, shard, tabletType)
data, err := json.MarshalIndent(addrs, "", " ")
if err != nil {
return err
}
if existingVersion == -1 {
// Update or create unconditionally.
_, err := zk.CreateRecursive(zkts.zconn, path, string(data), 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
// Node already exists - just stomp away. Multiple writers shouldn't be here.
// We use RetryChange here because it won't update the node unnecessarily.
f := func(oldValue string, oldStat zk.Stat) (string, error) {
return string(data), nil
}
err = zkts.zconn.RetryChange(path, 0, zookeeper.WorldACL(zookeeper.PERM_ALL), f)
}
}
return err
}
// Compare And Set
if _, err = zkts.zconn.Set(path, string(data), int(existingVersion)); err != nil {
if zookeeper.IsError(err, zookeeper.ZBADVERSION) {
err = topo.ErrBadVersion
} else if zookeeper.IsError(err, zookeeper.ZNONODE) {
err = topo.ErrNoNode
}
}
return err
}
开发者ID:aaijazi,项目名称:vitess,代码行数:34,代码来源:serving_graph.go
示例14: CreateShard
func (zkts *Server) CreateShard(keyspace, shard string) 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 {
s := topo.Shard{}
c = s.Json()
}
_, 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
}
return nil
}
开发者ID:shrutip,项目名称:vitess,代码行数:29,代码来源:global.go
示例15: UpdateSrvKeyspace
func (zkts *Server) UpdateSrvKeyspace(cell, keyspace string, srvKeyspace *topo.SrvKeyspace) error {
path := zkPathForVtKeyspace(cell, keyspace)
data := jscfg.ToJson(srvKeyspace)
_, err := zkts.zconn.Set(path, data, -1)
if zookeeper.IsError(err, zookeeper.ZNONODE) {
_, err = zk.CreateRecursive(zkts.zconn, path, data, 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
}
return err
}
开发者ID:chinna1986,项目名称:vitess,代码行数:9,代码来源:serving_graph.go
示例16: newFakeTeeServer
func newFakeTeeServer(t *testing.T) topo.Server {
cells := []string{"test", "global"} // global has to be last
zconn1 := fakezk.NewConn()
zconn2 := fakezk.NewConn()
for _, cell := range cells {
if _, err := zk.CreateRecursive(zconn1, fmt.Sprintf("/zk/%v/vt", cell), "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("cannot init ZooKeeper: %v", err)
}
if _, err := zk.CreateRecursive(zconn2, fmt.Sprintf("/zk/%v/vt", cell), "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("cannot init ZooKeeper: %v", err)
}
}
s1 := fakeServer{Server: zktopo.NewServer(zconn1), localCells: cells[:len(cells)-1]}
s2 := fakeServer{Server: zktopo.NewServer(zconn2), localCells: cells[:len(cells)-1]}
return NewTee(s1, s2, false)
}
开发者ID:rjammala,项目名称:vitess,代码行数:19,代码来源:tee_topo_test.go
示例17: StoreTabletActionResponse
// StoreTabletActionResponse stores the data both in action and actionlog
func (zkts *Server) StoreTabletActionResponse(actionPath, data string) error {
_, err := zkts.zconn.Set(actionPath, data, -1)
if err != nil {
return err
}
actionLogPath := strings.Replace(actionPath, "/action/", "/actionlog/", 1)
_, err = zk.CreateRecursive(zkts.zconn, actionLogPath, data, 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
return err
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:11,代码来源:cell.go
示例18: setPathData
func setPathData(filePath, data string) error {
if isZkFile(filePath) {
_, err := zconn.Set(filePath, data, -1)
if err != nil && zookeeper.IsError(err, zookeeper.ZNONODE) {
_, err = zk.CreateRecursive(zconn, filePath, data, 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
}
return err
}
return ioutil.WriteFile(filePath, []byte(data), 0666)
}
开发者ID:CowLeo,项目名称:vitess,代码行数:10,代码来源:zkcmd.go
示例19: unlockForAction
func (zkts *Server) unlockForAction(lockPath, results string) error {
// Write the data to the actionlog
actionLogPath := strings.Replace(lockPath, "/action/", "/actionlog/", 1)
if _, err := zk.CreateRecursive(zkts.zconn, actionLogPath, results, 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
return err
}
// and delete the action
return zk.DeleteRecursive(zkts.zconn, lockPath, -1)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:10,代码来源:global.go
示例20: setPathData
func setPathData(filePath string, data []byte) error {
if isZkFile(filePath) {
_, err := zconn.Set(filePath, data, -1)
if err == zookeeper.ErrNoNode {
_, err = zk.CreateRecursive(zconn, filePath, data, 0, zookeeper.WorldACL(zookeeper.PermAll))
}
return err
}
return ioutil.WriteFile(filePath, []byte(data), 0666)
}
开发者ID:erzel,项目名称:vitess,代码行数:10,代码来源:zkcmd.go
注:本文中的github.com/youtube/vitess/go/zk.CreateRecursive函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论