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

add concurrent access in lru cache #272

Merged
merged 4 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- run: pip3 install -r $HOME/project/tests/requirements.txt
# install from sources because pip install git+https://github.com/mysql/mysql-connector-python not support recursive submodules
- run: git clone https://github.com/Lagovas/mysql-connector-python; cd mysql-connector-python; sudo python3 setup.py clean build_py install_lib
- run: cd $HOME && GOPATH=$HOME/$GOPATH_FOLDER go get -u -v github.com/golang/lint/golint
- run: cd $HOME && GOPATH=$HOME/$GOPATH_FOLDER go get -u -v golang.org/x/lint/golint
- run: sudo ldconfig
# testing
# check that code formatted with gofmt
Expand Down
2 changes: 1 addition & 1 deletion cmd/acra-rollback/acra-rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func main() {
}
decrypted, err := base.DecryptAcrastruct(data, privateKey, zone)
if err != nil {
log.WithError(err).Errorln("Can't decrypt acrastruct in row with number %v", i)
log.WithError(err).Errorf("Can't decrypt acrastruct in row with number %v", i)
continue
}
for e := executors.Front(); e != nil; e = e.Next() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/acra-server/acra-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func main() {
server, err = NewServer(config, keyStore, errorSignalChannel, restartSignalsChannel)
if err != nil {
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantStartService).
Errorln("System error: can't start %s", SERVICE_NAME)
Errorf("System error: can't start %s", SERVICE_NAME)
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/acra-translator/acra-translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func main() {
readerServer, err = NewReaderServer(config, keyStore, waitTimeout)
if err != nil {
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantStartService).
Errorln("System error: can't start %s", SERVICE_NAME)
Errorf("System error: can't start %s", SERVICE_NAME)
panic(err)
}

Expand Down
10 changes: 9 additions & 1 deletion keystore/lru_cache/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"github.com/cossacklabs/acra/utils"
"github.com/cossacklabs/themis/gothemis/keys"
"github.com/golang/groupcache/lru"
"sync"
)

// LRUCache implement keystore.Cache
type LRUCache struct {
lru *lru.Cache
lru *lru.Cache
mutex sync.RWMutex
}

// clearCacheValue callback for lru.Cache that called on value remove operation
Expand All @@ -48,11 +50,15 @@ func NewLRUCacheKeystoreWrapper(size int) (*LRUCache, error) {

// Add value by keyID
func (cache *LRUCache) Add(keyID string, keyValue []byte) {
cache.mutex.Lock()
cache.lru.Add(keyID, keyValue)
cache.mutex.Unlock()
}

// Get value by keyID
func (cache *LRUCache) Get(keyID string) ([]byte, bool) {
cache.mutex.RLock()
defer cache.mutex.RUnlock()
value, ok := cache.lru.Get(keyID)
if ok {
return value.([]byte), ok
Expand All @@ -62,5 +68,7 @@ func (cache *LRUCache) Get(keyID string) ([]byte, bool) {

// Clear cache and remove all values with zeroing
func (cache *LRUCache) Clear() {
cache.mutex.Lock()
cache.lru.Clear()
cache.mutex.Unlock()
}