2022-07-22 10:20:29 +08:00
package metastore
import (
"context"
2023-06-09 01:28:37 +08:00
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
2022-07-22 10:20:29 +08:00
"github.com/milvus-io/milvus/internal/metastore/model"
2022-08-20 10:24:51 +08:00
"github.com/milvus-io/milvus/internal/proto/datapb"
2022-09-15 18:48:32 +08:00
"github.com/milvus-io/milvus/internal/proto/querypb"
2023-04-06 19:14:32 +08:00
"github.com/milvus-io/milvus/pkg/util/typeutil"
2022-07-22 10:20:29 +08:00
)
2022-09-27 19:18:54 +08:00
//go:generate mockery --name=RootCoordCatalog
2022-08-20 10:24:51 +08:00
type RootCoordCatalog interface {
2023-06-25 17:20:43 +08:00
CreateDatabase ( ctx context . Context , db * model . Database , ts typeutil . Timestamp ) error
DropDatabase ( ctx context . Context , dbID int64 , ts typeutil . Timestamp ) error
ListDatabases ( ctx context . Context , ts typeutil . Timestamp ) ( [ ] * model . Database , error )
2024-03-19 19:21:06 +08:00
AlterDatabase ( ctx context . Context , newDB * model . Database , ts typeutil . Timestamp ) error
2023-06-25 17:20:43 +08:00
2022-07-22 10:20:29 +08:00
CreateCollection ( ctx context . Context , collectionInfo * model . Collection , ts typeutil . Timestamp ) error
2023-06-25 17:20:43 +08:00
GetCollectionByID ( ctx context . Context , dbID int64 , ts typeutil . Timestamp , collectionID typeutil . UniqueID ) ( * model . Collection , error )
GetCollectionByName ( ctx context . Context , dbID int64 , collectionName string , ts typeutil . Timestamp ) ( * model . Collection , error )
ListCollections ( ctx context . Context , dbID int64 , ts typeutil . Timestamp ) ( [ ] * model . Collection , error )
CollectionExists ( ctx context . Context , dbID int64 , collectionID typeutil . UniqueID , ts typeutil . Timestamp ) bool
2022-07-22 10:20:29 +08:00
DropCollection ( ctx context . Context , collectionInfo * model . Collection , ts typeutil . Timestamp ) error
2022-09-05 13:29:11 +08:00
AlterCollection ( ctx context . Context , oldColl * model . Collection , newColl * model . Collection , alterType AlterType , ts typeutil . Timestamp ) error
2022-07-22 10:20:29 +08:00
2023-06-25 17:20:43 +08:00
CreatePartition ( ctx context . Context , dbID int64 , partition * model . Partition , ts typeutil . Timestamp ) error
DropPartition ( ctx context . Context , dbID int64 , collectionID typeutil . UniqueID , partitionID typeutil . UniqueID , ts typeutil . Timestamp ) error
AlterPartition ( ctx context . Context , dbID int64 , oldPart * model . Partition , newPart * model . Partition , alterType AlterType , ts typeutil . Timestamp ) error
2022-07-22 10:20:29 +08:00
2022-08-10 10:22:38 +08:00
CreateAlias ( ctx context . Context , alias * model . Alias , ts typeutil . Timestamp ) error
2023-06-25 17:20:43 +08:00
DropAlias ( ctx context . Context , dbID int64 , alias string , ts typeutil . Timestamp ) error
2022-08-10 10:22:38 +08:00
AlterAlias ( ctx context . Context , alias * model . Alias , ts typeutil . Timestamp ) error
2023-06-25 17:20:43 +08:00
ListAliases ( ctx context . Context , dbID int64 , ts typeutil . Timestamp ) ( [ ] * model . Alias , error )
2022-07-22 10:20:29 +08:00
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// GetCredential gets the credential info for the username, returns error if no credential exists for this username.
2022-07-22 10:20:29 +08:00
GetCredential ( ctx context . Context , username string ) ( * model . Credential , error )
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// CreateCredential creates credential by Username and EncryptedPassword in crediential. Please make sure credential.Username isn't empty before calling this API. Credentials already exists will be altered.
2022-07-22 10:20:29 +08:00
CreateCredential ( ctx context . Context , credential * model . Credential ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// AlterCredential does exactly the same as CreateCredential
2022-08-24 14:32:56 +08:00
AlterCredential ( ctx context . Context , credential * model . Credential ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// DropCredential removes the credential of this username
2022-07-22 10:20:29 +08:00
DropCredential ( ctx context . Context , username string ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// ListCredentials gets all usernames.
2022-07-22 10:20:29 +08:00
ListCredentials ( ctx context . Context ) ( [ ] string , error )
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// CreateRole creates role by the entity for the tenant. Please make sure the tenent and entity.Name aren't empty. Empty entity.Name may end up with deleting all roles
// Returns common.IgnorableError if the role already existes
2022-08-04 11:04:34 +08:00
CreateRole ( ctx context . Context , tenant string , entity * milvuspb . RoleEntity ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// DropRole removes a role by name
2022-08-04 11:04:34 +08:00
DropRole ( ctx context . Context , tenant string , roleName string ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// AlterUserRole changes the role of a user for the tenant. Please make sure the userEntity.Name and roleEntity.Name aren't empty before calling this API.
// Returns common.IgnorableError
// - if user has the role when AddUserToRole
// - if user doen't have the role when RemoveUserFromRole
2022-08-23 10:26:53 +08:00
AlterUserRole ( ctx context . Context , tenant string , userEntity * milvuspb . UserEntity , roleEntity * milvuspb . RoleEntity , operateType milvuspb . OperateUserRoleType ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// ListRole returns lists of RoleResults for the tenant
// Returns all role results if entity is nill
// Returns only role results if entity.Name is provided
// Returns UserInfo inside each RoleResult if includeUserInfo is True
2022-08-23 10:26:53 +08:00
ListRole ( ctx context . Context , tenant string , entity * milvuspb . RoleEntity , includeUserInfo bool ) ( [ ] * milvuspb . RoleResult , error )
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// ListUser returns list of UserResults for the tenant
// Returns all users if entity is nill
// Returns the specific user if enitity is provided
// Returns RoleInfo inside each UserResult if includeRoleInfo is True
2022-08-23 10:26:53 +08:00
ListUser ( ctx context . Context , tenant string , entity * milvuspb . UserEntity , includeRoleInfo bool ) ( [ ] * milvuspb . UserResult , error )
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// AlterGrant grants or revokes a grant of a role to an object, according to the operateType.
// Please make sure entity and operateType are valid before calling this API
2022-08-23 10:26:53 +08:00
AlterGrant ( ctx context . Context , tenant string , entity * milvuspb . GrantEntity , operateType milvuspb . OperatePrivilegeType ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// DeleteGrant deletes all the grant for a role.
// Please make sure the role.Name isn't empty before call this API.
2022-08-26 19:22:56 +08:00
DeleteGrant ( ctx context . Context , tenant string , role * milvuspb . RoleEntity ) error
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// ListGrant lists all grant infos accoording to entity for the tenant
// Please make sure entity valid before calling this API
2022-08-23 10:26:53 +08:00
ListGrant ( ctx context . Context , tenant string , entity * milvuspb . GrantEntity ) ( [ ] * milvuspb . GrantEntity , error )
2022-08-04 11:04:34 +08:00
ListPolicy ( ctx context . Context , tenant string ) ( [ ] string , error )
Add ut for rootcoord/kv/kv_catalog.go (#20909)
Add ut for CreateCredential, GetCredential, Dropcredential,
ListCredentials, CreateRole, DropRole AlterUserRole, ListRole,
ListUser, ListUserRole, DeleteGrant, AlterGrant, ListGrant, and, ListPolicy
Fixes: #20833
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2022-12-05 11:05:17 +08:00
// List all user role pair in string for the tenant
// For example []string{"user1/role1"}
2022-08-04 11:04:34 +08:00
ListUserRole ( ctx context . Context , tenant string ) ( [ ] string , error )
2022-07-22 10:20:29 +08:00
Close ( )
}
type AlterType int32
const (
ADD AlterType = iota
DELETE
MODIFY
)
2022-08-20 10:24:51 +08:00
2022-09-05 13:29:11 +08:00
func ( t AlterType ) String ( ) string {
switch t {
case ADD :
return "ADD"
case DELETE :
return "DELETE"
case MODIFY :
return "MODIFY"
}
return ""
}
2023-07-06 18:20:26 +08:00
type BinlogsIncrement struct {
2023-07-19 15:28:57 +08:00
Segment * datapb . SegmentInfo
2023-07-06 18:20:26 +08:00
}
2023-01-06 14:33:36 +08:00
//go:generate mockery --name=DataCoordCatalog --with-expecter
2022-08-20 10:24:51 +08:00
type DataCoordCatalog interface {
ListSegments ( ctx context . Context ) ( [ ] * datapb . SegmentInfo , error )
AddSegment ( ctx context . Context , segment * datapb . SegmentInfo ) error
2022-10-27 15:15:32 +08:00
// TODO Remove this later, we should update flush segments info for each segment separately, so far we still need transaction
2023-07-06 18:20:26 +08:00
AlterSegments ( ctx context . Context , newSegments [ ] * datapb . SegmentInfo , binlogs ... BinlogsIncrement ) error
2022-08-25 16:48:53 +08:00
SaveDroppedSegmentsInBatch ( ctx context . Context , segments [ ] * datapb . SegmentInfo ) error
2022-08-20 10:24:51 +08:00
DropSegment ( ctx context . Context , segment * datapb . SegmentInfo ) error
2022-11-10 22:13:04 +08:00
2023-03-09 14:13:52 +08:00
MarkChannelAdded ( ctx context . Context , channel string ) error
2022-08-20 10:24:51 +08:00
MarkChannelDeleted ( ctx context . Context , channel string ) error
2023-03-09 14:13:52 +08:00
ShouldDropChannel ( ctx context . Context , channel string ) bool
ChannelExists ( ctx context . Context , channel string ) bool
2022-08-20 10:24:51 +08:00
DropChannel ( ctx context . Context , channel string ) error
2022-09-23 10:50:51 +08:00
2023-03-04 23:21:50 +08:00
ListChannelCheckpoint ( ctx context . Context ) ( map [ string ] * msgpb . MsgPosition , error )
SaveChannelCheckpoint ( ctx context . Context , vChannel string , pos * msgpb . MsgPosition ) error
2024-03-07 20:39:02 +08:00
SaveChannelCheckpoints ( ctx context . Context , positions [ ] * msgpb . MsgPosition ) error
2022-11-10 22:13:04 +08:00
DropChannelCheckpoint ( ctx context . Context , vChannel string ) error
2023-01-04 19:37:36 +08:00
CreateIndex ( ctx context . Context , index * model . Index ) error
ListIndexes ( ctx context . Context ) ( [ ] * model . Index , error )
AlterIndexes ( ctx context . Context , newIndexes [ ] * model . Index ) error
DropIndex ( ctx context . Context , collID , dropIdxID typeutil . UniqueID ) error
CreateSegmentIndex ( ctx context . Context , segIdx * model . SegmentIndex ) error
ListSegmentIndexes ( ctx context . Context ) ( [ ] * model . SegmentIndex , error )
AlterSegmentIndexes ( ctx context . Context , newSegIdxes [ ] * model . SegmentIndex ) error
DropSegmentIndex ( ctx context . Context , collID , partID , segID , buildID typeutil . UniqueID ) error
2023-01-12 09:55:42 +08:00
2024-03-01 18:31:02 +08:00
SaveImportJob ( job * datapb . ImportJob ) error
ListImportJobs ( ) ( [ ] * datapb . ImportJob , error )
DropImportJob ( jobID int64 ) error
SavePreImportTask ( task * datapb . PreImportTask ) error
ListPreImportTasks ( ) ( [ ] * datapb . PreImportTask , error )
DropPreImportTask ( taskID int64 ) error
SaveImportTask ( task * datapb . ImportTaskV2 ) error
ListImportTasks ( ) ( [ ] * datapb . ImportTaskV2 , error )
DropImportTask ( taskID int64 ) error
2023-01-12 09:55:42 +08:00
GcConfirm ( ctx context . Context , collectionID , partitionID typeutil . UniqueID ) bool
2022-08-20 10:24:51 +08:00
}
2022-08-25 15:48:54 +08:00
2022-09-15 18:48:32 +08:00
type QueryCoordCatalog interface {
2023-03-20 14:55:57 +08:00
SaveCollection ( collection * querypb . CollectionLoadInfo , partitions ... * querypb . PartitionLoadInfo ) error
2022-09-15 18:48:32 +08:00
SavePartition ( info ... * querypb . PartitionLoadInfo ) error
SaveReplica ( replica * querypb . Replica ) error
GetCollections ( ) ( [ ] * querypb . CollectionLoadInfo , error )
GetPartitions ( ) ( map [ int64 ] [ ] * querypb . PartitionLoadInfo , error )
GetReplicas ( ) ( [ ] * querypb . Replica , error )
2023-03-20 14:55:57 +08:00
ReleaseCollection ( collection int64 ) error
2022-09-15 18:48:32 +08:00
ReleasePartition ( collection int64 , partitions ... int64 ) error
ReleaseReplicas ( collectionID int64 ) error
ReleaseReplica ( collection , replica int64 ) error
2023-01-30 10:19:48 +08:00
SaveResourceGroup ( rgs ... * querypb . ResourceGroup ) error
RemoveResourceGroup ( rgName string ) error
GetResourceGroups ( ) ( [ ] * querypb . ResourceGroup , error )
2024-03-15 14:19:03 +08:00
2024-03-27 00:09:08 +08:00
SaveCollectionTargets ( target ... * querypb . CollectionTarget ) error
2024-03-15 14:19:03 +08:00
RemoveCollectionTarget ( collectionID int64 ) error
GetCollectionTargets ( ) ( map [ int64 ] * querypb . CollectionTarget , error )
2022-09-15 18:48:32 +08:00
}