Skip to content

Conversation

@crozzy
Copy link
Contributor

@crozzy crozzy commented Jun 5, 2023

During the indexing cycle many operations try to read information from the scanner table, this can occasionally lead to resource contention depending on the DB. This reads the table into memory when the indexer store is instanciated and uses when asked for scanner info.

@crozzy crozzy force-pushed the cached-scanners branch 2 times, most recently from 8620166 to 33f440f Compare June 5, 2023 17:43
@crozzy crozzy force-pushed the cached-scanners branch from 33f440f to bfaf2af Compare June 21, 2023 16:30
@crozzy crozzy force-pushed the cached-scanners branch 2 times, most recently from 294bced to fd5f4e9 Compare June 12, 2025 15:05
@crozzy crozzy added this to the v1.5.40 milestone Jun 18, 2025
@crozzy crozzy force-pushed the cached-scanners branch 5 times, most recently from 3a98167 to 69a3557 Compare June 20, 2025 14:05
During the indexing cycle many operations try to read information
from the scanner table, this can occasionally lead to resource
contention depending on the DB. This reads the table into memory when
the indexer store is instanciated and uses when asked for scanner info.

Signed-off-by: crozzy <[email protected]>
@crozzy crozzy force-pushed the cached-scanners branch from 69a3557 to 2035bce Compare June 20, 2025 15:07
@crozzy crozzy marked this pull request as ready for review June 20, 2025 15:26
@crozzy crozzy requested a review from a team as a code owner June 20, 2025 15:26
@crozzy crozzy requested review from RTann and removed request for a team June 20, 2025 15:26
@RTann
Copy link
Contributor

RTann commented Jun 20, 2025

crozzy force-pushed the cached-scanners branch 2 times, most recently from 8620166 to 33f440f
2 years ago

2 years ago???

Copy link
Contributor

@RTann RTann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let's say we are in the process of updating the Indexer and/or Matcher version(s) to add or delete a scanner.

Add: I think this is ok. The older versions won't even look for it (I believe)

Delete: The older versions will still claim the scanner exists, though I guess it'll still fail the next part of the scan process, maybe?

Can you add any commentary to potential race scenarios to see if we are ok with the possibilities?

`

func (s *IndexerStore) populateScanners(ctx context.Context) error {
s.scanners = make(map[string]int64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done in indexer_store.go

return s.populateScanners(ctx)
}

const selectAllScanner = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: selectAllScanners?

if err != nil {
return fmt.Errorf("failed to retrieve scanners: %w", err)
}
for rows.Next() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need a defer rows.Close() (I don't think it'll close if rows.Scan fails) and a rows.Err() check, too

type IndexerStore struct {
pool *pgxpool.Pool
pool *pgxpool.Pool
scanners map[string]int64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be a decent candidate for map[unique.Handle[string]]int64 since I think this map will be rather static once it's initially populated

registerScannerDuration.WithLabelValues("insert").Observe(time.Since(start).Seconds())
}

return s.populateScanners(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it assumed that RegisterScanners is called only once and in the very beginning of the process?

scanner;
`

func (s *IndexerStore) populateScanners(ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: initScanners

@crozzy crozzy modified the milestones: v1.5.40, v1.5.41 Aug 29, 2025
@crozzy crozzy modified the milestones: v1.5.41, v1.5.45 Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants