Skip to content

Commit

Permalink
Guard against using LZ4 with old kafka protocol versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rtreffer-sc committed Nov 22, 2016
1 parent fea677b commit 28e948f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ func (c *Config) Validate() error {
return ConfigurationError("Producer.Retry.Backoff must be >= 0")
}

if c.Producer.Compression == CompressionLZ4 && (c.Version == V0_8_2_0 || c.Version == V0_8_2_1 ||

This comment has been minimized.

Copy link
@eapache

eapache Nov 22, 2016

Contributor

you should be able to use c.Version.IsAtLeast(V0_10_0_0) to simplify the version check

c.Version == V0_8_2_2 || c.Version == V0_9_0_0 ||
c.Version == V0_9_0_1) {
return ConfigurationError("lz4 compression requires Version >= V0_10_0_0")
}

// validate the Consumer values
switch {
case c.Consumer.Fetch.Min <= 0:
Expand Down
12 changes: 12 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ func TestEmptyClientIDConfigValidates(t *testing.T) {
}
}

func TestLZ4ConfigValidation(t *testing.T) {
config := NewConfig()
config.Producer.Compression = CompressionLZ4
if err := config.Validate(); string(err.(ConfigurationError)) != "lz4 compression requires Version >= V0_10_0_0" {
t.Error("Expected invalid lz4/kakfa version error, got ", err)
}
config.Version = V0_10_0_0
if err := config.Validate(); err != nil {
t.Error("Expected lz4 to work, got ", err)
}
}

// This example shows how to integrate with an existing registry as well as publishing metrics
// on the standard output
func ExampleConfig_metrics() {
Expand Down

0 comments on commit 28e948f

Please sign in to comment.