Skip to content
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

Retain user record partition keys #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ func (a *Aggregator) Count() int {

// Put record using `data` and `partitionKey`. This method is thread-safe.
func (a *Aggregator) Put(data []byte, partitionKey string) {
// For now, all records in the aggregated record will have
// the same partition key.
// later, we will add shard-mapper same as the KPL use.
// see: https://github.com/a8m/kinesis-producer/issues/1
if len(a.pkeys) == 0 {
a.pkeys = []string{partitionKey}
a.nbytes += len([]byte(partitionKey))
}
a.pkeys = append(a.pkeys, partitionKey)
a.nbytes += len([]byte(partitionKey))
keyIndex := uint64(len(a.pkeys) - 1)

a.nbytes++ // protobuf message index and wire type
a.nbytes += partitionKeyIndexSize
a.buf = append(a.buf, &Record{
Data: data,
Expand Down
2 changes: 1 addition & 1 deletion aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestSizeAndCount(t *testing.T) {
for i := 0; i < n; i++ {
a.Put(data, pkey)
}
assert(t, a.Size() == 5*n+5+8*n, "size should equal to the data and the partition-key")
assert(t, a.Size() == n+5*n+5*n+8*n, "size should equal to size of data, partition-keys, partition key indexes, and protobuf wire type")
assert(t, a.Count() == n, "count should be equal to the number of Put calls")
}

Expand Down