forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vschema.go
46 lines (40 loc) · 1.3 KB
/
vschema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zktopo
import (
"github.com/youtube/vitess/go/vt/vtgate/planbuilder"
"golang.org/x/net/context"
// vindexes needs to be imported so that they register
// themselves against vtgate/planbuilder. This will allow
// us to sanity check the schema being uploaded.
_ "github.com/youtube/vitess/go/vt/vtgate/vindexes"
"github.com/youtube/vitess/go/zk"
"launchpad.net/gozk/zookeeper"
)
/*
This file contains the vschema management code for zktopo.Server
*/
const (
globalVSchemaPath = "/zk/global/vt/vschema"
)
// SaveVSchema saves the JSON vschema into the topo.
func (zkts *Server) SaveVSchema(ctx context.Context, vschema string) error {
_, err := planbuilder.NewSchema([]byte(vschema))
if err != nil {
return err
}
_, err = zk.CreateOrUpdate(zkts.zconn, globalVSchemaPath, vschema, 0, zookeeper.WorldACL(zookeeper.PERM_ALL), true)
return err
}
// GetVSchema fetches the JSON vschema from the topo.
func (zkts *Server) GetVSchema(ctx context.Context) (string, error) {
data, _, err := zkts.zconn.Get(globalVSchemaPath)
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNONODE) {
return "{}", nil
}
return "", err
}
return data, nil
}