|
| 1 | +// Copyright 2025 The LevelDB-Go and Pebble Authors. All rights reserved. Use |
| 2 | +// of this source code is governed by a BSD-style license that can be found in |
| 3 | +// the LICENSE file. |
| 4 | + |
1 | 5 | package block
|
2 | 6 |
|
3 | 7 | import (
|
4 |
| - "fmt" |
5 |
| - "iter" |
6 | 8 | "math/rand"
|
7 |
| - "strings" |
8 | 9 |
|
9 | 10 | "github.com/cockroachdb/pebble/internal/compression"
|
10 | 11 | "github.com/cockroachdb/pebble/sstable/block/blockkind"
|
@@ -108,76 +109,6 @@ func (c *Compressor) Stats() *CompressionStats {
|
108 | 109 | return &c.stats
|
109 | 110 | }
|
110 | 111 |
|
111 |
| -// CompressionStats collects compression statistics for a single file - the |
112 |
| -// total compressed and uncompressed sizes for each distinct compression.Setting |
113 |
| -// used. |
114 |
| -type CompressionStats struct { |
115 |
| - n int |
116 |
| - // Compression profiles have three settings (data, value, other) and |
117 |
| - // NoCompression can also be used for data that didn't compress. |
118 |
| - buf [4]CompressionStatsForSetting |
119 |
| -} |
120 |
| - |
121 |
| -type CompressionStatsForSetting struct { |
122 |
| - Setting compression.Setting |
123 |
| - UncompressedBytes uint64 |
124 |
| - CompressedBytes uint64 |
125 |
| -} |
126 |
| - |
127 |
| -// add updates the stats to reflect a block that was compressed with the given setting. |
128 |
| -func (c *CompressionStats) add( |
129 |
| - setting compression.Setting, sizeUncompressed, sizeCompressed uint64, |
130 |
| -) { |
131 |
| - for i := 0; i < c.n; i++ { |
132 |
| - if c.buf[i].Setting == setting { |
133 |
| - c.buf[i].UncompressedBytes += sizeUncompressed |
134 |
| - c.buf[i].CompressedBytes += sizeCompressed |
135 |
| - return |
136 |
| - } |
137 |
| - } |
138 |
| - if c.n >= len(c.buf)-1 { |
139 |
| - panic("too many compression settings") |
140 |
| - } |
141 |
| - c.buf[c.n] = CompressionStatsForSetting{ |
142 |
| - Setting: setting, |
143 |
| - UncompressedBytes: sizeUncompressed, |
144 |
| - CompressedBytes: sizeCompressed, |
145 |
| - } |
146 |
| - c.n++ |
147 |
| -} |
148 |
| - |
149 |
| -// MergeWith updates the receiver stats to include the other stats. |
150 |
| -func (c *CompressionStats) MergeWith(other *CompressionStats) { |
151 |
| - for i := 0; i < other.n; i++ { |
152 |
| - c.add(other.buf[i].Setting, other.buf[i].UncompressedBytes, other.buf[i].CompressedBytes) |
153 |
| - } |
154 |
| -} |
155 |
| - |
156 |
| -// All returns an iterator over the collected stats, in arbitrary order. |
157 |
| -func (c CompressionStats) All() iter.Seq[CompressionStatsForSetting] { |
158 |
| - return func(yield func(cs CompressionStatsForSetting) bool) { |
159 |
| - for i := 0; i < c.n; i++ { |
160 |
| - if !yield(c.buf[i]) { |
161 |
| - return |
162 |
| - } |
163 |
| - } |
164 |
| - } |
165 |
| -} |
166 |
| - |
167 |
| -// String returns a string representation of the stats, in the format: |
168 |
| -// "<setting1>:<compressed1>/<uncompressed1>,<setting2>:<compressed2>/<uncompressed2>,..." |
169 |
| -func (c CompressionStats) String() string { |
170 |
| - var buf strings.Builder |
171 |
| - buf.Grow(c.n * 64) |
172 |
| - for i := 0; i < c.n; i++ { |
173 |
| - if i > 0 { |
174 |
| - buf.WriteString(",") |
175 |
| - } |
176 |
| - fmt.Fprintf(&buf, "%s:%d/%d", c.buf[i].Setting.String(), c.buf[i].CompressedBytes, c.buf[i].UncompressedBytes) |
177 |
| - } |
178 |
| - return buf.String() |
179 |
| -} |
180 |
| - |
181 | 112 | type Decompressor = compression.Decompressor
|
182 | 113 |
|
183 | 114 | func GetDecompressor(c CompressionIndicator) Decompressor {
|
|
0 commit comments