-
Notifications
You must be signed in to change notification settings - Fork 198
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
En 6455 lrucache maxsize #1819
En 6455 lrucache maxsize #1819
Conversation
iulianpascalau
commented
May 28, 2020
- implemented a LRU cache with size limit
- changed cacher interface: added sizeInBytes parameter in Put and HasOrAdd functions
- changed shardedData interface: added sizeInBytes parameter in Add function
- adapted mocks and code to the new interfaces signatures
…sOrAdd functions - changed shardedData interface: added sizeInBytes parameter in Add function - adapted mocks and code to the new interfaces signatures
# Conflicts: # dataRetriever/txpool/shardedTxPool_test.go # process/block/preprocess/adapterGenericCacheToSortedTransactionsProvider_test.go # process/throttle/antiflood/blackList/p2pBlackListProcessor.go # process/throttle/antiflood/floodPreventers/quotaFloodPreventer.go # process/throttle/antiflood/floodPreventers/quotaFloodPreventer_test.go # storage/txcache/txCache.go # storage/txcache/txCache_test.go
- added new cache type, adapted implementations to interfaces
- added unit tests, fixed lru cache with size implementation
config/config.go
Outdated
@@ -5,7 +5,7 @@ type CacheConfig struct { | |||
Type string `json:"type"` | |||
Size uint32 `json:"size"` | |||
SizePerSender uint32 `json:"sizePerSender"` | |||
SizeInBytes uint32 `json:"sizeInBytes"` | |||
SizeInBytes uint64 `json:"sizeInBytes"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we serialize these configs anywhere so json tags are not neccesarry. Please check before removing (or at least leave a TODO)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
consensus/mock/validatorMock.go
Outdated
@@ -30,6 +30,11 @@ func (v *validator) Index() uint32 { | |||
return v.index | |||
} | |||
|
|||
// Size - | |||
func (v *validator) Size() int { | |||
return len(v.pubKey) + 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why +8
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 uint32 (4+4 bytes, without associated pointers), moved to a const
@@ -8,10 +8,11 @@ import ( | |||
|
|||
const defaultMemDBSize = 10000 | |||
const defaultNumShards = 1 | |||
const noSizeInBytes = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zeroSize
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zeroSize
shall be
@@ -243,7 +243,7 @@ func TestValidatorInfoProcessor_ProcesStartOfEpochWithMissinPeerMiniblocksShould | |||
} | |||
return nil, false | |||
}, | |||
PutCalled: func(key []byte, value interface{}) (evicted bool) { | |||
PutCalled: func(key []byte, value interface{}, sizeInBytes int) (evicted bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used, rename to _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -14,6 +14,7 @@ import ( | |||
) | |||
|
|||
const maxNumPidsPerPk = 3 | |||
const shardIdSize = 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to uint32Size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
storage/interface.go
Outdated
} | ||
|
||
//SizeLRUCacheHandler is the interface for size capable LRU cache. | ||
type SizeLRUCacheHandler interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might rename to SizedLRUCacheHandler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
log.Error("size LRU cache add error", | ||
"key", fmt.Sprintf("%v", key), | ||
"value", fmt.Sprintf("%v", value), | ||
"error", "size in bytes is negative", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define an error for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a print. Added.
} | ||
|
||
func (c *CapacityLRU) addNew(key interface{}, value interface{}, sizeInBytes int64) { | ||
ent := &entry{key, value, sizeInBytes} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please name the fields. (key: key
for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// ContainsOrAddSized checks if a key is in the cache without updating the | ||
// recent-ness or deleting it for being stale, and if not, adds the value. | ||
// Returns whether found and whether an eviction occurred. | ||
func (c *CapacityLRU) ContainsOrAddSized(key, value interface{}, sizeInBytes int64) (bool, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to AddSizedIfMissing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
# Conflicts: # dataRetriever/mock/shardedDataStub.go # dataRetriever/txpool/shardedTxPool.go # dataRetriever/txpool/shardedTxPool_test.go # epochStart/mock/stardedDataStub.go # integrationTests/mock/shardedDataStub.go # node/mock/shardedDataStub.go # process/mock/shardedDataStub.go # storage/errors.go # storage/interface.go # storage/txcache/disabledCache.go
…etwork/elrond-go into EN-6455-lrucache-maxsize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System tests passed.