From 59d7e89d8766b78bbc845e4cb27940c06c436ba7 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 8 Sep 2015 16:54:09 +0200 Subject: [PATCH] serverinit,blobpacked: wipe blobpacked meta before reindexing Fixes #639 Change-Id: Ic202e4478e4979a29b71404c08c3188cbb3c292b --- pkg/blobserver/blobpacked/blobpacked.go | 16 ++++++++++++++++ pkg/serverinit/serverinit.go | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/blobserver/blobpacked/blobpacked.go b/pkg/blobserver/blobpacked/blobpacked.go index 95e1ebfad..a897fc1c7 100644 --- a/pkg/blobserver/blobpacked/blobpacked.go +++ b/pkg/blobserver/blobpacked/blobpacked.go @@ -270,6 +270,22 @@ func newFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (blobserver.Storag return sto, nil } +func WipeMeta(s blobserver.Storage) error { + bps, ok := s.(*storage) + if !ok { + return fmt.Errorf("argument is not blobpacked storage but a %T", s) + } + wiper, ok := bps.meta.(sorted.Wiper) + if !ok { + return fmt.Errorf("blobpacked meta storage type %T doesn't support sorted.Wiper", bps.meta) + } + log.Printf("Wiping blobpacked meta type %T ...", bps.meta) + if err := wiper.Wipe(); err != nil { + return fmt.Errorf("error wiping blobpacked meta sorted key/value type %T: %v", bps.meta, err) + } + return nil +} + func (s *storage) anyMeta() (v bool) { // TODO: we only care about getting 1 row, but the // sorted.KeyValue interface doesn't let us give it that diff --git a/pkg/serverinit/serverinit.go b/pkg/serverinit/serverinit.go index 6c1379b4d..603fb9482 100644 --- a/pkg/serverinit/serverinit.go +++ b/pkg/serverinit/serverinit.go @@ -39,6 +39,7 @@ import ( "camlistore.org/pkg/auth" "camlistore.org/pkg/blobserver" + "camlistore.org/pkg/blobserver/blobpacked" "camlistore.org/pkg/blobserver/handlers" "camlistore.org/pkg/httputil" "camlistore.org/pkg/index" @@ -324,6 +325,13 @@ func (hl *handlerLoader) setupHandler(prefix string) { exitFailure("Error reindexing %s: %v", h.prefix, err) } } + // TODO(mpl): make an interface that is "storage that has an internal index" and switch type on it? + if h.htype == "storage-blobpacked" && hl.reindex { + log.Printf("Wiping %s, because reindexing ...", h.prefix) + if err := blobpacked.WipeMeta(pstorage); err != nil { + exitFailure("Error wiping %s's meta: %v", h.prefix, err) + } + } hl.handler[h.prefix] = pstorage if h.internal { hl.installer.Handle(prefix, unauthorizedHandler{})