2022-08-25 15:48:54 +08:00
|
|
|
package indexnode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
|
2022-09-23 14:40:51 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-08-25 15:48:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StorageFactory interface {
|
|
|
|
NewChunkManager(ctx context.Context, config *indexpb.StorageConfig) (storage.ChunkManager, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type chunkMgr struct {
|
|
|
|
cached sync.Map
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *chunkMgr) NewChunkManager(ctx context.Context, config *indexpb.StorageConfig) (storage.ChunkManager, error) {
|
2022-09-06 17:19:11 +08:00
|
|
|
key := m.cacheKey(config.StorageType, config.BucketName, config.Address)
|
|
|
|
if v, ok := m.cached.Load(key); ok {
|
|
|
|
return v.(storage.ChunkManager), nil
|
2022-08-25 15:48:54 +08:00
|
|
|
}
|
2022-09-06 17:19:11 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
chunkManagerFactory := storage.NewChunkManagerFactoryWithParam(Params)
|
2022-09-23 14:40:51 +08:00
|
|
|
mgr, err := chunkManagerFactory.NewPersistentStorageChunkManager(ctx)
|
2022-08-25 15:48:54 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-09-06 17:19:11 +08:00
|
|
|
v, _ := m.cached.LoadOrStore(key, mgr)
|
2022-09-23 14:40:51 +08:00
|
|
|
log.Ctx(ctx).Info("index node successfully init chunk manager")
|
2022-09-06 17:19:11 +08:00
|
|
|
return v.(storage.ChunkManager), nil
|
2022-08-25 15:48:54 +08:00
|
|
|
}
|
|
|
|
|
2022-09-06 17:19:11 +08:00
|
|
|
func (m *chunkMgr) cacheKey(storageType, bucket, address string) string {
|
|
|
|
return fmt.Sprintf("%s/%s/%s", storageType, bucket, address)
|
2022-08-25 15:48:54 +08:00
|
|
|
}
|