Creating ZK higher level directories.

It seems it's just simpler all around if the zk topology plugin creates
the higher level directories when needed. The deletion still stops at
the root though, seems safer.
This commit is contained in:
Alain Jobart 2017-12-13 13:24:10 -08:00
Родитель 79d7e1f590
Коммит a5a6fc287a
6 изменённых файлов: 13 добавлений и 35 удалений

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

@ -264,8 +264,9 @@ and by the root directory to put the Vitess data in. For instance, assuming we
want to use servers `global_server1,global_server2` in path `/vitess/global`:
``` sh
# First create the directory in the global server:
zk -server global_server1,global_server2 touch -p /vitess/global
# The root directory in the global server will be created
# automatically, same as when running this command:
# zk -server global_server1,global_server2 touch -p /vitess/global
# Set the following flags to let Vitess use this global server:
# -topo_implementation zk2

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

@ -50,11 +50,7 @@ done
echo "Started zk servers."
# Now create the toplevel directories we'll need, if not there.
$VTROOT/bin/zk -server $ZK_SERVER touch -p /vitess/global
$VTROOT/bin/zk -server $ZK_SERVER touch -p /vitess/test
# And also add the CellInfo description for the 'test' cell.
# Add the CellInfo description for the 'test' cell.
# If the node already exists, it's fine, means we used existing data.
$VTROOT/bin/vtctl $TOPOLOGY_FLAGS AddCellInfo \
-root /vitess/test \

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

@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"path"
"strings"
"github.com/samuel/go-zookeeper/zk"
"golang.org/x/net/context"
@ -30,11 +29,9 @@ import (
// Create is part of the topo.Conn interface.
func (zs *Server) Create(ctx context.Context, filePath string, contents []byte) (topo.Version, error) {
filePath = path.Clean(filePath)
depth := strings.Count(filePath, "/")
zkPath := path.Join(zs.root, filePath)
pathCreated, err := CreateRecursive(ctx, zs.conn, zkPath, contents, 0, zk.WorldACL(PermFile), depth)
pathCreated, err := CreateRecursive(ctx, zs.conn, zkPath, contents, 0, zk.WorldACL(PermFile), -1)
if err != nil {
return nil, convertError(err)
}

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

@ -21,7 +21,6 @@ import (
"path"
"testing"
"github.com/samuel/go-zookeeper/zk"
"golang.org/x/net/context"
"github.com/youtube/vitess/go/testfiles"
@ -41,22 +40,12 @@ func TestZk2Topo(t *testing.T) {
testIndex := 0
test.TopoServerTestSuite(t, func() *topo.Server {
// Each test will use its own sub-directories.
// The directories will be created when used the first time.
testRoot := fmt.Sprintf("/test-%v", testIndex)
testIndex++
ctx := context.Background()
c := Connect(serverAddr)
if _, err := c.Create(ctx, testRoot, nil, 0, zk.WorldACL(PermDirectory)); err != nil {
t.Fatalf("Create(%v) failed: %v", testRoot, err)
}
globalRoot := path.Join(testRoot, topo.GlobalCell)
if _, err := c.Create(ctx, globalRoot, nil, 0, zk.WorldACL(PermDirectory)); err != nil {
t.Fatalf("Create(%v) failed: %v", globalRoot, err)
}
cellRoot := path.Join(testRoot, test.LocalCellName)
if _, err := c.Create(ctx, cellRoot, nil, 0, zk.WorldACL(PermDirectory)); err != nil {
t.Fatalf("Create(%v) failed: %v", cellRoot, err)
}
// Note we exercise the observer feature here by passing in
// the same server twice, with a "|" separator.

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

@ -33,8 +33,9 @@ import (
// CreateRecursive is a helper function on top of Create. It will
// create a path and any pieces required, think mkdir -p.
// Intermediate znodes are always created empty.
func CreateRecursive(ctx context.Context, conn Conn, zkPath string, value []byte, flags int32, aclv []zk.ACL, maxCreationDepth int) (pathCreated string, err error) {
pathCreated, err = conn.Create(ctx, zkPath, value, flags, aclv)
// Pass maxCreationDepth=-1 to create all nodes to the top.
func CreateRecursive(ctx context.Context, conn Conn, zkPath string, value []byte, flags int32, aclv []zk.ACL, maxCreationDepth int) (string, error) {
pathCreated, err := conn.Create(ctx, zkPath, value, flags, aclv)
if err == zk.ErrNoNode {
if maxCreationDepth == 0 {
return "", zk.ErrNoNode
@ -54,7 +55,7 @@ func CreateRecursive(ctx context.Context, conn Conn, zkPath string, value []byte
}
pathCreated, err = conn.Create(ctx, zkPath, value, flags, aclv)
}
return
return pathCreated, err
}
// ChildrenRecursive returns the relative path of all the children of

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

@ -50,12 +50,6 @@ class Zk2TopoServer(server.TopoServer):
'-zk.cfg', '1@%s:%s' % (self.hostname, self.zk_ports),
'init'])
# Create toplevel directories for global ZK, and one per cell.
run(binary_args('zk') + ['-server', self.addr, 'touch', '-p', '/global'])
run(binary_args('zk') + ['-server', self.addr, 'touch', '-p', '/test_nj'])
run(binary_args('zk') + ['-server', self.addr, 'touch', '-p', '/test_ny'])
run(binary_args('zk') + ['-server', self.addr, 'touch', '-p', '/test_ca'])
# Create the cell configurations using 'vtctl AddCellInfo'
utils.run_vtctl_vtctl(['AddCellInfo',
'-root', '/test_nj',