-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance: implement balancer at streaming coord #34435
Merged
jaime0815
merged 1 commit into
milvus-io:master
from
chyezh:feat_streaming_service_coord_server
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package streamingcoord | ||
|
||
const ( | ||
MetaPrefix = "streamingcoord-meta" | ||
PChannelMeta = MetaPrefix + "/pchannel-meta" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package streamingcoord | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/golang/protobuf/proto" | ||
|
||
"github.com/milvus-io/milvus/internal/metastore" | ||
"github.com/milvus-io/milvus/internal/proto/streamingpb" | ||
"github.com/milvus-io/milvus/pkg/kv" | ||
) | ||
|
||
// NewCataLog creates a new catalog instance | ||
func NewCataLog(metaKV kv.MetaKv) metastore.StreamingCoordCataLog { | ||
return &catalog{ | ||
metaKV: metaKV, | ||
} | ||
} | ||
|
||
// catalog is a kv based catalog. | ||
type catalog struct { | ||
metaKV kv.MetaKv | ||
} | ||
|
||
// ListPChannels returns all pchannels | ||
func (c *catalog) ListPChannel(ctx context.Context) ([]*streamingpb.PChannelMeta, error) { | ||
keys, values, err := c.metaKV.LoadWithPrefix(PChannelMeta) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
infos := make([]*streamingpb.PChannelMeta, 0, len(values)) | ||
for k, value := range values { | ||
info := &streamingpb.PChannelMeta{} | ||
err = proto.Unmarshal([]byte(value), info) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "unmarshal pchannel %s failed", keys[k]) | ||
} | ||
infos = append(infos, info) | ||
} | ||
return infos, nil | ||
} | ||
|
||
// SavePChannels saves a pchannel | ||
func (c *catalog) SavePChannels(ctx context.Context, infos []*streamingpb.PChannelMeta) error { | ||
kvs := make(map[string]string, len(infos)) | ||
for _, info := range infos { | ||
key := buildPChannelInfoPath(info.GetChannel().GetName()) | ||
v, err := proto.Marshal(info) | ||
if err != nil { | ||
return errors.Wrapf(err, "marshal pchannel %s failed", info.GetChannel().GetName()) | ||
} | ||
kvs[key] = string(v) | ||
} | ||
return c.metaKV.MultiSave(kvs) | ||
} | ||
|
||
// buildPChannelInfoPath builds the path for pchannel info. | ||
func buildPChannelInfoPath(name string) string { | ||
return PChannelMeta + "/" + name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package streamingcoord | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/milvus-io/milvus/internal/proto/streamingpb" | ||
"github.com/milvus-io/milvus/pkg/mocks/mock_kv" | ||
) | ||
|
||
func TestCatalog(t *testing.T) { | ||
kv := mock_kv.NewMockMetaKv(t) | ||
|
||
kvStorage := make(map[string]string) | ||
kv.EXPECT().LoadWithPrefix(mock.Anything).RunAndReturn(func(s string) ([]string, []string, error) { | ||
keys := make([]string, 0, len(kvStorage)) | ||
vals := make([]string, 0, len(kvStorage)) | ||
for k, v := range kvStorage { | ||
keys = append(keys, k) | ||
vals = append(vals, v) | ||
} | ||
return keys, vals, nil | ||
}) | ||
kv.EXPECT().MultiSave(mock.Anything).RunAndReturn(func(kvs map[string]string) error { | ||
for k, v := range kvs { | ||
kvStorage[k] = v | ||
} | ||
return nil | ||
}) | ||
|
||
catalog := NewCataLog(kv) | ||
metas, err := catalog.ListPChannel(context.Background()) | ||
assert.NoError(t, err) | ||
assert.Empty(t, metas) | ||
|
||
err = catalog.SavePChannels(context.Background(), []*streamingpb.PChannelMeta{ | ||
{ | ||
Channel: &streamingpb.PChannelInfo{Name: "test", Term: 1}, | ||
Node: &streamingpb.StreamingNodeInfo{ServerId: 1}, | ||
}, | ||
{ | ||
Channel: &streamingpb.PChannelInfo{Name: "test2", Term: 1}, | ||
Node: &streamingpb.StreamingNodeInfo{ServerId: 1}, | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
|
||
metas, err = catalog.ListPChannel(context.Background()) | ||
assert.NoError(t, err) | ||
assert.Len(t, metas, 2) | ||
|
||
// error path. | ||
kv.EXPECT().LoadWithPrefix(mock.Anything).Unset() | ||
kv.EXPECT().LoadWithPrefix(mock.Anything).Return(nil, nil, errors.New("load error")) | ||
metas, err = catalog.ListPChannel(context.Background()) | ||
assert.Error(t, err) | ||
assert.Nil(t, metas) | ||
|
||
kv.EXPECT().MultiSave(mock.Anything).Unset() | ||
kv.EXPECT().MultiSave(mock.Anything).Return(errors.New("save error")) | ||
assert.Error(t, err) | ||
} |
135 changes: 135 additions & 0 deletions
135
internal/mocks/mock_metastore/mock_StreamingCoordCataLog.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to exceed the maximum txn number of etcd, which requires executing multiple saves with multiple batches. you can refer to SaveByBatch method in datacoord catalog