func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	if DBG {
		fmt.Println("Entered storageserver GetList")
	}
	if !ss.inRange(libstore.StoreHash(args.Key)) {
		reply.Status = storagerpc.WrongServer
		return nil
	}
	ss.dataLock.Lock()
	val, ok := ss.dataStore[args.Key]
	ss.dataLock.Unlock()
	if ok {
		reply.Status = storagerpc.OK
		reply.Value = ListToSlice(val.(*list.List))
		if args.WantLease && ss.pendingMap[args.Key].pending == 0 {
			ss.leaseLock.Lock()
			lease := storagerpc.Lease{Granted: true, ValidSeconds: storagerpc.LeaseSeconds}
			reply.Lease = lease
			// Track that this lease was issued
			leaseWrap := LeaseWrapper{lease: lease, timeGranted: time.Now(), hostport: args.HostPort}
			_, ok := ss.leaseStore[args.Key]
			if !ok {
				ss.leaseStore[args.Key] = list.New()
			}
			ss.leaseStore[args.Key].PushBack(leaseWrap)
			ss.leaseLock.Unlock()
		}
	} else {
		reply.Status = storagerpc.KeyNotFound
	}
	return nil
}
Example #2
0
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	key := args.Key

	if !correctServer(ss, key) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	wantLease := args.WantLease
	hostPort := args.HostPort

	being := beingRevoked(ss, key)
	if wantLease && !being {
		makeLease(ss, key, hostPort)
		reply.Lease = storagerpc.Lease{Granted: true, ValidSeconds: storagerpc.LeaseSeconds}
	}

	ss.listMapLock.Lock()
	defer ss.listMapLock.Unlock()

	value, in := ss.listMap[key]

	if !in {
		reply.Status = storagerpc.KeyNotFound
	} else {
		reply.Status = storagerpc.OK
		reply.Value = value
	}
	return nil
}
Example #3
0
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	if ss.isReady == false {
		reply.Status = storagerpc.NotReady
	} else {
		if ss.getServerID(args.Key) != ss.nodeID {
			reply.Status = storagerpc.WrongServer
			return nil
		}
		ss.serverMutex.Lock()
		if ss.userListMutex[args.Key] == nil {
			ss.userListMutex[args.Key] = &sync.Mutex{}
		}
		ss.serverMutex.Unlock()
		ss.userListMutex[args.Key].Lock()
		defer ss.userListMutex[args.Key].Unlock()
		_, exist := ss.userList[args.Key]
		if exist == false {
			reply.Status = storagerpc.KeyNotFound
		} else {
			reply.Status = storagerpc.OK
			reply.Value = list2SliceString(ss.userList[args.Key])
			if args.WantLease == true {
				ss.grantLease(args.HostPort, ss.userListLease[args.Key], &reply.Lease)
			}
		}
	}
	return nil
}
Example #4
0
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	if !ss.isInServerRange(args.Key) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	//get the lock for current key
	ss.mutex.Lock()
	lock, exist := ss.lockMap[args.Key]
	if !exist {
		lock = new(sync.Mutex)
		ss.lockMap[args.Key] = lock
	}
	ss.mutex.Unlock()

	//Lock current key we are going to work on
	lock.Lock()

	//process lease request
	grantLease := false
	if args.WantLease {
		//add to lease map
		var libServerList *list.List
		libServerList, exist := ss.leaseMap[args.Key]
		if !exist {
			libServerList = new(list.List)
		}
		leaseRecord := LeaseRecord{args.HostPort, time.Now()}
		libServerList.PushBack(leaseRecord)
		ss.leaseMap[args.Key] = libServerList
		grantLease = true
	}
	reply.Lease = storagerpc.Lease{grantLease, storagerpc.LeaseSeconds}

	//retrieve list
	list, exist := ss.keyListMap[args.Key]
	if !exist {
		reply.Status = storagerpc.KeyNotFound
	} else {
		//convert list format from "map" to "[]string"
		listSize := list.Len()
		replyList := make([]string, listSize)

		i := 0
		for e := list.Front(); e != nil; e = e.Next() {
			val := (e.Value).(string)
			replyList[i] = val
			i = i + 1
		}

		reply.Value = replyList
		reply.Status = storagerpc.OK
	}

	lock.Unlock()
	return nil
}
Example #5
0
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	generalReply, value := ss.generalGet(args)

	reply.Status = generalReply.Status
	if reply.Status != storagerpc.OK {
		return nil
	}

	reply.Lease = generalReply.Lease
	for e := value.(*list.List).Front(); e != nil; e = e.Next() {
		reply.Value = append(reply.Value, e.Value.(string))
	}

	return nil
}
Example #6
0
func (pc *proxyCounter) GetList(args *storagerpc.GetArgs, reply *storagerpc.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("StorageServer.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
}
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	if !ss.IsKeyInRange(args.Key) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	list, exist := ss.listTable[args.Key]
	if !exist {
		reply.Status = storagerpc.KeyNotFound
	} else {
		reply.Value = list
		reply.Status = storagerpc.OK
		if args.WantLease {
			granted := ss.GrantLease(args.Key, args.HostPort)
			reply.Lease = storagerpc.Lease{granted, storagerpc.LeaseSeconds}
		}
	}
	return nil
}
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	if args == nil {
		return errors.New("ss: Can't getList nil K/V pair")
	}
	if reply == nil {
		return errors.New("ss: Can't reply with nil in GetList")
	}
	if !(ss.CheckKeyInRange(args.Key)) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	ss.sMutex.Lock()
	keyLock, exist := ss.keyLockMap[args.Key]
	if !exist {
		// Create new lock for the key
		keyLock = &sync.Mutex{}
		ss.keyLockMap[args.Key] = keyLock
	}
	ss.sMutex.Unlock()

	granted := false
	keyLock.Lock()
	defer keyLock.Unlock()

	if args.WantLease {
		leasedLibStores, ok := ss.leaseMap[args.Key]
		if !ok {
			leasedLibStores = make(map[string]time.Time)
			ss.leaseMap[args.Key] = leasedLibStores
		}
		ss.leaseMap[args.Key][args.HostPort] = time.Now()
		granted = true

	}
	reply.Lease = storagerpc.Lease{granted, storagerpc.LeaseSeconds}

	lst, ok := ss.lMap[args.Key]
	if ok {
		// Copy and return the current list
		rst := make([]string, len(lst.value), cap(lst.value))
		copy(rst, lst.value)
		reply.Value = rst
		reply.Status = storagerpc.OK
	} else {
		reply.Value = make([]string, 0, 0)
		reply.Status = storagerpc.KeyNotFound
	}
	return nil
}
Example #9
0
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
	key := args.Key
	if rightStorageServer(ss, key) == false {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	if data, found := ss.topMap[key]; found {
		if strList, ok := data.([]string); ok {
			// key was found, had valid []string data
			reply.Status = storagerpc.OK
			reply.Value = strList
		} else {
			// key was found with string data, return empty list (This shouldn't happen)
			reply.Status = storagerpc.OK
			reply.Value = make([]string, 0)
		}
	} else {
		reply.Status = storagerpc.KeyNotFound
	}
	return nil
}
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {

	//	fmt.Println("GetList Function Called!.", args);
	if FindPartitionNode(ss.ring, args.Key).NodeID != ss.nodeID {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	reply.Lease.Granted = false

	// first get the value from the storage map
	ss.sMutex.Lock()
	data, ok := ss.storage[args.Key]
	ss.sMutex.Unlock()

	if !ok {
		// if the key is not found
		reply.Status = storagerpc.KeyNotFound
		return nil //errors.New("Key not found for GetList Function.")
	} else {
		data.dMutex.Lock()
		defer data.dMutex.Unlock()

		if args.WantLease {
			// want a lease
			// grant a lease
			reply.Lease = storagerpc.Lease{Granted: true, ValidSeconds: storagerpc.LeaseSeconds}
			reply.Status = storagerpc.OK
			reply.Value = data.data.([]string)

			if data.Set == nil {
				lMap := make(map[string](*leaseCallBack))
				data.Set = lMap
			}

			// add this one to the lease list
			var val *leaseCallBack
			val, ok = data.Set[args.HostPort]
			if ok {
				// only update the lease time, don't need to create the hanlder
				val.registerTime = time.Now().Unix()
			} else {
				// need to create a new leaseCallBack struct
				//				cli, err := rpc.DialHTTP("tcp", args.HostPort)
				//				if err != nil {
				//					fmt.Println("GetFunction add callback lease failed.")
				//					return err
				//				}

				val = &leaseCallBack{
					//					cli:          cli,
					cbAddr:       args.HostPort,
					registerTime: time.Now().Unix(),
					validation:   storagerpc.LeaseGuardSeconds + storagerpc.LeaseSeconds}

				data.Set[args.HostPort] = val
			}
		} else {
			reply.Status = storagerpc.OK
			reply.Value = data.data.([]string)
		}
	}
	//	fmt.Println("Get function returns.", reply.Value);
	return nil
}