func runDataserver(args []string) { cfg := &conf.DSConfig{} err := cfg.ReadConfig(args[0]) if err != nil { usage(err) return } services, err := integration.NewClient(cfg.NameAddr, cfg.LeaseAddr, 1) if err != nil { usage(err) return } ds, err := dataserver.NewDataServer(cfg.VolumeRoots, cfg.DataClientBindAddr, cfg.NameDataBindAddr, cfg.WebBindAddr, services.Names, services.Datas) if err != nil { usage(err) return } ds.Start() if len(args) > 1 { mountPoint := args[1] // start client client, err := newMountedClient(services.Leases, services.Names, services.Datas, mountPoint) if err != nil { usage(err) return } client.Loop() ds.Close() } ds.WaitClosed() }
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 }
// TODO refactor to use NewConfSet func NewSingleNodeCluster(nncfg *conf.NSConfig, ds []*conf.DSConfig, format bool) (*SingleNodeCluster, error) { cl := &SingleNodeCluster{} nls, err := NewNameServer(nncfg, format) if err != nil { return nil, err } cl.LeaseServer = nls.leaseServer cl.NameServer = nls.nameserver fmt.Println("Starting name client") cl.Names, err = NewNameClient(nncfg.NameBindAddr) if err != nil { return cl, err } fmt.Println("starting lease client") cl.Leases, err = leaseserver.NewLeaseClient(nncfg.LeaseBindAddr) if err != nil { return cl, err } // start data client dc, err := dataserver.NewDataClient(cl.Names, 1) if err != nil { return cl, fmt.Errorf("error building dataclient : %s", err.Error()) } cl.Datas = dc // start dataservers cl.DataNodes = make([]*dataserver.DataServer, len(ds)) for idx, dscfg := range ds { fmt.Println("Starting DS with cfg %+v\n", dscfg) cl.DataNodes[idx], err = dataserver.NewDataServer(dscfg.VolumeRoots, dscfg.DataClientBindAddr, dscfg.NameDataBindAddr, dscfg.WebBindAddr, cl.Names, dc) if err != nil { return cl, err } } return cl, nil }
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 }