Example #1
0
func getLockClient() *FsLockClient {
	// TODO: use more lock servers....
	rc, e := trib.LoadRC(*frc)
	noError(e)
	lockServerAddr := rc.LockServers[0]
	return NewFsLockClient(lockServerAddr)
}
Example #2
0
// Init initializes a filesystem.
// Called before any other filesystem method.
func (d *MyFileSystem) Init(*fuse.ConnInfo) {
	fmt.Println("Init func: ")

	rc, e := trib.LoadRC(*frc)
	noError(e)
	binClient = NewBinClient(rc.Backs)
	LockTimeTable = make(map[string]time.Time) //lock time table keeps what locks you have and when they expire

	rootDir, _ := GetInodeHelper(1)
	if rootDir == nil {
		now := time.Now()
		rootDir := Inode{
			Dir:       true,
			File:      false,
			Parent:    -1,
			Ctime:     now,
			Mtime:     now,
			Atime:     now,
			Mode:      0777 | fuse.S_IFDIR,
			Inos:      make([]NameIdPair, 0),
			LargeFlag: false,
		}
		SetInodeHelper(1, &rootDir, d.FsName, d.UserName)
		// GetNextIdHelper(d.FsName, d.UserName) // just to avoid to release an empty lock
		SetNextIdHelper(2, d.FsName, d.UserName) //root is 1
	}
	fmt.Println("end of init")
}
Example #3
0
func makeServer() trib.Server {
	if !*lab {
		return ref.NewServer()
	}

	rc, e := trib.LoadRC(*frc)
	ne(e)

	c := triblab.NewBinClient(rc.Backs)

	return triblab.NewFront(c)
}
Example #4
0
func main() {
	flag.Parse()

	rc, e := trib.LoadRC(*frc)
	noError(e)

	s := triblab.NewBinClient(rc.Backs)

	cl := &client{s: s}
	cl.runPrompt()
	fmt.Println()
}
Example #5
0
func main() {
	flag.Parse()

	store.Logging = *verbose

	rc, e := trib.LoadRC(*frc)
	noError(e)

	run := func(i int) {
		if i > len(rc.Backs) {
			noError(fmt.Errorf("back-end index out of range: %d", i))
		}

		backConfig := rc.BackConfig(i, store.NewStorage())

		if *readyAddr != "" {
			backConfig.Ready = ready.Chan(*readyAddr, backConfig.Addr)
		}

		log.Printf("bin storage back-end serving on %s", backConfig.Addr)
		noError(triblab.ServeBack(backConfig))
	}

	args := flag.Args()

	n := 0
	if len(args) == 0 {
		// scan for addresses on this machine
		for i, b := range rc.Backs {
			if local.Check(b) {
				go run(i)
				n++
			}
		}

		if n == 0 {
			log.Fatal("no back-end found for this host")
		}
	} else {
		// scan for indices for the addresses
		for _, a := range args {
			i, e := strconv.Atoi(a)
			noError(e)
			go run(i)
			n++
		}
	}

	if n > 0 {
		select {}
	}
}
Example #6
0
func uploadFile(file, fsNa, userNa string, chunkSz int64) {
	var fileName string
	slashPos := strings.LastIndexAny(file, "/")
	if slashPos == -1 {
		fileName = file
	} else {
		fileName = file[slashPos+1:]
	}
	dir, err := filepath.Abs(filepath.Dir(file))
	noError(err)
	fmt.Println(dir)
	fmt.Println(fileName)

	var fsName, userName string
	fsName = fsNa
	userName = userNa

	nextId, err := triblab.GetNextIdHelper(fsName, userName)
	noError(err)
	err = triblab.SetNextIdHelper(nextId+1, fsName, userName)
	noError(err)

	fileHandle, err := os.Open(dir + "/" + fileName)
	fileInfo, err := fileHandle.Stat()
	noError(err)
	fiSz := fileInfo.Size()

	rc, err := trib.LoadRC(*frc)
	noError(err)
	partNum := int(math.Ceil(float64(fiSz) / float64(chunkSz)))
	doneChan := make(chan bool, partNum+10)
	errChan := make(chan error, partNum+10)

	var addr string
	var curOffset int64
	fiConf := triblab.FileConf{
		FileName:     fileName,
		PartNum:      partNum,
		ChunkSize:    chunkSz,
		OffAddrPairs: make([]*triblab.OffsetAddr, partNum),
	}
	// fmt.Println("partNum", partNum)
	for i := 0; i < partNum; i++ {
		curOffset = int64(i) * chunkSz
		addr = rc.Backs[rand.Intn(len(rc.Backs))]
		fiConf.OffAddrPairs[i] = &triblab.OffsetAddr{Offset: curOffset, Addr: addr}
		uploadChunk(addr, dir, fileName, nextId, chunkSz, curOffset, fiSz, doneChan, errChan)
	}

	var doneFlag bool
	for i := 0; i < partNum; i++ {
		doneFlag = <-doneChan
		if !doneFlag {
			fmt.Fprintln(os.Stderr, <-errChan)
			os.Exit(1)
		}
	}

	now := time.Now()
	ind := triblab.Inode{
		Dir:       false,
		File:      true,
		Parent:    1,
		Ctime:     now,
		Mtime:     now,
		Atime:     now,
		Mode:      0444 | fuse.S_IFREG,
		Size:      fiSz,
		Inos:      make([]triblab.NameIdPair, 0),
		LargeFlag: true,
	}
	// fmt.Println("step 1")
	err = triblab.SetInodeHelper(nextId, &ind, fsName, userName)
	noError(err)

	inodir, err := triblab.GetInodeHelper(1)
	noError(err)
	inodir.Inos = append(inodir.Inos, triblab.NameIdPair{Name: fileName, InoID: nextId, DirFlag: false})
	err = triblab.SetInodeHelper(1, inodir, fsName, userName)
	noError(err)

	// fmt.Println("step 2")
	jsonStr, err := json.Marshal(fiConf)
	noError(err)
	fmt.Println(string(jsonStr))
	// fmt.Println("step 3")
	err = triblab.SetFileHelper(nextId, string(jsonStr), fsName, userName)
	// fmt.Println("step 4")
	noError(err)

}
Example #7
0
func main() {
	flag.Parse()

	rc, e := trib.LoadRC(*frc)
	noError(e)

	run := func(i int) {
		if i > len(rc.Keepers) {
			noError(fmt.Errorf("keeper index out of range: %d", i))
		}

		keeperConfig := rc.KeeperConfig(i)
		c := make(chan bool)
		keeperConfig.Ready = c
		go func() {
			noError(triblab.ServeKeeper(keeperConfig))
		}()

		b := <-c
		if b {
			log.Printf("bin storage keeper serving on %s",
				keeperConfig.Addr())
			if *readyAddr != "" {
				ready.Notify(*readyAddr, keeperConfig.Addr())
			}
		} else {
			log.Printf("bin storage keeper on %s init failed",
				keeperConfig.Addr())
			if *readyAddr != "" {
				ready.NotifyFail(*readyAddr, keeperConfig.Addr())
			}
		}
	}

	args := flag.Args()
	n := 0
	if len(args) == 0 {
		for i, k := range rc.Keepers {
			if local.Check(k) {
				go run(i)
				n++
			}
		}

		if n == 0 {
			log.Fatal("no keeper found for this host")
		}
	} else {
		for _, a := range args {
			i, e := strconv.Atoi(a)
			noError(e)

			go run(i)
			n++
		}
	}

	if n > 0 {
		select {}
	}
}