Esempio n. 1
0
func (pc *ProxyCounter) GetList(args *storageproto.GetArgs, reply *storageproto.GetListReply) 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.GetList", args, reply)
	for _, s := range reply.Value {
		byteCount += len(s)
	}
	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
}
Esempio n. 2
0
// GetList
// function:
// - fetch stored list value with the key
// - register lease
func (ss *Storageserver) GetList(args *storageproto.GetArgs, reply *storageproto.GetListReply) error {
	if !ss.isKeyInRange(args.Key) {
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}

	req := &cacheReq{GET_LIST_VALUE, args.Key, ""}
	replyc := make(chan interface{})
	ss.cacheReqC <- Request{req, replyc}
	valueList := <-replyc
	if valueList != nil {
		lsplog.Vlogf(5, "Return Value List %s", args.Key)
		reply.Status = storageproto.OK
		reply.Value = valueList.([]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.EITEMNOTFOUND
	}
	return nil
}