Skip to content

Commit 91a1c46

Browse files
committed
fix race condition in lz4_raw compression
1 parent 9ddb178 commit 91a1c46

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

compress/lz4_raw.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
func init() {
12-
lz4hc := lz4.CompressorHC{
13-
Level: lz4.CompressionLevel(9),
14-
}
1512
compressors[parquet.CompressionCodec_LZ4_RAW] = &Compressor{
1613
Compress: func(buf []byte) []byte {
14+
lz4hc := lz4.CompressorHC{
15+
Level: lz4.CompressionLevel(9),
16+
}
1717
res := make([]byte, lz4.CompressBlockBound(len(buf)))
1818
count, _ := lz4hc.CompressBlock(buf, res)
1919
return res[:count]

compress/lz4_raw_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package compress
22

33
import (
44
"bytes"
5+
"sync"
56
"testing"
67

78
"github.com/xitongsys/parquet-go/parquet"
@@ -15,10 +16,18 @@ func TestLz4RawCompress(t *testing.T) {
1516
}
1617

1718
// compression
18-
output := lz4RawCompressor.Compress(input)
19-
if !bytes.Equal(compressed, output) {
20-
t.Fatalf("expected output %s but was %s", string(compressed), string(output))
19+
var wg sync.WaitGroup
20+
for i := 0; i < 10; i++ {
21+
go func() {
22+
wg.Add(1)
23+
defer wg.Done()
24+
output := lz4RawCompressor.Compress(input)
25+
if !bytes.Equal(compressed, output) {
26+
t.Fatalf("expected output %s but was %s", string(compressed), string(output))
27+
}
28+
}()
2129
}
30+
wg.Wait()
2231

2332
// uncompression
2433
output, err := lz4RawCompressor.Uncompress(compressed)

0 commit comments

Comments
 (0)