예제 #1
0
파일: volume.go 프로젝트: jonpugh/maggiefs
func (v *volume) BlockReport() ([]maggiefs.Block, error) {
	ret := make([]maggiefs.Block, 0, 0)
	it := v.blockData.NewIterator(readOpts)
	defer it.Close()
	it.SeekToFirst()
	for it = it; it.Valid(); it.Next() {
		blk := maggiefs.Block{}
		blk.FromBytes(it.Value())
		ret = append(ret, blk)
	}
	return ret, it.GetError()
}
예제 #2
0
파일: volume.go 프로젝트: jonpugh/maggiefs
func (v *volume) AddBlock(blk maggiefs.Block) error {
	// TODO should blow up here if blk already exists
	// create file representing block
	f, err := os.Create(v.resolvePath(blk.Id))
	if err != nil {
		return fmt.Errorf("Error creating block for %d : %s\n", blk.Id, err.Error())
	}
	defer f.Close()
	// add to blockmeta db
	key := make([]byte, 8)
	binary.LittleEndian.PutUint64(key, blk.Id)
	binSize := blk.BinSize()
	val := make([]byte, binSize)
	blk.ToBytes(val)
	err = v.blockData.Put(writeOpts, key, val)
	return err
}
예제 #3
0
func (ns *NameServer) AddBlock(nodeid uint64, length uint32) (newBlock maggiefs.Block, err error) {
	i, err := ns.nd.GetInode(nodeid)
	if err != nil {
		return maggiefs.Block{}, nil
	}
	// check which hosts we want
	vols, err := ns.rm.volumesForNewBlock(nil)
	if err != nil {
		return maggiefs.Block{}, err
	}
	volIds := make([]uint32, len(vols))
	for idx, v := range vols {
		volIds[idx] = v.VolId
	}

	var startPos uint64 = 0
	if len(i.Blocks) > 0 {
		lastBlock := i.Blocks[len(i.Blocks)-1]
		startPos = lastBlock.EndPos + 1
	} else {
		startPos = 0
	}

	endPos := startPos + uint64(length) - 1
	// allocate block and id
	b := maggiefs.Block{
		Id:       0,
		Inodeid:  i.Inodeid,
		Version:  0,
		StartPos: startPos,
		EndPos:   endPos,
		Volumes:  volIds,
	}
	newId, err := ns.nd.AddBlock(b, i.Inodeid)
	b.Id = newId
	//fmt.Printf("nameserver addblock returning new block %+v\n",b)
	if err != nil {
		return maggiefs.Block{}, err
	}

	// replicate block to datanodes
	err = ns.rm.AddBlock(b)
	return b, err
}
예제 #4
0
// adds a block to persistent store as the last block of inodeid,
// setting its blockid to the generated ID, and returning the generated ID and error
func (nd *NameData) AddBlock(b maggiefs.Block, inodeid uint64) (uint64, error) {
	newBlockId, err := nd.GetIncrCounter(COUNTER_BLOCK, 1)
	b.Id = newBlockId
	_, err = nd.Mutate(inodeid, func(i *maggiefs.Inode) error {
		i.Blocks = append(i.Blocks, b)
		return nil
	})
	if err != nil {
		return 0, err
	}
	return b.Id, nil
}