當前位置: 首頁>>代碼示例>>Golang>>正文


Golang storagerpc.DeleteReply類代碼示例

本文整理匯總了Golang中github.com/cmu440/tribbler/rpc/storagerpc.DeleteReply的典型用法代碼示例。如果您正苦於以下問題:Golang DeleteReply類的具體用法?Golang DeleteReply怎麽用?Golang DeleteReply使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DeleteReply類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Delete

func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {
	if !ss.IsKeyInRange(args.Key) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	ss.lockForTableLocks.Lock()
	/* Lock table for writing */
	lock, exist := ss.tableLocks[args.Key]
	if !exist {
		lock = new(sync.Mutex)
		ss.tableLocks[args.Key] = lock
	}
	ss.lockForTableLocks.Unlock()
	lock.Lock()
	defer lock.Unlock()

	ss.RevokeLease(args.Key)

	_, exist = ss.stringTable[args.Key]
	if !exist {
		reply.Status = storagerpc.KeyNotFound
	} else {

		delete(ss.stringTable, args.Key)
		reply.Status = storagerpc.OK
	}
	return nil
}
開發者ID:mallocanswer,項目名稱:Tribbler,代碼行數:29,代碼來源:storageserver_impl.go

示例2: Delete

func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {

	key := args.Key

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

	leases := getLeases(ss, key)
	if leases != nil {
		ss.editLock.Lock()
		revokeLease(ss, key)
		ss.editLock.Unlock()
	}
	ss.valMapLock.Lock()
	defer ss.valMapLock.Unlock()

	_, in := ss.valMap[key]
	if !in {
		reply.Status = storagerpc.KeyNotFound
	} else {
		delete(ss.valMap, key)
		reply.Status = storagerpc.OK
	}

	return nil

}
開發者ID:jbuckman,項目名稱:p2-440,代碼行數:29,代碼來源:storageserver_impl.go

示例3: Delete

// Delete remove the specified key from the data store.
// If the key does not fall within the storage server's range,
// it should reply with status WrongServer.
// If the key is not found, it should reply with status KeyNotFound.
func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {

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

	// lock the whole storage first
	ss.sMutex.Lock()
	defer ss.sMutex.Unlock()

	// retrieve the data unit
	data, ok := ss.storage[args.Key]
	if ok {
		reply.Status = storagerpc.OK
		data.dMutex.Lock()
		// WARNING: here we might meet the situation of wild pointer.
		// that is the value is already deleted from the map, but the
		ss.RevokeCallBacksForKey(args.Key, data)
		data.dMutex.Unlock()

		// aplly changes
		delete(ss.storage, args.Key)

		return nil
	} else {
		reply.Status = storagerpc.KeyNotFound
		return nil
	}

	return nil
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:37,代碼來源:storageserver_impl.go

示例4: Delete

func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) 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.userValueMutex[args.Key] == nil {
			ss.userValueMutex[args.Key] = &sync.Mutex{}
		}
		ss.serverMutex.Unlock()
		ss.userValueMutex[args.Key].Lock()
		defer ss.userValueMutex[args.Key].Unlock()
		_, exist := ss.userValue[args.Key]
		if exist == false {
			reply.Status = storagerpc.KeyNotFound
		} else {
			// revoke all leases if already exist in server before
			err := ss.revokeLease(args.Key, ss.userValueLease[args.Key])
			if err != nil {
				return err
			}
			ss.userValueLease[args.Key] = make(map[string]*lease)

			reply.Status = storagerpc.OK
			delete(ss.userValue, args.Key)
		}
	}
	return nil
}
開發者ID:thuhujin,項目名稱:Tribbler,代碼行數:32,代碼來源:storageserver_impl.go

示例5: Delete

func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {
	if DBG {
		fmt.Println("Entered storageserver delete")
	}
	if !ss.inRange(libstore.StoreHash(args.Key)) {
		reply.Status = storagerpc.WrongServer
		return nil
	}

	_, ok := ss.dataStore[args.Key]
	if !ok {
		reply.Status = storagerpc.KeyNotFound
		return nil
	}

	// Leasing check
	ss.leaseLock.Lock()
	pendingModifications, ok := ss.pendingMap[args.Key]

	if !ok {
		reply.Status = storagerpc.KeyNotFound
		ss.leaseLock.Unlock()
		return nil
	}

	pendingModifications.pending++
	leaseHolders, ok := ss.leaseStore[args.Key]
	ss.leaseLock.Unlock()

	if pendingModifications.pending > 1 { // Block until it's our turn to modify key
		response := make(chan int)
		pendingModifications.pendingCh <- response
		<-response
	}

	if ok {
		ss.revokeLeases(leaseHolders, args.Key)
	}

	ss.dataLock.Lock()
	delete(ss.dataStore, args.Key)
	ss.dataLock.Unlock()
	reply.Status = storagerpc.OK
	pendingModifications.pending--
Loop:
	for {
		select {
		case ch := <-pendingModifications.pendingCh:
			ch <- 1
			break Loop
		default:
			break Loop
		}
	}
	return nil
}
開發者ID:aditij1,項目名稱:p2aditijakkamat,代碼行數:56,代碼來源:storageserver_impl.go

示例6: Delete

func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {
	if args == nil {
		return errors.New("ss: Can't delete nil K/V pair")
	}
	if reply == nil {
		return errors.New("ss: Can't reply with nil in Delete")
	}
	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()

	keyLock.Lock()
	defer keyLock.Unlock()

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

	if !ok {
		reply.Status = storagerpc.KeyNotFound
		return nil
	}

	hpTimeMap, leaseExists := ss.leaseMap[args.Key]
	if leaseExists {
		// Revoke all issued leases.
		successChan := make(chan int, 1)
		finishChan := make(chan int, 1)
		expected := len(hpTimeMap)
		go ss.CheckRevokeStatus(args.Key, successChan, finishChan, expected)
		for hp, _ := range hpTimeMap {
			go ss.RevokeLeaseAt(hp, args.Key, successChan)
		}

		<-finishChan

		delete(ss.leaseMap, args.Key)
	}

	delete(ss.sMap, args.Key)
	reply.Status = storagerpc.OK
	return nil
}
開發者ID:iedwardwangi,項目名稱:Tribbler,代碼行數:51,代碼來源:storageserver_impl.go

示例7: Delete

func (pc *proxyCounter) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {
	if pc.override {
		reply.Status = pc.overrideStatus
		return pc.overrideErr
	}
	byteCount := len(args.Key)
	err := pc.srv.Call("StorageServer.Delete", args, reply)
	atomic.AddUint32(&pc.rpcCount, 1)
	atomic.AddUint32(&pc.byteCount, uint32(byteCount))
	return err
}
開發者ID:codingfrenzy,項目名稱:p2,代碼行數:11,代碼來源:proxycounter.go

示例8: Delete

func (ss *storageServer) Delete(args *storagerpc.DeleteArgs, reply *storagerpc.DeleteReply) error {

	key := args.Key
	if rightStorageServer(ss, key) == false {
		reply.Status = storagerpc.WrongServer

		return nil
	}
	if _, found := ss.keyLocks[key]; found == false {
		ss.keyLocks[key] = make(chan int, 1)
	} else {
		<-ss.keyLocks[key]
	}

	if _, found := ss.topMap[key]; found {
		delete(ss.topMap, key)
		reply.Status = storagerpc.OK
	} else {
		reply.Status = storagerpc.KeyNotFound
	}
	ss.keyLocks[key] <- 1
	return nil
}
開發者ID:pyurky,項目名稱:p2,代碼行數:23,代碼來源:storageserver_impl.go


注:本文中的github.com/cmu440/tribbler/rpc/storagerpc.DeleteReply類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。