From a236737a6800cbae04aa5eab5fbee04fbe64db08 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Mon, 1 Feb 2016 12:31:26 -0500 Subject: [PATCH] temporary workaround to avoid crashing when an index is not behaving consistent with the API contracts --- index_impl.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index_impl.go b/index_impl.go index eab46174..51c5f3c2 100644 --- a/index_impl.go +++ b/index_impl.go @@ -358,6 +358,10 @@ func (i *indexImpl) DocCount() (uint64, error) { return i.i.DocCount() } +// this error message is a temporary measure to avoid crashing when an +// inconsistent state of the index is encountered +var errMsg17298 = fmt.Errorf("Internal Error Detected - A known inconsistency has been detected, and this search cannot be completed. The index is not corrupt and the search may succeed if you try again. Please see the following bug for the latest information: https://issues.couchbase.com/browse/MB-17298") + // Search executes a search request operation. // Returns a SearchResult object or an error. func (i *indexImpl) Search(req *SearchRequest) (sr *SearchResult, err error) { @@ -462,7 +466,7 @@ func (i *indexImpl) Search(req *SearchRequest) (sr *SearchResult, err error) { } else if err == nil { // unexpected case, a doc ID that was found as a search hit // was unable to be found during document lookup - panic(fmt.Sprintf("search hit with doc id: '%s' not found in doc lookup", hit.ID)) + return nil, errMsg17298 } } } @@ -472,7 +476,7 @@ func (i *indexImpl) Search(req *SearchRequest) (sr *SearchResult, err error) { // FIXME avoid loading doc second time // if we already loaded it for highlighting doc, err := indexReader.Document(hit.ID) - if err == nil { + if err == nil && doc != nil { for _, f := range req.Fields { for _, docF := range doc.Fields { if f == "*" || docF.Name() == f { @@ -502,6 +506,10 @@ func (i *indexImpl) Search(req *SearchRequest) (sr *SearchResult, err error) { } } } + } else if doc == nil { + // unexpected case, a doc ID that was found as a search hit + // was unable to be found during document lookup + return nil, errMsg17298 } } }