Skip to content

Commit

Permalink
More granular locking (#1033)
Browse files Browse the repository at this point in the history
This is a result of mutex profiling:

<img width="244" alt="Screenshot 2024-11-22 at 16 13 36"
src="https://github.com/user-attachments/assets/626e3f9e-bb13-44d6-be1d-b42294cff588">

Yes, we should keep our critical section as small  as possible
  • Loading branch information
nablaone authored Nov 22, 2024
1 parent 32e99dc commit 458fdde
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions quesma/table_resolver/table_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ func (r *tableRegistryImpl) Resolve(pipeline string, indexPattern string) *Decis
}

func (r *tableRegistryImpl) updateIndexes() {
r.m.Lock()
defer r.m.Unlock()

defer func() {
for _, res := range r.pipelineResolvers {
res.recentDecisions = make(map[string]*Decision)
}
}()

logger.Info().Msgf("Index registry updating state.")

Expand All @@ -174,7 +166,6 @@ func (r *tableRegistryImpl) updateIndexes() {
return true
})

r.clickhouseIndexes = clickhouseIndexes
logger.Info().Msgf("Clickhouse tables updated: %v", clickhouseIndexes)

elasticIndexes := make(map[string]table)
Expand All @@ -193,7 +184,18 @@ func (r *tableRegistryImpl) updateIndexes() {
}

logger.Info().Msgf("Elastic tables updated: %v", elasticIndexes)

// Let's update the state

r.m.Lock()
defer r.m.Unlock()

// this is a critical section
r.elasticIndexes = elasticIndexes
r.clickhouseIndexes = clickhouseIndexes
for _, res := range r.pipelineResolvers {
res.recentDecisions = make(map[string]*Decision)
}
}

func (r *tableRegistryImpl) updateState() {
Expand Down

0 comments on commit 458fdde

Please sign in to comment.