Skip to content

Commit

Permalink
Merge "vendor fastCache to use as ledger cache"
Browse files Browse the repository at this point in the history
  • Loading branch information
manish-sethi authored and Gerrit Code Review committed Nov 11, 2019
2 parents 7b3fafc + 3a8dae8 commit a90f67d
Show file tree
Hide file tree
Showing 17 changed files with 1,729 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ noverify = [
[[constraint]]
branch = "master"
name = "github.com/hyperledger/fabric-chaincode-go"

[[constraint]]
name = "github.com/VictoriaMetrics/fastcache"
version = "1.4.6"
37 changes: 37 additions & 0 deletions core/ledger/kvledger/txmgmt/statedb/cache.go
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
}
30 changes: 30 additions & 0 deletions core/ledger/kvledger/txmgmt/statedb/cache_test.go
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)
}
22 changes: 22 additions & 0 deletions vendor/github.com/VictoriaMetrics/fastcache/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 152 additions & 0 deletions vendor/github.com/VictoriaMetrics/fastcache/bigcache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a90f67d

Please sign in to comment.