@@ -29,13 +29,20 @@ type CompressionProfile struct {
2929 //
3030 // Note that MinLZ is only supported with table formats v6+. Older formats
3131 // fall back to Snappy.
32- DataBlocks compression. Setting
33- ValueBlocks compression. Setting
32+ DataBlocks CompressionSetting
33+ ValueBlocks CompressionSetting
3434 OtherBlocks compression.Setting
3535
3636 // Blocks that are reduced by less than this percentage are stored
3737 // uncompressed.
3838 MinReductionPercent uint8
39+ }
40+
41+ // CompressionSetting is a compression setting for value or data blocks. It
42+ // contains a compression.Setting and an optional percentage which enables
43+ // adaptive compression.
44+ type CompressionSetting struct {
45+ compression.Setting
3946
4047 // AdaptiveReductionCutoffPercent (when set to a non-zero value) enables
4148 // adaptive compressors for data and value blocks which fall back to the
@@ -45,6 +52,20 @@ type CompressionProfile struct {
4552 AdaptiveReductionCutoffPercent uint8
4653}
4754
55+ // SimpleCompressionSetting returns a CompressionSetting that always uses the
56+ // given compression.
57+ func SimpleCompressionSetting (s compression.Setting ) CompressionSetting {
58+ return CompressionSetting {Setting : s }
59+ }
60+
61+ // AdaptiveCompressionSetting returns a CompressionSetting that adaptively
62+ // chooses between the enclosed setting or the "other blocks" setting.
63+ func AdaptiveCompressionSetting (
64+ s compression.Setting , reductionCutoffPercent uint8 ,
65+ ) CompressionSetting {
66+ return CompressionSetting {Setting : s , AdaptiveReductionCutoffPercent : reductionCutoffPercent }
67+ }
68+
4869// UsesMinLZ returns true if the profile uses the MinLZ compression algorithm
4970// (for any block kind).
5071func (p * CompressionProfile ) UsesMinLZ () bool {
@@ -68,33 +89,32 @@ var (
6889 // FastCompression automatically chooses between Snappy/MinLZ1 and Zstd1 for
6990 // sstable and blob file value blocks.
7091 FastCompression = registerCompressionProfile (CompressionProfile {
71- Name : "Fast" ,
72- DataBlocks : fastestCompression ,
73- ValueBlocks : compression .ZstdLevel1 ,
74- OtherBlocks : fastestCompression ,
75- MinReductionPercent : 10 ,
76- AdaptiveReductionCutoffPercent : 30 ,
92+ Name : "Fast" ,
93+ DataBlocks : SimpleCompressionSetting (fastestCompression ),
94+ ValueBlocks : AdaptiveCompressionSetting (compression .ZstdLevel1 , 30 ),
95+ OtherBlocks : fastestCompression ,
96+ MinReductionPercent : 10 ,
7797 })
7898
7999 // BalancedCompression automatically chooses between Snappy/MinLZ1 and Zstd1
80100 // for data and value blocks.
81101 BalancedCompression = registerCompressionProfile (CompressionProfile {
82- Name : "Balanced" ,
83- DataBlocks : compression .ZstdLevel1 ,
84- ValueBlocks : compression .ZstdLevel1 ,
85- OtherBlocks : fastestCompression ,
86- MinReductionPercent : 5 ,
87- AdaptiveReductionCutoffPercent : 15 ,
102+ Name : "Balanced" ,
103+ DataBlocks : AdaptiveCompressionSetting (compression .ZstdLevel1 , 30 ),
104+ ValueBlocks : AdaptiveCompressionSetting (compression .ZstdLevel1 , 15 ),
105+ OtherBlocks : fastestCompression ,
106+ MinReductionPercent : 5 ,
88107 })
89108
90109 // GoodCompression uses Zstd1 for data and value blocks.
110+ //
111+ // Note: in practice, we have observed very little size benefit to using
112+ // higher zstd levels like ZstdLevel3 (while paying a significant compression
113+ // performance cost).
91114 GoodCompression = registerCompressionProfile (CompressionProfile {
92- Name : "Good" ,
93- // In practice, we have observed very little size benefit to using higher
94- // zstd levels like ZstdLevel3 while paying a significant compression
95- // performance cost.
96- DataBlocks : compression .ZstdLevel1 ,
97- ValueBlocks : compression .ZstdLevel1 ,
115+ Name : "Good" ,
116+ DataBlocks : SimpleCompressionSetting (compression .ZstdLevel1 ),
117+ ValueBlocks : SimpleCompressionSetting (compression .ZstdLevel1 ),
98118 OtherBlocks : fastestCompression ,
99119 MinReductionPercent : 3 ,
100120 })
@@ -119,8 +139,8 @@ var fastestCompression = func() compression.Setting {
119139func simpleCompressionProfile (name string , setting compression.Setting ) * CompressionProfile {
120140 return registerCompressionProfile (CompressionProfile {
121141 Name : name ,
122- DataBlocks : setting ,
123- ValueBlocks : setting ,
142+ DataBlocks : SimpleCompressionSetting ( setting ) ,
143+ ValueBlocks : SimpleCompressionSetting ( setting ) ,
124144 OtherBlocks : setting ,
125145 MinReductionPercent : 12 ,
126146 })
0 commit comments