Exemplo n.º 1
0
func actualRemovePeer(future *removePeerFuture) {
	defer close(future.resultChannel)

	future.ctx.Debugf("[RemovePeer] Removing peer: (hash: %s) (ID: %s)", future.hash, future.peerID)
	err := ds.Delete(future.ctx, getPeerKey(future.ctx, future.hash, future.peerID))

	if err == nil {
		future.ctx.Debugf("[RemovePeer] Deleted peer from datastore.")
		for removalsAttempted := 1; removalsAttempted <= 3; removalsAttempted++ {
			future.ctx.Debugf("[RemovePeer] Attempting cache removal #%d", removalsAttempted)
			var peers []*Peer
			if peersItem, memcacheErr := memcache.Gob.Get(future.ctx, getHashKey(future.ctx, future.hash), &peers); memcacheErr == nil {
				for i, peer := range peers {
					if peer.ID == future.peerID {
						peers = append(peers[:i], peers[i+1:]...)
					}
				}

				peersItem.Object = peers
				memcacheErr := memcache.Gob.CompareAndSwap(future.ctx, peersItem)
				if memcacheErr == nil {
					future.ctx.Debugf("[RemovePeer] Deleted peer from cached peer list.")
					break
				} else if memcacheErr == memcache.ErrCASConflict {
					future.ctx.Debugf("[RemovePeer] Cached peer list conflicted during modification: %s", memcacheErr)
					continue
				} else if memcacheErr == memcache.ErrNotStored {
					future.ctx.Debugf("[RemovePeer] Cached peer list was deleted during modification: %s", memcacheErr)
					break
				} else {
					future.ctx.Errorf("[RemovePeer] Error when attempting to set cached peer list using CAS: %s", memcacheErr)
					future.resultChannel <- memcacheErr
					return
				}
			} else if memcacheErr == memcache.ErrCacheMiss {
				future.ctx.Debugf("[RemovePeer] Peer list not cached.")
				break
			} else if appengine.IsCapabilityDisabled(memcacheErr) {
				future.ctx.Warningf("[RemovePeer] Memcache capability is disabled.")
				break
			} else {
				future.ctx.Errorf("[RemovePeer] Error when attempting to get cache list for deletion: %s", memcacheErr)
				future.resultChannel <- memcacheErr
				return
			}
		}
	} else if err == dserrors.ErrNoSuchEntity {
		future.ctx.Debugf("[RemovePeer] Peer does not exist in datastore")
		return
	}

	future.ctx.Debugf("[RemovePeer] Successfully removed peer")

	if err != nil {
		future.resultChannel <- err
	}
}
Exemplo n.º 2
0
Arquivo: token.go Projeto: gaego/user
func (e *Token) Delete(c context.Context) error {
	return ds.Delete(c, e.Key)
}