-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "vendor fastCache to use as ledger cache"
- Loading branch information
Showing
17 changed files
with
1,729 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,37 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package statedb | ||
|
||
import ( | ||
"github.com/VictoriaMetrics/fastcache" | ||
) | ||
|
||
// Cache holds both the system and user cache | ||
type Cache struct { | ||
sysCache *fastcache.Cache | ||
usrCache *fastcache.Cache | ||
} | ||
|
||
// New creates a Cache. The cache consists of both system state cache (for lscc, _lifecycle) | ||
// and user state cache (for all user deployed chaincodes). The size of the | ||
// system state cache is 64 MB, by default. The size of the user state cache, in terms of MB, is | ||
// specified via usrCacheSize parameter. Note that the fastcache allocates memory | ||
// only in the multiples of 32 MB (due to 512 buckets & an equal number of 64 KB chunks per bucket). | ||
// If the usrCacheSize is not a multiple of 32 MB, the fastcache would round the size | ||
// to the next multiple of 32 MB. | ||
func New(usrCacheSize int) *Cache { | ||
cache := &Cache{} | ||
// By default, 64 MB is allocated for the system cache | ||
cache.sysCache = fastcache.New(64 * 1024 * 1024) | ||
|
||
// User passed size is used to allocate memory for the user cache | ||
if usrCacheSize <= 0 { | ||
return cache | ||
} | ||
cache.usrCache = fastcache.New(usrCacheSize * 1024 * 1024) | ||
return cache | ||
} |
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,30 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package statedb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/VictoriaMetrics/fastcache" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewCache(t *testing.T) { | ||
cache := New(10) | ||
expectedCache := &Cache{ | ||
sysCache: fastcache.New(64 * 1024 * 1024), | ||
usrCache: fastcache.New(10 * 1024 * 1024), | ||
} | ||
assert.Equal(t, expectedCache, cache) | ||
|
||
cache = New(0) | ||
expectedCache = &Cache{ | ||
sysCache: fastcache.New(64 * 1024 * 1024), | ||
usrCache: nil, | ||
} | ||
assert.Equal(t, expectedCache, cache) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
152 changes: 152 additions & 0 deletions
152
vendor/github.com/VictoriaMetrics/fastcache/bigcache.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.