fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Support reading v15 shards (#22)

We can update our read code to support reading older shards. This will allow us
to continue serving indexed search when we are busy re-indexing everything from
v15 to v16.

+85 -22
+4 -2
matchtree.go
··· 176 176 continue 177 177 } 178 178 179 - secID := cp.id.fileEndSymbol[cp.idx] + uint32(i) 180 179 cm := &candidateMatch{ 181 180 byteOffset: sec.Start + uint32(idx[0]), 182 181 byteMatchSz: uint32(idx[1] - idx[0]), 183 - symbolInfo: cp.id.symbolData.data(secID), 182 + } 183 + if cp.idx < uint32(len(cp.id.fileEndSymbol)) { // If v15 fileEndSymbol is empty 184 + secID := cp.id.fileEndSymbol[cp.idx] + uint32(i) 185 + cm.symbolInfo = cp.id.symbolData.data(secID) 184 186 } 185 187 found = append(found, cm) 186 188 }
+30 -19
read.go
··· 77 77 return err 78 78 } 79 79 80 - secs := toc.sections() 80 + secs := toc.sectionsHACK(sectionCount) 81 81 82 82 if len(secs) != int(sectionCount) { 83 83 return fmt.Errorf("section count mismatch: got %d want %d", sectionCount, len(secs)) 84 84 } 85 85 86 - for _, s := range toc.sections() { 86 + for _, s := range secs { 87 87 if err := s.read(r); err != nil { 88 88 return err 89 89 } ··· 154 154 return nil, err 155 155 } 156 156 157 - if d.metaData.IndexFormatVersion != IndexFormatVersion { 157 + ensureSourcegraphSymbolsHack() 158 + 159 + // Once we are not on version 16 use this code again 160 + // if d.metaData.IndexFormatVersion != IndexFormatVersion { 161 + if d.metaData.IndexFormatVersion != 16 && d.metaData.IndexFormatVersion != 15 { 158 162 return nil, fmt.Errorf("file is v%d, want v%d", d.metaData.IndexFormatVersion, IndexFormatVersion) 159 163 } 164 + readSymbols := d.metaData.IndexFormatVersion == 16 160 165 161 166 blob, err = d.readSectionBlob(toc.repoMetaData) 162 167 if err != nil { ··· 173 178 d.docSectionsStart = toc.fileSections.data.off 174 179 d.docSectionsIndex = toc.fileSections.relativeIndex() 175 180 176 - d.symIndex = toc.symbolMap.relativeIndex() 177 - d.symKindIndex = toc.symbolKindMap.relativeIndex() 181 + if readSymbols { 182 + d.symIndex = toc.symbolMap.relativeIndex() 183 + d.symKindIndex = toc.symbolKindMap.relativeIndex() 184 + } 178 185 179 186 d.checksums, err = d.readSectionBlob(toc.contentChecksums) 180 187 if err != nil { ··· 202 209 } 203 210 } 204 211 205 - d.fileEndSymbol, err = readSectionU32(d.file, toc.fileEndSymbol) 206 - if err != nil { 207 - return nil, err 212 + if readSymbols { 213 + d.fileEndSymbol, err = readSectionU32(d.file, toc.fileEndSymbol) 214 + if err != nil { 215 + return nil, err 216 + } 208 217 } 209 218 210 219 d.fileBranchMasks, err = readSectionU64(d.file, toc.branchMasks) ··· 212 221 return nil, err 213 222 } 214 223 215 - d.symContent, err = d.readSectionBlob(toc.symbolMap.data) 216 - if err != nil { 217 - return nil, err 218 - } 224 + if readSymbols { 225 + d.symContent, err = d.readSectionBlob(toc.symbolMap.data) 226 + if err != nil { 227 + return nil, err 228 + } 219 229 220 - d.symKindContent, err = d.readSectionBlob(toc.symbolKindMap.data) 221 - if err != nil { 222 - return nil, err 223 - } 230 + d.symKindContent, err = d.readSectionBlob(toc.symbolKindMap.data) 231 + if err != nil { 232 + return nil, err 233 + } 224 234 225 - d.symMetaData, err = d.readSectionBlob(toc.symbolMetaData) 226 - if err != nil { 227 - return nil, err 235 + d.symMetaData, err = d.readSectionBlob(toc.symbolMetaData) 236 + if err != nil { 237 + return nil, err 238 + } 228 239 } 229 240 230 241 d.fileNameContent, err = d.readSectionBlob(toc.fileNames.data)
+51 -1
toc.go
··· 14 14 15 15 package zoekt 16 16 17 - // FormatVersion is a version number. It is increased every time the 17 + // IndexFormatVersion is a version number. It is increased every time the 18 18 // on-disk index format is changed. 19 19 // 5: subrepositories. 20 20 // 6: remove size prefix for posting varint list. ··· 42 42 // 9: Store ctags metadata 43 43 const FeatureVersion = 9 44 44 45 + func init() { 46 + ensureSourcegraphSymbolsHack() 47 + } 48 + 49 + func ensureSourcegraphSymbolsHack() { 50 + if IndexFormatVersion != 16 { 51 + panic(`Sourcegraph: While we are on version 16 we have added code into 52 + read.go which supports reading IndexFormatVersion 15. If you change the 53 + IndexFormatVersion please reach out to Kevin and Keegan.`) 54 + } 55 + if FeatureVersion != 9 { 56 + panic(`Sourcegraph: While we are on FeatureVersion 9 we have added code into 57 + read.go which supports reading FeatureVersion 8. If you change the 58 + FeatureVersion please reach out to Kevin and Keegan.`) 59 + } 60 + } 61 + 45 62 type indexTOC struct { 46 63 fileContents compoundSection 47 64 fileNames compoundSection ··· 69 86 nameEndRunes simpleSection 70 87 contentChecksums simpleSection 71 88 runeDocSections simpleSection 89 + } 90 + 91 + func (t *indexTOC) sectionsHACK(expectedSectionCount uint32) []section { 92 + ensureSourcegraphSymbolsHack() 93 + 94 + // Sourcegraph hack for v15. 95 + if expectedSectionCount == 19 { 96 + return []section{ 97 + // This must be first, so it can be reliably read across 98 + // file format versions. 99 + &t.metaData, 100 + &t.repoMetaData, 101 + &t.fileContents, 102 + &t.fileNames, 103 + &t.fileSections, 104 + &t.newlines, 105 + &t.ngramText, 106 + &t.postings, 107 + &t.nameNgramText, 108 + &t.namePostings, 109 + &t.branchMasks, 110 + &t.subRepos, 111 + &t.runeOffsets, 112 + &t.nameRuneOffsets, 113 + &t.fileEndRunes, 114 + &t.nameEndRunes, 115 + &t.contentChecksums, 116 + &t.languages, 117 + &t.runeDocSections, 118 + } 119 + } 120 + 121 + return t.sections() 72 122 } 73 123 74 124 func (t *indexTOC) sections() []section {