Skip to content

Commit

Permalink
[FABG-755] Round-robin balancer using block height
Browse files Browse the repository at this point in the history
Change-Id: I4ceef5888e7b965547e791ca03ab62febe213188
Signed-off-by: Firas Qutishat <[email protected]>
  • Loading branch information
fqutishat committed Sep 7, 2018
1 parent 915a932 commit b368032
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/client/common/selection/fabricselection/selectionfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func resolveBalancer(channelID string, channelConfig *fab.ChannelEndpointConfig)
}

func (s *selectionFilter) Filter(endorsers discclient.Endorsers) discclient.Endorsers {

// Convert the endorsers to peers
peers := s.asPeerValues(endorsers)

Expand All @@ -96,7 +97,7 @@ func (s *selectionFilter) Filter(endorsers discclient.Endorsers) discclient.Endo
sortedPeers := s.sortPeers(filteredPeers)

// Convert the filtered peers to endorsers
return asEndorsers(endorsers, sortedPeers)
return s.asEndorsers(endorsers, sortedPeers)
}

func (s *selectionFilter) sortPeers(peers []fab.Peer) []fab.Peer {
Expand Down Expand Up @@ -179,10 +180,10 @@ func (s *selectionFilter) sortByURL(peers []fab.Peer) []fab.Peer {
return peers
}

func asEndorsers(allEndorsers discclient.Endorsers, filteredPeers []fab.Peer) discclient.Endorsers {
func (s *selectionFilter) asEndorsers(allEndorsers discclient.Endorsers, filteredPeers []fab.Peer) discclient.Endorsers {
var filteredEndorsers discclient.Endorsers
for _, peer := range filteredPeers {
endorser, found := asEndorser(allEndorsers, peer)
endorser, found := s.asEndorser(allEndorsers, peer)
if !found {
// This should never happen since the peer was composed from the initial list of endorsers
logger.Warnf("Endorser [%s] not found. Endorser will be excluded.", peer.URL())
Expand All @@ -194,9 +195,9 @@ func asEndorsers(allEndorsers discclient.Endorsers, filteredPeers []fab.Peer) di
return filteredEndorsers
}

func asEndorser(endorsers discclient.Endorsers, peer fab.Peer) (*discclient.Peer, bool) {
func (s *selectionFilter) asEndorser(endorsers discclient.Endorsers, peer fab.Peer) (*discclient.Peer, bool) {
for _, endorser := range endorsers {
url := endorser.AliveMessage.GetAliveMsg().GetMembership().Endpoint
url := s.asPeerValue(endorser).URL()
if peer.URL() == url {
return endorser, true
}
Expand Down

0 comments on commit b368032

Please sign in to comment.