Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 458fdde

Browse files
authored
More granular locking (#1033)
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
1 parent 32e99dc commit 458fdde

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

quesma/table_resolver/table_resolver.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,6 @@ func (r *tableRegistryImpl) Resolve(pipeline string, indexPattern string) *Decis
146146
}
147147

148148
func (r *tableRegistryImpl) updateIndexes() {
149-
r.m.Lock()
150-
defer r.m.Unlock()
151-
152-
defer func() {
153-
for _, res := range r.pipelineResolvers {
154-
res.recentDecisions = make(map[string]*Decision)
155-
}
156-
}()
157149

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

@@ -174,7 +166,6 @@ func (r *tableRegistryImpl) updateIndexes() {
174166
return true
175167
})
176168

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

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

195186
logger.Info().Msgf("Elastic tables updated: %v", elasticIndexes)
187+
188+
// Let's update the state
189+
190+
r.m.Lock()
191+
defer r.m.Unlock()
192+
193+
// this is a critical section
196194
r.elasticIndexes = elasticIndexes
195+
r.clickhouseIndexes = clickhouseIndexes
196+
for _, res := range r.pipelineResolvers {
197+
res.recentDecisions = make(map[string]*Decision)
198+
}
197199
}
198200

199201
func (r *tableRegistryImpl) updateState() {

0 commit comments

Comments
 (0)