Exemplo n.º 1
0
func handleSet(req *gomemcached.MCRequest, s *luxStor, id int) (ret *gomemcached.MCResponse) {
	ret = &gomemcached.MCResponse{}

	/*
		item.Flags = binary.BigEndian.Uint32(req.Extras)
		item.Expiration = binary.BigEndian.Uint32(req.Extras[4:])
		item.Data = req.Body
		ret.Status = gomemcached.SUCCESS
		s.cas++
		item.Cas = s.cas
		ret.Cas = s.cas
	*/

	flags := binary.BigEndian.Uint32(req.Extras)
	// flags == 0 is a normal write and must be replicated
	if flags == 0 {
		if replica.IsOwner(req) != true {
			// nothing more to be done
			replica.ProxyRemoteWrite(req)
			return
		} else {
			replica.QueueRemoteWrite(req)
		}
	}

	data := newByteItem(req.Key, req.Body)
	itm := memstore.NewItem(data)

	w := s.writers[id]
	w.Put(itm)

	luxstats.Sets++

	return
}
Exemplo n.º 2
0
func handleGet(req *gomemcached.MCRequest, s *luxStor, id int) (ret *gomemcached.MCResponse) {
	ret = &gomemcached.MCResponse{}

	if replica.IsOwner(req) != true {
		return replica.ProxyRemoteRead(req)
	}

	data := newByteItem(req.Key, nil)
	itm := memstore.NewItem(data)
	w := s.writers[id]
	gotItm := w.Get(itm)
	if gotItm == nil {
		ret.Status = gomemcached.KEY_ENOENT
	} else {
		bItem := byteItem(gotItm.Bytes())
		ret.Body = bItem.Value()
		ret.Status = gomemcached.SUCCESS
	}

	luxstats.Gets++

	return
}