示例#1
0
func (ss *StorageServer) Get(args *sp.GetArgs, reply *sp.GetReply) error {
	ss.mu.RLock()
	value, present := ss.hashmap[args.Key]
	ss.mu.RUnlock()

	if !present {
		lsplog.Vlogf(3, "[StorageServer] Get key: %s nonexist\n", args.Key)
		reply.Status = sp.EWRONGSERVER
		return nil
	}

	json.Unmarshal(value, &reply.Value)
	if args.WantLease {
		ss.addLeasePool(args, &reply.Lease)
	}
	reply.Status = sp.OK

	lsplog.Vlogf(3, "[StorageServer] Get, key=%v, value=%v\n", args.Key, reply.Value)

	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
}