当前位置: 首页>>代码示例>>Golang>>正文


Golang GetReply.Lease方法代码示例

本文整理汇总了Golang中github.com/cmu440/tribbler/rpc/storagerpc.GetReply.Lease方法的典型用法代码示例。如果您正苦于以下问题:Golang GetReply.Lease方法的具体用法?Golang GetReply.Lease怎么用?Golang GetReply.Lease使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cmu440/tribbler/rpc/storagerpc.GetReply的用法示例。


在下文中一共展示了GetReply.Lease方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: addLeaseRecord

func (ss *storageServer) addLeaseRecord(args *storagerpc.GetArgs, reply *storagerpc.GetReply) *storagerpc.GetReply {
	ss.rwl.Lock()
	defer ss.rwl.Unlock()

	// to refuse the lease request
	if ss.inRevoking[args.Key] {
		reply.Lease = storagerpc.Lease{Granted: false}
		return reply
	}

	// append a lease record
	leaseList := ss.leases[args.Key]
	if leaseList == nil {
		ss.leases[args.Key] = list.New()
		leaseList = ss.leases[args.Key]
	}

	leaseList.PushBack(&leaseRecord{
		expirationTime: time.Now().Add(time.Second * time.Duration(leaseSeconds)),
		hostport:       args.HostPort,
	})

	reply.Lease = storagerpc.Lease{
		Granted:      true,
		ValidSeconds: storagerpc.LeaseSeconds,
	}
	return reply
}
开发者ID:oldady,项目名称:ds_p2,代码行数:28,代码来源:storageserver_impl.go

示例2: Get

func (ss *storageServer) Get(args *storagerpc.GetArgs, reply *storagerpc.GetReply) 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 {
		print(ss.beingRevoked)
		makeLease(ss, key, hostPort)
		reply.Lease = storagerpc.Lease{Granted: true, ValidSeconds: storagerpc.LeaseSeconds}
	}

	ss.valMapLock.Lock()
	defer ss.valMapLock.Unlock()

	value, in := ss.valMap[key]
	if !in {
		reply.Status = storagerpc.KeyNotFound
	} else {
		reply.Status = storagerpc.OK
		reply.Value = value
	}

	return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:31,代码来源:storageserver_impl.go

示例3: Get

func (ss *storageServer) Get(args *storagerpc.GetArgs, reply *storagerpc.GetReply) error {
	if DBG {
		fmt.Println("Entered storage server get")
	}

	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.KeyNotFound
	} else {
		reply.Status = storagerpc.OK
		reply.Value = val.(string)
		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()
		}
	}
	return nil
}
开发者ID:aditij1,项目名称:p2aditijakkamat,代码行数:34,代码来源:storageserver_impl.go

示例4: Get

func (ss *storageServer) Get(args *storagerpc.GetArgs, reply *storagerpc.GetReply) error {
	generalReply, value := ss.generalGet(args)

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

	reply.Lease = generalReply.Lease
	reply.Value = value.(string)

	return nil
}
开发者ID:oldady,项目名称:ds_p2,代码行数:13,代码来源:storageserver_impl.go

示例5: Get

func (ss *storageServer) Get(args *storagerpc.GetArgs, reply *storagerpc.GetReply) error {
	if args == nil {
		return errors.New("ss: Can't get nil K/V pair")
	}
	if reply == nil {
		return errors.New("ss: Can't reply with nil in Get")
	}
	if !(ss.CheckKeyInRange(args.Key)) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	// Step 1: Lock the keyLockMap access so as to find the lock for this specific key.
	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()

	// Step 2: Release the sMutex lock so that the ss can serve other GET requests.
	// Meanwhile, since we are dealing with lease related to args.Key, we must lock
	// it using its own lock, keyLock.
	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}

	val, ok := ss.sMap[args.Key]

	if ok {
		reply.Value = val.value
		reply.Status = storagerpc.OK
	} else {
		reply.Status = storagerpc.KeyNotFound
	}
	return nil
}
开发者ID:iedwardwangi,项目名称:Tribbler,代码行数:51,代码来源:storageserver_impl.go

示例6: Get

func (ss *storageServer) Get(args *storagerpc.GetArgs, reply *storagerpc.GetReply) 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 value
	value, exist := ss.keyValueMap[args.Key]
	if !exist {
		reply.Status = storagerpc.KeyNotFound
	} else {
		reply.Status = storagerpc.OK
		reply.Value = value
	}

	lock.Unlock()
	return nil
}
开发者ID:oldady,项目名称:Tribbler,代码行数:46,代码来源:storageserver_impl.go

示例7: Get

func (ss *storageServer) Get(args *storagerpc.GetArgs, reply *storagerpc.GetReply) error {
	if !ss.IsKeyInRange(args.Key) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	value, exist := ss.stringTable[args.Key]
	if !exist {
		reply.Status = storagerpc.KeyNotFound
	} else {
		reply.Status = storagerpc.OK
		reply.Value = value
		if args.WantLease {
			granted := ss.GrantLease(args.Key, args.HostPort)
			reply.Lease = storagerpc.Lease{granted, storagerpc.LeaseSeconds}
		}
	}
	//fmt.Println("Get Value ", value, " for key ", args.Key)
	return nil
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:20,代码来源:storageserver_impl.go


注:本文中的github.com/cmu440/tribbler/rpc/storagerpc.GetReply.Lease方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。