Skip to content

Commit

Permalink
Fix rootcoord failure to start when reaching the limit of role num (#…
Browse files Browse the repository at this point in the history
…27361)

Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG authored Sep 27, 2023
1 parent dedb90f commit 9fb4c27
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions internal/rootcoord/meta_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,18 @@ func (mt *MetaTable) CreateRole(tenant string, entity *milvuspb.RoleEntity) erro

results, err := mt.catalog.ListRole(mt.ctx, tenant, nil, false)
if err != nil {
log.Error("fail to list roles", zap.Error(err))
log.Warn("fail to list roles", zap.Error(err))
return err
}
for _, result := range results {
if result.GetRole().GetName() == entity.Name {
log.Info("role already exists", zap.String("role", entity.Name))
return common.NewIgnorableError(errors.Newf("role [%s] already exists", entity))
}
}
if len(results) >= Params.ProxyCfg.MaxRoleNum.GetAsInt() {
errMsg := "unable to create role because the number of roles has reached the limit"
log.Error(errMsg, zap.Int("max_role_num", Params.ProxyCfg.MaxRoleNum.GetAsInt()))
log.Warn(errMsg, zap.Int("max_role_num", Params.ProxyCfg.MaxRoleNum.GetAsInt()))
return errors.New(errMsg)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/rootcoord/meta_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
pb "github.com/milvus-io/milvus/internal/proto/etcdpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
mocktso "github.com/milvus-io/milvus/internal/tso/mocks"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/util"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
Expand Down Expand Up @@ -102,6 +103,11 @@ func TestRbacCreateRole(t *testing.T) {
assert.Error(t, err)
})
}
t.Run("role has existed", func(t *testing.T) {
err := mt.CreateRole(util.DefaultTenant, &milvuspb.RoleEntity{Name: "role1"})
assert.Error(t, err)
assert.True(t, common.IsIgnorableError(err))
})

{
mockCata := mocks.NewRootCoordCatalog(t)
Expand Down
2 changes: 1 addition & 1 deletion internal/rootcoord/root_coord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ func TestCore_Import(t *testing.T) {
meta.GetPartitionByNameFunc = func(collID UniqueID, partitionName string, ts Timestamp) (UniqueID, error) {
return common.InvalidPartitionID, fmt.Errorf("partition ID not found for partition name '%s'", partitionName)
}
resp2, err := c.Import(ctx, &milvuspb.ImportRequest{
resp2, _ := c.Import(ctx, &milvuspb.ImportRequest{
CollectionName: "a-good-name",
PartitionName: "a-bad-name",
Options: []*commonpb.KeyValuePair{
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/funcutil/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func GetPrivilegeExtObj(m proto.GeneratedMessage) (commonpb.PrivilegeExt, error)

extObj, err := proto.GetExtension(md.Options, commonpb.E_PrivilegeExtObj)
if err != nil {
log.Warn("GetExtension fail", zap.Error(err))
log.Info("GetExtension fail", zap.Error(err))
return commonpb.PrivilegeExt{}, err
}
privilegeExt := extObj.(*commonpb.PrivilegeExt)
Expand Down

0 comments on commit 9fb4c27

Please sign in to comment.