From bf1ec32e39e09bb9d90a3e8d09535d0375e20714 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 17 Mar 2014 23:05:27 -0700 Subject: [PATCH] sync: add paranoia around checking storage's Enumerate implementation Didn't find anything, but is useful to keep in, to maybe find bugs in the future for other storage types. Change-Id: If0fd37e03578de233be8da95ca45623c5f12156b --- pkg/server/sync.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/server/sync.go b/pkg/server/sync.go index 0dc3659c1..418949db5 100644 --- a/pkg/server/sync.go +++ b/pkg/server/sync.go @@ -739,10 +739,21 @@ func (sh *SyncHandler) startValidatePrefix(ctx *context.Context, pfx string, doD errc := make(chan error, 1) go func() { defer close(c) + var last string // last blobref seen; to double check storage's enumeration works correctly. err := blobserver.EnumerateAllFrom(ctx, e, pfx, func(sb blob.SizedRef) error { + // Just double-check that the storage target is returning sorted results correctly. + brStr := sb.Ref.String() + if brStr < pfx { + log.Fatalf("Storage target %T enumerate not behaving: %q < requested prefix %q", e, brStr, pfx) + } + if last != "" && last >= brStr { + log.Fatalf("Storage target %T enumerate not behaving: previous %q >= current %q", e, last, brStr) + } + last = brStr + // TODO: could add a more efficient method on blob.Ref to do this, // that doesn't involve call String(). - if !strings.HasPrefix(sb.Ref.String(), pfx) { + if !strings.HasPrefix(brStr, pfx) { return errNotPrefix } select {