forked from milvus-io/milvus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: enable rmq for streaming (milvus-io#38669)
issue: milvus-io#38399 --------- Signed-off-by: chyezh <[email protected]>
- Loading branch information
1 parent
9cbfd40
commit 487ddb1
Showing
15 changed files
with
207 additions
and
37 deletions.
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
45 changes: 45 additions & 0 deletions
45
internal/mocks/distributed/mock_streaming/mock_WALAccesser.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,53 @@ | ||
package client | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/cockroachdb/errors" | ||
"google.golang.org/protobuf/proto" | ||
|
||
"github.com/milvus-io/milvus/pkg/mq/common" | ||
"github.com/milvus-io/milvus/pkg/mq/mqimpl/rocksmq/server" | ||
"github.com/milvus-io/milvus/pkg/streaming/proto/messagespb" | ||
) | ||
|
||
var ( | ||
// magicPrefix is used to identify the rocksmq legacy message and new message for streaming service. | ||
// Make a low probability of collision with the legacy proto message. | ||
magicPrefix = append([]byte{0xFF, 0xFE, 0xFD, 0xFC}, []byte("STREAM")...) | ||
errNotStreamingServiceMessage = errors.New("not a streaming service message") | ||
) | ||
|
||
// marshalStreamingMessage marshals a streaming message to bytes. | ||
func marshalStreamingMessage(message *common.ProducerMessage) ([]byte, error) { | ||
rmqMessage := &messagespb.RMQMessageLayout{ | ||
Payload: message.Payload, | ||
Properties: message.Properties, | ||
} | ||
payload, err := proto.Marshal(rmqMessage) | ||
if err != nil { | ||
return nil, err | ||
} | ||
finalPayload := make([]byte, len(payload)+len(magicPrefix)) | ||
copy(finalPayload, magicPrefix) | ||
copy(finalPayload[len(magicPrefix):], payload) | ||
return finalPayload, nil | ||
} | ||
|
||
// unmarshalStreamingMessage unmarshals a streaming message from bytes. | ||
func unmarshalStreamingMessage(topic string, msg server.ConsumerMessage) (*RmqMessage, error) { | ||
if !bytes.HasPrefix(msg.Payload, magicPrefix) { | ||
return nil, errNotStreamingServiceMessage | ||
} | ||
|
||
var rmqMessage messagespb.RMQMessageLayout | ||
if err := proto.Unmarshal(msg.Payload[len(magicPrefix):], &rmqMessage); err != nil { | ||
return nil, err | ||
} | ||
return &RmqMessage{ | ||
msgID: msg.MsgID, | ||
payload: rmqMessage.Payload, | ||
properties: rmqMessage.Properties, | ||
topic: topic, | ||
}, nil | ||
} |
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,36 @@ | ||
package client | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/milvus-io/milvus/pkg/mq/common" | ||
"github.com/milvus-io/milvus/pkg/mq/mqimpl/rocksmq/server" | ||
) | ||
|
||
func TestStreaming(t *testing.T) { | ||
payload, err := marshalStreamingMessage(&common.ProducerMessage{ | ||
Payload: []byte("payload"), | ||
Properties: map[string]string{ | ||
"key": "value", | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, payload) | ||
|
||
msg, err := unmarshalStreamingMessage("topic", server.ConsumerMessage{ | ||
MsgID: 1, | ||
Payload: payload, | ||
}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, string(msg.Payload()), "payload") | ||
assert.Equal(t, msg.Properties()["key"], "value") | ||
msg, err = unmarshalStreamingMessage("topic", server.ConsumerMessage{ | ||
MsgID: 1, | ||
Payload: payload[1:], | ||
}) | ||
assert.Error(t, err) | ||
assert.ErrorIs(t, err, errNotStreamingServiceMessage) | ||
assert.Nil(t, msg) | ||
} |
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
Oops, something went wrong.