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

Configure Feed

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

sourcegraph: remove GRPC index methods (#977)

This was part of an effort to move the queue from Zoekt to Sourcegraph.
However, we are not going to pursue this for now and we can remove
the corresponging grpc methods.

Sourcegraph never had callers of Index and Delete, so both are save to remove.

`DeleteAllData` is still being called from Sourcegraph.

Test plan:
CI

author
Stefan Hengl
committer
GitHub
date (Aug 15, 2025, 2:51 PM +0200) commit 74399876 parent 87bb21ae
+31 -867
+31 -326
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/indexserver.pb.go
··· 7 7 package v1 8 8 9 9 import ( 10 - v1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1" 11 10 protoreflect "google.golang.org/protobuf/reflect/protoreflect" 12 11 protoimpl "google.golang.org/protobuf/runtime/protoimpl" 13 12 reflect "reflect" ··· 97 96 return file_zoekt_indexserver_v1_indexserver_proto_rawDescGZIP(), []int{1} 98 97 } 99 98 100 - type DeleteRequest struct { 101 - state protoimpl.MessageState 102 - sizeCache protoimpl.SizeCache 103 - unknownFields protoimpl.UnknownFields 104 - 105 - // repo_ids are the Sourcegraph repository IDs to delete. 106 - RepoIds []uint32 `protobuf:"varint,1,rep,packed,name=repo_ids,json=repoIds,proto3" json:"repo_ids,omitempty"` 107 - } 108 - 109 - func (x *DeleteRequest) Reset() { 110 - *x = DeleteRequest{} 111 - if protoimpl.UnsafeEnabled { 112 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[2] 113 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 114 - ms.StoreMessageInfo(mi) 115 - } 116 - } 117 - 118 - func (x *DeleteRequest) String() string { 119 - return protoimpl.X.MessageStringOf(x) 120 - } 121 - 122 - func (*DeleteRequest) ProtoMessage() {} 123 - 124 - func (x *DeleteRequest) ProtoReflect() protoreflect.Message { 125 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[2] 126 - if protoimpl.UnsafeEnabled && x != nil { 127 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 128 - if ms.LoadMessageInfo() == nil { 129 - ms.StoreMessageInfo(mi) 130 - } 131 - return ms 132 - } 133 - return mi.MessageOf(x) 134 - } 135 - 136 - // Deprecated: Use DeleteRequest.ProtoReflect.Descriptor instead. 137 - func (*DeleteRequest) Descriptor() ([]byte, []int) { 138 - return file_zoekt_indexserver_v1_indexserver_proto_rawDescGZIP(), []int{2} 139 - } 140 - 141 - func (x *DeleteRequest) GetRepoIds() []uint32 { 142 - if x != nil { 143 - return x.RepoIds 144 - } 145 - return nil 146 - } 147 - 148 - type DeleteResponse struct { 149 - state protoimpl.MessageState 150 - sizeCache protoimpl.SizeCache 151 - unknownFields protoimpl.UnknownFields 152 - } 153 - 154 - func (x *DeleteResponse) Reset() { 155 - *x = DeleteResponse{} 156 - if protoimpl.UnsafeEnabled { 157 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[3] 158 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 159 - ms.StoreMessageInfo(mi) 160 - } 161 - } 162 - 163 - func (x *DeleteResponse) String() string { 164 - return protoimpl.X.MessageStringOf(x) 165 - } 166 - 167 - func (*DeleteResponse) ProtoMessage() {} 168 - 169 - func (x *DeleteResponse) ProtoReflect() protoreflect.Message { 170 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[3] 171 - if protoimpl.UnsafeEnabled && x != nil { 172 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 173 - if ms.LoadMessageInfo() == nil { 174 - ms.StoreMessageInfo(mi) 175 - } 176 - return ms 177 - } 178 - return mi.MessageOf(x) 179 - } 180 - 181 - // Deprecated: Use DeleteResponse.ProtoReflect.Descriptor instead. 182 - func (*DeleteResponse) Descriptor() ([]byte, []int) { 183 - return file_zoekt_indexserver_v1_indexserver_proto_rawDescGZIP(), []int{3} 184 - } 185 - 186 - type IndexRequest struct { 187 - state protoimpl.MessageState 188 - sizeCache protoimpl.SizeCache 189 - unknownFields protoimpl.UnknownFields 190 - 191 - Options *v1.ZoektIndexOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"` 192 - } 193 - 194 - func (x *IndexRequest) Reset() { 195 - *x = IndexRequest{} 196 - if protoimpl.UnsafeEnabled { 197 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[4] 198 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 199 - ms.StoreMessageInfo(mi) 200 - } 201 - } 202 - 203 - func (x *IndexRequest) String() string { 204 - return protoimpl.X.MessageStringOf(x) 205 - } 206 - 207 - func (*IndexRequest) ProtoMessage() {} 208 - 209 - func (x *IndexRequest) ProtoReflect() protoreflect.Message { 210 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[4] 211 - if protoimpl.UnsafeEnabled && x != nil { 212 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 213 - if ms.LoadMessageInfo() == nil { 214 - ms.StoreMessageInfo(mi) 215 - } 216 - return ms 217 - } 218 - return mi.MessageOf(x) 219 - } 220 - 221 - // Deprecated: Use IndexRequest.ProtoReflect.Descriptor instead. 222 - func (*IndexRequest) Descriptor() ([]byte, []int) { 223 - return file_zoekt_indexserver_v1_indexserver_proto_rawDescGZIP(), []int{4} 224 - } 225 - 226 - func (x *IndexRequest) GetOptions() *v1.ZoektIndexOptions { 227 - if x != nil { 228 - return x.Options 229 - } 230 - return nil 231 - } 232 - 233 - type IndexResponse struct { 234 - state protoimpl.MessageState 235 - sizeCache protoimpl.SizeCache 236 - unknownFields protoimpl.UnknownFields 237 - 238 - // repo_id is the Sourcegraph repository ID. 239 - RepoId uint32 `protobuf:"varint,1,opt,name=repo_id,json=repoId,proto3" json:"repo_id,omitempty"` 240 - // branches is the list of branches that the client has indexed. 241 - Branches []*v1.ZoektRepositoryBranch `protobuf:"bytes,2,rep,name=branches,proto3" json:"branches,omitempty"` 242 - // index_time_unix is the unix timestamp for when the index was created. 243 - IndexTimeUnix int64 `protobuf:"varint,3,opt,name=index_time_unix,json=indexTimeUnix,proto3" json:"index_time_unix,omitempty"` 244 - } 245 - 246 - func (x *IndexResponse) Reset() { 247 - *x = IndexResponse{} 248 - if protoimpl.UnsafeEnabled { 249 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[5] 250 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 251 - ms.StoreMessageInfo(mi) 252 - } 253 - } 254 - 255 - func (x *IndexResponse) String() string { 256 - return protoimpl.X.MessageStringOf(x) 257 - } 258 - 259 - func (*IndexResponse) ProtoMessage() {} 260 - 261 - func (x *IndexResponse) ProtoReflect() protoreflect.Message { 262 - mi := &file_zoekt_indexserver_v1_indexserver_proto_msgTypes[5] 263 - if protoimpl.UnsafeEnabled && x != nil { 264 - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 265 - if ms.LoadMessageInfo() == nil { 266 - ms.StoreMessageInfo(mi) 267 - } 268 - return ms 269 - } 270 - return mi.MessageOf(x) 271 - } 272 - 273 - // Deprecated: Use IndexResponse.ProtoReflect.Descriptor instead. 274 - func (*IndexResponse) Descriptor() ([]byte, []int) { 275 - return file_zoekt_indexserver_v1_indexserver_proto_rawDescGZIP(), []int{5} 276 - } 277 - 278 - func (x *IndexResponse) GetRepoId() uint32 { 279 - if x != nil { 280 - return x.RepoId 281 - } 282 - return 0 283 - } 284 - 285 - func (x *IndexResponse) GetBranches() []*v1.ZoektRepositoryBranch { 286 - if x != nil { 287 - return x.Branches 288 - } 289 - return nil 290 - } 291 - 292 - func (x *IndexResponse) GetIndexTimeUnix() int64 { 293 - if x != nil { 294 - return x.IndexTimeUnix 295 - } 296 - return 0 297 - } 298 - 299 99 var File_zoekt_indexserver_v1_indexserver_proto protoreflect.FileDescriptor 300 100 301 101 var file_zoekt_indexserver_v1_indexserver_proto_rawDesc = []byte{ 302 102 0x0a, 0x26, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 303 103 0x76, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 304 104 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 305 - 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x1a, 0x36, 306 - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 307 - 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 308 - 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 309 - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 310 - 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x17, 311 - 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 312 - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2a, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 313 - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x6f, 314 - 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x07, 0x72, 0x65, 0x70, 0x6f, 315 - 0x49, 0x64, 0x73, 0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 316 - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x5f, 0x0a, 0x0c, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 317 - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x4f, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 318 - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x35, 0x2e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 319 - 0x72, 0x61, 0x70, 0x68, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 320 - 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x5a, 0x6f, 0x65, 0x6b, 321 - 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 322 - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xa7, 0x01, 0x0a, 0x0d, 0x49, 0x6e, 0x64, 0x65, 0x78, 323 - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x72, 0x65, 0x70, 0x6f, 324 - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x72, 0x65, 0x70, 0x6f, 0x49, 325 - 0x64, 0x12, 0x55, 0x0a, 0x08, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x18, 0x02, 0x20, 326 - 0x03, 0x28, 0x0b, 0x32, 0x39, 0x2e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 327 - 0x68, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 328 - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x5a, 0x6f, 0x65, 0x6b, 0x74, 0x52, 0x65, 329 - 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x08, 330 - 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x69, 0x6e, 0x64, 0x65, 331 - 0x78, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 332 - 0x03, 0x52, 0x0d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 333 - 0x32, 0xbf, 0x02, 0x0a, 0x1d, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 334 - 0x49, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 335 - 0x63, 0x65, 0x12, 0x6d, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 336 - 0x61, 0x74, 0x61, 0x12, 0x2a, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 337 - 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 338 - 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 339 - 0x2b, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 340 - 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 341 - 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 342 - 0x02, 0x12, 0x58, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x7a, 0x6f, 343 - 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 344 - 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 345 - 0x1a, 0x24, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 346 - 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 347 - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 0x02, 0x12, 0x55, 0x0a, 0x05, 0x49, 348 - 0x6e, 0x64, 0x65, 0x78, 0x12, 0x22, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 349 - 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x64, 0x65, 350 - 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 351 - 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 352 - 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 353 - 0x02, 0x02, 0x42, 0x5c, 0x5a, 0x5a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 354 - 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 355 - 0x6b, 0x74, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2d, 0x73, 0x6f, 0x75, 356 - 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 357 - 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 358 - 0x74, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x76, 0x31, 359 - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 105 + 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x22, 0x16, 106 + 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 107 + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x17, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 108 + 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 109 + 0x8e, 0x01, 0x0a, 0x1d, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x49, 110 + 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 111 + 0x65, 0x12, 0x6d, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 112 + 0x74, 0x61, 0x12, 0x2a, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 113 + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 114 + 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 115 + 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 116 + 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 117 + 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 0x02, 118 + 0x42, 0x5c, 0x5a, 0x5a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 119 + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 120 + 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2d, 0x73, 0x6f, 0x75, 0x72, 0x63, 121 + 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 122 + 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 123 + 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x62, 0x06, 124 + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 360 125 } 361 126 362 127 var ( ··· 371 136 return file_zoekt_indexserver_v1_indexserver_proto_rawDescData 372 137 } 373 138 374 - var file_zoekt_indexserver_v1_indexserver_proto_msgTypes = make([]protoimpl.MessageInfo, 6) 139 + var file_zoekt_indexserver_v1_indexserver_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 375 140 var file_zoekt_indexserver_v1_indexserver_proto_goTypes = []interface{}{ 376 - (*DeleteAllDataRequest)(nil), // 0: zoekt.indexserver.v1.DeleteAllDataRequest 377 - (*DeleteAllDataResponse)(nil), // 1: zoekt.indexserver.v1.DeleteAllDataResponse 378 - (*DeleteRequest)(nil), // 2: zoekt.indexserver.v1.DeleteRequest 379 - (*DeleteResponse)(nil), // 3: zoekt.indexserver.v1.DeleteResponse 380 - (*IndexRequest)(nil), // 4: zoekt.indexserver.v1.IndexRequest 381 - (*IndexResponse)(nil), // 5: zoekt.indexserver.v1.IndexResponse 382 - (*v1.ZoektIndexOptions)(nil), // 6: sourcegraph.zoekt.configuration.v1.ZoektIndexOptions 383 - (*v1.ZoektRepositoryBranch)(nil), // 7: sourcegraph.zoekt.configuration.v1.ZoektRepositoryBranch 141 + (*DeleteAllDataRequest)(nil), // 0: zoekt.indexserver.v1.DeleteAllDataRequest 142 + (*DeleteAllDataResponse)(nil), // 1: zoekt.indexserver.v1.DeleteAllDataResponse 384 143 } 385 144 var file_zoekt_indexserver_v1_indexserver_proto_depIdxs = []int32{ 386 - 6, // 0: zoekt.indexserver.v1.IndexRequest.options:type_name -> sourcegraph.zoekt.configuration.v1.ZoektIndexOptions 387 - 7, // 1: zoekt.indexserver.v1.IndexResponse.branches:type_name -> sourcegraph.zoekt.configuration.v1.ZoektRepositoryBranch 388 - 0, // 2: zoekt.indexserver.v1.SourcegraphIndexserverService.DeleteAllData:input_type -> zoekt.indexserver.v1.DeleteAllDataRequest 389 - 2, // 3: zoekt.indexserver.v1.SourcegraphIndexserverService.Delete:input_type -> zoekt.indexserver.v1.DeleteRequest 390 - 4, // 4: zoekt.indexserver.v1.SourcegraphIndexserverService.Index:input_type -> zoekt.indexserver.v1.IndexRequest 391 - 1, // 5: zoekt.indexserver.v1.SourcegraphIndexserverService.DeleteAllData:output_type -> zoekt.indexserver.v1.DeleteAllDataResponse 392 - 3, // 6: zoekt.indexserver.v1.SourcegraphIndexserverService.Delete:output_type -> zoekt.indexserver.v1.DeleteResponse 393 - 5, // 7: zoekt.indexserver.v1.SourcegraphIndexserverService.Index:output_type -> zoekt.indexserver.v1.IndexResponse 394 - 5, // [5:8] is the sub-list for method output_type 395 - 2, // [2:5] is the sub-list for method input_type 396 - 2, // [2:2] is the sub-list for extension type_name 397 - 2, // [2:2] is the sub-list for extension extendee 398 - 0, // [0:2] is the sub-list for field type_name 145 + 0, // 0: zoekt.indexserver.v1.SourcegraphIndexserverService.DeleteAllData:input_type -> zoekt.indexserver.v1.DeleteAllDataRequest 146 + 1, // 1: zoekt.indexserver.v1.SourcegraphIndexserverService.DeleteAllData:output_type -> zoekt.indexserver.v1.DeleteAllDataResponse 147 + 1, // [1:2] is the sub-list for method output_type 148 + 0, // [0:1] is the sub-list for method input_type 149 + 0, // [0:0] is the sub-list for extension type_name 150 + 0, // [0:0] is the sub-list for extension extendee 151 + 0, // [0:0] is the sub-list for field type_name 399 152 } 400 153 401 154 func init() { file_zoekt_indexserver_v1_indexserver_proto_init() } ··· 428 181 return nil 429 182 } 430 183 } 431 - file_zoekt_indexserver_v1_indexserver_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 432 - switch v := v.(*DeleteRequest); i { 433 - case 0: 434 - return &v.state 435 - case 1: 436 - return &v.sizeCache 437 - case 2: 438 - return &v.unknownFields 439 - default: 440 - return nil 441 - } 442 - } 443 - file_zoekt_indexserver_v1_indexserver_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 444 - switch v := v.(*DeleteResponse); i { 445 - case 0: 446 - return &v.state 447 - case 1: 448 - return &v.sizeCache 449 - case 2: 450 - return &v.unknownFields 451 - default: 452 - return nil 453 - } 454 - } 455 - file_zoekt_indexserver_v1_indexserver_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { 456 - switch v := v.(*IndexRequest); i { 457 - case 0: 458 - return &v.state 459 - case 1: 460 - return &v.sizeCache 461 - case 2: 462 - return &v.unknownFields 463 - default: 464 - return nil 465 - } 466 - } 467 - file_zoekt_indexserver_v1_indexserver_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { 468 - switch v := v.(*IndexResponse); i { 469 - case 0: 470 - return &v.state 471 - case 1: 472 - return &v.sizeCache 473 - case 2: 474 - return &v.unknownFields 475 - default: 476 - return nil 477 - } 478 - } 479 184 } 480 185 type x struct{} 481 186 out := protoimpl.TypeBuilder{ ··· 483 188 GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 484 189 RawDescriptor: file_zoekt_indexserver_v1_indexserver_proto_rawDesc, 485 190 NumEnums: 0, 486 - NumMessages: 6, 191 + NumMessages: 2, 487 192 NumExtensions: 0, 488 193 NumServices: 1, 489 194 },
-37
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/indexserver.proto
··· 2 2 3 3 package zoekt.indexserver.v1; 4 4 5 - import "sourcegraph/zoekt/configuration/v1/configuration.proto"; 6 - 7 5 option go_package = "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/zoekt/indexserver/v1"; 8 6 9 7 message DeleteAllDataRequest {} 10 8 11 9 message DeleteAllDataResponse {} 12 10 13 - message DeleteRequest { 14 - // repo_ids are the Sourcegraph repository IDs to delete. 15 - repeated uint32 repo_ids = 1; 16 - } 17 - 18 - message DeleteResponse {} 19 - 20 - message IndexRequest { 21 - sourcegraph.zoekt.configuration.v1.ZoektIndexOptions options = 1; 22 - } 23 - 24 - message IndexResponse { 25 - // repo_id is the Sourcegraph repository ID. 26 - uint32 repo_id = 1; 27 - 28 - // branches is the list of branches that the client has indexed. 29 - repeated sourcegraph.zoekt.configuration.v1.ZoektRepositoryBranch branches = 2; 30 - 31 - // index_time_unix is the unix timestamp for when the index was created. 32 - int64 index_time_unix = 3; 33 - } 34 - 35 11 service SourcegraphIndexserverService { 36 12 // DeleteAllData deletes all data for the tenant in the request context. 37 13 // This is used for pruning all data after a tenant has been deleted. 38 14 rpc DeleteAllData(DeleteAllDataRequest) returns (DeleteAllDataResponse) { 39 - option idempotency_level = IDEMPOTENT; 40 - } 41 - 42 - // Delete deletes the index for a specific repository. 43 - // This is used when a repository needs to be reindexed from scratch or when it's deleted. 44 - rpc Delete(DeleteRequest) returns (DeleteResponse) { 45 - option idempotency_level = IDEMPOTENT; 46 - } 47 - 48 - // Index indexes a repository with the given options and returns the repository information 49 - // including the index timestamp. This information is needed by the frontend to update its state 50 - // since Zoekt no longer sends status updates to Sourcegraph. 51 - rpc Index(IndexRequest) returns (IndexResponse) { 52 15 option idempotency_level = IDEMPOTENT; 53 16 } 54 17 }
-84
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/indexserver_grpc.pb.go
··· 20 20 21 21 const ( 22 22 SourcegraphIndexserverService_DeleteAllData_FullMethodName = "/zoekt.indexserver.v1.SourcegraphIndexserverService/DeleteAllData" 23 - SourcegraphIndexserverService_Delete_FullMethodName = "/zoekt.indexserver.v1.SourcegraphIndexserverService/Delete" 24 - SourcegraphIndexserverService_Index_FullMethodName = "/zoekt.indexserver.v1.SourcegraphIndexserverService/Index" 25 23 ) 26 24 27 25 // SourcegraphIndexserverServiceClient is the client API for SourcegraphIndexserverService service. ··· 31 29 // DeleteAllData deletes all data for the tenant in the request context. 32 30 // This is used for pruning all data after a tenant has been deleted. 33 31 DeleteAllData(ctx context.Context, in *DeleteAllDataRequest, opts ...grpc.CallOption) (*DeleteAllDataResponse, error) 34 - // Delete deletes the index for a specific repository. 35 - // This is used when a repository needs to be reindexed from scratch or when it's deleted. 36 - Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) 37 - // Index indexes a repository with the given options and returns the repository information 38 - // including the index timestamp. This information is needed by the frontend to update its state 39 - // since Zoekt no longer sends status updates to Sourcegraph. 40 - Index(ctx context.Context, in *IndexRequest, opts ...grpc.CallOption) (*IndexResponse, error) 41 32 } 42 33 43 34 type sourcegraphIndexserverServiceClient struct { ··· 57 48 return out, nil 58 49 } 59 50 60 - func (c *sourcegraphIndexserverServiceClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { 61 - out := new(DeleteResponse) 62 - err := c.cc.Invoke(ctx, SourcegraphIndexserverService_Delete_FullMethodName, in, out, opts...) 63 - if err != nil { 64 - return nil, err 65 - } 66 - return out, nil 67 - } 68 - 69 - func (c *sourcegraphIndexserverServiceClient) Index(ctx context.Context, in *IndexRequest, opts ...grpc.CallOption) (*IndexResponse, error) { 70 - out := new(IndexResponse) 71 - err := c.cc.Invoke(ctx, SourcegraphIndexserverService_Index_FullMethodName, in, out, opts...) 72 - if err != nil { 73 - return nil, err 74 - } 75 - return out, nil 76 - } 77 - 78 51 // SourcegraphIndexserverServiceServer is the server API for SourcegraphIndexserverService service. 79 52 // All implementations must embed UnimplementedSourcegraphIndexserverServiceServer 80 53 // for forward compatibility ··· 82 55 // DeleteAllData deletes all data for the tenant in the request context. 83 56 // This is used for pruning all data after a tenant has been deleted. 84 57 DeleteAllData(context.Context, *DeleteAllDataRequest) (*DeleteAllDataResponse, error) 85 - // Delete deletes the index for a specific repository. 86 - // This is used when a repository needs to be reindexed from scratch or when it's deleted. 87 - Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) 88 - // Index indexes a repository with the given options and returns the repository information 89 - // including the index timestamp. This information is needed by the frontend to update its state 90 - // since Zoekt no longer sends status updates to Sourcegraph. 91 - Index(context.Context, *IndexRequest) (*IndexResponse, error) 92 58 mustEmbedUnimplementedSourcegraphIndexserverServiceServer() 93 59 } 94 60 ··· 98 64 99 65 func (UnimplementedSourcegraphIndexserverServiceServer) DeleteAllData(context.Context, *DeleteAllDataRequest) (*DeleteAllDataResponse, error) { 100 66 return nil, status.Errorf(codes.Unimplemented, "method DeleteAllData not implemented") 101 - } 102 - func (UnimplementedSourcegraphIndexserverServiceServer) Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) { 103 - return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") 104 - } 105 - func (UnimplementedSourcegraphIndexserverServiceServer) Index(context.Context, *IndexRequest) (*IndexResponse, error) { 106 - return nil, status.Errorf(codes.Unimplemented, "method Index not implemented") 107 67 } 108 68 func (UnimplementedSourcegraphIndexserverServiceServer) mustEmbedUnimplementedSourcegraphIndexserverServiceServer() { 109 69 } ··· 137 97 return interceptor(ctx, in, info, handler) 138 98 } 139 99 140 - func _SourcegraphIndexserverService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 141 - in := new(DeleteRequest) 142 - if err := dec(in); err != nil { 143 - return nil, err 144 - } 145 - if interceptor == nil { 146 - return srv.(SourcegraphIndexserverServiceServer).Delete(ctx, in) 147 - } 148 - info := &grpc.UnaryServerInfo{ 149 - Server: srv, 150 - FullMethod: SourcegraphIndexserverService_Delete_FullMethodName, 151 - } 152 - handler := func(ctx context.Context, req interface{}) (interface{}, error) { 153 - return srv.(SourcegraphIndexserverServiceServer).Delete(ctx, req.(*DeleteRequest)) 154 - } 155 - return interceptor(ctx, in, info, handler) 156 - } 157 - 158 - func _SourcegraphIndexserverService_Index_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 159 - in := new(IndexRequest) 160 - if err := dec(in); err != nil { 161 - return nil, err 162 - } 163 - if interceptor == nil { 164 - return srv.(SourcegraphIndexserverServiceServer).Index(ctx, in) 165 - } 166 - info := &grpc.UnaryServerInfo{ 167 - Server: srv, 168 - FullMethod: SourcegraphIndexserverService_Index_FullMethodName, 169 - } 170 - handler := func(ctx context.Context, req interface{}) (interface{}, error) { 171 - return srv.(SourcegraphIndexserverServiceServer).Index(ctx, req.(*IndexRequest)) 172 - } 173 - return interceptor(ctx, in, info, handler) 174 - } 175 - 176 100 // SourcegraphIndexserverService_ServiceDesc is the grpc.ServiceDesc for SourcegraphIndexserverService service. 177 101 // It's only intended for direct use with grpc.RegisterService, 178 102 // and not to be introspected or modified (even as a copy) ··· 183 107 { 184 108 MethodName: "DeleteAllData", 185 109 Handler: _SourcegraphIndexserverService_DeleteAllData_Handler, 186 - }, 187 - { 188 - MethodName: "Delete", 189 - Handler: _SourcegraphIndexserverService_Delete_Handler, 190 - }, 191 - { 192 - MethodName: "Index", 193 - Handler: _SourcegraphIndexserverService_Index_Handler, 194 110 }, 195 111 }, 196 112 Streams: []grpc.StreamDesc{},
-228
cmd/zoekt-sourcegraph-indexserver/main.go
··· 35 35 "os" 36 36 "os/exec" 37 37 "os/signal" 38 - "path" 39 38 "path/filepath" 40 39 "runtime" 41 40 "slices" ··· 74 73 "google.golang.org/grpc/codes" 75 74 "google.golang.org/grpc/credentials/insecure" 76 75 "google.golang.org/grpc/metadata" 77 - "google.golang.org/grpc/status" 78 76 ) 79 77 80 78 var ( ··· 1074 1072 return fmt.Sprintf("Indexing %s failed: %s", args.String(), err), err 1075 1073 } 1076 1074 return fmt.Sprintf("Indexed %s with state %s", args.String(), state), nil 1077 - } 1078 - 1079 - // Index implements the gRPC method for indexing a repository. If the repository 1080 - // exists in the trash, it will attempt to recover it before indexing. The 1081 - // method returns metadata about the indexed repository including branches and 1082 - // and the time of indexing. The metadata might be empty if we fail to read the 1083 - // metadata after the index or if the repository is empty. 1084 - // 1085 - // Possible GRPC error codes: 1086 - // - InvalidArgument: returned when the index options are missing or invalid 1087 - // - AlreadyExists: returned when the repository is already being indexed by another process 1088 - // - Internal: returned when indexing fails 1089 - // - Canceled: returned when the context is canceled while waiting for an index slot 1090 - func (s *Server) Index(ctx context.Context, req *indexserverv1.IndexRequest) (*indexserverv1.IndexResponse, error) { 1091 - return s.indexGRPC(ctx, req, s.index) 1092 - } 1093 - 1094 - // indexGRPC takes an index func which is used for testing. For production GRPC calls, use 1095 - // Server.Index instead 1096 - func (s *Server) indexGRPC(ctx context.Context, req *indexserverv1.IndexRequest, indexFunc func(ctx context.Context, args *indexArgs) (indexState, error)) (*indexserverv1.IndexResponse, error) { 1097 - // Validate request 1098 - if req.Options == nil { 1099 - return nil, status.Error(codes.InvalidArgument, "index options are required") 1100 - } 1101 - 1102 - // Try to acquire semaphore, but respect context cancellation 1103 - select { 1104 - case s.indexSemaphore <- struct{}{}: 1105 - defer func() { <-s.indexSemaphore }() 1106 - case <-ctx.Done(): 1107 - return nil, status.Error(codes.Canceled, "context canceled while waiting for index slot") 1108 - case <-time.After(s.timeout): 1109 - return nil, status.Error(codes.DeadlineExceeded, "timed out while waiting for index slot") 1110 - } 1111 - 1112 - var opts IndexOptions 1113 - opts.FromProto(req.Options) 1114 - opts.CloneURL = s.rootURL.ResolveReference(&url.URL{Path: path.Join("/.internal/git", req.Options.Name)}).String() 1115 - args := s.indexArgs(opts) 1116 - 1117 - // Recover the index from the trash if possible. First we have to make sure 1118 - // the shard doesn't exist in the index dir, because it might potentially be 1119 - // overwritten if we recover a shard from the trash. If we can find a shard 1120 - // in the index dir, we skip recovery. In both cases we continue and let the 1121 - // index process figure out whether the shard is up-to-date or requires a 1122 - // reindex. 1123 - if _, _, ok, err := args.BuildOptions().FindRepositoryMetadata(); err == nil && !ok { 1124 - if s.recoverFromTrash(opts.RepoID) { 1125 - infoLog.Printf("restored repository %d from trash", opts.RepoID) 1126 - } 1127 - } 1128 - 1129 - // Index the repository. 1130 - var indexErr error 1131 - var indexTimeUnix int64 1132 - var zoektRepo *zoekt.Repository 1133 - 1134 - ran := s.muIndexDir.With(opts.Name, func() { 1135 - // only record time taken once we hold the lock. This avoids us 1136 - // recording time taken while merging/cleanup runs. 1137 - start := time.Now() 1138 - 1139 - var state indexState 1140 - state, indexErr = indexFunc(ctx, args) 1141 - elapsed := time.Since(start) 1142 - metricIndexDuration.WithLabelValues(string(state), repoNameForMetric(opts.Name)).Observe(elapsed.Seconds()) 1143 - 1144 - if indexErr != nil { 1145 - errorLog.Printf("error indexing %s: %s", args.String(), indexErr) 1146 - indexErr = status.Errorf(codes.Internal, "failed to index repository: %v", indexErr) 1147 - return 1148 - } 1149 - 1150 - readMetadata := func(args *indexArgs) (*zoekt.Repository, int64, error) { 1151 - repo, metadata, ok, err := args.BuildOptions().FindRepositoryMetadata() 1152 - if err != nil || !ok { 1153 - return nil, 0, fmt.Errorf("failed to read metadata for %s: %w", args.String(), err) 1154 - } 1155 - return repo, metadata.IndexTime.Unix(), nil 1156 - } 1157 - 1158 - switch state { 1159 - case indexStateSuccess: 1160 - zoektRepo, indexTimeUnix, indexErr = readMetadata(args) 1161 - if indexErr != nil { 1162 - return 1163 - } 1164 - var branches []string 1165 - for _, b := range zoektRepo.Branches { 1166 - branches = append(branches, fmt.Sprintf("%s=%s", b.Name, b.Version)) 1167 - } 1168 - s.logger.Info("updated index", 1169 - sglog.Int("tenant", args.TenantID), 1170 - sglog.String("repo", args.Name), 1171 - sglog.Uint32("id", args.RepoID), 1172 - sglog.Strings("branches", branches), 1173 - sglog.Duration("duration", elapsed), 1174 - ) 1175 - case indexStateSuccessMeta: 1176 - zoektRepo, indexTimeUnix, indexErr = readMetadata(args) 1177 - if indexErr != nil { 1178 - return 1179 - } 1180 - infoLog.Printf("updated meta %s in %v", args.String(), elapsed) 1181 - case indexStateNoop: 1182 - zoektRepo, indexTimeUnix, indexErr = readMetadata(args) 1183 - if indexErr != nil { 1184 - return 1185 - } 1186 - case indexStateEmpty: 1187 - zoektRepo = &zoekt.Repository{ 1188 - ID: args.RepoID, 1189 - } 1190 - case indexStateFail: 1191 - // This should never happen, because indexStateFail implies 1192 - // indexErr!=nil and we exit early, but we'll handle it gracefully 1193 - // just in case. 1194 - indexErr = status.Error(codes.Internal, "failed to index repository") 1195 - // Repository exists but is empty, return OK with empty response 1196 - default: 1197 - indexErr = status.Errorf(codes.Internal, "unknown index state: %s", state) 1198 - } 1199 - }) 1200 - 1201 - if !ran { 1202 - // Someone else is processing the repository. 1203 - debugLog.Printf("index job for repository already running: %s", args) 1204 - return nil, status.Error(codes.AlreadyExists, "repository is already being indexed") 1205 - } 1206 - 1207 - if indexErr != nil { 1208 - return nil, indexErr 1209 - } 1210 - 1211 - if zoektRepo == nil { 1212 - // This should never happen, because zoektRepo=nil means we either 1213 - // failed to index or failed to read the metadata, both of which yield 1214 - // indexErr!=nil. 1215 - return nil, status.Error(codes.Internal, fmt.Sprintf("unexpected error: zoektRepo is nil for options %+v", opts)) 1216 - } 1217 - 1218 - // Convert branches to proto format 1219 - repoBranchesProto := make([]*configv1.ZoektRepositoryBranch, len(zoektRepo.Branches)) 1220 - for i, b := range zoektRepo.Branches { 1221 - repoBranchesProto[i] = &configv1.ZoektRepositoryBranch{ 1222 - Name: b.Name, 1223 - Version: b.Version, 1224 - } 1225 - } 1226 - 1227 - return &indexserverv1.IndexResponse{ 1228 - RepoId: zoektRepo.ID, 1229 - Branches: repoBranchesProto, 1230 - IndexTimeUnix: indexTimeUnix, 1231 - }, nil 1232 - } 1233 - 1234 - // recoverFromTrash attempts to recover an index from the trash or tombstones. 1235 - // It returns true if the repository was recovered. 1236 - func (s *Server) recoverFromTrash(repoID uint32) bool { 1237 - trashShards := getShards(filepath.Join(s.IndexDir, ".trash")) 1238 - if shards, ok := trashShards[repoID]; ok { 1239 - moveAll(s.IndexDir, shards) 1240 - return true 1241 - } 1242 - 1243 - tombstones := getTombstonedRepos(s.IndexDir) 1244 - if tombstone, ok := tombstones[repoID]; ok { 1245 - if err := index.UnsetTombstone(tombstone.Path, repoID); err == nil { 1246 - return true 1247 - } 1248 - } 1249 - 1250 - return false 1251 - } 1252 - 1253 - // Delete implements the gRPC method for deleting a repository. It moves the 1254 - // simple shards to the trash dir and tombstones repos in compound shards. 1255 - func (s *Server) Delete(ctx context.Context, req *indexserverv1.DeleteRequest) (*indexserverv1.DeleteResponse, error) { 1256 - var err error 1257 - 1258 - // Run the delete operation in a goroutine to be able to respond to context 1259 - // cancellation while waiting for the lock. 1260 - done := make(chan struct{}) 1261 - go func() { 1262 - defer close(done) 1263 - s.muIndexDir.Global(func() { 1264 - indexShards := getShards(s.IndexDir) 1265 - for _, repoID := range req.RepoIds { 1266 - if ctx.Err() != nil { 1267 - err = status.Error(codes.Canceled, "context canceled") 1268 - return 1269 - } 1270 - 1271 - if shards, ok := indexShards[repoID]; ok { 1272 - simple := shards[:0] 1273 - for _, shardItem := range shards { 1274 - if s.shardMerging && maybeSetTombstone([]shard{shardItem}, repoID) { 1275 - continue 1276 - } 1277 - 1278 - simple = append(simple, shardItem) 1279 - } 1280 - 1281 - if len(simple) == 0 { 1282 - continue 1283 - } 1284 - 1285 - moveAll(filepath.Join(s.IndexDir, ".trash"), simple) 1286 - } 1287 - } 1288 - }) 1289 - }() 1290 - 1291 - select { 1292 - case <-done: 1293 - if err != nil { 1294 - return nil, err 1295 - } 1296 - case <-ctx.Done(): 1297 - return nil, status.Error(codes.Canceled, "context canceled") 1298 - case <-time.After(s.timeout): 1299 - return nil, status.Error(codes.DeadlineExceeded, "timed out while waiting for delete operation to complete") 1300 - } 1301 - 1302 - return &indexserverv1.DeleteResponse{}, nil 1303 1075 } 1304 1076 1305 1077 // DeleteAllData deletes all shards in the index and trash dir belonging to the
-192
cmd/zoekt-sourcegraph-indexserver/main_test.go
··· 12 12 "slices" 13 13 "strings" 14 14 "testing" 15 - "time" 16 15 17 16 "github.com/google/go-cmp/cmp" 18 17 sglog "github.com/sourcegraph/log" ··· 20 19 "github.com/stretchr/testify/require" 21 20 "github.com/xeipuuv/gojsonschema" 22 21 "google.golang.org/grpc" 23 - "google.golang.org/grpc/codes" 24 - "google.golang.org/grpc/status" 25 22 26 23 "github.com/sourcegraph/zoekt" 27 24 configv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1" 28 - indexserverv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1" 29 - "github.com/sourcegraph/zoekt/index" 30 25 "github.com/sourcegraph/zoekt/internal/tenant" 31 26 ) 32 27 ··· 451 446 }) 452 447 } 453 448 } 454 - 455 - func TestIndexGRPC(t *testing.T) { 456 - indexDir := t.TempDir() 457 - 458 - // Minimal server setup 459 - s := &Server{ 460 - logger: logtest.NoOp(t), 461 - IndexDir: indexDir, 462 - rootURL: &url.URL{Scheme: "http", Host: "example.com"}, 463 - indexSemaphore: make(chan struct{}, 1), 464 - timeout: time.Hour, // no timeout 465 - } 466 - 467 - branches := []*configv1.ZoektRepositoryBranch{ 468 - { 469 - Name: "HEAD", 470 - Version: "abc123", 471 - }, 472 - } 473 - 474 - req := &indexserverv1.IndexRequest{ 475 - Options: &configv1.ZoektIndexOptions{ 476 - RepoId: 42, 477 - Name: "repo", 478 - TenantId: 1, 479 - Branches: branches, 480 - }, 481 - } 482 - 483 - resp, err := s.indexGRPC(context.Background(), req, mockIndexFunc(t)) 484 - require.NoError(t, err) 485 - require.Equal(t, &indexserverv1.IndexResponse{ 486 - RepoId: 42, 487 - Branches: branches, 488 - IndexTimeUnix: resp.IndexTimeUnix, // Hack: this changes every time so we don't check it 489 - }, resp) 490 - 491 - require.NotZero(t, resp.IndexTimeUnix) 492 - } 493 - 494 - func TestIndexGRPC_Timeout(t *testing.T) { 495 - indexDir := t.TempDir() 496 - 497 - s := &Server{ 498 - logger: logtest.NoOp(t), 499 - IndexDir: indexDir, 500 - IndexConcurrency: 0, // impossible to acquire index slot 501 - timeout: time.Millisecond, 502 - } 503 - 504 - req := &indexserverv1.IndexRequest{ 505 - Options: &configv1.ZoektIndexOptions{ 506 - RepoId: 42, 507 - Name: "repo", 508 - }, 509 - } 510 - 511 - // use context.Background() to make sure we don't return because of context cancellation 512 - _, err := s.indexGRPC(context.Background(), req, mockIndexFunc(t)) 513 - require.Error(t, err) 514 - require.Equal(t, codes.DeadlineExceeded, status.Code(err)) 515 - } 516 - 517 - func TestDelete(t *testing.T) { 518 - indexDir := t.TempDir() 519 - trashDir := filepath.Join(indexDir, ".trash") 520 - if err := os.MkdirAll(trashDir, 0o755); err != nil { 521 - t.Fatal(err) 522 - } 523 - 524 - // Create a simple shard 525 - createShard(t, indexDir) 526 - 527 - // Verify the shard exists in index dir 528 - shards := getShards(indexDir) 529 - if len(shards) != 1 { 530 - t.Fatalf("expected 1 shard, got %d", len(shards)) 531 - } 532 - 533 - // Create server and call Delete 534 - s := &Server{ 535 - logger: logtest.NoOp(t), 536 - IndexDir: indexDir, 537 - rootURL: &url.URL{Scheme: "http", Host: "example.com"}, 538 - indexSemaphore: make(chan struct{}, 1), 539 - timeout: time.Hour, // no timeout 540 - } 541 - 542 - req := &indexserverv1.DeleteRequest{ 543 - RepoIds: []uint32{42}, // matches the repo ID in createShard 544 - } 545 - 546 - // Test case: context is canceled 547 - cancledCtx, cancel := context.WithCancel(context.Background()) 548 - cancel() 549 - _, err := s.Delete(cancledCtx, req) 550 - require.Error(t, err) 551 - 552 - shards = getShards(indexDir) 553 - require.Len(t, shards, 1) 554 - 555 - // Test case: context is not canceled 556 - _, err = s.Delete(context.Background(), req) 557 - require.NoError(t, err) 558 - 559 - // Verify shard was moved to trash 560 - trashShards := getShards(trashDir) 561 - require.Len(t, trashShards, 1) 562 - 563 - // Verify shard is no longer in index dir 564 - shards = getShards(indexDir) 565 - require.Len(t, shards, 0) 566 - } 567 - 568 - func mockIndexFunc(t *testing.T) func(ctx context.Context, args *indexArgs) (indexState, error) { 569 - return func(ctx context.Context, args *indexArgs) (indexState, error) { 570 - createShard(t, args.IndexDir) 571 - return indexStateSuccess, nil 572 - } 573 - } 574 - 575 - func createShard(t *testing.T, dir string) { 576 - opts := index.Options{ 577 - IndexDir: dir, 578 - RepositoryDescription: zoekt.Repository{ 579 - ID: 42, 580 - Name: "repo", 581 - Branches: []zoekt.RepositoryBranch{ 582 - { 583 - Name: "HEAD", 584 - Version: "abc123", 585 - }, 586 - }, 587 - }, 588 - } 589 - 590 - b, err := index.NewBuilder(opts) 591 - require.NoError(t, err) 592 - require.NoError(t, b.AddFile("test.txt", []byte("hello"))) 593 - require.NoError(t, b.Finish()) 594 - } 595 - 596 - func TestRecoverFromTrash(t *testing.T) { 597 - dir := t.TempDir() 598 - trashDir := filepath.Join(dir, ".trash") 599 - require.NoError(t, os.MkdirAll(trashDir, 0o755)) 600 - 601 - // Create a simple shard in trash 602 - createTestShard(t, "repo1", 1, filepath.Join(trashDir, "repo1.zoekt")) 603 - 604 - // Create a compound shard with two repos, one of them tombstoned 605 - cs := createCompoundShard(t, dir, []uint32{2, 3}) 606 - require.NoError(t, index.SetTombstone(cs, 2)) 607 - 608 - s := &Server{ 609 - IndexDir: dir, 610 - } 611 - 612 - // Test recovering from trash 613 - recovered := s.recoverFromTrash(1) 614 - require.True(t, recovered, "should have recovered repo1 from trash") 615 - 616 - // Verify shard was moved from trash to index 617 - indexShards := getShards(dir) 618 - trashShards := getShards(trashDir) 619 - 620 - require.Contains(t, indexShards, uint32(1), "repo1 should be in index") 621 - require.NotContains(t, trashShards, uint32(1), "repo1 should not be in trash") 622 - 623 - // Test unsetting tombstone 624 - recovered = s.recoverFromTrash(2) 625 - require.True(t, recovered, "should have recovered repo2 from tombstone") 626 - 627 - // Verify tombstone was unset 628 - repos, _, err := index.ReadMetadataPath(cs) 629 - require.NoError(t, err) 630 - 631 - for _, repo := range repos { 632 - if repo.ID == 2 { 633 - require.False(t, repo.Tombstone, "repo2 should not be tombstoned") 634 - } 635 - } 636 - 637 - // Test non-existent repo 638 - recovered = s.recoverFromTrash(99) 639 - require.False(t, recovered, "should not have recovered non-existent repo") 640 - }