code: func (s *Scanner) Next() error {
  	bo := NewBackoffer(context.WithValue(context.Background(), txnStartKey, s.snapshot.version.Ver), scannerNextMaxBackoff)
  	if !s.valid {
  		return errors.New("scanner iterator is invalid")
  	}
  	for {
  		s.idx++
  		if s.idx >= len(s.cache) {
  			if s.eof {
  				s.Close()
  				return nil
  			}
  			err := s.getData(bo)
  			if err != nil {
  				s.Close()
  				return errors.Trace(err)
  			}
  			if s.idx >= len(s.cache) {
  				continue
  			}
  		}
  
  		current := s.cache[s.idx]
  		if len(s.endKey) > 0 && kv.Key(current.Key).Cmp(kv.Key(s.endKey)) >= 0 {
  			s.eof = true
  			s.Close()
  			return nil
  		}
  		// Try to resolve the lock
  		if current.GetError() != nil {
  			// 'current' would be modified if the lock being resolved
  			if err := s.resolveCurrentLock(bo, current); err != nil {
  				s.Close()
  				return errors.Trace(err)
  			}
  
  			// The check here does not violate the KeyOnly semantic, because current's value
  			// is filled by resolveCurrentLock which fetches the value by snapshot.get, so an empty
  			// value stands for NotExist
  			if len(current.Value) == 0 {
  				continue
  			}
  		}
  		return nil
  	}
  }
docs: // Next return next element.