code: func (c *RegionCache) loadRegion(bo *Backoffer, key []byte, isEndKey bool) (*Region, error) {
  	var backoffErr error
  	searchPrev := false
  	for {
  		if backoffErr != nil {
  			err := bo.Backoff(BoPDRPC, backoffErr)
  			if err != nil {
  				return nil, errors.Trace(err)
  			}
  		}
  		var meta *metapb.Region
  		var leader *metapb.Peer
  		var err error
  		if searchPrev {
  			meta, leader, err = c.pdClient.GetPrevRegion(bo.ctx, key)
  		} else {
  			meta, leader, err = c.pdClient.GetRegion(bo.ctx, key)
  		}
  		if err != nil {
  			tikvRegionCacheCounterWithGetRegionError.Inc()
  		} else {
  			tikvRegionCacheCounterWithGetRegionOK.Inc()
  		}
  		if err != nil {
  			backoffErr = errors.Errorf("loadRegion from PD failed, key: %q, err: %v", key, err)
  			continue
  		}
  		if meta == nil {
  			backoffErr = errors.Errorf("region not found for key %q", key)
  			continue
  		}
  		if len(meta.Peers) == 0 {
  			return nil, errors.New("receive Region with no peer")
  		}
  		if isEndKey && !searchPrev && bytes.Compare(meta.StartKey, key) == 0 && len(meta.StartKey) != 0 {
  			searchPrev = true
  			continue
  		}
  		region := &Region{
  			meta: meta,
  			peer: meta.Peers[0],
  		}
  		if leader != nil {
  			region.SwitchPeer(leader.GetStoreId())
  		}
  		return region, nil
  	}
  }
docs: // loadRegion loads region from pd client, and picks the first peer as leader.
  // If the given key is the end key of the region that you want, you may set the second argument to true. This is useful when processing in reverse order.