index: re-index on file failure. Issue 103.

Change-Id: I740dbcf951d865df32c2f54d9d4119af135713db
This commit is contained in:
Brad Fitzpatrick 2013-02-07 19:31:44 -08:00
parent f8639c5c5c
commit 51d79e8759
2 changed files with 22 additions and 0 deletions

View File

@ -545,6 +545,7 @@ func (x *Index) GetFileInfo(fileRef *blobref.BlobRef) (*search.FileInfo, error)
key := "fileinfo|" + fileRef.String()
v, err := x.s.Get(key)
if err == ErrNotFound {
go x.reindex(fileRef) // kinda a hack. Issue 103.
return nil, os.ErrNotExist
}
valPart := strings.Split(v, "|")

View File

@ -42,6 +42,27 @@ func (ix *Index) GetBlobHub() blobserver.BlobHub {
return ix.SimpleBlobHubPartitionMap.GetBlobHub()
}
func (ix *Index) reindex(br *blobref.BlobRef) {
bs := ix.BlobSource
if bs == nil {
log.Printf("index: can't re-index %v: no BlobSource", br)
return
}
log.Printf("index: starting re-index of %v", br)
rc, _, err := bs.FetchStreaming(br)
if err != nil {
log.Printf("index: failed to fetch %v for reindexing: %v", br, err)
return
}
defer rc.Close()
sb, err := ix.ReceiveBlob(br, rc)
if err != nil {
log.Printf("index: reindex of %v failed: %v", br, err)
return
}
log.Printf("index: successfully reindexed %v", sb)
}
func (ix *Index) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader) (retsb blobref.SizedBlobRef, err error) {
sniffer := NewBlobSniffer(blobRef)
hash := blobRef.Hash()