コード例 #1
0
func (ls *Libstore) iGet(key string) (string, error) {
	var args sp.GetArgs = sp.GetArgs{key, false, ls.hostport}
	var reply sp.GetReply

	if val, err := ls.leases.Get(key, &args); err == nil {
		return val.(string), nil
	}

	if (ls.flags & ALWAYS_LEASE) != 0 {
		args.WantLease = true
	}

	cli, err := ls.pickServer(key)
	if err != nil {
		return "", err
	}

	err = cli.Call("StorageRPC.Get", &args, &reply)
	if err != nil {
		lsplog.Vlogf(3, "[Libstore] rpc call error: %v\n", err)
		return "", err
	}

	if reply.Status != sp.OK {
		lsplog.Vlogf(3, "[Libstore] Get error, status=%d\n", reply.Status)
		return "", lsplog.MakeErr("Get error")
	}

	if reply.Lease.Granted {
		ls.leases.Grant(key, reply.Value, reply.Lease)
	}

	return reply.Value, nil
}
コード例 #2
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
}
コード例 #3
0
ファイル: cache.go プロジェクト: kedebug/golang-programming
func (c *Cache) Get(key string, args *sp.GetArgs) (interface{}, error) {
	c.mu.Lock()
	c.evict()

	e, ok := c.cache[key]
	if !ok {
		e = &entry{ll: list.New()}
		c.cache[key] = e
	}
	c.mu.Unlock()

	e.mu.Lock()
	defer e.mu.Unlock()

	if e.granted {
		return e.val, nil
	}

	e.ll.PushBack(time.Now())
	if e.ll.Len() > sp.QUERY_CACHE_THRESH {
		args.WantLease = true
	}

	return nil, lsplog.MakeErr("key nonexist in cache")
}