Skip to content

Commit

Permalink
levelcache: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Sep 28, 2023
1 parent 35aa870 commit 9e7656a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
45 changes: 44 additions & 1 deletion ributil/levelcache/levelcache.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
package levelcache

import "github.com/multiformats/go-multihash"
import (
"github.com/lotus-web3/ribs/ributil/logcache"
"github.com/lotus-web3/ribs/ributil/mlru"
"github.com/multiformats/go-multihash"
"sync"
)

type mhStr string

type LevelCache struct {
// root dir
// Contents:
// /l0.lru
// /l0.car
// /l0.offs
// ...
root string

// settings
l0size int64
levelExpansion int

// mlru group
lrugroup *mlru.LRUGroup

// persistent top level lru
// (the top layer is special because it's the only actively mutated layer)
topLru *mlru.MLRU[mhStr, bool]
topLog *logcache.LogCache

// levels, with, at least for now, one logcache+mlru per level
levels []*cacheLevel

// compaction stuff
compactLk sync.RWMutex

// todo mem tier
// temp memory cache used during compaction
compactCache map[mhStr][]byte
}

type cacheLevel struct {
lru *mlru.MLRU[mhStr, bool]
log *logcache.LogCache
}

func (c *LevelCache) compactTop() error {
c.compactLk.Lock()
defer c.compactLk.Unlock()

c.levels[0].lru.EvictStats()

Check failure on line 53 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go this)

c.levels[0].lru.EvictStats undefined (type *mlru.MLRU[mhStr, bool] has no field or method EvictStats)

Check failure on line 53 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-check / All

c.levels[0].lru.EvictStats undefined (type *mlru.MLRU[mhStr, bool] has no field or method EvictStats)

Check failure on line 53 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go this)

c.levels[0].lru.EvictStats undefined (type *mlru.MLRU[mhStr, bool] has no field or method EvictStats)

Check failure on line 53 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go this)

c.levels[0].lru.EvictStats undefined (type *mlru.MLRU[mhStr, bool] has no field or method EvictStats)
}

Check failure on line 54 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go this)

missing return

Check failure on line 54 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-check / All

missing return

Check failure on line 54 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go this)

missing return

Check failure on line 54 in ributil/levelcache/levelcache.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go this)

missing return

func (c *LevelCache) Put(k multihash.Multihash, v []byte) error {
Expand Down
5 changes: 3 additions & 2 deletions ributil/logcache/logcache_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package logcache

import (
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/assert"
"io/ioutil"

Check failure on line 4 in ributil/logcache/logcache_test.go

View workflow job for this annotation

GitHub Actions / go-check / All

"io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (SA1019)
"os"
"testing"

"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/assert"
)

func TestOpen(t *testing.T) {
Expand Down

0 comments on commit 9e7656a

Please sign in to comment.