func (s *Scan) processResponse(response pb.Message) []*ResultRow { var res *proto.ScanResponse switch r := response.(type) { case *proto.ScanResponse: res = r default: s.err = errors.New(response.(*exception).msg) return nil } nextRegion := true s.nextStartRow = nil s.id = res.GetScannerId() results := res.GetResults() n := len(results) lastRegionRows += n if (n == s.numCached) || len(s.location.EndKey) == 0 || (s.StopRow != nil && bytes.Compare(s.location.EndKey, s.StopRow) > 0 && n < s.numCached) || res.GetMoreResultsInRegion() { nextRegion = false } if n < s.numCached { s.nextStartRow = incrementByteString(s.location.EndKey, len(s.location.EndKey)-1) } if nextRegion { s.closeScan(s.server, s.location, s.id) s.server = nil s.location = nil s.id = 0 lastRegionRows = 0 } if n == 0 && !nextRegion { s.Close() } tbr := make([]*ResultRow, n) for i, v := range results { tbr[i] = NewResultRow(v) } return tbr }
func (s *Scan) processResponse(response pb.Message) ([]*ResultRow, error) { var res *proto.ScanResponse switch r := response.(type) { case *proto.ScanResponse: res = r case *exception: return nil, errors.New(r.msg) default: return nil, errors.Errorf("Invalid response seen [response: %#v]", response) } // Check whether response is nil. if res == nil { return nil, errors.Errorf("Empty response: [table=%s] [StartRow=%q] [StopRow=%q] ", s.table, s.StartRow, s.StopRow) } nextRegion := true s.nextStartKey = nil s.id = res.GetScannerId() results := res.GetResults() n := len(results) if (n == s.numCached) || len(s.location.EndKey) == 0 || (s.StopRow != nil && bytes.Compare(s.location.EndKey, s.StopRow) > 0 && n < s.numCached) || res.GetMoreResultsInRegion() { nextRegion = false } var err error if nextRegion { s.nextStartKey = s.location.EndKey err = s.closeScan(s.server, s.location, s.id) if err != nil { return nil, errors.Trace(err) } s.server = nil s.location = nil s.id = 0 } if n == 0 && !nextRegion { err = s.Close() if err != nil { return nil, errors.Trace(err) } } if s.skipFirst { results = results[1:] s.skipFirst = false n = len(results) } tbr := make([]*ResultRow, n) for i, v := range results { if v != nil { tbr[i] = NewResultRow(v) } } return tbr, nil }