Skip to content

Commit

Permalink
vendor fastCache to use as ledger cache
Browse files Browse the repository at this point in the history
FastCache is chosen as the caching library.

FAB-15537 #done

Change-Id: I4733fa64872e5743f38d1dd46adf1fad6d70d59e
Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu committed Nov 9, 2019
1 parent 53a1bce commit 3a8dae8
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 3a8dae8

Please sign in to comment.