2022-04-07 22:05:32 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-02-26 11:31:49 +08:00
|
|
|
|
|
|
|
"github.com/cockroachdb/errors"
|
2022-09-23 14:40:51 +08:00
|
|
|
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2022-04-07 22:05:32 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ChunkManagerFactory struct {
|
2022-09-23 14:40:51 +08:00
|
|
|
persistentStorage string
|
|
|
|
config *config
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewChunkManagerFactoryWithParam(params *paramtable.ComponentParam) *ChunkManagerFactory {
|
2022-12-07 18:01:19 +08:00
|
|
|
if params.CommonCfg.StorageType.GetValue() == "local" {
|
2022-11-17 18:59:09 +08:00
|
|
|
return NewChunkManagerFactory("local", RootPath(params.LocalStorageCfg.Path.GetValue()))
|
2022-09-23 14:40:51 +08:00
|
|
|
}
|
2023-09-19 10:01:23 +08:00
|
|
|
return NewChunkManagerFactory(params.CommonCfg.StorageType.GetValue(),
|
2022-11-17 18:59:09 +08:00
|
|
|
RootPath(params.MinioCfg.RootPath.GetValue()),
|
|
|
|
Address(params.MinioCfg.Address.GetValue()),
|
|
|
|
AccessKeyID(params.MinioCfg.AccessKeyID.GetValue()),
|
|
|
|
SecretAccessKeyID(params.MinioCfg.SecretAccessKey.GetValue()),
|
|
|
|
UseSSL(params.MinioCfg.UseSSL.GetAsBool()),
|
2024-03-21 11:15:20 +08:00
|
|
|
SslCACert(params.MinioCfg.SslCACert.GetValue()),
|
2022-11-17 18:59:09 +08:00
|
|
|
BucketName(params.MinioCfg.BucketName.GetValue()),
|
|
|
|
UseIAM(params.MinioCfg.UseIAM.GetAsBool()),
|
|
|
|
CloudProvider(params.MinioCfg.CloudProvider.GetValue()),
|
|
|
|
IAMEndpoint(params.MinioCfg.IAMEndpoint.GetValue()),
|
2023-08-11 10:37:36 +08:00
|
|
|
UseVirtualHost(params.MinioCfg.UseVirtualHost.GetAsBool()),
|
|
|
|
Region(params.MinioCfg.Region.GetValue()),
|
2023-10-23 20:08:08 +08:00
|
|
|
RequestTimeout(params.MinioCfg.RequestTimeoutMs.GetAsInt64()),
|
2024-09-30 13:23:32 +08:00
|
|
|
CreateBucket(true),
|
|
|
|
GcpCredentialJSON(params.MinioCfg.GcpCredentialJSON.GetValue()))
|
2022-04-07 22:05:32 +08:00
|
|
|
}
|
|
|
|
|
2022-09-23 14:40:51 +08:00
|
|
|
func NewChunkManagerFactory(persistentStorage string, opts ...Option) *ChunkManagerFactory {
|
2022-04-07 22:05:32 +08:00
|
|
|
c := newDefaultConfig()
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(c)
|
|
|
|
}
|
|
|
|
return &ChunkManagerFactory{
|
2022-09-23 14:40:51 +08:00
|
|
|
persistentStorage: persistentStorage,
|
|
|
|
config: c,
|
2022-04-07 22:05:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ChunkManagerFactory) newChunkManager(ctx context.Context, engine string) (ChunkManager, error) {
|
|
|
|
switch engine {
|
|
|
|
case "local":
|
|
|
|
return NewLocalChunkManager(RootPath(f.config.rootPath)), nil
|
2024-04-25 20:41:27 +08:00
|
|
|
case "remote", "minio", "opendal":
|
2023-09-19 10:01:23 +08:00
|
|
|
return NewRemoteChunkManager(ctx, f.config)
|
2022-04-07 22:05:32 +08:00
|
|
|
default:
|
|
|
|
return nil, errors.New("no chunk manager implemented with engine: " + engine)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 14:40:51 +08:00
|
|
|
func (f *ChunkManagerFactory) NewPersistentStorageChunkManager(ctx context.Context) (ChunkManager, error) {
|
|
|
|
return f.newChunkManager(ctx, f.persistentStorage)
|
2022-04-07 22:05:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type Factory interface {
|
2022-09-23 14:40:51 +08:00
|
|
|
NewPersistentStorageChunkManager(ctx context.Context) (ChunkManager, error)
|
2022-04-07 22:05:32 +08:00
|
|
|
}
|