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

fix: influx gzip writes #2479

Merged
merged 1 commit into from
Feb 12, 2021
Merged

fix: influx gzip writes #2479

merged 1 commit into from
Feb 12, 2021

Conversation

docmerlin
Copy link
Contributor

This is a fix for a data race in kapacitor 1.5.8 where large batch writes were not completely writing to influxdb.

@@ -571,6 +568,33 @@ func (p Point) Bytes(precision string) []byte {
return bytes
}

func (p Point) BytesWithLineFeed(precision string) []byte {
key := imodels.MakeKey([]byte(p.Name), imodels.NewTags(p.Tags))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy of the func (p Point) Bytes method, only it adds a line feed to the end of the line to avoid the allocation of doing it afterwards.

@@ -196,6 +197,59 @@ func TestClient_Write(t *testing.T) {
}
}

func TestClient_WriteLarge(t *testing.T) {
expected := &bytes.Buffer{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This writes a million points to an httptest server and checks to make sure that it is delivered properly. The million points are gzipped.

@@ -78,5 +78,10 @@ func TestPoint_Bytes(t *testing.T) {
t.Errorf("%s: Bytes() mismatch:\n actual: %v\n exp: %v",
test.name, got, exp)
}
if got, exp := string(p.BytesWithLineFeed(test.precision)), test.exp+"\n"; got != exp {
t.Errorf("%s: Bytes() mismatch:\n actual: %v\n exp: %v",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to test not just the Point.Bytes() but also Point.BytesWithLineFeed()

return err
}

if err := b.WriteByte('\n'); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very surprising to me that this would be allocating - what is the allocation caused by?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That line doesn't allocate, but the gzip writer doesn't have a WriteByte, it only has Write, which means allocating a single element byte slice.

Copy link
Contributor

@davidby-influx davidby-influx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. I prefer the synchronous copy to the go proc pattern unless you are using a channel to handle the EOF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants