コード例 #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
// Get the block from data server
// Will start an tcp connect to request block
func (self *DataServer) GetBlock(param *proc.GetBlockParam, lease *proc.CatLease) error {
	// init lease
	lease.New()
	self.leaseMap[lease.ID] = lease

	block := param.Block
	data := make(chan []byte)
	go self.readBlockFromDisk(data, block)
	trans := NewProviderTransaction(lease.ID, data)
	self.blockServer.StartTransaction(trans)
	return nil
}