Exemplo n.º 1
0
func (ns *NameServer) Start() error {
	var err error = nil
	ns.rpcServer, err = mrpc.CloseableRPC(ns.listenAddr, mrpc.NewNameServiceService(ns), "NameService")
	if err != nil {
		return err
	}
	ns.rpcServer.Start()
	go func() {
		ns.webServer.Serve(ns.webListen)
	}()
	return err
}
Exemplo n.º 2
0
func NewPeer(cfg *PeerConfig, debug bool) (*Peer, error) {

	cl, err := NewClient(cfg.MasterAddr)
	if err != nil {
		return nil, err
	}
	ret := &Peer{}
	ret.Cfg = cfg
	ret.Datanode, err = dataserver.NewDataServer(cfg.BindAddr, cfg.VolumeRoots, cl.Names, cl.Datas)
	if err != nil {
		return ret, err
	}
	dnStat, err := ret.Datanode.HeartBeat()
	if err != nil {
		return ret, err
	}
	fuseConnector, err := client.NewMaggieFuse(cl.Leases, cl.Names, cl.Datas, &dnStat.DnId)
	if err != nil {
		return ret, err
	}
	ret.Mfs = fuseConnector
	ret.Mountpoint, err = NewMount(fuseConnector, cfg.MountPoint, false)

	opMap := make(map[uint32]func(*net.TCPConn))
	opMap[dataserver.DIAL_READ] = ret.Datanode.ServeReadConn
	opMap[dataserver.DIAL_WRITE] = ret.Datanode.ServeWriteConn

	dataServ, err := mrpc.CloseableRPC(cfg.BindAddr, "Peer", maggiefs.NewPeerService(ret.Datanode), opMap)
	if err != nil {
		return ret, err
	}
	multiServ := NewMultiService()

	err = multiServ.AddService(dataServ)
	if err != nil {
		return ret, err
	}
	err = multiServ.AddService(ret.Mountpoint)
	if err != nil {
		return ret, err
	}
	// now that services are started, tell master to connect to us
	err = cl.Names.Join(dnStat.DnId, cfg.BindAddr)

	ret.svc = multiServ
	return ret, err
}
Exemplo n.º 3
0
// returns a started nameserver -- we must start lease server in order to boot up nameserver, so
func NewMaster(cfg *MasterConfig, format bool) (*Master, error) {
	nls := &Master{}
	var err error = nil
	nls.leaseServer = leaseserver.NewLeaseServer()
	nls.nameserver, err = nameserver.NewNameServer(cfg.NameHome, cfg.ReplicationFactor, format)
	if err != nil {
		log.Printf("Error creating nameserver: %s\n\n Nameserver config: %+v\n", err.Error(), cfg)
		return nls, err
	}
	opMap := make(map[uint32]func(*net.TCPConn))
	opMap[SERVNO_LEASESERVER] = nls.leaseServer.ServeConn
	log.Printf("Starting master on addr %s", cfg.BindAddr)
	nls.serv, err = mrpc.CloseableRPC(cfg.BindAddr, "NameService", maggiefs.NewNameServiceService(nls.nameserver), opMap)
	if err != nil {
		return nls, err
	}
	_, port, _ := net.SplitHostPort(cfg.BindAddr)
	nls.port, _ = strconv.Atoi(port)
	return nls, err
}
Exemplo n.º 4
0
// create a new dataserver serving the specified volumes, on the specified addrs, joining the specified nameservice
func NewDataServer(volRoots []string,
	dataClientBindAddr string,
	nameDataBindAddr string,
	webBindAddr string,
	ns maggiefs.NameService,
	dc *DataClient) (ds *DataServer, err error) {
	// scan volumes
	volumes := make(map[uint32]*volume)
	unformatted := make([]string, 0)
	for _, volRoot := range volRoots {
		if validVolume(volRoot) {
			// initialize existing volume
			vol, err := loadVolume(volRoot)
			if err != nil {
				return nil, err
			}
			volumes[vol.id] = vol
		} else {
			// mark unformatted, wait for order from namenode to format
			unformatted = append(unformatted, volRoot)
		}
	}
	// form consensus on host across volumes or error
	var dnInfo maggiefs.DataNodeInfo = maggiefs.DataNodeInfo{}
	for _, vol := range volumes {
		if dnInfo.DnId != 0 {
			dnInfo = vol.info.DnInfo
		} else {
			// compare new to previous
			if !dnInfo.Equals(vol.info.DnInfo) {
				return nil, errors.New("Incompatible dataNodeInfo across volumes!")
			}
		}
	}
	if dnInfo.DnId == 0 {
		dnInfo.DnId, err = ns.NextDnId()
	}
	dnInfo.Addr = dataClientBindAddr

	// format unformatted volumes
	for _, path := range unformatted {
		volId, err := ns.NextVolId()
		if err != nil {
			return nil, err
		}
		vol, err := formatVolume(path, maggiefs.VolumeInfo{volId, dnInfo})
		if err != nil {
			return nil, err
		}
		volumes[volId] = vol
	}

	// start up listeners
	dataClientBind, err := net.ResolveTCPAddr("tcp", dataClientBindAddr)
	if err != nil {
		return nil, err
	}

	dataClientListen, err := net.ListenTCP("tcp", dataClientBind)
	if err != nil {
		return nil, err
	}

	// start servicing namedata
	ds = &DataServer{ns, dnInfo, volumes, dataClientListen, nil, dc}

	ds.nameDataIface, err = mrpc.CloseableRPC(nameDataBindAddr, mrpc.NewNameDataIfaceService(ds), "NameDataIface")
	if err != nil {
		return ds, err
	}
	ds.nameDataIface.Start()
	// start servicing client data
	go ds.serveClientData()
	// register ourselves with namenode, namenode will query us for volumes
	err = ns.Join(dnInfo.DnId, nameDataBindAddr)
	return ds, nil
}
Exemplo n.º 5
0
func NewSingleNodeCluster(startPort int, numDNs int, volsPerDn int, replicationFactor uint32, baseDir string, mountPoint string, debugMode bool) (*SingleNodeCluster, error) {
	cl := &SingleNodeCluster{}
	nncfg, ds, err := NewConfSet2(startPort, numDNs, volsPerDn, replicationFactor, baseDir)
	if err != nil {
		return nil, err
	}
	log.Printf("Creating singleNodeCluster with master conf: %s, ds confs: %s", nncfg, ds)
	nls, err := NewMaster(nncfg, true)
	if err != nil {
		return nil, err
	}
	cl.LeaseServer = nls.leaseServer
	cl.NameServer = nls.nameserver

	// make service wrapper
	multiServ := NewMultiService()
	cl.svc = multiServ
	multiServ.AddService(nls) // add nameLeaseServer
	masterAddr := fmt.Sprintf("127.0.0.1:%d", nls.port)
	log.Printf("Connecting client to started master at %s", masterAddr)
	cli, err := NewClient(masterAddr)
	if err != nil {
		return cl, err
	}
	cl.Names = cli.Names
	cl.Leases = cli.Leases
	cl.Datas = cli.Datas
	// start dataservers
	cl.DataNodes = make([]*dataserver.DataServer, len(ds))
	cl.DataNodeServs = make([]*mrpc.CloseableServer, len(ds))
	for idx, dscfg := range ds {
		log.Printf("Starting DS with cfg %+v", dscfg)
		// create and register with SingleNodeCluster struct
		ds, err := dataserver.NewDataServer(dscfg.BindAddr, dscfg.VolumeRoots, cl.Names, cl.Datas)
		if err != nil {
			return cl, err
		}
		cl.DataNodes[idx] = ds
		// start and register with MultiServ
		opMap := make(map[uint32]func(*net.TCPConn))
		opMap[dataserver.DIAL_READ] = ds.ServeReadConn
		opMap[dataserver.DIAL_WRITE] = ds.ServeWriteConn
		dataServ, err := mrpc.CloseableRPC(dscfg.BindAddr, "Peer", maggiefs.NewPeerService(ds), opMap)
		if err != nil {
			return cl, err
		}
		cl.DataNodeServs[idx] = dataServ
		err = multiServ.AddService(dataServ)
		if err != nil {
			return cl, err
		}
		dnInfo, _ := ds.HeartBeat()
		err = cl.Names.Join(dnInfo.DnId, dscfg.BindAddr)
		if err != nil {
			return cl, err
		}
	}

	// create mountpoint if necessary
	if mountPoint != "" {
		maggieFuse, err := client.NewMaggieFuse(cl.Leases, cl.Names, cl.Datas, nil)
		if err != nil {
			return cl, err
		}
		mount, err := NewMount(maggieFuse, mountPoint, debugMode)
		if err != nil {
			return cl, err
		}
		err = multiServ.AddService(mount)
		if err != nil {
			return cl, err
		}
	}
	time.Sleep(1 * time.Second)
	return cl, nil
}