2022-07-22 10:20:29 +08:00
package metastore
import (
"context"
2022-10-16 20:49:27 +08:00
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
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-11-10 22:13:04 +08:00
"github.com/milvus-io/milvus/internal/proto/internalpb"
2022-09-15 18:48:32 +08:00
"github.com/milvus-io/milvus/internal/proto/querypb"
2022-07-22 10:20:29 +08:00
"github.com/milvus-io/milvus/internal/util/typeutil"
)
2022-09-27 19:18:54 +08:00
//go:generate mockery --name=RootCoordCatalog
2022-08-20 10:24:51 +08:00
type RootCoordCatalog interface {
2022-07-22 10:20:29 +08:00
CreateCollection ( ctx context . Context , collectionInfo * model . Collection , ts typeutil . Timestamp ) error
GetCollectionByID ( ctx context . Context , collectionID typeutil . UniqueID , ts typeutil . Timestamp ) ( * model . Collection , error )
GetCollectionByName ( ctx context . Context , collectionName string , ts typeutil . Timestamp ) ( * model . Collection , error )
ListCollections ( ctx context . Context , ts typeutil . Timestamp ) ( map [ string ] * model . Collection , error )
CollectionExists ( ctx context . Context , collectionID typeutil . UniqueID , ts typeutil . Timestamp ) bool
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
2022-08-10 10:22:38 +08:00
CreatePartition ( ctx context . Context , partition * model . Partition , ts typeutil . Timestamp ) error
DropPartition ( ctx context . Context , collectionID typeutil . UniqueID , partitionID typeutil . UniqueID , ts typeutil . Timestamp ) error
2022-09-05 13:29:11 +08:00
AlterPartition ( ctx context . Context , 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
DropAlias ( ctx context . Context , alias string , ts typeutil . Timestamp ) error
AlterAlias ( ctx context . Context , alias * model . Alias , ts typeutil . Timestamp ) error
ListAliases ( ctx context . Context , 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-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
AlterSegments ( ctx context . Context , newSegments [ ] * datapb . SegmentInfo ) error
2022-08-20 10:24:51 +08:00
// AlterSegmentsAndAddNewSegment for transaction
AlterSegmentsAndAddNewSegment ( ctx context . Context , segments [ ] * datapb . SegmentInfo , newSegment * datapb . SegmentInfo ) error
2022-10-27 15:15:32 +08:00
AlterSegment ( ctx context . Context , newSegment * datapb . SegmentInfo , oldSegment * datapb . SegmentInfo ) 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
RevertAlterSegmentsAndAddNewSegment ( ctx context . Context , segments [ ] * datapb . SegmentInfo , removalSegment * datapb . SegmentInfo ) error
2022-08-20 10:24:51 +08:00
MarkChannelDeleted ( ctx context . Context , channel string ) error
IsChannelDropped ( ctx context . Context , channel string ) bool
DropChannel ( ctx context . Context , channel string ) error
2022-09-23 10:50:51 +08:00
2022-11-10 22:13:04 +08:00
ListChannelCheckpoint ( ctx context . Context ) ( map [ string ] * internalpb . MsgPosition , error )
SaveChannelCheckpoint ( ctx context . Context , vChannel string , pos * internalpb . MsgPosition ) error
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 )
AlterIndex ( ctx context . Context , newIndex * 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 )
AlterSegmentIndex ( ctx context . Context , newSegIndex * 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
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
type IndexCoordCatalog interface {
CreateIndex ( ctx context . Context , index * model . Index ) error
ListIndexes ( ctx context . Context ) ( [ ] * model . Index , error )
AlterIndex ( ctx context . Context , newIndex * 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 )
AlterSegmentIndex ( ctx context . Context , newSegIndex * model . SegmentIndex ) error
AlterSegmentIndexes ( ctx context . Context , newSegIdxes [ ] * model . SegmentIndex ) error
DropSegmentIndex ( ctx context . Context , collID , partID , segID , buildID typeutil . UniqueID ) error
}
2022-09-15 18:48:32 +08:00
type QueryCoordCatalog interface {
SaveCollection ( info * querypb . CollectionLoadInfo ) error
SavePartition ( info ... * querypb . PartitionLoadInfo ) error
SaveReplica ( replica * querypb . Replica ) error
GetCollections ( ) ( [ ] * querypb . CollectionLoadInfo , error )
GetPartitions ( ) ( map [ int64 ] [ ] * querypb . PartitionLoadInfo , error )
GetReplicas ( ) ( [ ] * querypb . Replica , error )
ReleaseCollection ( id int64 ) error
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 )
2022-09-15 18:48:32 +08:00
}