Skip to content

Commit c70e9f8

Browse files
authored
[rank] adds background job that maps and counts references to definitions (sourcegraph#48004)
Depends on https://github.com/sourcegraph/sourcegraph/pull/48002, https://github.com/sourcegraph/sourcegraph/pull/47997 Adds background job that maps references to definitions and counts references per path. ## Test plan Tested manually. <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles -->
1 parent d280cca commit c70e9f8

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

enterprise/internal/codeintel/uploads/init.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func NewService(
7777

7878
var (
7979
bucketName = env.Get("CODEINTEL_UPLOADS_RANKING_BUCKET", "lsif-pagerank-experiments", "The GCS bucket.")
80+
rankingMapReduceBatchSize = env.MustGetInt("CODEINTEL_UPLOADS_MAP_REDUCE_RANKING_BATCH_SIZE", 10000, "How many references, definitions, and path counts to map and reduce at once.")
8081
rankingGraphKey = env.Get("CODEINTEL_UPLOADS_RANKING_GRAPH_KEY", "dev", "An identifier of the graph export. Change to start a new export in the configured bucket.")
8182
rankingGraphBatchSize = env.MustGetInt("CODEINTEL_UPLOADS_RANKING_GRAPH_BATCH_SIZE", 16, "How many uploads to process at once.")
8283
rankingGraphDeleteBatchSize = env.MustGetInt("CODEINTEL_UPLOADS_RANKING_GRAPH_DELETE_BATCH_SIZE", 32, "How many stale uploads to delete at once.")
@@ -208,5 +209,12 @@ func NewGraphExporters(observationCtx *observation.Context, uploadSvc *Service)
208209
ConfigExportInst.RankingBatchSize,
209210
ConfigExportInst.RankingJobsEnabled,
210211
),
212+
background.NewRankingGraphMapper(
213+
observationCtx,
214+
uploadSvc,
215+
ConfigExportInst.NumRankingRoutines,
216+
ConfigExportInst.RankingInterval,
217+
ConfigExportInst.RankingJobsEnabled,
218+
),
211219
}
212220
}

enterprise/internal/codeintel/uploads/internal/background/iface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
type UploadService interface {
2323
ExportRankingGraph(ctx context.Context, numRankingRoutines int, numBatchSize int, rankingJobEnabled bool) error
24+
MapRankingGraph(ctx context.Context, numRankingRoutines int, rankingJobEnabled bool) error
2425
VacuumRankingGraph(ctx context.Context) error
2526
}
2627

enterprise/internal/codeintel/uploads/internal/background/job_graph_exporter.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,22 @@ func NewRankingGraphExporter(
3333
return nil
3434
}))
3535
}
36+
37+
func NewRankingGraphMapper(
38+
observationCtx *observation.Context,
39+
uploadsService UploadService,
40+
numRankingRoutines int,
41+
interval time.Duration,
42+
rankingJobEnabled bool,
43+
) goroutine.BackgroundRoutine {
44+
return goroutine.NewPeriodicGoroutine(
45+
context.Background(),
46+
"rank.graph-mapper", "maps definitions and references data to path_counts_inputs table in store",
47+
interval,
48+
goroutine.HandlerFunc(func(ctx context.Context) error {
49+
if err := uploadsService.MapRankingGraph(ctx, numRankingRoutines, rankingJobEnabled); err != nil {
50+
return err
51+
}
52+
return nil
53+
}))
54+
}

enterprise/internal/codeintel/uploads/observability.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type operations struct {
6464

6565
// Ranking
6666
exportRankingGraph *observation.Operation
67+
mapRankingGraph *observation.Operation
6768

6869
numUploadsRead prometheus.Counter
6970
numBytesUploaded prometheus.Counter
@@ -181,6 +182,7 @@ func newOperations(observationCtx *observation.Context) *operations {
181182

182183
// Ranking
183184
exportRankingGraph: op("ExportRankingGraph"),
185+
mapRankingGraph: op("MapRankingGraph"),
184186

185187
numUploadsRead: numUploadsRead,
186188
numBytesUploaded: numBytesUploaded,

enterprise/internal/codeintel/uploads/ranking.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ func (s *Service) VacuumRankingGraph(ctx context.Context) error {
180180
return nil
181181
}
182182

183+
func (s *Service) MapRankingGraph(ctx context.Context, numRankingRoutines int, rankingJobEnabled bool) (err error) {
184+
ctx, _, endObservation := s.operations.mapRankingGraph.With(ctx, &err, observation.Args{})
185+
defer endObservation(1, observation.Args{})
186+
187+
if !rankingJobEnabled {
188+
return nil
189+
}
190+
191+
if err := s.store.InsertPathCountInputs(ctx, rankingGraphKey, rankingMapReduceBatchSize); err != nil {
192+
return err
193+
}
194+
195+
return nil
196+
}
197+
183198
const maxBytesPerObject = 1024 * 1024 * 1024 // 1GB
184199

185200
func (s *Service) serializeAndPersistRankingGraphForUpload(

0 commit comments

Comments
 (0)