Example #1
0
func (ss *Storageserver) GetList(args *storageproto.GetArgs,
	reply *storageproto.GetListReply) error {

	lsplog.Vlogf(3, "storage try to getlist with key %s", args.Key)

	//ss.rwlock.RLock()

	val, present := ss.hash[args.Key]
	if !present {
		if ss.numnodes == 1 {
			reply.Status = storageproto.EKEYNOTFOUND
		} else {
			reply.Status = storageproto.EWRONGSERVER
		}
		reply.Value = nil
		//ss.rwlock.RUnlock()
		return nil
	}

	lsplog.Vlogf(3, "storage getlist key %s, val %s", args.Key, val)

	err := json.Unmarshal([]byte(val), &(reply.Value))
	if err != nil {
		lsplog.Vlogf(0, "WARNING: unmarshal data generate an error")
	}

	reply.Status = storageproto.OK

	if args.WantLease {
		ss.addLeasePool(args, &(reply.Lease))
	}

	//ss.rwlock.RUnlock()
	return nil
}
Example #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
}
Example #3
0
func (ss *Storageserver) GetList(args *storageproto.GetArgs, reply *storageproto.GetListReply) error {
	lsplog.Vlogf(1, "[GetList] GetList is called with Key=[%v]", args.Key)
	if !ss.CheckWithinRange(args.Key) {
		reply.Status = storageproto.EWRONGSERVER
		lsplog.Vlogf(1, "[GetList] The key is given to the wrong server")
		return nil
	}
	if args.WantLease {
		lsplog.Vlogf(1, "[GetList] A lease is requested")
		ss.modifyingListLock.Lock()
		if ss.modifyingList[args.Key] != nil {
			reply.Lease.Granted = false
		} else {
			reply.Lease.Granted = true
			ss.leasesListLock.Lock()
			currentLeaseList := ss.leasesList[args.Key]
			if currentLeaseList == nil {
				currentLeaseList = list.New()
			}
			currentLeaseList.PushBack(&ClientLease{args.LeaseClient, time.Now().Add((storageproto.LEASE_SECONDS + storageproto.LEASE_GUARD_SECONDS) * time.Second)})
			ss.leasesListLock.Unlock()
		}
		ss.modifyingListLock.Unlock()
	}
	lsplog.Vlogf(1, "[GetList] Locking stoargeList")
	ss.storageListLock.Lock()
	if ss.storageList[args.Key] == nil {
		reply.Status = storageproto.EKEYNOTFOUND
		lsplog.Vlogf(1, "[GetList] returned EKEYNOTFOUND")
	} else {
		valueList := ss.storageList[args.Key]
		reply.Value = make([]string, valueList.Len())
		i := 0
		for e := valueList.Front(); e != nil; e = e.Next() {
			reply.Value[i] = e.Value.(string)
			i++
		}
		reply.Status = storageproto.OK
		lsplog.Vlogf(1, "[GetList] returned OK")
	}
	ss.storageListLock.Unlock()
	return nil
}
Example #4
0
/**@brief given a key, get list of strings
 * @param key
 * @return string[]
 * @return error
 */
func (ls *Libstore) iGetList(key string) ([]string, error) {
	var cli *rpc.Client
	var args storageproto.GetArgs = storageproto.GetArgs{key, false, ls.Addr}
	var reply storageproto.GetListReply
	var err error

	//try cache first
	if tmp, err := ls.Leases.Get(key, &args); err == nil {
		reply.Value = tmp.([]string)
		return reply.Value, nil
	}

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

	cli, err = ls.GetServer(key)
	if lsplog.CheckReport(1, err) {
		return nil, err
	}

	//lsplog.Vlogf(0, "GetList args %v", args)

	err = cli.Call("StorageRPC.GetList", &args, &reply)
	if lsplog.CheckReport(1, err) {
		return nil, err
	}

	//lsplog.Vlogf(0, "GetList reply %v", reply)

	if reply.Lease.Granted {
		ls.Leases.LeaseGranted(key, reply.Value, reply.Lease)
	}

	if reply.Status != storageproto.OK {
		return nil, MakeErr("GetList()", reply.Status)
	}

	return reply.Value, nil
}
Example #5
0
func (ss *Storageserver) GetList(args *storageproto.GetArgs, reply *storageproto.GetListReply) error {

	//fmt.Println("called getList")
	//fmt.Printf("key: %v\n", args.Key)

	rightServer := ss.checkServer(args.Key)

	if rightServer == false {
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}

	<-ss.leaseMapM
	leaseInfo, exists := ss.leaseMap[args.Key]
	ss.leaseMapM <- 1

	if exists == true {
		list := *leaseInfo.ClientKeys
		for i := 0; i < len(list); i++ {
			if list[i] == args.LeaseClient {
				args.WantLease = false
			}
		}
	}

	if args.WantLease == true {
		//grant lease
		//is there any reason to not grant it?
		reply.Lease.Granted = true
		reply.Lease.ValidSeconds = storageproto.LEASE_SECONDS
		if exists == true {
			<-leaseInfo.Mutex
			*leaseInfo.ClientKeys = append(*leaseInfo.ClientKeys, args.LeaseClient)
			leaseInfo.Mutex <- 1
			// fmt.Printf("**GETLIST added %v to %v lease list\n", args.LeaseClient, args.Key)
			ss.PrintLeaseMap()
		} else {
			keys := []string{}
			keys = append(keys, args.LeaseClient)
			<-ss.leaseMapM
			mutex := make(chan int, 1)
			mutex <- 1
			ss.leaseMap[args.Key] = &LeaseInfo{Mutex: mutex, ClientKeys: &keys}
			ss.leaseMapM <- 1
			// fmt.Printf("**GETLIST added %v to %v lease list\n", args.LeaseClient, args.Key)
			ss.PrintLeaseMap()
		}

		<-ss.clientLeaseMapM
		leaseExpiration := time.Now().Add((storageproto.LEASE_SECONDS + storageproto.LEASE_GUARD_SECONDS) * time.Second).UnixNano()
		ss.clientLeaseMap[args.LeaseClient+"@"+args.Key] = leaseExpiration
		ss.clientLeaseMapM <- 1

	} else {
		reply.Lease.Granted = false
		reply.Lease.ValidSeconds = 0
	}

	<-ss.listMapM
	list, ok := ss.listMap[args.Key]
	ss.listMapM <- 1

	if ok != true {
		reply.Status = storageproto.EITEMNOTFOUND
		reply.Value = []string{}
	} else {
		reply.Status = storageproto.OK
		reply.Value = list
	}

	return nil
}