MCPcopy
hub / github.com/perkeep/perkeep / startValidatePrefix

Method startValidatePrefix

pkg/server/sync.go:836–890  ·  view source on GitHub ↗

doDest is false for source and true for dest.

(ctx context.Context, pfx string, doDest bool)

Source from the content-addressed store, hash-verified

834
835// doDest is false for source and true for dest.
836func (sh *SyncHandler) startValidatePrefix(ctx context.Context, pfx string, doDest bool) (<-chan blob.SizedRef, <-chan error) {
837 var e blobserver.BlobEnumerator
838 if doDest {
839 e = sh.to
840 } else {
841 e = sh.from
842 }
843 c := make(chan blob.SizedRef, 64)
844 errc := make(chan error, 1)
845 go func() {
846 defer close(c)
847 var last string // last blobref seen; to double check storage's enumeration works correctly.
848 err := blobserver.EnumerateAllFrom(ctx, e, pfx, func(sb blob.SizedRef) error {
849 // Just double-check that the storage target is returning sorted results correctly.
850 brStr := sb.Ref.String()
851 if brStr < pfx {
852 log.Fatalf("Storage target %T enumerate not behaving: %q < requested prefix %q", e, brStr, pfx)
853 }
854 if last != "" && last >= brStr {
855 log.Fatalf("Storage target %T enumerate not behaving: previous %q >= current %q", e, last, brStr)
856 }
857 last = brStr
858
859 // TODO: could add a more efficient method on blob.Ref to do this,
860 // that doesn't involve call String().
861 if !strings.HasPrefix(brStr, pfx) {
862 return errNotPrefix
863 }
864 select {
865 case c <- sb:
866 sh.mu.Lock()
867 if doDest {
868 sh.vdestCount++
869 sh.vdestBytes += int64(sb.Size)
870 } else {
871 sh.vsrcCount++
872 sh.vsrcBytes += int64(sb.Size)
873 }
874 sh.mu.Unlock()
875 return nil
876 case <-ctx.Done():
877 return ctx.Err()
878 }
879 })
880 if err == errNotPrefix {
881 err = nil
882 }
883 if err != nil {
884 // Send a zero value to shut down ListMissingDestinationBlobs.
885 c <- blob.SizedRef{}
886 }
887 errc <- err
888 }()
889 return c, errc
890}
891
892func (sh *SyncHandler) shardPrefixes() []string {
893 var pfx []string

Callers 1

validateShardPrefixMethod · 0.95

Calls 7

EnumerateAllFromFunction · 0.92
HasPrefixMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
FatalfMethod · 0.65
StringMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected