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

En 6455 lrucache maxsize #1819

Merged
merged 20 commits into from
Jun 1, 2020
Merged

Conversation

iulianpascalau
Copy link
Contributor

  • 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

raduchis and others added 3 commits May 25, 2020 15:23
…sOrAdd functions

- changed shardedData interface: added sizeInBytes parameter in Add function
- adapted mocks and code to the new interfaces signatures
iulianpascalau and others added 8 commits May 28, 2020 22:25
# 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
@iulianpascalau iulianpascalau marked this pull request as ready for review May 29, 2020 15:25
@sasurobert sasurobert self-requested a review June 1, 2020 06:21
dataRetriever/factory/dataPoolFactory.go Show resolved Hide resolved
dataRetriever/shardedData/shardedData.go Outdated Show resolved Hide resolved
dataRetriever/shardedData/shardedData.go Outdated Show resolved Hide resolved
debug/resolver/interceptorResolver.go Outdated Show resolved Hide resolved
factory/triesComponents_test.go Outdated Show resolved Hide resolved
storage/lrucache/simpleLruCacheAdapter.go Outdated Show resolved Hide resolved
storage/pruning/pruningStorer.go Outdated Show resolved Hide resolved
storage/storageUnit/storageunit.go Outdated Show resolved Hide resolved
storage/lrucache/capacity/capacityLRUCache.go Outdated Show resolved Hide resolved
storage/lrucache/capacity/capacityLRUCache.go Show resolved Hide resolved
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"`
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@@ -30,6 +30,11 @@ func (v *validator) Index() uint32 {
return v.index
}

// Size -
func (v *validator) Size() int {
return len(v.pubKey) + 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why +8 ?

Copy link
Contributor Author

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

dataRetriever/shardedData/shardedData.go Outdated Show resolved Hide resolved
@@ -8,10 +8,11 @@ import (

const defaultMemDBSize = 10000
const defaultNumShards = 1
const noSizeInBytes = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zeroSize ?

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used, rename to _

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to uint32Size

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

//SizeLRUCacheHandler is the interface for size capable LRU cache.
type SizeLRUCacheHandler interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might rename to SizedLRUCacheHandler

Copy link
Contributor Author

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",
Copy link
Contributor

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

Copy link
Contributor Author

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}
Copy link
Contributor

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)

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to AddSizedIfMissing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

iulianpascalau and others added 5 commits June 1, 2020 16:14
# 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
@iulianpascalau iulianpascalau changed the base branch from development to release-candidate June 1, 2020 17:51
Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System tests passed.

@LucianMincu LucianMincu merged commit 76e4000 into release-candidate Jun 1, 2020
@LucianMincu LucianMincu deleted the EN-6455-lrucache-maxsize branch June 1, 2020 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants