Skip to content

Commit

Permalink
Write the cache file to the cacheStorage.rootpath dir (#25715)
Browse files Browse the repository at this point in the history
Signed-off-by: xige-16 <xi.ge@zilliz.com>
  • Loading branch information
xige-16 authored Jul 28, 2023
1 parent d7cd1c8 commit f33451b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
11 changes: 7 additions & 4 deletions internal/storage/vector_chunk_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package storage
import (
"context"
"io"
"path"
"sync"
"time"

Expand Down Expand Up @@ -91,9 +92,10 @@ func (vcm *VectorChunkManager) initCache(ctx context.Context) error {
if err != nil {
log.Error("close mmap file failed", zap.Any("file", filePath))
}
err = vcm.cacheStorage.Remove(ctx, filePath)
localPath := path.Join(vcm.cacheStorage.RootPath(), filePath)
err = vcm.cacheStorage.Remove(ctx, localPath)
if err != nil {
log.Error("cache storage remove file failed", zap.Any("file", filePath))
log.Error("cache storage remove file failed", zap.Any("file", localPath))
}

vcm.cacheSizeMutex.Lock()
Expand Down Expand Up @@ -173,12 +175,13 @@ func (vcm *VectorChunkManager) readFile(ctx context.Context, filePath string) (*
if err != nil {
return nil, err
}
err = vcm.cacheStorage.Write(ctx, filePath, results)
localPath := path.Join(vcm.cacheStorage.RootPath(), filePath)
err = vcm.cacheStorage.Write(ctx, localPath, results)
if err != nil {
return nil, err
}

r, err := vcm.cacheStorage.Mmap(ctx, filePath)
r, err := vcm.cacheStorage.Mmap(ctx, localPath)
if err != nil {
return nil, err
}
Expand Down
57 changes: 41 additions & 16 deletions internal/storage/vector_chunk_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,21 @@ func initBinlogFile(schema *etcdpb.CollectionMeta) []*Blob {
return blobs
}

func buildVectorChunkManager(localPath string, localCacheEnable bool) (*VectorChunkManager, context.CancelFunc, error) {
ctx, cancel := context.WithCancel(context.Background())

func buildVectorChunkManager(ctx context.Context, localPath string, localCacheEnable bool) (*VectorChunkManager, error) {
bucketName := "vector-chunk-manager"

rcm, err := newMinIOChunkManager(ctx, bucketName, "")
if err != nil {
return nil, cancel, err
return nil, err
}
lcm := NewLocalChunkManager(RootPath(localPath))

vcm, err := NewVectorChunkManager(ctx, lcm, rcm, 16, localCacheEnable)
if err != nil {
return nil, cancel, err
return nil, err
}

return vcm, cancel, nil
return vcm, nil
}

var Params = paramtable.Get()
Expand Down Expand Up @@ -171,7 +169,7 @@ func TestVectorChunkManager_GetPath(t *testing.T) {
defer cancel()
localCaches := []bool{true, false}
for _, localCache := range localCaches {
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
vcm, err := buildVectorChunkManager(ctx, localPath, localCache)
assert.NoError(t, err)
assert.NotNil(t, vcm)

Expand All @@ -190,7 +188,6 @@ func TestVectorChunkManager_GetPath(t *testing.T) {

err = vcm.RemoveWithPrefix(ctx, localPath)
assert.NoError(t, err)
cancel()
vcm.Close()
}
}
Expand All @@ -200,7 +197,7 @@ func TestVectorChunkManager_GetSize(t *testing.T) {
defer cancel()
localCaches := []bool{true, false}
for _, localCache := range localCaches {
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
vcm, err := buildVectorChunkManager(ctx, localPath, localCache)
assert.NoError(t, err)
assert.NotNil(t, vcm)

Expand All @@ -219,7 +216,6 @@ func TestVectorChunkManager_GetSize(t *testing.T) {

err = vcm.RemoveWithPrefix(ctx, localPath)
assert.NoError(t, err)
cancel()
vcm.Close()
}
}
Expand All @@ -230,7 +226,7 @@ func TestVectorChunkManager_Write(t *testing.T) {

localCaches := []bool{true, false}
for _, localCache := range localCaches {
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
vcm, err := buildVectorChunkManager(ctx, localPath, localCache)
assert.NoError(t, err)
assert.NotNil(t, vcm)

Expand Down Expand Up @@ -259,7 +255,6 @@ func TestVectorChunkManager_Write(t *testing.T) {

err = vcm.RemoveWithPrefix(ctx, localPath)
assert.NoError(t, err)
cancel()
vcm.Close()
}
}
Expand All @@ -270,7 +265,7 @@ func TestVectorChunkManager_Remove(t *testing.T) {

localCaches := []bool{true, false}
for _, localCache := range localCaches {
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
vcm, err := buildVectorChunkManager(ctx, localPath, localCache)
assert.NoError(t, err)
assert.NotNil(t, vcm)

Expand Down Expand Up @@ -305,7 +300,6 @@ func TestVectorChunkManager_Remove(t *testing.T) {

err = vcm.RemoveWithPrefix(ctx, localPath)
assert.NoError(t, err)
cancel()
vcm.Close()
}
}
Expand Down Expand Up @@ -348,13 +342,45 @@ func TestVectorChunkManager_Remove_Fail(t *testing.T) {
assert.Error(t, vcm.RemoveWithPrefix(ctx, "test"))
}

func TestVectorChunkManager_LocalPath(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
vcm, err := buildVectorChunkManager(ctx, localPath, true)
assert.NotNil(t, vcm)
assert.NoError(t, err)

meta := initMeta()
binlogs := initBinlogFile(meta)
keys := make([]string, len(binlogs))
for i, binlog := range binlogs {
err = vcm.vectorStorage.Write(ctx, binlog.Key, binlog.Value)
assert.Nil(t, err)
keys[i] = binlog.Key
}

// cache file to cacheStorage
_, err = vcm.Read(ctx, keys[0])
assert.NoError(t, err)

// check file under cacheStorage.rootPath
absLocalPath := path.Join(vcm.cacheStorage.RootPath(), keys[0])
exit, err := vcm.cacheStorage.Exist(ctx, absLocalPath)
assert.NoError(t, err)
assert.True(t, exit)

err = vcm.RemoveWithPrefix(ctx, localPath)
assert.NoError(t, err)

vcm.Close()
}

func TestVectorChunkManager_Read(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

localCaches := []bool{true, false}
for _, localCache := range localCaches {
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
vcm, err := buildVectorChunkManager(ctx, localPath, localCache)
assert.NotNil(t, vcm)
assert.NoError(t, err)

Expand Down Expand Up @@ -453,7 +479,6 @@ func TestVectorChunkManager_Read(t *testing.T) {
err = vcm.RemoveWithPrefix(ctx, localPath)
assert.NoError(t, err)

cancel()
vcm.Close()
}
}

0 comments on commit f33451b

Please sign in to comment.