From 51d79e8759ef76d60240c78ca92a08fd96c403e8 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 7 Feb 2013 19:31:44 -0800 Subject: [PATCH] index: re-index on file failure. Issue 103. Change-Id: I740dbcf951d865df32c2f54d9d4119af135713db --- pkg/index/index.go | 1 + pkg/index/receive.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/index/index.go b/pkg/index/index.go index d042d2339..c92897956 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -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, "|") diff --git a/pkg/index/receive.go b/pkg/index/receive.go index baebbf975..faf24b255 100644 --- a/pkg/index/receive.go +++ b/pkg/index/receive.go @@ -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()