milvus/internal/storage/factory.go
godchen bb7a0766fe
Add dependency factory (#16204)
Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com>
2022-04-07 22:05:32 +08:00

49 lines
1.3 KiB
Go

package storage
import (
"context"
"errors"
)
type ChunkManagerFactory struct {
cacheStorage string
vectorStorage string
config *config
}
func NewChunkManagerFactory(cacheStorage, vectorStorage string, opts ...Option) *ChunkManagerFactory {
c := newDefaultConfig()
for _, opt := range opts {
opt(c)
}
return &ChunkManagerFactory{
cacheStorage: cacheStorage,
vectorStorage: vectorStorage,
config: c,
}
}
func (f *ChunkManagerFactory) newChunkManager(ctx context.Context, engine string) (ChunkManager, error) {
switch engine {
case "local":
return NewLocalChunkManager(RootPath(f.config.rootPath)), nil
case "minio":
return newMinioChunkManagerWithConfig(ctx, f.config)
default:
return nil, errors.New("no chunk manager implemented with engine: " + engine)
}
}
func (f *ChunkManagerFactory) NewCacheStorageChunkManager(ctx context.Context) (ChunkManager, error) {
return f.newChunkManager(ctx, f.cacheStorage)
}
func (f *ChunkManagerFactory) NewVectorStorageChunkManager(ctx context.Context) (ChunkManager, error) {
return f.newChunkManager(ctx, f.vectorStorage)
}
type Factory interface {
NewCacheStorageChunkManager(ctx context.Context) (ChunkManager, error)
NewVectorStorageChunkManager(ctx context.Context) (ChunkManager, error)
}