forked from IBM/sarama
-
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.
Merge pull request IBM#2006 from faillefer/fix-1912-delete-offsets
Add support for DeleteOffsets operation
- Loading branch information
Showing
12 changed files
with
550 additions
and
0 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
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,92 @@ | ||
package sarama | ||
|
||
type DeleteOffsetsRequest struct { | ||
Group string | ||
partitions map[string][]int32 | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) encode(pe packetEncoder) (err error) { | ||
err = pe.putString(r.Group) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if r.partitions == nil { | ||
pe.putInt32(0) | ||
} else { | ||
if err = pe.putArrayLength(len(r.partitions)); err != nil { | ||
return err | ||
} | ||
} | ||
for topic, partitions := range r.partitions { | ||
err = pe.putString(topic) | ||
if err != nil { | ||
return err | ||
} | ||
err = pe.putInt32Array(partitions) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) decode(pd packetDecoder, version int16) (err error) { | ||
r.Group, err = pd.getString() | ||
if err != nil { | ||
return err | ||
} | ||
var partitionCount int | ||
|
||
partitionCount, err = pd.getArrayLength() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if (partitionCount == 0 && version < 2) || partitionCount < 0 { | ||
return nil | ||
} | ||
|
||
r.partitions = make(map[string][]int32, partitionCount) | ||
for i := 0; i < partitionCount; i++ { | ||
var topic string | ||
topic, err = pd.getString() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var partitions []int32 | ||
partitions, err = pd.getInt32Array() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
r.partitions[topic] = partitions | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) key() int16 { | ||
return 47 | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) version() int16 { | ||
return 0 | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) headerVersion() int16 { | ||
return 1 | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) requiredVersion() KafkaVersion { | ||
return V2_4_0_0 | ||
} | ||
|
||
func (r *DeleteOffsetsRequest) AddPartition(topic string, partitionID int32) { | ||
if r.partitions == nil { | ||
r.partitions = make(map[string][]int32) | ||
} | ||
|
||
r.partitions[topic] = append(r.partitions[topic], partitionID) | ||
} |
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 sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
emptyDeleteOffsetsRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', // group name: foo | ||
0, 0, 0, 0, // 0 partition | ||
} | ||
|
||
doubleDeleteOffsetsRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', // group name: foo | ||
0, 0, 0, 1, // 1 topic | ||
0, 3, 'b', 'a', 'r', // topic name: bar | ||
0, 0, 0, 2, // 2 partitions | ||
0, 0, 0, 6, // partition 6 | ||
0, 0, 0, 7, // partition 7 | ||
} | ||
|
||
tripleDeleteOffsetsRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', // group name: foo | ||
0, 0, 0, 2, // 2 topics | ||
0, 3, 'b', 'a', 'r', // topic name: bar | ||
0, 0, 0, 2, // 2 partitions | ||
0, 0, 0, 6, // partition 6 | ||
0, 0, 0, 7, // partition 7 | ||
0, 3, 'b', 'a', 'z', // topic name: baz | ||
0, 0, 0, 1, // 1 partition | ||
0, 0, 0, 0, // partition 0 | ||
} | ||
) | ||
|
||
func TestDeleteOffsetsRequest(t *testing.T) { | ||
var request *DeleteOffsetsRequest | ||
|
||
request = new(DeleteOffsetsRequest) | ||
request.Group = "foo" | ||
|
||
testRequest(t, "no offset", request, emptyDeleteOffsetsRequest) | ||
|
||
request = new(DeleteOffsetsRequest) | ||
request.Group = "foo" | ||
request.AddPartition("bar", 6) | ||
request.AddPartition("bar", 7) | ||
testRequest(t, "two offsets on one topic", request, doubleDeleteOffsetsRequest) | ||
|
||
request = new(DeleteOffsetsRequest) | ||
request.Group = "foo" | ||
request.AddPartition("bar", 6) | ||
request.AddPartition("bar", 7) | ||
request.AddPartition("baz", 0) | ||
testRequest(t, "three offsets on two topics", request, tripleDeleteOffsetsRequest) | ||
} |
Oops, something went wrong.