-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
refactor ConsumerMetadataReq/Resp -> FindCoordinatorReq/Resp #1010
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
refactor ConsumerMetadataRequest/Response to FindCoordinatorRequest/R…
…esponse
- Loading branch information
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
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,61 @@ | ||
package sarama | ||
|
||
type CoordinatorType int8 | ||
|
||
const ( | ||
CoordinatorGroup CoordinatorType = 0 | ||
CoordinatorTransaction CoordinatorType = 1 | ||
) | ||
|
||
type FindCoordinatorRequest struct { | ||
Version int16 | ||
CoordinatorKey string | ||
CoordinatorType CoordinatorType | ||
} | ||
|
||
func (f *FindCoordinatorRequest) encode(pe packetEncoder) error { | ||
if err := pe.putString(f.CoordinatorKey); err != nil { | ||
return err | ||
} | ||
|
||
if f.Version >= 1 { | ||
pe.putInt8(int8(f.CoordinatorType)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorRequest) decode(pd packetDecoder, version int16) (err error) { | ||
if f.CoordinatorKey, err = pd.getString(); err != nil { | ||
return err | ||
} | ||
|
||
if version >= 1 { | ||
f.Version = version | ||
coordinatorType, err := pd.getInt8() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.CoordinatorType = CoordinatorType(coordinatorType) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorRequest) key() int16 { | ||
return 10 | ||
} | ||
|
||
func (f *FindCoordinatorRequest) version() int16 { | ||
return f.Version | ||
} | ||
|
||
func (f *FindCoordinatorRequest) requiredVersion() KafkaVersion { | ||
switch f.Version { | ||
case 1: | ||
return V0_11_0_0 | ||
default: | ||
return V0_8_2_0 | ||
} | ||
} |
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,33 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
findCoordinatorRequestConsumerGroup = []byte{ | ||
0, 5, 'g', 'r', 'o', 'u', 'p', | ||
0, | ||
} | ||
|
||
findCoordinatorRequestTransaction = []byte{ | ||
0, 13, 't', 'r', 'a', 'n', 's', 'a', 'c', 't', 'i', 'o', 'n', 'i', 'd', | ||
1, | ||
} | ||
) | ||
|
||
func TestFindCoordinatorRequest(t *testing.T) { | ||
req := &FindCoordinatorRequest{ | ||
Version: 1, | ||
CoordinatorKey: "group", | ||
CoordinatorType: CoordinatorGroup, | ||
} | ||
|
||
testRequest(t, "version 1 - group", req, findCoordinatorRequestConsumerGroup) | ||
|
||
req = &FindCoordinatorRequest{ | ||
Version: 1, | ||
CoordinatorKey: "transactionid", | ||
CoordinatorType: CoordinatorTransaction, | ||
} | ||
|
||
testRequest(t, "version 1 - transaction", req, findCoordinatorRequestTransaction) | ||
} |
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,121 @@ | ||
package sarama | ||
|
||
import ( | ||
"net" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type FindCoordinatorResponse struct { | ||
Version int16 | ||
ThrottleTime time.Duration | ||
Err KError | ||
ErrMsg *string | ||
Coordinator *Broker | ||
CoordinatorID int32 // deprecated: use Coordinator.ID() | ||
CoordinatorHost string // deprecated: use Coordinator.Addr() | ||
CoordinatorPort int32 // deprecated: use Coordinator.Addr() | ||
} | ||
|
||
func (f *FindCoordinatorResponse) decode(pd packetDecoder, version int16) (err error) { | ||
if version >= 1 { | ||
f.Version = version | ||
|
||
throttleTime, err := pd.getInt32() | ||
if err != nil { | ||
return err | ||
} | ||
f.ThrottleTime = time.Duration(throttleTime) * time.Millisecond | ||
} | ||
|
||
tmp, err := pd.getInt16() | ||
if err != nil { | ||
return err | ||
} | ||
f.Err = KError(tmp) | ||
|
||
if version >= 1 { | ||
if f.ErrMsg, err = pd.getNullableString(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
coordinator := new(Broker) | ||
if err := coordinator.decode(pd); err != nil { | ||
return err | ||
} | ||
if coordinator.addr == ":0" { | ||
return nil | ||
} | ||
f.Coordinator = coordinator | ||
|
||
// this can all go away in 2.0, but we have to fill in deprecated fields to maintain | ||
// backwards compatibility | ||
host, portstr, err := net.SplitHostPort(f.Coordinator.Addr()) | ||
if err != nil { | ||
return err | ||
} | ||
port, err := strconv.ParseInt(portstr, 10, 32) | ||
if err != nil { | ||
return err | ||
} | ||
f.CoordinatorID = f.Coordinator.ID() | ||
f.CoordinatorHost = host | ||
f.CoordinatorPort = int32(port) | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorResponse) encode(pe packetEncoder) error { | ||
if f.Version >= 1 { | ||
pe.putInt32(int32(f.ThrottleTime / time.Millisecond)) | ||
} | ||
|
||
pe.putInt16(int16(f.Err)) | ||
|
||
if f.Version >= 1 { | ||
if err := pe.putNullableString(f.ErrMsg); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if f.Coordinator != nil { | ||
host, portstr, err := net.SplitHostPort(f.Coordinator.Addr()) | ||
if err != nil { | ||
return err | ||
} | ||
port, err := strconv.ParseInt(portstr, 10, 32) | ||
if err != nil { | ||
return err | ||
} | ||
pe.putInt32(f.Coordinator.ID()) | ||
if err := pe.putString(host); err != nil { | ||
return err | ||
} | ||
pe.putInt32(int32(port)) | ||
return nil | ||
} | ||
pe.putInt32(f.CoordinatorID) | ||
if err := pe.putString(f.CoordinatorHost); err != nil { | ||
return err | ||
} | ||
pe.putInt32(f.CoordinatorPort) | ||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorResponse) key() int16 { | ||
return 10 | ||
} | ||
|
||
func (f *FindCoordinatorResponse) version() int16 { | ||
return f.Version | ||
} | ||
|
||
func (f *FindCoordinatorResponse) requiredVersion() KafkaVersion { | ||
switch f.Version { | ||
case 1: | ||
return V0_11_0_0 | ||
default: | ||
return V0_8_2_0 | ||
} | ||
} |
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.
Can we take this opportunity to remove these, since this is technically a new struct?
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.
Good call. Done.