// 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 }