forked from TrueCloudLab/frostfs-s3-gw
[#650] Drop unused object cache methods
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
821df3d648
commit
0d0ecf5b10
3 changed files with 43 additions and 65 deletions
11
api/cache/cache_test.go
vendored
11
api/cache/cache_test.go
vendored
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
||||||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -104,17 +103,17 @@ func TestObjectsListCacheType(t *testing.T) {
|
||||||
|
|
||||||
cnrID := cidtest.ID()
|
cnrID := cidtest.ID()
|
||||||
key := ObjectsListKey{cid: cnrID, prefix: "obj"}
|
key := ObjectsListKey{cid: cnrID, prefix: "obj"}
|
||||||
objIDs := []oid.ID{oidtest.ID()}
|
versions := []*data.NodeVersion{{BaseNodeVersion: data.BaseNodeVersion{OID: oidtest.ID()}}}
|
||||||
|
|
||||||
err := cache.Put(key, objIDs)
|
err := cache.PutVersions(key, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
val := cache.Get(key)
|
val := cache.GetVersions(key)
|
||||||
require.Equal(t, objIDs, val)
|
require.Equal(t, versions, val)
|
||||||
require.Equal(t, 0, observedLog.Len())
|
require.Equal(t, 0, observedLog.Len())
|
||||||
|
|
||||||
err = cache.cache.Set(key, "tmp")
|
err = cache.cache.Set(key, "tmp")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assertInvalidCacheEntry(t, cache.Get(key), observedLog)
|
assertInvalidCacheEntry(t, cache.GetVersions(key), observedLog)
|
||||||
|
|
||||||
err = cache.cache.Set("key", "tmp")
|
err = cache.cache.Set("key", "tmp")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
25
api/cache/objectslist.go
vendored
25
api/cache/objectslist.go
vendored
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/bluele/gcache"
|
"github.com/bluele/gcache"
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,23 +66,6 @@ func NewObjectsListCache(config *Config) *ObjectsListCache {
|
||||||
return &ObjectsListCache{cache: gc, logger: config.Logger}
|
return &ObjectsListCache{cache: gc, logger: config.Logger}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns a list of ObjectInfo.
|
|
||||||
func (l *ObjectsListCache) Get(key ObjectsListKey) []oid.ID {
|
|
||||||
entry, err := l.cache.Get(key)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
result, ok := entry.([]oid.ID)
|
|
||||||
if !ok {
|
|
||||||
l.logger.Warn("invalid cache entry type", zap.String("actual", fmt.Sprintf("%T", entry)),
|
|
||||||
zap.String("expected", fmt.Sprintf("%T", result)))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVersions returns a list of ObjectInfo.
|
// GetVersions returns a list of ObjectInfo.
|
||||||
func (l *ObjectsListCache) GetVersions(key ObjectsListKey) []*data.NodeVersion {
|
func (l *ObjectsListCache) GetVersions(key ObjectsListKey) []*data.NodeVersion {
|
||||||
entry, err := l.cache.Get(key)
|
entry, err := l.cache.Get(key)
|
||||||
|
@ -93,17 +75,14 @@ func (l *ObjectsListCache) GetVersions(key ObjectsListKey) []*data.NodeVersion {
|
||||||
|
|
||||||
result, ok := entry.([]*data.NodeVersion)
|
result, ok := entry.([]*data.NodeVersion)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
l.logger.Warn("invalid cache entry type", zap.String("actual", fmt.Sprintf("%T", entry)),
|
||||||
|
zap.String("expected", fmt.Sprintf("%T", result)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put puts a list of objects to cache.
|
|
||||||
func (l *ObjectsListCache) Put(key ObjectsListKey, oids []oid.ID) error {
|
|
||||||
return l.cache.Set(key, oids)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutVersions puts a list of object versions to cache.
|
// PutVersions puts a list of object versions to cache.
|
||||||
func (l *ObjectsListCache) PutVersions(key ObjectsListKey, versions []*data.NodeVersion) error {
|
func (l *ObjectsListCache) PutVersions(key ObjectsListKey, versions []*data.NodeVersion) error {
|
||||||
return l.cache.Set(key, versions)
|
return l.cache.Set(key, versions)
|
||||||
|
|
62
api/cache/objectslist_test.go
vendored
62
api/cache/objectslist_test.go
vendored
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
||||||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -25,26 +25,26 @@ func getTestObjectsListConfig() *Config {
|
||||||
func TestObjectsListCache(t *testing.T) {
|
func TestObjectsListCache(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
listSize = 10
|
listSize = 10
|
||||||
ids []oid.ID
|
versions []*data.NodeVersion
|
||||||
cidKey, cidKey2 = cidtest.ID(), cidtest.ID()
|
cidKey, cidKey2 = cidtest.ID(), cidtest.ID()
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < listSize; i++ {
|
for i := 0; i < listSize; i++ {
|
||||||
ids = append(ids, oidtest.ID())
|
versions = append(versions, &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{OID: oidtest.ID()}})
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("lifetime", func(t *testing.T) {
|
t.Run("lifetime", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
config = getTestObjectsListConfig()
|
config = getTestObjectsListConfig()
|
||||||
cache = NewObjectsListCache(config)
|
cache = NewObjectsListCache(config)
|
||||||
cacheKey = ObjectsListKey{cid: cidKey}
|
listKey = ObjectsListKey{cid: cidKey}
|
||||||
)
|
)
|
||||||
|
|
||||||
err := cache.Put(cacheKey, ids)
|
err := cache.PutVersions(listKey, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
condition := func() bool {
|
condition := func() bool {
|
||||||
return cache.Get(cacheKey) == nil
|
return cache.GetVersions(listKey) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Never(t, condition, config.Lifetime, time.Second)
|
require.Never(t, condition, config.Lifetime, time.Second)
|
||||||
|
@ -54,40 +54,40 @@ func TestObjectsListCache(t *testing.T) {
|
||||||
t.Run("get cache with empty prefix", func(t *testing.T) {
|
t.Run("get cache with empty prefix", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
cache = NewObjectsListCache(getTestObjectsListConfig())
|
cache = NewObjectsListCache(getTestObjectsListConfig())
|
||||||
cacheKey = ObjectsListKey{cid: cidKey}
|
listKey = ObjectsListKey{cid: cidKey}
|
||||||
)
|
)
|
||||||
err := cache.Put(cacheKey, ids)
|
err := cache.PutVersions(listKey, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
actual := cache.Get(cacheKey)
|
actual := cache.GetVersions(listKey)
|
||||||
|
|
||||||
require.Equal(t, len(ids), len(actual))
|
require.Equal(t, len(versions), len(actual))
|
||||||
for i := range ids {
|
for i := range versions {
|
||||||
require.Equal(t, ids[i], actual[i])
|
require.Equal(t, versions[i], actual[i])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get cache with prefix", func(t *testing.T) {
|
t.Run("get cache with prefix", func(t *testing.T) {
|
||||||
cacheKey := ObjectsListKey{
|
listKey := ObjectsListKey{
|
||||||
cid: cidKey,
|
cid: cidKey,
|
||||||
prefix: "dir",
|
prefix: "dir",
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := NewObjectsListCache(getTestObjectsListConfig())
|
cache := NewObjectsListCache(getTestObjectsListConfig())
|
||||||
err := cache.Put(cacheKey, ids)
|
err := cache.PutVersions(listKey, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
actual := cache.Get(cacheKey)
|
actual := cache.GetVersions(listKey)
|
||||||
|
|
||||||
require.Equal(t, len(ids), len(actual))
|
require.Equal(t, len(versions), len(actual))
|
||||||
for i := range ids {
|
for i := range versions {
|
||||||
require.Equal(t, ids[i], actual[i])
|
require.Equal(t, versions[i], actual[i])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get cache with other prefix", func(t *testing.T) {
|
t.Run("get cache with other prefix", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
cacheKey = ObjectsListKey{
|
listKey = ObjectsListKey{
|
||||||
cid: cidKey,
|
cid: cidKey,
|
||||||
prefix: "dir",
|
prefix: "dir",
|
||||||
}
|
}
|
||||||
|
@ -99,16 +99,16 @@ func TestObjectsListCache(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
cache := NewObjectsListCache(getTestObjectsListConfig())
|
cache := NewObjectsListCache(getTestObjectsListConfig())
|
||||||
err := cache.Put(cacheKey, ids)
|
err := cache.PutVersions(listKey, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
actual := cache.Get(newKey)
|
actual := cache.GetVersions(newKey)
|
||||||
require.Nil(t, actual)
|
require.Nil(t, actual)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get cache with non-existing key", func(t *testing.T) {
|
t.Run("get cache with non-existing key", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
cacheKey = ObjectsListKey{
|
listKey = ObjectsListKey{
|
||||||
cid: cidKey,
|
cid: cidKey,
|
||||||
}
|
}
|
||||||
newKey = ObjectsListKey{
|
newKey = ObjectsListKey{
|
||||||
|
@ -117,10 +117,10 @@ func TestObjectsListCache(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
cache := NewObjectsListCache(getTestObjectsListConfig())
|
cache := NewObjectsListCache(getTestObjectsListConfig())
|
||||||
err := cache.Put(cacheKey, ids)
|
err := cache.PutVersions(listKey, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
actual := cache.Get(newKey)
|
actual := cache.GetVersions(newKey)
|
||||||
require.Nil(t, actual)
|
require.Nil(t, actual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func TestObjectsListCache(t *testing.T) {
|
||||||
func TestCleanCacheEntriesChangedWithPutObject(t *testing.T) {
|
func TestCleanCacheEntriesChangedWithPutObject(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
id = cidtest.ID()
|
id = cidtest.ID()
|
||||||
oids = []oid.ID{oidtest.ID()}
|
versions = []*data.NodeVersion{{BaseNodeVersion: data.BaseNodeVersion{OID: oidtest.ID()}}}
|
||||||
keys []ObjectsListKey
|
keys []ObjectsListKey
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -141,12 +141,12 @@ func TestCleanCacheEntriesChangedWithPutObject(t *testing.T) {
|
||||||
config.Lifetime = time.Minute
|
config.Lifetime = time.Minute
|
||||||
cache := NewObjectsListCache(config)
|
cache := NewObjectsListCache(config)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
err := cache.Put(k, oids)
|
err := cache.PutVersions(k, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
cache.CleanCacheEntriesContainingObject("obj1", id)
|
cache.CleanCacheEntriesContainingObject("obj1", id)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
list := cache.Get(k)
|
list := cache.GetVersions(k)
|
||||||
if k.prefix == "" {
|
if k.prefix == "" {
|
||||||
require.Nil(t, list)
|
require.Nil(t, list)
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,12 +160,12 @@ func TestCleanCacheEntriesChangedWithPutObject(t *testing.T) {
|
||||||
config.Lifetime = time.Minute
|
config.Lifetime = time.Minute
|
||||||
cache := NewObjectsListCache(config)
|
cache := NewObjectsListCache(config)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
err := cache.Put(k, oids)
|
err := cache.PutVersions(k, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
cache.CleanCacheEntriesContainingObject("dir/obj", id)
|
cache.CleanCacheEntriesContainingObject("dir/obj", id)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
list := cache.Get(k)
|
list := cache.GetVersions(k)
|
||||||
if k.prefix == "" || k.prefix == "dir/" {
|
if k.prefix == "" || k.prefix == "dir/" {
|
||||||
require.Nil(t, list)
|
require.Nil(t, list)
|
||||||
} else {
|
} else {
|
||||||
|
@ -179,12 +179,12 @@ func TestCleanCacheEntriesChangedWithPutObject(t *testing.T) {
|
||||||
config.Lifetime = time.Minute
|
config.Lifetime = time.Minute
|
||||||
cache := NewObjectsListCache(config)
|
cache := NewObjectsListCache(config)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
err := cache.Put(k, oids)
|
err := cache.PutVersions(k, versions)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
cache.CleanCacheEntriesContainingObject("dir/lol/obj", id)
|
cache.CleanCacheEntriesContainingObject("dir/lol/obj", id)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
list := cache.Get(k)
|
list := cache.GetVersions(k)
|
||||||
require.Nil(t, list)
|
require.Nil(t, list)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue