Example #1
0
func (cnf *ZkConfig) DataDir() string {
	baseDir := env.VtDataRoot()
	if cnf.Global {
		return fmt.Sprintf("%v/zk_global_%03d", baseDir, cnf.ServerId)
	}
	return fmt.Sprintf("%v/zk_%03d", baseDir, cnf.ServerId)
}
Example #2
0
// HttpHandleSnapshots handles the serving of files from the local tablet
func HttpHandleSnapshots(mycnf *mysqlctl.Mycnf, uid uint32) {
	// make a list of paths we can serve HTTP traffic from.
	// we don't resolve them here to real paths, as they might not exits yet
	snapshotDir := mysqlctl.SnapshotDir(uid)
	allowedPaths := []string{
		path.Join(vtenv.VtDataRoot(), "data"),
		mysqlctl.TabletDir(uid),
		mysqlctl.SnapshotDir(uid),
		mycnf.DataDir,
		mycnf.InnodbDataHomeDir,
		mycnf.InnodbLogGroupHomeDir,
	}

	// NOTE: trailing slash in pattern means we handle all paths with this prefix
	http.Handle(mysqlctl.SnapshotURLPath+"/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		handleSnapshot(w, r, snapshotDir, allowedPaths)
	}))

}
Example #3
0
// createTopDir creates a top level directory under TabletDir.
// However, if a directory of the same name already exists under
// vtenv.VtDataRoot(), it creates a directory named after the tablet
// id under that directory, and then creates a symlink under TabletDir
// that points to the newly created directory.  For example, if
// /vt/data is present, it will create the following structure:
// /vt/data/vt_xxxx /vt/vt_xxxx/data -> /vt/data/vt_xxxx
func (mysqld *Mysqld) createTopDir(dir string) error {
	vtname := path.Base(mysqld.TabletDir)
	target := path.Join(vtenv.VtDataRoot(), dir)
	_, err := os.Lstat(target)
	if err != nil {
		if os.IsNotExist(err) {
			topdir := path.Join(mysqld.TabletDir, dir)
			log.Infof("creating directory %s", topdir)
			return os.MkdirAll(topdir, 0775)
		}
		return err
	}
	linkto := path.Join(target, vtname)
	source := path.Join(mysqld.TabletDir, dir)
	log.Infof("creating directory %s", linkto)
	err = os.MkdirAll(linkto, 0775)
	if err != nil {
		return err
	}
	log.Infof("creating symlink %s -> %s", source, linkto)
	return os.Symlink(linkto, source)
}
Example #4
0
// SnapshotDir returns the default directory for a tablet's snapshots
func SnapshotDir(uid uint32) string {
	return fmt.Sprintf("%s/%s/vt_%010d", env.VtDataRoot(), snapshotDir, uid)
}
Example #5
0
// TabletDir returns the default directory for a tablet
func TabletDir(uid uint32) string {
	return fmt.Sprintf("%s/vt_%010d", env.VtDataRoot(), uid)
}