func (m *membership) onePeerForDataStructureId(dataStructureId *ID) (*pb.RaftPeer, error) {
	m.serfTagMutex.Lock()
	defer m.serfTagMutex.Unlock()

	raftIdsMap, ok := m.dataStructureIdToRaftIds[*dataStructureId]
	// we got nothing in our local cache
	// let's make sure the entire cluster doesn't know about this data structure
	if !ok {
		peer, err := m.findDataStructureWithId(dataStructureId)
		if err != nil {
			return nil, err
		} else if peer == nil {
			return nil, fmt.Errorf("Can't find data structure with id [%s]", dataStructureId)
		}

		return peer, nil
	}

	m.logger.Warnf("Cache hit: %d", len(raftIdsMap))
	// cache hit!
	for raftId := range raftIdsMap {
		v, ok := m.raftIdToAddress[raftId]
		if ok {
			return &pb.RaftPeer{
				RaftId:      raftId,
				PeerAddress: v,
			}, nil
		}
	}

	return nil, fmt.Errorf("Can't find data structure with id [%d]", dataStructureId)
}
// For connection use cases, we just need one peer in the raft group
// We don't care to get the complete list of peers - one is enough.
// What we do care about though is that if we say the data structure doesn't exist,
// it really doesn't exist.
For connection use cases, we just need one peer in the raft group
We don't care to get the complete list of peers - one is enough.
What we do care about though is that if we say the data structure doesn't exist,
it really doesn't exist.
// For connection use cases we just need one peer in the raft group // We don ' t care to get the complete list of peers - one is enough . // What we do care about though is that if we say the data structure doesn ' t exist // it really doesn ' t exist .
func (m *membership) onePeerForDataStructureId(dataStructureId *ID) (*pb.RaftPeer, error) {
	m.serfTagMutex.Lock()
	defer m.serfTagMutex.Unlock()
	raftIdsMap, ok := m.dataStructureIdToRaftIds[*dataStructureId]
	if !ok {
		peer, err := m.findDataStructureWithId(dataStructureId)
		if err != nil {
			return nil, err
		} else if peer == nil {
			return nil, fmt.Errorf("Can't find data structure with id [%s]", dataStructureId)
		}
		return peer, nil
	}
	m.logger.Warnf("Cache hit: %d", len(raftIdsMap))
	for raftId := range raftIdsMap {
		v, ok := m.raftIdToAddress[raftId]
		if ok {
			return &pb.RaftPeer{
				RaftId:      raftId,
				PeerAddress: v,
			}, nil
		}
	}
	return nil, fmt.Errorf("Can't find data structure with id [%d]", dataStructureId)
}
func ( m * membership ) onePeerForDataStructureId ( dataStructureId * ID ) ( * pb . RaftPeer , error ) { m . serfTagMutex . Lock ( ) defer m . serfTagMutex . Unlock ( ) raftIdsMap , ok := m . dataStructureIdToRaftIds [ * dataStructureId ] if ! ok { peer , err := m . findDataStructureWithId ( dataStructureId ) if err != nil { return nil , err } else if peer == nil { return nil , fmt . Errorf ( " " , dataStructureId ) } return peer , nil } m . logger . Warnf ( " " , len ( raftIdsMap ) ) for raftId := range raftIdsMap { v , ok := m . raftIdToAddress [ raftId ] if ok { return & pb . RaftPeer { RaftId : raftId , PeerAddress : v , } , nil } } return nil , fmt . Errorf ( " " , dataStructureId ) }
For connection use cases, we just need one peer in the raft group
We don't care to get the complete list of peers - one is enough.
For connection use cases we just need one peer in the raft group We don ' t care to get the complete list of peers - one is enough .
// we got nothing in our local cache // let's make sure the entire cluster doesn't know about this data structure // cache hit!