-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixed a concurrency edge-case on the persister
- added & integrated removalTrackingCache implementation
- Loading branch information
1 parent
5fca300
commit f6cf07c
Showing
24 changed files
with
765 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package common | |
|
||
import ( | ||
"errors" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package lrucache | ||
|
||
// AddedDataHandlers - | ||
func (c *lruCache) AddedDataHandlers() map[string]func(key []byte, value interface{}) { | ||
return c.mapDataHandlers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package rtcache | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
"github.com/multiversx/mx-chain-storage-go/common" | ||
"github.com/multiversx/mx-chain-storage-go/types" | ||
) | ||
|
||
type unexportedCacher = types.Cacher | ||
|
||
type removalTrackingCache struct { | ||
unexportedCacher | ||
mutCriticalArea sync.RWMutex | ||
removalCache types.Cacher | ||
} | ||
|
||
// NewRemovalTrackingCache will create a new instance of a cache that is able to track removal events | ||
func NewRemovalTrackingCache(mainCache types.Cacher, removalCache types.Cacher) (*removalTrackingCache, error) { | ||
if check.IfNil(mainCache) { | ||
return nil, fmt.Errorf("%w for the main cache", common.ErrNilCacher) | ||
} | ||
if check.IfNil(removalCache) { | ||
return nil, fmt.Errorf("%w for the removal cache", common.ErrNilCacher) | ||
} | ||
|
||
return &removalTrackingCache{ | ||
unexportedCacher: mainCache, | ||
removalCache: removalCache, | ||
}, nil | ||
} | ||
|
||
// Put adds a value into the main cache. Returns true if an eviction occurred. | ||
// It also removes the key from the removalCache | ||
func (cache *removalTrackingCache) Put(key []byte, value interface{}, sizeInBytes int) (evicted bool) { | ||
cache.mutCriticalArea.Lock() | ||
defer cache.mutCriticalArea.Unlock() | ||
|
||
cache.removalCache.Remove(key) | ||
return cache.unexportedCacher.Put(key, value, sizeInBytes) | ||
} | ||
|
||
// Remove removes the provided key from the main cache. | ||
// It also stores the key in the removalCache | ||
func (cache *removalTrackingCache) Remove(key []byte) { | ||
cache.mutCriticalArea.Lock() | ||
defer cache.mutCriticalArea.Unlock() | ||
|
||
_ = cache.removalCache.Put(key, struct{}{}, len(key)) | ||
cache.unexportedCacher.Remove(key) | ||
} | ||
|
||
// GetRemovalStatus will return the removal status by searching the key in both caches | ||
func (cache *removalTrackingCache) GetRemovalStatus(key []byte) types.RemovalStatus { | ||
cache.mutCriticalArea.RLock() | ||
defer cache.mutCriticalArea.RUnlock() | ||
|
||
_, found := cache.removalCache.Get(key) | ||
if found { | ||
return types.ExplicitlyRemovedStatus | ||
} | ||
_, found = cache.unexportedCacher.Get(key) | ||
if found { | ||
return types.NotRemovedStatus | ||
} | ||
|
||
return types.UnknownRemovalStatus | ||
} | ||
|
||
// Clear is used to completely clear both caches. | ||
func (cache *removalTrackingCache) Clear() { | ||
cache.mutCriticalArea.RLock() | ||
defer cache.mutCriticalArea.RUnlock() | ||
|
||
cache.removalCache.Clear() | ||
cache.unexportedCacher.Clear() | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (cache *removalTrackingCache) IsInterfaceNil() bool { | ||
return cache == nil | ||
} |
Oops, something went wrong.