// Get // function: // - fetch stored value with the key // - register lease func (ss *Storageserver) Get(args *storageproto.GetArgs, reply *storageproto.GetReply) error { if !ss.isKeyInRange(args.Key) { reply.Status = storageproto.EWRONGSERVER return nil } req := &cacheReq{GET_VALUE, args.Key, ""} replyc := make(chan interface{}) ss.cacheReqC <- Request{req, replyc} value := <-replyc if value != nil { lsplog.Vlogf(5, "Return Value %s", args.Key) reply.Status = storageproto.OK reply.Value = value.(string) // lease if args.WantLease { req := &cacheReq{PUT_LEASE, args.Key, args.LeaseClient} replyc := make(chan interface{}) ss.cacheReqC <- Request{req, replyc} status := (<-replyc).(bool) if status { lsplog.Vlogf(5, "Get Lease successfully %s", args.Key) reply.Lease.Granted = true reply.Lease.ValidSeconds = storageproto.LEASE_SECONDS } else { lsplog.Vlogf(5, "Get Lease failed %s", args.Key) reply.Lease.Granted = false } } else { reply.Lease.Granted = false } } else { lsplog.Vlogf(5, "Value not found %s", args.Key) reply.Status = storageproto.EKEYNOTFOUND } return nil }
func (pc *ProxyCounter) Get(args *storageproto.GetArgs, reply *storageproto.GetReply) error { if pc.override { reply.Status = pc.overrideStatus return pc.overrideErr } byteCount := len(args.Key) if args.WantLease { atomic.AddUint32(&pc.leaseRequestCount, 1) } if pc.disableLease { args.WantLease = false } err := pc.srv.Call("StorageRPC.Get", args, reply) byteCount += len(reply.Value) if reply.Lease.Granted { if pc.overrideLeaseSeconds > 0 { reply.Lease.ValidSeconds = pc.overrideLeaseSeconds } atomic.AddUint32(&pc.leaseGrantedCount, 1) } atomic.AddUint32(&pc.rpcCount, 1) atomic.AddUint32(&pc.byteCount, uint32(byteCount)) return err }