// Scan implements part of the graphstore.Service interface. func (s *Store) Scan(ctx context.Context, req *spb.ScanRequest, f graphstore.EntryFunc) error { iter, err := s.db.ScanPrefix(entryKeyPrefixBytes, &Options{LargeRead: true}) if err != nil { return fmt.Errorf("db seek error: %v", err) } defer iter.Close() for { key, val, err := iter.Next() if err == io.EOF { break } else if err != nil { return fmt.Errorf("db iteration error: %v", err) } entry, err := Entry(key, val) if err != nil { return fmt.Errorf("invalid key/value entry: %v", err) } if !graphstore.EntryMatchesScan(req, entry) { continue } else if err := f(entry); err == io.EOF { return nil } else if err != nil { return err } } return nil }
// Scan implements part of the graphstore.Service interface. func (s *GraphStore) Scan(ctx context.Context, req *spb.ScanRequest, f graphstore.EntryFunc) error { s.mu.RLock() defer s.mu.RUnlock() for _, e := range s.entries { if !graphstore.EntryMatchesScan(req, e) { continue } else if err := f(e); err == io.EOF { return nil } else if err != nil { return err } } return nil }