Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check conflict key before updating expiration map. #154

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,32 +156,28 @@ func (m *lockedMap) Set(i *item) {
}

m.Lock()
defer m.Unlock()
item, ok := m.data[i.key]

if ok {
// The item existed already. We need to check the conflict key and reject the
// update if they do not match. Only after that the expiration map is updated.
if i.conflict != 0 && (i.conflict != item.conflict) {
return
}
m.em.update(i.key, i.conflict, item.expiration, i.expiration)
} else {
// The value is not in the map already. There's no need to return anything.
// Simply add the expiration map.
m.em.add(i.key, i.conflict, i.expiration)
m.data[i.key] = storeItem{
key: i.key,
conflict: i.conflict,
value: i.value,
expiration: i.expiration,
}
m.Unlock()
return
}
if i.conflict != 0 && (i.conflict != item.conflict) {
m.Unlock()
return
}

m.data[i.key] = storeItem{
key: i.key,
conflict: i.conflict,
value: i.value,
expiration: i.expiration,
}
m.Unlock()
}

func (m *lockedMap) Del(key, conflict uint64) (uint64, interface{}) {
Expand Down