示例#1
0
文件: data.go 项目: proj-223/CatFs
// Prepare send a block to datanode
func (self *DataServer) PrepareSendBlock(param *proc.PrepareBlockParam, lease *proc.CatLease) error {
	var nextLease proc.CatLease
	var deliverChan chan []byte
	nextParam := param.NextPipeParam()
	if nextParam != nil {
		// if there is another replica
		location := nextParam.ServerLocation()
		nextDataServer := self.pool.DataServer(location)
		// prepare next data server
		err := nextDataServer.PrepareSendBlock(nextParam, &nextLease)
		if err != nil {
			return err
		}
		// prepare deliverChan block to next data server
		nextBlockClient := self.pool.NewBlockClient(location)
		deliverChan = make(chan []byte)
		go nextBlockClient.SendBlock(deliverChan, nextLease.ID)
	}

	writeDiskChan := make(chan []byte, DEFAULT_CHAN_SIZE)
	done := make(chan bool, 1)

	// init the lease
	lease.New()
	self.leaseMap[lease.ID] = lease
	self.pipelineMap[lease.ID] = NewPipelineParam(&nextLease, nextParam)

	trans := NewReadTransaction(lease.ID, done, deliverChan, writeDiskChan)
	go self.writeBlockToDisk(writeDiskChan, param.Block)
	// init data receiver
	self.blockServer.StartTransaction(trans)
	return nil
}
示例#2
0
文件: data.go 项目: proj-223/CatFs
func NewPipelineParam(lease *proc.CatLease, param *proc.PrepareBlockParam) *PipelineParam {
	p := &PipelineParam{
		lease: lease,
	}
	if param != nil {
		p.location = param.ServerLocation()
	}
	return p
}