Skip to content

Commit

Permalink
Merge pull request #6 from ced42/CC-2661
Browse files Browse the repository at this point in the history
CC-2661 - fix error: concurrent map read and map write
  • Loading branch information
alexdebril authored Apr 8, 2024
2 parents 7f717ce + db3da6f commit 13de23b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mapping/to_event.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mapping

import "sync"

// turnToShortColumn is a default seeker that simply translates the column's name if a match exists.
func seekFromShortColumn(m *Mapping, column string, value string) (bool, string, string) {
r, ok := m.Raws[column]
Expand Down Expand Up @@ -41,19 +43,17 @@ type cacheEntry struct {

// reverseTransformer is to use for data stored in a "reversed way" meaning that the column qualifier is the actual data and is a kind of enum value
type reverseSeeker struct {
cache map[string]*cacheEntry
cache sync.Map
}

func newReverseSeeker() *reverseSeeker {
return &reverseSeeker{
cache: make(map[string]*cacheEntry),
}
return &reverseSeeker{}
}

// seekFromCache returns the column and value from the cache if it exists.
func (c *reverseSeeker) seekFromCache(_ *Mapping, column string, _ string) (bool, string, string) {
if entry, ok := c.cache[column]; ok {
return true, entry.col, entry.value
if entry, ok := c.cache.Load(column); ok {
return true, entry.(cacheEntry).col, entry.(cacheEntry).value
}
return false, "", ""
}
Expand All @@ -63,7 +63,7 @@ func (c *reverseSeeker) seekFromMapping(m *Mapping, column string, _ string) (bo
for _, ma := range m.Reversed {
for short, val := range ma.Values {
if column == short {
c.cache[column] = &cacheEntry{col: ma.Name, value: val}
c.cache.Store(column, cacheEntry{col: ma.Name, value: val})
return true, ma.Name, val
}
}
Expand Down

0 comments on commit 13de23b

Please sign in to comment.