serverinit,blobpacked: wipe blobpacked meta before reindexing

Fixes #639

Change-Id: Ic202e4478e4979a29b71404c08c3188cbb3c292b
This commit is contained in:
mpl 2015-09-08 16:54:09 +02:00
parent fc890a65cd
commit 59d7e89d87
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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{})