Check if any of the existing transfers should be restarted from a different source because the initial source is no longer a member.
189260
private void restartBrokenTransfers(CacheTopology cacheTopology, IntSet addedSegments) {
      Set<Address> members = new HashSet<>(cacheTopology.getReadConsistentHash().getMembers());
      synchronized (transferMapsLock) {
         for (Iterator<Map.Entry<Address, List<InboundTransferTask>>> it = transfersBySource.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<Address, List<InboundTransferTask>> entry = it.next();
            Address source = entry.getKey();
            if (!members.contains(source)) {
               if (trace) {
                  log.tracef("Removing inbound transfers from source %s for cache %s", source, cacheName);
               }
               List<InboundTransferTask> inboundTransfers = entry.getValue();
               it.remove();
               for (InboundTransferTask inboundTransfer : inboundTransfers) {
                  // these segments will be restarted if they are still in new write CH
                  if (trace) {
                     log.tracef("Removing inbound transfers from node %s for segments %s", source, inboundTransfer.getSegments());
                  }
                  IntSet unfinishedSegments = inboundTransfer.getUnfinishedSegments();
                  inboundTransfer.cancel();
                  addedSegments.addAll(unfinishedSegments);
                  transfersBySegment.keySet().removeAll(unfinishedSegments);
               }
            }
         }

         // exclude those that are already in progress from a valid source
         addedSegments.removeAll(transfersBySegment.keySet());
      }
   }
176534
def brpoplpush(self, source, destination, timeout=0):
        """"""
        transfer_item = self.brpop(source, timeout)
        if transfer_item is None:
            return None

        key, val = transfer_item
        self.lpush(destination, val)
        return val
1259163
def need_rejoin(self):
        
        if not self._subscription.partitions_auto_assigned():
            return False

        if self._auto_assign_all_partitions():
            return False

        # we need to rejoin if we performed the assignment and metadata has changed
        if (self._assignment_snapshot is not None
            and self._assignment_snapshot != self._metadata_snapshot):
            return True

        # we need to join if our subscription has changed since the last join
        if (self._joined_subscription is not None
            and self._joined_subscription != self._subscription.subscription):
            return True

        return super(ConsumerCoordinator, self).need_rejoin()
599365
public void cancelSegments(IntSet cancelledSegments) {
      if (segments.removeAll(cancelledSegments)) {
         if (trace) {
            log.tracef("Cancelling outbound transfer to node %s, segments %s (remaining segments %s)",
                       destination, cancelledSegments, segments);
         }
         entriesBySegment.keySet().removeAll(cancelledSegments);  // here we do not update accumulatedEntries but this inaccuracy does not cause any harm
         if (segments.isEmpty()) {
            cancel();
         }
      }
   }
793305
function (transfer, cb) {

		Transfer.findOrCreate(transfer.id, transfer)
	    .exec(function (err, foundTransfer){
	      if (err) return cb(err);
	      if (foundTransfer.lastStripeEvent > transfer.lastStripeEvent) return cb(null, foundTransfer);
	      if (foundTransfer.lastStripeEvent == transfer.lastStripeEvent) return Transfer.afterStripeTransferCreated(foundTransfer, function(err, transfer){ return cb(err, transfer)});
	      Transfer.update(foundTransfer.id, transfer)
	      .exec(function(err, updatedTransfers){
	      	if (err) return cb(err);
	      	if(!updatedTransfers) return cb(null, null);
	      	Transfer.afterStripeTransferCreated(updatedTransfers[0], function(err, transfer){
	      		cb(err, transfer);
	      	});
	      });
	    });
	}
860753
private function isInTransaction()
    {
        $poolName = $this->poolName;
        if(null === $poolName)
        {
            $poolName = Db::getDefaultPoolName();
        }
        if(PoolManager::hasRequestContextResource($poolName))
        {
            $resource = PoolManager::getRequestContextResource($poolName);
            $db = $resource->getInstance();
            return $db->inTransaction();
        }
        else
        {
            return false;
        }
    }
641932
def clear_if_finalized(
        iteration: TransitionResult,
) -> TransitionResult[InitiatorPaymentState]:
    
    state = cast(InitiatorPaymentState, iteration.new_state)

    if state is None:
        return iteration

    if len(state.initiator_transfers) == 0:
        return TransitionResult(None, iteration.events)

    return iteration
1310753
private void checkForMembershipChanges() throws KeeperException, InterruptedException {
        Set<String> children = ImmutableSet.copyOf(m_zk.getChildren(m_stateMachineMemberPath, m_membershipWatcher));

        Set<String> removedMembers;
        Set<String> addedMembers;
        if (m_registeredStateMachineInstances == m_registeredStateMachines.length && !m_groupMembers.equals(children)) {
            removedMembers = Sets.difference(m_groupMembers, children);
            addedMembers = Sets.difference(children, m_groupMembers);
            m_groupMembers = children;
            for (StateMachineInstance stateMachine : m_registeredStateMachines) {
                stateMachine.membershipChanged(m_groupMembers, addedMembers, removedMembers);
            }
        }
    }
468679
private boolean continuousColocation(ReconfigurationProblem rp, List<Slice> dSlices) {

      Set<VM> alreadyRunning = new HashSet<>();
        Mapping map = rp.getSourceModel().getMapping();
        Node loc = null;
        for (VM vm : cstr.getInvolvedVMs()) {
            if (map.isRunning(vm)) {
              alreadyRunning.add(vm);
                Node node = map.getVMLocation(vm);
                if (loc == null) {
                    loc = node;
                } else if (!loc.equals(node)) {
                    rp.getLogger().error("Some VMs in '{}' are already running but not co-located", cstr.getInvolvedVMs());
                    return false;
                }
            }
        }
        if (loc != null) {
          if (cstr.getInvolvedVMs().size() == 1 && dSlices.size() == 1) {
            // The VM may migrate, we don't care as it is alone.
            return true;
          }
            return placeDSlices(rp, dSlices, rp.getNode(loc));
        }
        return true;
    }
1040567
public boolean isDataSinkModeSupported() {
	String id = getHandlerID(session.transferMode, session.transferType, SINK);
	return (dataHandlers.get(id) != null);
    }
538525
def is_running(self, is_stopped):
        '''  '''
        if is_stopped and self.is_stopped():
            return False

        return faspmanager2.isRunning(self.get_transfer_id())
534050
def request_transfer(subject, recipient, comment):
    ''''''
    TransferPermission(subject).test()
    if recipient == (subject.organization or subject.owner):
        raise ValueError(
            'Recipient should be different than the current owner')
    transfer = Transfer.objects.create(
        owner=subject.organization or subject.owner,
        recipient=recipient,
        subject=subject,
        comment=comment
    )
    return transfer
687009
def is_complete(self):
        """"""

        if 'status' in self.transfer_info:
            self._complete = self.transfer_info['status'] == 'STATUS_COMPLETE'

        return self._complete
499988
def detach(self):
		

		# First, wipe default source on all customers that use this.
		Customer.objects.filter(default_source=self.id).update(default_source=None)

		try:
			# TODO - we could use the return value of sync_from_stripe_data
			#  or call its internals - self._sync/_attach_objects_hook etc here
			#  to update `self` at this point?
			self.sync_from_stripe_data(self.api_retrieve().detach())
			return True
		except (InvalidRequestError, NotImplementedError):
			# The source was already detached. Resyncing.
			# NotImplementedError is an artifact of stripe-python<2.0
			# https://github.com/stripe/stripe-python/issues/376
			self.sync_from_stripe_data(self.api_retrieve())
			return False
1307044
private void consolidateIfNeeded() {
        // Consolidate if the number of components will exceed the allowed maximum by the current
        // operation.
        int size = componentCount;
        if (size > maxNumComponents) {
            final int capacity = components[size - 1].endOffset;

            ByteBuf consolidated = allocBuffer(capacity);
            lastAccessed = null;

            // We're not using foreach to avoid creating an iterator.
            for (int i = 0; i < size; i ++) {
                components[i].transferTo(consolidated);
            }

            components[0] = new Component(consolidated, 0, 0, capacity, consolidated);
            removeCompRange(1, size);
        }
    }
228725
def start(self, segment):
        """"""

        if self.closed:
            raise UserCritical(msg='attempt to transfer wal after closing',
                               hint='report a bug')

        g = gevent.Greenlet(self.transferer, segment)
        g.link(self._complete_execution)
        self.greenlets.add(g)

        # Increment .expect before starting the greenlet, or else a
        # very unlucky .join could be fooled as to when pool is
        # complete.
        self.expect += 1

        g.start()
858098
private void migrateMemberships() throws Exception
   {
      Session session = service.getStorageSession();
      try
      {
         if (session.itemExists(usersStorageOld))
         {
            NodeIterator iterator = ((ExtendedNode)session.getItem(usersStorageOld)).getNodesLazily();
            MembershipHandlerImpl mh = ((MembershipHandlerImpl)service.getMembershipHandler());
            while (iterator.hasNext())
            {
               Node oldUserNode = iterator.nextNode();
               mh.migrateMemberships(oldUserNode);
               oldUserNode.remove();
               session.save();
            }
         }
      }
      finally
      {
         session.logout();
      }
   }