Skip to content

Commit

Permalink
Make index counts configurable and disable by default
Browse files Browse the repository at this point in the history
Index count is enabled by default across both ingestion and find server.
While we look into how to do it without extensive lock contention make
the feature configurable and disable it by default on both ingest and
find server.
  • Loading branch information
masih committed Jun 30, 2023
1 parent 860860c commit e9e0b28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
23 changes: 16 additions & 7 deletions command/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ func daemonAction(cctx *cli.Context) error {
// Create indexer core
indexerCore := engine.New(valueStore, engine.WithCache(resultCache))

indexCounts := counter.NewIndexCounts(dstore)
indexCounts.SetTotalAddend(cfg.Indexer.IndexCountTotalAddend)
var indexCounts *counter.IndexCounts
if cfg.Ingest.IndexCountsEnabled || cfg.Finder.IndexCountsEnabled {
indexCounts = counter.NewIndexCounts(dstore)
indexCounts.SetTotalAddend(cfg.Indexer.IndexCountTotalAddend)
}

// Create registry
reg, err := registry.New(cctx.Context, cfg.Discovery, dstore,
Expand All @@ -192,14 +195,17 @@ func daemonAction(cctx *cli.Context) error {
if err != nil {
return fmt.Errorf("bad find address %s: %s", findAddr, err)
}
findSvr, err = httpfind.New(findNetAddr.String(), indexerCore, reg,
opts := []httpfind.Option{
httpfind.WithReadTimeout(time.Duration(cfg.Finder.ApiReadTimeout)),
httpfind.WithWriteTimeout(time.Duration(cfg.Finder.ApiWriteTimeout)),
httpfind.WithMaxConnections(cfg.Finder.MaxConnections),
httpfind.WithHomepage(cfg.Finder.Webpage),
httpfind.WithIndexCounts(indexCounts),
httpfind.WithVersion(cctx.App.Version),
)
}
if cfg.Finder.IndexCountsEnabled {
opts = append(opts, httpfind.WithIndexCounts(indexCounts))
}
findSvr, err = httpfind.New(findNetAddr.String(), indexerCore, reg, opts...)
if err != nil {
return err
}
Expand Down Expand Up @@ -247,9 +253,12 @@ func daemonAction(cctx *cli.Context) error {
cfg.Ingest.ResendDirectAnnounce = false
}

var ingestOpts []ingest.Option
if cfg.Ingest.IndexCountsEnabled {
ingestOpts = append(ingestOpts, ingest.WithIndexCounts(indexCounts))
}
// Initialize ingester.
ingester, err = ingest.NewIngester(cfg.Ingest, p2pHost, indexerCore, reg, dstore, dsTmp,
ingest.WithIndexCounts(indexCounts))
ingester, err = ingest.NewIngester(cfg.Ingest, p2pHost, indexerCore, reg, dstore, dsTmp, ingestOpts...)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions config/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Finder struct {
// Webpage is a domain to display when the homepage of the finder is
// accessed over HTTP.
Webpage string
// IndexCountsEnabled sets whether showing provider index count is enabled on the find server at /providers.
// Disabled by default. See Ingest.IndexCountsEnabled.
IndexCountsEnabled bool
}

func NewFinder() Finder {
Expand Down
3 changes: 3 additions & 0 deletions config/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type Ingest struct {
// or a chain of advertisement entries. The value is an integer string
// ending in "s", "m", "h" for seconds. minutes, hours.
SyncTimeout Duration
// IndexCountsEnabled sets whether ingest process should count the number of index records per provider.
// Disabled by default. See: Finder.IndexCountsEnabled.
IndexCountsEnabled bool
}

type Mirror struct {
Expand Down

0 comments on commit e9e0b28

Please sign in to comment.