Skip to content

Commit

Permalink
Revert "Remove friends map mutex because map access won't occur concu…
Browse files Browse the repository at this point in the history
…rrently"

This reverts commit 94a0dc2.
  • Loading branch information
Sambigeara committed Nov 1, 2021
1 parent 5df230d commit 3001a80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type DBListRepo struct {

email string
friends map[string]map[string]int64
friendsMapLock sync.Mutex
friendsMostRecentChangeDT int64
friendsLastPushDT int64

Expand Down Expand Up @@ -125,7 +126,8 @@ func NewDBListRepo(localWalFile LocalWalFile, webTokenStore WebTokenStore, syncF
processedPartialWals: make(map[string]struct{}),
processedPartialWalsLock: &sync.Mutex{},

friends: make(map[string]map[string]int64),
friends: make(map[string]map[string]int64),
friendsMapLock: sync.Mutex{},
}

// The localWalFile gets attached to the Wal independently (there are certain operations
Expand Down
7 changes: 6 additions & 1 deletion pkg/service/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ func (r *DBListRepo) generateFriendChangeEvents(e EventLog, item *ListItem) {
var friendItems map[string]int64
var friendExists bool
func() {
r.friendsMapLock.Lock()
defer r.friendsMapLock.Unlock()
if friendItems, friendExists = r.friends[email]; !friendExists {
friendItems = make(map[string]int64)
r.friends[email] = friendItems
Expand All @@ -388,6 +390,8 @@ func (r *DBListRepo) generateFriendChangeEvents(e EventLog, item *ListItem) {
if friendItems, friendExists := r.friends[email]; friendExists {
if dtLastChange, exists := friendItems[key]; exists && e.UnixNanoTime > dtLastChange {
func() {
r.friendsMapLock.Lock()
defer r.friendsMapLock.Unlock()
delete(r.friends[email], key)
if len(r.friends[email]) == 0 {
delete(r.friends, email)
Expand Down Expand Up @@ -961,7 +965,8 @@ func checkWalIntegrity(wal *[]EventLog) (*ListItem, []*ListItem, error) {
allWalFileMut: &sync.RWMutex{},
syncWalFileMut: &sync.RWMutex{},

friends: make(map[string]map[string]int64),
friends: make(map[string]map[string]int64),
friendsMapLock: sync.Mutex{},
}

// Use the Replay function to generate the linked lists
Expand Down

0 comments on commit 3001a80

Please sign in to comment.