예제 #1
0
파일: trib-impl.go 프로젝트: ammarar/DS-P2
func NewTribserver(storagemaster string, myhostport string) *Tribserver {
	libstore, err := libstore.NewLibstore(storagemaster, myhostport, 0)
	if err != nil {
		return nil
	}
	return &Tribserver{libstore}
}
예제 #2
0
파일: libtest.go 프로젝트: ammarar/DS-P2
// Test libstore returns nil when it cannot connect to the server
func testNonexistentServer() {
	if l, err := libstore.NewLibstore(fmt.Sprintf("localhost:%d", *portnum), fmt.Sprintf("localhost:%d", *portnum), libstore.NONE); l == nil || err != nil {
		fmt.Fprintln(output, "PASS")
		passCount++
	} else {
		fmt.Fprintln(output, "FAIL: libstore does not return nil when it cannot connect to nonexistent storage server")
		failCount++
	}
	cleanupLibstore(nil)
}
예제 #3
0
func main() {
	lsplog.SetVerbose(10)
	ls, e := libstore.NewLibstore("localhost:9009", "localhost:9999", 0)
	e = ls.AppendToList("ammar:hey", "Helly")
	e = ls.AppendToList("ammar:hey", "Helly")
	e = ls.AppendToList("ammar:hey", "Kelly")
	lsplog.Vlogf(1, "%v", e)
	var k []string
	k, e = ls.GetList("ammar:hey")
	lsplog.Vlogf(1, "%v %v", k, e)
	e = ls.RemoveFromList("ammar:hey", "Helly")
	lsplog.Vlogf(1, "%v ", e)
	e = ls.RemoveFromList("ammar:hey", "Helly")
	lsplog.Vlogf(1, "%v ", e)
	k, e = ls.GetList("ammar:hey")
	lsplog.Vlogf(1, "%v %v", k, e)
}
예제 #4
0
func NewTribserver(storagemaster string, myhostport string) *Tribserver {
	lstore, err := libstore.NewLibstore(storagemaster, myhostport, 0)

	if err != nil {
		return nil
	}

	//pass storagemaster and hostport to new libstore with flags for debugging
	//make new libstore

	//store other shits

	//make tribserver

	//return the thing

	return &Tribserver{storagemaster: storagemaster, hostport: myhostport, lstore: lstore}
}
예제 #5
0
파일: trib-impl.go 프로젝트: yuguess/440_P2
/**@brief create a new tribserver
 * @param string
 * @param string
 * @return *tribserver
 */
func NewTribserver(storagemaster, myhostport string) *Tribserver {
	lsplog.SetVerbose(3)
	fmt.Printf("st_master:%s, port:%s\n", storagemaster, myhostport)

	var svr *Tribserver = new(Tribserver)
	var err error

	lsplog.Vlogf(3, "try to create libstore")
	// libstore.NONE forces no leases on Get and GetList requests
	svr.Store, err =
		libstore.NewLibstore(storagemaster, myhostport, libstore.NONE)

	if lsplog.CheckReport(1, err) {
		return nil
	}

	svr.Id = 1

	return svr
}
예제 #6
0
파일: libtest.go 프로젝트: ammarar/DS-P2
// Initialize proxy and libstore
func initLibstore(storage string, server string, myhostport string, flags int) net.Listener {
	// Start proxy
	l, err := net.Listen("tcp", server)
	if err != nil {
		log.Fatal("listen error:", err)
	}
	pc = proxycounter.NewProxyCounter(storage, server)
	if pc == nil {
		fmt.Println("Could not start proxy")
		return nil
	}
	srpc := storagerpc.NewStorageRPC(pc)
	rpc.Register(srpc)
	rpc.HandleHTTP()
	go http.Serve(l, nil)

	// Start libstore
	ls, err = libstore.NewLibstore(server, myhostport, flags)
	if ls == nil || err != nil {
		fmt.Println("Could not start libstore")
		return nil
	}
	return l
}
예제 #7
0
파일: libclient.go 프로젝트: ammarar/DS-P2
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s  <command>:\n", os.Args[0])
		flag.PrintDefaults()
		fmt.Fprintf(os.Stderr, "\n")
		fmt.Fprintf(os.Stderr, "   commands:  p  key val   (put)\n")
		fmt.Fprintf(os.Stderr, "              g  key       (get)\n")
		fmt.Fprintf(os.Stderr, "              la key val   (list append)\n")
		fmt.Fprintf(os.Stderr, "              lr key val   (list remove)\n")
		fmt.Fprintf(os.Stderr, "              lg key       (list get)\n")
	}

	flag.Parse()
	if flag.NArg() < 2 {
		log.Fatal("Insufficient arguments to client")
	}

	cmd := flag.Arg(0)

	cmdlist := []cmd_info{
		{"p", 2},
		{"g", 1},
		{"la", 2},
		{"lr", 2},
		{"lg", 1},
	}

	cmdmap := make(map[string]cmd_info)
	for _, j := range cmdlist {
		cmdmap[j.cmdline] = j
	}

	ci, found := cmdmap[cmd]
	if !found {
		log.Fatal("Unknown command ", cmd)
	}
	if flag.NArg() < (ci.nargs + 1) {
		log.Fatal("Insufficient arguments for ", cmd)
	}

	leaseCBaddr := ""
	flags := 0
	if *handleLeases {
		l, e := net.Listen("tcp", ":0")
		if e != nil {
			log.Fatal("listen error:", e)
		}
		_, listenport, _ := net.SplitHostPort(l.Addr().String())
		leaseCBaddr = net.JoinHostPort("localhost", listenport)
		log.Println("Starting HTTP server on ", listenport)
		rpc.HandleHTTP()
		go http.Serve(l, nil)
	}

	if *handleLeases && *forceLease {
		flags |= libstore.ALWAYS_LEASE
	}
	ls, err := libstore.NewLibstore(net.JoinHostPort(*serverAddress, fmt.Sprintf("%d", *portnum)), leaseCBaddr, flags)
	if err != nil {
		log.Fatal("Could not create a libstore")
	}

	for i := 0; i < *numTimes; i++ {
		switch cmd {
		case "g":
			val, err := ls.Get(flag.Arg(1))
			if err != nil {
				fmt.Println("error: ", err)
			} else {
				fmt.Println("  ", val)
			}
		case "lg":
			val, err := ls.GetList(flag.Arg(1))
			if err != nil {
				fmt.Println("error: ", err)
			} else {
				for _, i := range val {
					fmt.Println("  ", i)
				}
			}
		case "p", "la", "lr":
			var err error
			switch cmd {
			case "p":
				err = ls.Put(flag.Arg(1), flag.Arg(2))
			case "la":
				err = ls.AppendToList(flag.Arg(1), flag.Arg(2))
			case "lr":
				err = ls.RemoveFromList(flag.Arg(1), flag.Arg(2))
			}
			switch err {
			case nil:
				fmt.Println("OK")
			default:
				fmt.Println("Error: ", err)
			}
		}
	}
	if *handleLeases {
		fmt.Println("waiting 20 seconds for lease callbacks")
		time.Sleep(20 * time.Second)
	}
}