Line data Source code
1 : // Copyright 2011 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 :
5 : package pebble
6 :
7 : import (
8 : "bytes"
9 : "fmt"
10 : "io"
11 : "regexp"
12 : "runtime"
13 : "sort"
14 : "strconv"
15 : "strings"
16 : "time"
17 : "unicode"
18 :
19 : "github.com/cockroachdb/crlib/fifo"
20 : "github.com/cockroachdb/errors"
21 : "github.com/cockroachdb/pebble/internal/base"
22 : "github.com/cockroachdb/pebble/internal/cache"
23 : "github.com/cockroachdb/pebble/internal/humanize"
24 : "github.com/cockroachdb/pebble/internal/keyspan"
25 : "github.com/cockroachdb/pebble/internal/manifest"
26 : "github.com/cockroachdb/pebble/internal/testkeys"
27 : "github.com/cockroachdb/pebble/objstorage/objstorageprovider"
28 : "github.com/cockroachdb/pebble/objstorage/remote"
29 : "github.com/cockroachdb/pebble/rangekey"
30 : "github.com/cockroachdb/pebble/sstable"
31 : "github.com/cockroachdb/pebble/sstable/blob"
32 : "github.com/cockroachdb/pebble/sstable/block"
33 : "github.com/cockroachdb/pebble/sstable/colblk"
34 : "github.com/cockroachdb/pebble/vfs"
35 : "github.com/cockroachdb/pebble/wal"
36 : "github.com/cockroachdb/redact"
37 : )
38 :
39 : const (
40 : cacheDefaultSize = 8 << 20 // 8 MB
41 : defaultLevelMultiplier = 10
42 : )
43 :
44 : // Compression exports the base.Compression type.
45 : type Compression = block.Compression
46 :
47 : // Exported Compression constants.
48 : const (
49 : DefaultCompression = block.DefaultCompression
50 : NoCompression = block.NoCompression
51 : SnappyCompression = block.SnappyCompression
52 : ZstdCompression = block.ZstdCompression
53 : // MinLZCompression is only supported with table formats v6+. Older formats
54 : // fall back to snappy.
55 : MinLZCompression = block.MinLZCompression
56 : )
57 :
58 : // FilterType exports the base.FilterType type.
59 : type FilterType = base.FilterType
60 :
61 : // Exported TableFilter constants.
62 : const (
63 : TableFilter = base.TableFilter
64 : )
65 :
66 : // FilterWriter exports the base.FilterWriter type.
67 : type FilterWriter = base.FilterWriter
68 :
69 : // FilterPolicy exports the base.FilterPolicy type.
70 : type FilterPolicy = base.FilterPolicy
71 :
72 : var NoFilterPolicy = base.NoFilterPolicy
73 :
74 : // KeySchema exports the colblk.KeySchema type.
75 : type KeySchema = colblk.KeySchema
76 :
77 : // BlockPropertyCollector exports the sstable.BlockPropertyCollector type.
78 : type BlockPropertyCollector = sstable.BlockPropertyCollector
79 :
80 : // BlockPropertyFilter exports the sstable.BlockPropertyFilter type.
81 : type BlockPropertyFilter = base.BlockPropertyFilter
82 :
83 : // ShortAttributeExtractor exports the base.ShortAttributeExtractor type.
84 : type ShortAttributeExtractor = base.ShortAttributeExtractor
85 :
86 : // UserKeyPrefixBound exports the sstable.UserKeyPrefixBound type.
87 : type UserKeyPrefixBound = sstable.UserKeyPrefixBound
88 :
89 : // IterKeyType configures which types of keys an iterator should surface.
90 : type IterKeyType int8
91 :
92 : const (
93 : // IterKeyTypePointsOnly configures an iterator to iterate over point keys
94 : // only.
95 : IterKeyTypePointsOnly IterKeyType = iota
96 : // IterKeyTypeRangesOnly configures an iterator to iterate over range keys
97 : // only.
98 : IterKeyTypeRangesOnly
99 : // IterKeyTypePointsAndRanges configures an iterator iterate over both point
100 : // keys and range keys simultaneously.
101 : IterKeyTypePointsAndRanges
102 : )
103 :
104 : // String implements fmt.Stringer.
105 1 : func (t IterKeyType) String() string {
106 1 : switch t {
107 1 : case IterKeyTypePointsOnly:
108 1 : return "points-only"
109 1 : case IterKeyTypeRangesOnly:
110 1 : return "ranges-only"
111 1 : case IterKeyTypePointsAndRanges:
112 1 : return "points-and-ranges"
113 0 : default:
114 0 : panic(fmt.Sprintf("unknown key type %d", t))
115 : }
116 : }
117 :
118 : // IterOptions hold the optional per-query parameters for NewIter.
119 : //
120 : // Like Options, a nil *IterOptions is valid and means to use the default
121 : // values.
122 : type IterOptions struct {
123 : // LowerBound specifies the smallest key (inclusive) that the iterator will
124 : // return during iteration. If the iterator is seeked or iterated past this
125 : // boundary the iterator will return Valid()==false. Setting LowerBound
126 : // effectively truncates the key space visible to the iterator.
127 : LowerBound []byte
128 : // UpperBound specifies the largest key (exclusive) that the iterator will
129 : // return during iteration. If the iterator is seeked or iterated past this
130 : // boundary the iterator will return Valid()==false. Setting UpperBound
131 : // effectively truncates the key space visible to the iterator.
132 : UpperBound []byte
133 : // SkipPoint may be used to skip over point keys that don't match an
134 : // arbitrary predicate during iteration. If set, the Iterator invokes
135 : // SkipPoint for keys encountered. If SkipPoint returns true, the iterator
136 : // will skip the key without yielding it to the iterator operation in
137 : // progress.
138 : //
139 : // SkipPoint must be a pure function and always return the same result when
140 : // provided the same arguments. The iterator may call SkipPoint multiple
141 : // times for the same user key.
142 : SkipPoint func(userKey []byte) bool
143 : // PointKeyFilters can be used to avoid scanning tables and blocks in tables
144 : // when iterating over point keys. This slice represents an intersection
145 : // across all filters, i.e., all filters must indicate that the block is
146 : // relevant.
147 : //
148 : // Performance note: When len(PointKeyFilters) > 0, the caller should ensure
149 : // that cap(PointKeyFilters) is at least len(PointKeyFilters)+1. This helps
150 : // avoid allocations in Pebble internal code that mutates the slice.
151 : PointKeyFilters []BlockPropertyFilter
152 : // RangeKeyFilters can be usefd to avoid scanning tables and blocks in tables
153 : // when iterating over range keys. The same requirements that apply to
154 : // PointKeyFilters apply here too.
155 : RangeKeyFilters []BlockPropertyFilter
156 : // KeyTypes configures which types of keys to iterate over: point keys,
157 : // range keys, or both.
158 : KeyTypes IterKeyType
159 : // RangeKeyMasking can be used to enable automatic masking of point keys by
160 : // range keys. Range key masking is only supported during combined range key
161 : // and point key iteration mode (IterKeyTypePointsAndRanges).
162 : RangeKeyMasking RangeKeyMasking
163 :
164 : // OnlyReadGuaranteedDurable is an advanced option that is only supported by
165 : // the Reader implemented by DB. When set to true, only the guaranteed to be
166 : // durable state is visible in the iterator.
167 : // - This definition is made under the assumption that the FS implementation
168 : // is providing a durability guarantee when data is synced.
169 : // - The visible state represents a consistent point in the history of the
170 : // DB.
171 : // - The implementation is free to choose a conservative definition of what
172 : // is guaranteed durable. For simplicity, the current implementation
173 : // ignores memtables. A more sophisticated implementation could track the
174 : // highest seqnum that is synced to the WAL and published and use that as
175 : // the visible seqnum for an iterator. Note that the latter approach is
176 : // not strictly better than the former since we can have DBs that are (a)
177 : // synced more rarely than memtable flushes, (b) have no WAL. (a) is
178 : // likely to be true in a future CockroachDB context where the DB
179 : // containing the state machine may be rarely synced.
180 : // NB: this current implementation relies on the fact that memtables are
181 : // flushed in seqnum order, and any ingested sstables that happen to have a
182 : // lower seqnum than a non-flushed memtable don't have any overlapping keys.
183 : // This is the fundamental level invariant used in other code too, like when
184 : // merging iterators.
185 : //
186 : // Semantically, using this option provides the caller a "snapshot" as of
187 : // the time the most recent memtable was flushed. An alternate interface
188 : // would be to add a NewSnapshot variant. Creating a snapshot is heavier
189 : // weight than creating an iterator, so we have opted to support this
190 : // iterator option.
191 : OnlyReadGuaranteedDurable bool
192 : // UseL6Filters allows the caller to opt into reading filter blocks for L6
193 : // sstables. Helpful if a lot of SeekPrefixGEs are expected in quick
194 : // succession, that are also likely to not yield a single key. Filter blocks in
195 : // L6 can be relatively large, often larger than data blocks, so the benefit of
196 : // loading them in the cache is minimized if the probability of the key
197 : // existing is not low or if we just expect a one-time Seek (where loading the
198 : // data block directly is better).
199 : UseL6Filters bool
200 : // Category is used for categorized iterator stats. This should not be
201 : // changed by calling SetOptions.
202 : Category block.Category
203 :
204 : DebugRangeKeyStack bool
205 :
206 : // Internal options.
207 :
208 : logger Logger
209 : // Layer corresponding to this file. Only passed in if constructed by a
210 : // levelIter.
211 : layer manifest.Layer
212 : // disableLazyCombinedIteration is an internal testing option.
213 : disableLazyCombinedIteration bool
214 : // snapshotForHideObsoletePoints is specified for/by levelIter when opening
215 : // files and is used to decide whether to hide obsolete points. A value of 0
216 : // implies obsolete points should not be hidden.
217 : snapshotForHideObsoletePoints base.SeqNum
218 :
219 : // NB: If adding new Options, you must account for them in iterator
220 : // construction and Iterator.SetOptions.
221 : }
222 :
223 : // GetLowerBound returns the LowerBound or nil if the receiver is nil.
224 1 : func (o *IterOptions) GetLowerBound() []byte {
225 1 : if o == nil {
226 1 : return nil
227 1 : }
228 1 : return o.LowerBound
229 : }
230 :
231 : // GetUpperBound returns the UpperBound or nil if the receiver is nil.
232 1 : func (o *IterOptions) GetUpperBound() []byte {
233 1 : if o == nil {
234 1 : return nil
235 1 : }
236 1 : return o.UpperBound
237 : }
238 :
239 1 : func (o *IterOptions) pointKeys() bool {
240 1 : if o == nil {
241 0 : return true
242 0 : }
243 1 : return o.KeyTypes == IterKeyTypePointsOnly || o.KeyTypes == IterKeyTypePointsAndRanges
244 : }
245 :
246 1 : func (o *IterOptions) rangeKeys() bool {
247 1 : if o == nil {
248 0 : return false
249 0 : }
250 1 : return o.KeyTypes == IterKeyTypeRangesOnly || o.KeyTypes == IterKeyTypePointsAndRanges
251 : }
252 :
253 1 : func (o *IterOptions) getLogger() Logger {
254 1 : if o == nil || o.logger == nil {
255 1 : return DefaultLogger
256 1 : }
257 1 : return o.logger
258 : }
259 :
260 : // SpanIterOptions creates a SpanIterOptions from this IterOptions.
261 1 : func (o *IterOptions) SpanIterOptions() keyspan.SpanIterOptions {
262 1 : if o == nil {
263 1 : return keyspan.SpanIterOptions{}
264 1 : }
265 1 : return keyspan.SpanIterOptions{
266 1 : RangeKeyFilters: o.RangeKeyFilters,
267 1 : }
268 : }
269 :
270 : // scanInternalOptions is similar to IterOptions, meant for use with
271 : // scanInternalIterator.
272 : type scanInternalOptions struct {
273 : IterOptions
274 :
275 : category block.Category
276 :
277 : visitPointKey func(key *InternalKey, value LazyValue, iterInfo IteratorLevel) error
278 : visitRangeDel func(start, end []byte, seqNum SeqNum) error
279 : visitRangeKey func(start, end []byte, keys []rangekey.Key) error
280 : visitSharedFile func(sst *SharedSSTMeta) error
281 : visitExternalFile func(sst *ExternalFile) error
282 :
283 : // includeObsoleteKeys specifies whether keys shadowed by newer internal keys
284 : // are exposed. If false, only one internal key per user key is exposed.
285 : includeObsoleteKeys bool
286 :
287 : // rateLimitFunc is used to limit the amount of bytes read per second.
288 : rateLimitFunc func(key *InternalKey, value LazyValue) error
289 : }
290 :
291 : // RangeKeyMasking configures automatic hiding of point keys by range keys. A
292 : // non-nil Suffix enables range-key masking. When enabled, range keys with
293 : // suffixes ≥ Suffix behave as masks. All point keys that are contained within a
294 : // masking range key's bounds and have suffixes greater than the range key's
295 : // suffix are automatically skipped.
296 : //
297 : // Specifically, when configured with a RangeKeyMasking.Suffix _s_, and there
298 : // exists a range key with suffix _r_ covering a point key with suffix _p_, and
299 : //
300 : // _s_ ≤ _r_ < _p_
301 : //
302 : // then the point key is elided.
303 : //
304 : // Range-key masking may only be used when iterating over both point keys and
305 : // range keys with IterKeyTypePointsAndRanges.
306 : type RangeKeyMasking struct {
307 : // Suffix configures which range keys may mask point keys. Only range keys
308 : // that are defined at suffixes greater than or equal to Suffix will mask
309 : // point keys.
310 : Suffix []byte
311 : // Filter is an optional field that may be used to improve performance of
312 : // range-key masking through a block-property filter defined over key
313 : // suffixes. If non-nil, Filter is called by Pebble to construct a
314 : // block-property filter mask at iterator creation. The filter is used to
315 : // skip whole point-key blocks containing point keys with suffixes greater
316 : // than a covering range-key's suffix.
317 : //
318 : // To use this functionality, the caller must create and configure (through
319 : // Options.BlockPropertyCollectors) a block-property collector that records
320 : // the maxmimum suffix contained within a block. The caller then must write
321 : // and provide a BlockPropertyFilterMask implementation on that same
322 : // property. See the BlockPropertyFilterMask type for more information.
323 : Filter func() BlockPropertyFilterMask
324 : }
325 :
326 : // BlockPropertyFilterMask extends the BlockPropertyFilter interface for use
327 : // with range-key masking. Unlike an ordinary block property filter, a
328 : // BlockPropertyFilterMask's filtering criteria is allowed to change when Pebble
329 : // invokes its SetSuffix method.
330 : //
331 : // When a Pebble iterator steps into a range key's bounds and the range key has
332 : // a suffix greater than or equal to RangeKeyMasking.Suffix, the range key acts
333 : // as a mask. The masking range key hides all point keys that fall within the
334 : // range key's bounds and have suffixes > the range key's suffix. Without a
335 : // filter mask configured, Pebble performs this hiding by stepping through point
336 : // keys and comparing suffixes. If large numbers of point keys are masked, this
337 : // requires Pebble to load, iterate through and discard a large number of
338 : // sstable blocks containing masked point keys.
339 : //
340 : // If a block-property collector and a filter mask are configured, Pebble may
341 : // skip loading some point-key blocks altogether. If a block's keys are known to
342 : // all fall within the bounds of the masking range key and the block was
343 : // annotated by a block-property collector with the maximal suffix, Pebble can
344 : // ask the filter mask to compare the property to the current masking range
345 : // key's suffix. If the mask reports no intersection, the block may be skipped.
346 : //
347 : // If unsuffixed and suffixed keys are written to the database, care must be
348 : // taken to avoid unintentionally masking un-suffixed keys located in the same
349 : // block as suffixed keys. One solution is to interpret unsuffixed keys as
350 : // containing the maximal suffix value, ensuring that blocks containing
351 : // unsuffixed keys are always loaded.
352 : type BlockPropertyFilterMask interface {
353 : BlockPropertyFilter
354 :
355 : // SetSuffix configures the mask with the suffix of a range key. The filter
356 : // should return false from Intersects whenever it's provided with a
357 : // property encoding a block's minimum suffix that's greater (according to
358 : // Compare) than the provided suffix.
359 : SetSuffix(suffix []byte) error
360 : }
361 :
362 : // WriteOptions hold the optional per-query parameters for Set and Delete
363 : // operations.
364 : //
365 : // Like Options, a nil *WriteOptions is valid and means to use the default
366 : // values.
367 : type WriteOptions struct {
368 : // Sync is whether to sync writes through the OS buffer cache and down onto
369 : // the actual disk, if applicable. Setting Sync is required for durability of
370 : // individual write operations but can result in slower writes.
371 : //
372 : // If false, and the process or machine crashes, then a recent write may be
373 : // lost. This is due to the recently written data being buffered inside the
374 : // process running Pebble. This differs from the semantics of a write system
375 : // call in which the data is buffered in the OS buffer cache and would thus
376 : // survive a process crash.
377 : //
378 : // The default value is true.
379 : Sync bool
380 : }
381 :
382 : // Sync specifies the default write options for writes which synchronize to
383 : // disk.
384 : var Sync = &WriteOptions{Sync: true}
385 :
386 : // NoSync specifies the default write options for writes which do not
387 : // synchronize to disk.
388 : var NoSync = &WriteOptions{Sync: false}
389 :
390 : // GetSync returns the Sync value or true if the receiver is nil.
391 1 : func (o *WriteOptions) GetSync() bool {
392 1 : return o == nil || o.Sync
393 1 : }
394 :
395 : // LevelOptions holds the optional per-level parameters.
396 : type LevelOptions struct {
397 : // BlockRestartInterval is the number of keys between restart points
398 : // for delta encoding of keys.
399 : //
400 : // The default value is 16 for L0, and the value from the previous level for
401 : // all other levels.
402 : BlockRestartInterval int
403 :
404 : // BlockSize is the target uncompressed size in bytes of each table block.
405 : //
406 : // The default value is 4096 for L0, and the value from the previous level for
407 : // all other levels.
408 : BlockSize int
409 :
410 : // BlockSizeThreshold finishes a block if the block size is larger than the
411 : // specified percentage of the target block size and adding the next entry
412 : // would cause the block to be larger than the target block size.
413 : //
414 : // The default value is 90 for L0, and the value from the previous level for
415 : // all other levels.
416 : BlockSizeThreshold int
417 :
418 : // Compression defines the per-block compression to use.
419 : //
420 : // The default value is DefaultCompression (which uses Snappy) for L0, or the
421 : // function from the previous level for all other levels.
422 : Compression func() Compression
423 :
424 : // FilterPolicy defines a filter algorithm (such as a Bloom filter) that can
425 : // reduce disk reads for Get calls.
426 : //
427 : // One such implementation is bloom.FilterPolicy(10) from the pebble/bloom
428 : // package.
429 : //
430 : // The default value for L0 is NoFilterPolicy (no filter), and the value from
431 : // the previous level for all other levels.
432 : FilterPolicy FilterPolicy
433 :
434 : // FilterType is a legacy field. The default and only possible value is
435 : // TableFilter.
436 : FilterType FilterType
437 :
438 : // IndexBlockSize is the target uncompressed size in bytes of each index
439 : // block. When the index block size is larger than this target, two-level
440 : // indexes are automatically enabled. Setting this option to a large value
441 : // (such as math.MaxInt32) disables the automatic creation of two-level
442 : // indexes.
443 : //
444 : // The default value is the value of BlockSize for L0, or the value from the
445 : // previous level for all other levels.
446 : IndexBlockSize int
447 :
448 : // The target file size for the level.
449 : //
450 : // The default value is 2MB for L0, and double the value for the previous
451 : // level for all other levels.
452 : TargetFileSize int64
453 : }
454 :
455 : // EnsureL0Defaults ensures that the L0 default values for the options have been
456 : // initialized.
457 1 : func (o *LevelOptions) EnsureL0Defaults() {
458 1 : if o.BlockRestartInterval <= 0 {
459 1 : o.BlockRestartInterval = base.DefaultBlockRestartInterval
460 1 : }
461 1 : if o.BlockSize <= 0 {
462 1 : o.BlockSize = base.DefaultBlockSize
463 1 : } else if o.BlockSize > sstable.MaximumRestartOffset {
464 0 : panic(errors.Errorf("BlockSize %d exceeds MaximumRestartOffset", o.BlockSize))
465 : }
466 1 : if o.BlockSizeThreshold <= 0 {
467 1 : o.BlockSizeThreshold = base.DefaultBlockSizeThreshold
468 1 : }
469 1 : if o.Compression == nil {
470 1 : o.Compression = func() Compression { return DefaultCompression }
471 : }
472 1 : if o.FilterPolicy == nil {
473 1 : o.FilterPolicy = NoFilterPolicy
474 1 : }
475 1 : if o.IndexBlockSize <= 0 {
476 1 : o.IndexBlockSize = o.BlockSize
477 1 : }
478 1 : if o.TargetFileSize <= 0 {
479 1 : o.TargetFileSize = 2 << 20 // 2 MB
480 1 : }
481 : }
482 :
483 : // EnsureL1PlusDefaults ensures that the L1+ default values for the options have
484 : // been initialized. Requires the fully initialized options for the level above.
485 1 : func (o *LevelOptions) EnsureL1PlusDefaults(previousLevel *LevelOptions) {
486 1 : if o.BlockRestartInterval <= 0 {
487 1 : o.BlockRestartInterval = previousLevel.BlockRestartInterval
488 1 : }
489 1 : if o.BlockSize <= 0 {
490 1 : o.BlockSize = previousLevel.BlockSize
491 1 : } else if o.BlockSize > sstable.MaximumRestartOffset {
492 0 : panic(errors.Errorf("BlockSize %d exceeds MaximumRestartOffset", o.BlockSize))
493 : }
494 1 : if o.BlockSizeThreshold <= 0 {
495 1 : o.BlockSizeThreshold = previousLevel.BlockSizeThreshold
496 1 : }
497 1 : if o.Compression == nil {
498 1 : o.Compression = previousLevel.Compression
499 1 : }
500 1 : if o.FilterPolicy == nil {
501 1 : o.FilterPolicy = previousLevel.FilterPolicy
502 1 : }
503 1 : if o.IndexBlockSize <= 0 {
504 1 : o.IndexBlockSize = previousLevel.IndexBlockSize
505 1 : }
506 1 : if o.TargetFileSize <= 0 {
507 1 : o.TargetFileSize = previousLevel.TargetFileSize * 2
508 1 : }
509 : }
510 :
511 : // Options holds the optional parameters for configuring pebble. These options
512 : // apply to the DB at large; per-query options are defined by the IterOptions
513 : // and WriteOptions types.
514 : type Options struct {
515 : // Sync sstables periodically in order to smooth out writes to disk. This
516 : // option does not provide any persistency guarantee, but is used to avoid
517 : // latency spikes if the OS automatically decides to write out a large chunk
518 : // of dirty filesystem buffers. This option only controls SSTable syncs; WAL
519 : // syncs are controlled by WALBytesPerSync.
520 : //
521 : // The default value is 512KB.
522 : BytesPerSync int
523 :
524 : // Cache is used to cache uncompressed blocks from sstables. If it is nil,
525 : // a block cache of CacheSize will be created for each DB.
526 : Cache *cache.Cache
527 : // CacheSize is used when Cache is not set. The default value is 8 MB.
528 : CacheSize int64
529 :
530 : // LoadBlockSema, if set, is used to limit the number of blocks that can be
531 : // loaded (i.e. read from the filesystem) in parallel. Each load acquires one
532 : // unit from the semaphore for the duration of the read.
533 : LoadBlockSema *fifo.Semaphore
534 :
535 : // Cleaner cleans obsolete files.
536 : //
537 : // The default cleaner uses the DeleteCleaner.
538 : Cleaner Cleaner
539 :
540 : // Local contains option that pertain to files stored on the local filesystem.
541 : Local struct {
542 : // ReadaheadConfig is used to retrieve the current readahead mode; it is
543 : // consulted whenever a read handle is initialized.
544 : ReadaheadConfig *ReadaheadConfig
545 :
546 : // TODO(radu): move BytesPerSync, LoadBlockSema, Cleaner here.
547 : }
548 :
549 : // Comparer defines a total ordering over the space of []byte keys: a 'less
550 : // than' relationship. The same comparison algorithm must be used for reads
551 : // and writes over the lifetime of the DB.
552 : //
553 : // The default value uses the same ordering as bytes.Compare.
554 : Comparer *Comparer
555 :
556 : // DebugCheck is invoked, if non-nil, whenever a new version is being
557 : // installed. Typically, this is set to pebble.DebugCheckLevels in tests
558 : // or tools only, to check invariants over all the data in the database.
559 : DebugCheck func(*DB) error
560 :
561 : // Disable the write-ahead log (WAL). Disabling the write-ahead log prohibits
562 : // crash recovery, but can improve performance if crash recovery is not
563 : // needed (e.g. when only temporary state is being stored in the database).
564 : //
565 : // TODO(peter): untested
566 : DisableWAL bool
567 :
568 : // ErrorIfExists causes an error on Open if the database already exists.
569 : // The error can be checked with errors.Is(err, ErrDBAlreadyExists).
570 : //
571 : // The default value is false.
572 : ErrorIfExists bool
573 :
574 : // ErrorIfNotExists causes an error on Open if the database does not already
575 : // exist. The error can be checked with errors.Is(err, ErrDBDoesNotExist).
576 : //
577 : // The default value is false which will cause a database to be created if it
578 : // does not already exist.
579 : ErrorIfNotExists bool
580 :
581 : // ErrorIfNotPristine causes an error on Open if the database already exists
582 : // and any operations have been performed on the database. The error can be
583 : // checked with errors.Is(err, ErrDBNotPristine).
584 : //
585 : // Note that a database that contained keys that were all subsequently deleted
586 : // may or may not trigger the error. Currently, we check if there are any live
587 : // SSTs or log records to replay.
588 : ErrorIfNotPristine bool
589 :
590 : // EventListener provides hooks to listening to significant DB events such as
591 : // flushes, compactions, and table deletion.
592 : EventListener *EventListener
593 :
594 : // Experimental contains experimental options which are off by default.
595 : // These options are temporary and will eventually either be deleted, moved
596 : // out of the experimental group, or made the non-adjustable default. These
597 : // options may change at any time, so do not rely on them.
598 : Experimental struct {
599 : // The threshold of L0 read-amplification at which compaction concurrency
600 : // is enabled (if CompactionDebtConcurrency was not already exceeded).
601 : // Every multiple of this value enables another concurrent
602 : // compaction up to CompactionConcurrencyRange.
603 : L0CompactionConcurrency int
604 :
605 : // CompactionDebtConcurrency controls the threshold of compaction debt
606 : // at which additional compaction concurrency slots are added. For every
607 : // multiple of this value in compaction debt bytes, an additional
608 : // concurrent compaction is added. This works "on top" of
609 : // L0CompactionConcurrency, so the higher of the count of compaction
610 : // concurrency slots as determined by the two options is chosen.
611 : CompactionDebtConcurrency uint64
612 :
613 : // CompactionGarbageFractionForMaxConcurrency is the fraction of garbage
614 : // due to DELs and RANGEDELs that causes MaxConcurrentCompactions to be
615 : // allowed. Concurrent compactions are allowed in a linear manner upto
616 : // this limit being reached. A value <= 0.0 disables adding concurrency
617 : // due to garbage.
618 : CompactionGarbageFractionForMaxConcurrency func() float64
619 :
620 : // IngestSplit, if it returns true, allows for ingest-time splitting of
621 : // existing sstables into two virtual sstables to allow ingestion sstables to
622 : // slot into a lower level than they otherwise would have.
623 : IngestSplit func() bool
624 :
625 : // ReadCompactionRate controls the frequency of read triggered
626 : // compactions by adjusting `AllowedSeeks` in manifest.TableMetadata:
627 : //
628 : // AllowedSeeks = FileSize / ReadCompactionRate
629 : //
630 : // From LevelDB:
631 : // ```
632 : // We arrange to automatically compact this file after
633 : // a certain number of seeks. Let's assume:
634 : // (1) One seek costs 10ms
635 : // (2) Writing or reading 1MB costs 10ms (100MB/s)
636 : // (3) A compaction of 1MB does 25MB of IO:
637 : // 1MB read from this level
638 : // 10-12MB read from next level (boundaries may be misaligned)
639 : // 10-12MB written to next level
640 : // This implies that 25 seeks cost the same as the compaction
641 : // of 1MB of data. I.e., one seek costs approximately the
642 : // same as the compaction of 40KB of data. We are a little
643 : // conservative and allow approximately one seek for every 16KB
644 : // of data before triggering a compaction.
645 : // ```
646 : ReadCompactionRate int64
647 :
648 : // ReadSamplingMultiplier is a multiplier for the readSamplingPeriod in
649 : // iterator.maybeSampleRead() to control the frequency of read sampling
650 : // to trigger a read triggered compaction. A value of -1 prevents sampling
651 : // and disables read triggered compactions. The default is 1 << 4. which
652 : // gets multiplied with a constant of 1 << 16 to yield 1 << 20 (1MB).
653 : ReadSamplingMultiplier int64
654 :
655 : // NumDeletionsThreshold defines the minimum number of point tombstones
656 : // that must be present in a single data block for that block to be
657 : // considered tombstone-dense for the purposes of triggering a
658 : // tombstone density compaction. Data blocks may also be considered
659 : // tombstone-dense if they meet the criteria defined by
660 : // DeletionSizeRatioThreshold below. Tombstone-dense blocks are identified
661 : // when sstables are written, and so this is effectively an option for
662 : // sstable writers. The default value is 100.
663 : NumDeletionsThreshold int
664 :
665 : // DeletionSizeRatioThreshold defines the minimum ratio of the size of
666 : // point tombstones to the size of a data block that must be reached
667 : // for that block to be considered tombstone-dense for the purposes of
668 : // triggering a tombstone density compaction. Data blocks may also be
669 : // considered tombstone-dense if they meet the criteria defined by
670 : // NumDeletionsThreshold above. Tombstone-dense blocks are identified
671 : // when sstables are written, and so this is effectively an option for
672 : // sstable writers. The default value is 0.5.
673 : DeletionSizeRatioThreshold float32
674 :
675 : // TombstoneDenseCompactionThreshold is the minimum percent of data
676 : // blocks in a table that must be tombstone-dense for that table to be
677 : // eligible for a tombstone density compaction. It should be defined as a
678 : // ratio out of 1. The default value is 0.10.
679 : //
680 : // If multiple tables are eligible for a tombstone density compaction, then
681 : // tables with a higher percent of tombstone-dense blocks are still
682 : // prioritized for compaction.
683 : //
684 : // A zero or negative value disables tombstone density compactions.
685 : TombstoneDenseCompactionThreshold float64
686 :
687 : // FileCacheShards is the number of shards per file cache.
688 : // Reducing the value can reduce the number of idle goroutines per DB
689 : // instance which can be useful in scenarios with a lot of DB instances
690 : // and a large number of CPUs, but doing so can lead to higher contention
691 : // in the file cache and reduced performance.
692 : //
693 : // The default value is the number of logical CPUs, which can be
694 : // limited by runtime.GOMAXPROCS.
695 : FileCacheShards int
696 :
697 : // ValidateOnIngest schedules validation of sstables after they have
698 : // been ingested.
699 : //
700 : // By default, this value is false.
701 : ValidateOnIngest bool
702 :
703 : // LevelMultiplier configures the size multiplier used to determine the
704 : // desired size of each level of the LSM. Defaults to 10.
705 : LevelMultiplier int
706 :
707 : // MultiLevelCompactionHeuristic determines whether to add an additional
708 : // level to a conventional two level compaction. If nil, a multilevel
709 : // compaction will never get triggered.
710 : MultiLevelCompactionHeuristic MultiLevelHeuristic
711 :
712 : // EnableColumnarBlocks is used to decide whether to enable writing
713 : // TableFormatPebblev5 sstables. This setting is only respected by
714 : // FormatColumnarBlocks. In lower format major versions, the
715 : // TableFormatPebblev5 format is prohibited. If EnableColumnarBlocks is
716 : // nil and the DB is at FormatColumnarBlocks, the DB defaults to not
717 : // writing columnar blocks.
718 : EnableColumnarBlocks func() bool
719 :
720 : // EnableValueBlocks is used to decide whether to enable writing
721 : // TableFormatPebblev3 sstables. This setting is only respected by a
722 : // specific subset of format major versions: FormatSSTableValueBlocks,
723 : // FormatFlushableIngest and FormatPrePebblev1MarkedCompacted. In lower
724 : // format major versions, value blocks are never enabled. In higher
725 : // format major versions, value blocks are always enabled.
726 : EnableValueBlocks func() bool
727 :
728 : // ShortAttributeExtractor is used iff EnableValueBlocks() returns true
729 : // (else ignored). If non-nil, a ShortAttribute can be extracted from the
730 : // value and stored with the key, when the value is stored elsewhere.
731 : ShortAttributeExtractor ShortAttributeExtractor
732 :
733 : // DisableIngestAsFlushable disables lazy ingestion of sstables through
734 : // a WAL write and memtable rotation. Only effectual if the format
735 : // major version is at least `FormatFlushableIngest`.
736 : DisableIngestAsFlushable func() bool
737 :
738 : // RemoteStorage enables use of remote storage (e.g. S3) for storing
739 : // sstables. Setting this option enables use of CreateOnShared option and
740 : // allows ingestion of external files.
741 : RemoteStorage remote.StorageFactory
742 :
743 : // If CreateOnShared is non-zero, new sstables are created on remote storage
744 : // (using CreateOnSharedLocator and with the appropriate
745 : // CreateOnSharedStrategy). These sstables can be shared between different
746 : // Pebble instances; the lifecycle of such objects is managed by the
747 : // remote.Storage constructed by options.RemoteStorage.
748 : //
749 : // Can only be used when RemoteStorage is set (and recognizes
750 : // CreateOnSharedLocator).
751 : CreateOnShared remote.CreateOnSharedStrategy
752 : CreateOnSharedLocator remote.Locator
753 :
754 : // CacheSizeBytesBytes is the size of the on-disk block cache for objects
755 : // on shared storage in bytes. If it is 0, no cache is used.
756 : SecondaryCacheSizeBytes int64
757 :
758 : // EnableDeleteOnlyCompactionExcises enables delete-only compactions to also
759 : // apply delete-only compaction hints on sstables that partially overlap
760 : // with it. This application happens through an excise, similar to
761 : // the excise phase of IngestAndExcise.
762 : EnableDeleteOnlyCompactionExcises func() bool
763 :
764 : // CompactionScheduler, if set, is used to limit concurrent compactions as
765 : // well as to pace compactions already chosen. If nil, a default scheduler
766 : // is created and used.
767 : CompactionScheduler CompactionScheduler
768 :
769 : UserKeyCategories UserKeyCategories
770 :
771 : // ValueSeparationPolicy controls the policy for separating values into
772 : // external blob files. If nil, value separation is disabled. The value
773 : // separation policy is ignored if EnableColumnarBlocks() is false.
774 : ValueSeparationPolicy func() ValueSeparationPolicy
775 :
776 : // SpanPolicyFunc is used to determine the SpanPolicy for a key region.
777 : SpanPolicyFunc SpanPolicyFunc
778 : }
779 :
780 : // Filters is a map from filter policy name to filter policy. It is used for
781 : // debugging tools which may be used on multiple databases configured with
782 : // different filter policies. It is not necessary to populate this filters
783 : // map during normal usage of a DB (it will be done automatically by
784 : // EnsureDefaults).
785 : Filters map[string]FilterPolicy
786 :
787 : // FlushDelayDeleteRange configures how long the database should wait before
788 : // forcing a flush of a memtable that contains a range deletion. Disk space
789 : // cannot be reclaimed until the range deletion is flushed. No automatic
790 : // flush occurs if zero.
791 : FlushDelayDeleteRange time.Duration
792 :
793 : // FlushDelayRangeKey configures how long the database should wait before
794 : // forcing a flush of a memtable that contains a range key. Range keys in
795 : // the memtable prevent lazy combined iteration, so it's desirable to flush
796 : // range keys promptly. No automatic flush occurs if zero.
797 : FlushDelayRangeKey time.Duration
798 :
799 : // FlushSplitBytes denotes the target number of bytes per sublevel in
800 : // each flush split interval (i.e. range between two flush split keys)
801 : // in L0 sstables. When set to zero, only a single sstable is generated
802 : // by each flush. When set to a non-zero value, flushes are split at
803 : // points to meet L0's TargetFileSize, any grandparent-related overlap
804 : // options, and at boundary keys of L0 flush split intervals (which are
805 : // targeted to contain around FlushSplitBytes bytes in each sublevel
806 : // between pairs of boundary keys). Splitting sstables during flush
807 : // allows increased compaction flexibility and concurrency when those
808 : // tables are compacted to lower levels.
809 : FlushSplitBytes int64
810 :
811 : // FormatMajorVersion sets the format of on-disk files. It is
812 : // recommended to set the format major version to an explicit
813 : // version, as the default may change over time.
814 : //
815 : // At Open if the existing database is formatted using a later
816 : // format major version that is known to this version of Pebble,
817 : // Pebble will continue to use the later format major version. If
818 : // the existing database's version is unknown, the caller may use
819 : // FormatMostCompatible and will be able to open the database
820 : // regardless of its actual version.
821 : //
822 : // If the existing database is formatted using a format major
823 : // version earlier than the one specified, Open will automatically
824 : // ratchet the database to the specified format major version.
825 : FormatMajorVersion FormatMajorVersion
826 :
827 : // FS provides the interface for persistent file storage.
828 : //
829 : // The default value uses the underlying operating system's file system.
830 : FS vfs.FS
831 :
832 : // KeySchema is the name of the key schema that should be used when writing
833 : // new sstables. There must be a key schema with this name defined in
834 : // KeySchemas. If not set, colblk.DefaultKeySchema is used to construct a
835 : // default key schema.
836 : KeySchema string
837 :
838 : // KeySchemas defines the set of known schemas of user keys. When columnar
839 : // blocks are in use (see FormatColumnarBlocks), the user may specify how a
840 : // key should be decomposed into columns. Each KeySchema must have a unique
841 : // name. The schema named by Options.KeySchema is used while writing
842 : // sstables during flushes and compactions.
843 : //
844 : // Multiple KeySchemas may be used over the lifetime of a database. Once a
845 : // KeySchema is used, it must be provided in KeySchemas in subsequent calls
846 : // to Open for perpetuity.
847 : KeySchemas sstable.KeySchemas
848 :
849 : // Lock, if set, must be a database lock acquired through LockDirectory for
850 : // the same directory passed to Open. If provided, Open will skip locking
851 : // the directory. Closing the database will not release the lock, and it's
852 : // the responsibility of the caller to release the lock after closing the
853 : // database.
854 : //
855 : // Open will enforce that the Lock passed locks the same directory passed to
856 : // Open. Concurrent calls to Open using the same Lock are detected and
857 : // prohibited.
858 : Lock *Lock
859 :
860 : // The count of L0 files necessary to trigger an L0 compaction.
861 : L0CompactionFileThreshold int
862 :
863 : // The amount of L0 read-amplification necessary to trigger an L0 compaction.
864 : L0CompactionThreshold int
865 :
866 : // Hard limit on L0 read-amplification, computed as the number of L0
867 : // sublevels. Writes are stopped when this threshold is reached.
868 : L0StopWritesThreshold int
869 :
870 : // The maximum number of bytes for LBase. The base level is the level which
871 : // L0 is compacted into. The base level is determined dynamically based on
872 : // the existing data in the LSM. The maximum number of bytes for other levels
873 : // is computed dynamically based on the base level's maximum size. When the
874 : // maximum number of bytes for a level is exceeded, compaction is requested.
875 : LBaseMaxBytes int64
876 :
877 : // Per-level options.
878 : Levels [manifest.NumLevels]LevelOptions
879 :
880 : // LoggerAndTracer will be used, if non-nil, else Logger will be used and
881 : // tracing will be a noop.
882 :
883 : // Logger used to write log messages.
884 : //
885 : // The default logger uses the Go standard library log package.
886 : Logger Logger
887 : // LoggerAndTracer is used for writing log messages and traces.
888 : LoggerAndTracer LoggerAndTracer
889 :
890 : // MaxManifestFileSize is the maximum size the MANIFEST file is allowed to
891 : // become. When the MANIFEST exceeds this size it is rolled over and a new
892 : // MANIFEST is created.
893 : MaxManifestFileSize int64
894 :
895 : // MaxOpenFiles is a soft limit on the number of open files that can be
896 : // used by the DB.
897 : //
898 : // The default value is 1000.
899 : MaxOpenFiles int
900 :
901 : // The size of a MemTable in steady state. The actual MemTable size starts at
902 : // min(256KB, MemTableSize) and doubles for each subsequent MemTable up to
903 : // MemTableSize. This reduces the memory pressure caused by MemTables for
904 : // short lived (test) DB instances. Note that more than one MemTable can be
905 : // in existence since flushing a MemTable involves creating a new one and
906 : // writing the contents of the old one in the
907 : // background. MemTableStopWritesThreshold places a hard limit on the size of
908 : // the queued MemTables.
909 : //
910 : // The default value is 4MB.
911 : MemTableSize uint64
912 :
913 : // Hard limit on the number of queued of MemTables. Writes are stopped when
914 : // the sum of the queued memtable sizes exceeds:
915 : // MemTableStopWritesThreshold * MemTableSize.
916 : //
917 : // This value should be at least 2 or writes will stop whenever a MemTable is
918 : // being flushed.
919 : //
920 : // The default value is 2.
921 : MemTableStopWritesThreshold int
922 :
923 : // Merger defines the associative merge operation to use for merging values
924 : // written with {Batch,DB}.Merge.
925 : //
926 : // The default merger concatenates values.
927 : Merger *Merger
928 :
929 : // CompactionConcurrencyRange returns a [lower, upper] range for the number of
930 : // compactions Pebble runs in parallel (with the caveats below), not including
931 : // download compactions (which have a separate limit specified by
932 : // MaxConcurrentDownloads).
933 : //
934 : // The lower value is the concurrency allowed under normal circumstances.
935 : // Pebble can dynamically increase the concurrency based on heuristics (like
936 : // high read amplification or compaction debt) up to the maximum.
937 : //
938 : // The upper value is a rough upper bound since delete-only compactions (a) do
939 : // not use the CompactionScheduler, and (b) the CompactionScheduler may use
940 : // other criteria to decide on how many compactions to permit.
941 : //
942 : // Elaborating on (b), when the ConcurrencyLimitScheduler is being used, the
943 : // value returned by DB.GetAllowedWithoutPermission fully controls how many
944 : // compactions get to run. Other CompactionSchedulers may use additional
945 : // criteria, like resource availability.
946 : //
947 : // Elaborating on (a), we don't use the CompactionScheduler to schedule
948 : // delete-only compactions since they are expected to be almost free from a
949 : // CPU and disk usage perspective. Since the CompactionScheduler does not
950 : // know about their existence, the total running count can exceed this
951 : // value. For example, consider CompactionConcurrencyRange returns 3, and the
952 : // current value returned from DB.GetAllowedWithoutPermission is also 3. Say
953 : // 3 delete-only compactions are also running. Then the
954 : // ConcurrencyLimitScheduler can also start 3 other compactions, for a total
955 : // of 6.
956 : //
957 : // DB.GetAllowedWithoutPermission returns a value in the interval
958 : // [lower, upper]. A value > lower is returned:
959 : // - when L0 read-amplification passes the L0CompactionConcurrency threshold;
960 : // - when compaction debt passes the CompactionDebtConcurrency threshold;
961 : // - when there are multiple manual compactions waiting to run.
962 : //
963 : // lower and upper must be greater than 0. If lower > upper, then upper is
964 : // used for both.
965 : //
966 : // The default values are 1, 1.
967 : CompactionConcurrencyRange func() (lower, upper int)
968 :
969 : // MaxConcurrentDownloads specifies the maximum number of download
970 : // compactions. These are compactions that copy an external file to the local
971 : // store.
972 : //
973 : // This limit is independent of CompactionConcurrencyRange; at any point in
974 : // time, we may be running CompactionConcurrencyRange non-download compactions
975 : // and MaxConcurrentDownloads download compactions.
976 : //
977 : // MaxConcurrentDownloads() must be greater than 0.
978 : //
979 : // The default value is 1.
980 : MaxConcurrentDownloads func() int
981 :
982 : // DisableAutomaticCompactions dictates whether automatic compactions are
983 : // scheduled or not. The default is false (enabled). This option is only used
984 : // externally when running a manual compaction, and internally for tests.
985 : DisableAutomaticCompactions bool
986 :
987 : // DisableConsistencyCheck disables the consistency check that is performed on
988 : // open. Should only be used when a database cannot be opened normally (e.g.
989 : // some of the tables don't exist / aren't accessible).
990 : DisableConsistencyCheck bool
991 :
992 : // DisableTableStats dictates whether tables should be loaded asynchronously
993 : // to compute statistics that inform compaction heuristics. The collection
994 : // of table stats improves compaction of tombstones, reclaiming disk space
995 : // more quickly and in some cases reducing write amplification in the
996 : // presence of tombstones. Disabling table stats may be useful in tests
997 : // that require determinism as the asynchronicity of table stats collection
998 : // introduces significant nondeterminism.
999 : DisableTableStats bool
1000 :
1001 : // NoSyncOnClose decides whether the Pebble instance will enforce a
1002 : // close-time synchronization (e.g., fdatasync() or sync_file_range())
1003 : // on files it writes to. Setting this to true removes the guarantee for a
1004 : // sync on close. Some implementations can still issue a non-blocking sync.
1005 : NoSyncOnClose bool
1006 :
1007 : // NumPrevManifest is the number of non-current or older manifests which
1008 : // we want to keep around for debugging purposes. By default, we're going
1009 : // to keep one older manifest.
1010 : NumPrevManifest int
1011 :
1012 : // ReadOnly indicates that the DB should be opened in read-only mode. Writes
1013 : // to the DB will return an error, background compactions are disabled, and
1014 : // the flush that normally occurs after replaying the WAL at startup is
1015 : // disabled.
1016 : ReadOnly bool
1017 :
1018 : // FileCache is an initialized FileCache which should be set as an
1019 : // option if the DB needs to be initialized with a pre-existing file cache.
1020 : // If FileCache is nil, then a file cache which is unique to the DB instance
1021 : // is created. FileCache can be shared between db instances by setting it here.
1022 : // The FileCache set here must use the same underlying cache as Options.Cache
1023 : // and pebble will panic otherwise.
1024 : FileCache *FileCache
1025 :
1026 : // BlockPropertyCollectors is a list of BlockPropertyCollector creation
1027 : // functions. A new BlockPropertyCollector is created for each sstable
1028 : // built and lives for the lifetime of writing that table.
1029 : BlockPropertyCollectors []func() BlockPropertyCollector
1030 :
1031 : // WALBytesPerSync sets the number of bytes to write to a WAL before calling
1032 : // Sync on it in the background. Just like with BytesPerSync above, this
1033 : // helps smooth out disk write latencies, and avoids cases where the OS
1034 : // writes a lot of buffered data to disk at once. However, this is less
1035 : // necessary with WALs, as many write operations already pass in
1036 : // Sync = true.
1037 : //
1038 : // The default value is 0, i.e. no background syncing. This matches the
1039 : // default behaviour in RocksDB.
1040 : WALBytesPerSync int
1041 :
1042 : // WALDir specifies the directory to store write-ahead logs (WALs) in. If
1043 : // empty (the default), WALs will be stored in the same directory as sstables
1044 : // (i.e. the directory passed to pebble.Open).
1045 : WALDir string
1046 :
1047 : // WALFailover may be set to configure Pebble to monitor writes to its
1048 : // write-ahead log and failover to writing write-ahead log entries to a
1049 : // secondary location (eg, a separate physical disk). WALFailover may be
1050 : // used to improve write availability in the presence of transient disk
1051 : // unavailability.
1052 : WALFailover *WALFailoverOptions
1053 :
1054 : // WALRecoveryDirs is a list of additional directories that should be
1055 : // scanned for the existence of additional write-ahead logs. WALRecoveryDirs
1056 : // is expected to be used when starting Pebble with a new WALDir or a new
1057 : // WALFailover configuration. The directories associated with the previous
1058 : // configuration may still contain WALs that are required for recovery of
1059 : // the current database state.
1060 : //
1061 : // If a previous WAL configuration may have stored WALs elsewhere but there
1062 : // is not a corresponding entry in WALRecoveryDirs, Open will error.
1063 : WALRecoveryDirs []wal.Dir
1064 :
1065 : // WALMinSyncInterval is the minimum duration between syncs of the WAL. If
1066 : // WAL syncs are requested faster than this interval, they will be
1067 : // artificially delayed. Introducing a small artificial delay (500us) between
1068 : // WAL syncs can allow more operations to arrive and reduce IO operations
1069 : // while having a minimal impact on throughput. This option is supplied as a
1070 : // closure in order to allow the value to be changed dynamically. The default
1071 : // value is 0.
1072 : //
1073 : // TODO(peter): rather than a closure, should there be another mechanism for
1074 : // changing options dynamically?
1075 : WALMinSyncInterval func() time.Duration
1076 :
1077 : // The controls below manage deletion pacing, which slows down
1078 : // deletions when compactions finish or when readers close and
1079 : // obsolete files must be cleaned up. Rapid deletion of many
1080 : // files simultaneously can increase disk latency on certain
1081 : // SSDs, and this functionality helps protect against that.
1082 :
1083 : // TargetByteDeletionRate is the rate (in bytes per second) at which sstable file
1084 : // deletions are limited to (under normal circumstances).
1085 : //
1086 : // This value is only a best-effort target; the effective rate can be
1087 : // higher if deletions are falling behind or disk space is running low.
1088 : //
1089 : // Setting this to 0 disables deletion pacing, which is also the default.
1090 : TargetByteDeletionRate int
1091 :
1092 : // FreeSpaceThresholdBytes specifies the minimum amount of free disk space that Pebble
1093 : // attempts to maintain. If free disk space drops below this threshold, deletions
1094 : // are accelerated above TargetByteDeletionRate until the threshold is restored.
1095 : // Default is 16GB.
1096 : FreeSpaceThresholdBytes uint64
1097 :
1098 : // FreeSpaceTimeframe sets the duration (in seconds) within which Pebble attempts
1099 : // to restore the free disk space back to FreeSpaceThreshold. A lower value means
1100 : // more aggressive deletions. Default is 10s.
1101 : FreeSpaceTimeframe time.Duration
1102 :
1103 : // ObsoleteBytesMaxRatio specifies the maximum allowed ratio of obsolete files to
1104 : // live files. If this ratio is exceeded, Pebble speeds up deletions above the
1105 : // TargetByteDeletionRate until the ratio is restored. Default is 0.20.
1106 : ObsoleteBytesMaxRatio float64
1107 :
1108 : // ObsoleteBytesTimeframe sets the duration (in seconds) within which Pebble aims
1109 : // to restore the obsolete-to-live bytes ratio below ObsoleteBytesMaxRatio. A lower
1110 : // value means more aggressive deletions. Default is 300s.
1111 : ObsoleteBytesTimeframe time.Duration
1112 :
1113 : // EnableSQLRowSpillMetrics specifies whether the Pebble instance will only be used
1114 : // to temporarily persist data spilled to disk for row-oriented SQL query execution.
1115 : EnableSQLRowSpillMetrics bool
1116 :
1117 : // AllocatorSizeClasses provides a sorted list containing the supported size
1118 : // classes of the underlying memory allocator. This provides hints to the
1119 : // sstable block writer's flushing policy to select block sizes that
1120 : // preemptively reduce internal fragmentation when loaded into the block cache.
1121 : AllocatorSizeClasses []int
1122 :
1123 : // private options are only used by internal tests or are used internally
1124 : // for facilitating upgrade paths of unconfigurable functionality.
1125 : private struct {
1126 : // disableDeleteOnlyCompactions prevents the scheduling of delete-only
1127 : // compactions that drop sstables wholy covered by range tombstones or
1128 : // range key tombstones.
1129 : disableDeleteOnlyCompactions bool
1130 :
1131 : // disableElisionOnlyCompactions prevents the scheduling of elision-only
1132 : // compactions that rewrite sstables in place in order to elide obsolete
1133 : // keys.
1134 : disableElisionOnlyCompactions bool
1135 :
1136 : // disableLazyCombinedIteration is a private option used by the
1137 : // metamorphic tests to test equivalence between lazy-combined iteration
1138 : // and constructing the range-key iterator upfront. It's a private
1139 : // option to avoid littering the public interface with options that we
1140 : // do not want to allow users to actually configure.
1141 : disableLazyCombinedIteration bool
1142 :
1143 : // testingAlwaysWaitForCleanup is set by some tests to force waiting for
1144 : // obsolete file deletion (to make events deterministic).
1145 : testingAlwaysWaitForCleanup bool
1146 :
1147 : // fsCloser holds a closer that should be invoked after a DB using these
1148 : // Options is closed. This is used to automatically stop the
1149 : // long-running goroutine associated with the disk-health-checking FS.
1150 : // See the initialization of FS in EnsureDefaults. Note that care has
1151 : // been taken to ensure that it is still safe to continue using the FS
1152 : // after this closer has been invoked. However, if write operations
1153 : // against the FS are made after the DB is closed, the FS may leak a
1154 : // goroutine indefinitely.
1155 : fsCloser io.Closer
1156 : }
1157 : }
1158 :
1159 : // ValueSeparationPolicy controls the policy for separating values into
1160 : // external blob files.
1161 : type ValueSeparationPolicy struct {
1162 : // Enabled controls whether value separation is enabled.
1163 : Enabled bool
1164 : // MinimumSize imposes a lower bound on the size of values that can be
1165 : // separated into a blob file. Values smaller than this are always written
1166 : // to the sstable (but may still be written to a value block within the
1167 : // sstable).
1168 : MinimumSize int
1169 : // MaxBlobReferenceDepth limits the number of potentially overlapping (in
1170 : // the keyspace) blob files that can be referenced by a single sstable. If a
1171 : // compaction may produce an output sstable referencing more than this many
1172 : // overlapping blob files, the compaction will instead rewrite referenced
1173 : // values into new blob files.
1174 : MaxBlobReferenceDepth int
1175 : }
1176 :
1177 : // SpanPolicy contains policies that can vary by key range. The zero value is
1178 : // the default value.
1179 : type SpanPolicy struct {
1180 : // DisableValueSeparationBySuffix disables discriminating KVs depending on
1181 : // suffix.
1182 : //
1183 : // Among a set of keys with the same prefix, Pebble's default heuristics
1184 : // optimize access to the KV with the smallest suffix. This is useful for MVCC
1185 : // keys (where the smallest suffix is the latest version), but should be
1186 : // disabled for keys where the suffix does not correspond to a version.
1187 : DisableValueSeparationBySuffix bool
1188 :
1189 : // ValueStoragePolicy is a hint used to determine where to store the values
1190 : // for KVs.
1191 : ValueStoragePolicy ValueStoragePolicy
1192 : }
1193 :
1194 : // ValueStoragePolicy is a hint used to determine where to store the values for
1195 : // KVs.
1196 : type ValueStoragePolicy uint8
1197 :
1198 : const (
1199 : // ValueStorageDefault is the default value; Pebble will respect global
1200 : // configuration for value blocks and value separation.
1201 : ValueStorageDefault ValueStoragePolicy = iota
1202 :
1203 : // ValueStorageLowReadLatency indicates Pebble should prefer storing values
1204 : // in-place.
1205 : ValueStorageLowReadLatency
1206 : )
1207 :
1208 : // SpanPolicyFunc is used to determine the SpanPolicy for a key region.
1209 : //
1210 : // The returned policy is valid from the start key until (and not including) the
1211 : // end key.
1212 : //
1213 : // A flush or compaction will call this function once for the first key to be
1214 : // output. If the compaction reaches the end key, the current output sst is
1215 : // finished and the function is called again.
1216 : //
1217 : // The end key can be empty, in which case the policy is valid for the entire
1218 : // keyspace after startKey.
1219 : type SpanPolicyFunc func(startKey []byte) (policy SpanPolicy, endKey []byte, err error)
1220 :
1221 : // MakeStaticSpanPolicyFunc returns a SpanPolicyFunc that applies a given policy
1222 : // to the given span (and the default policy outside the span).
1223 1 : func MakeStaticSpanPolicyFunc(cmp base.Compare, span KeyRange, policy SpanPolicy) SpanPolicyFunc {
1224 1 : return func(startKey []byte) (_ SpanPolicy, endKey []byte, _ error) {
1225 1 : if cmp(startKey, span.End) >= 0 {
1226 1 : // Start End
1227 1 : // v v
1228 1 : // -----|---------|-----|---
1229 1 : // ^
1230 1 : // startKey
1231 1 : return SpanPolicy{}, nil, nil
1232 1 : }
1233 1 : if cmp(startKey, span.Start) < 0 {
1234 0 : // Start End
1235 0 : // v v
1236 0 : // --|--|---------|-----
1237 0 : // ^
1238 0 : // startKey
1239 0 : return SpanPolicy{}, span.Start, nil
1240 0 : }
1241 : // Start End
1242 : // v v
1243 : // -----|----|----|-----
1244 : // ^
1245 : // startKey
1246 1 : return policy, span.End, nil
1247 : }
1248 : }
1249 :
1250 : // WALFailoverOptions configures the WAL failover mechanics to use during
1251 : // transient write unavailability on the primary WAL volume.
1252 : type WALFailoverOptions struct {
1253 : // Secondary indicates the secondary directory and VFS to use in the event a
1254 : // write to the primary WAL stalls.
1255 : Secondary wal.Dir
1256 : // FailoverOptions provides configuration of the thresholds and intervals
1257 : // involved in WAL failover. If any of its fields are left unspecified,
1258 : // reasonable defaults will be used.
1259 : wal.FailoverOptions
1260 : }
1261 :
1262 : // ReadaheadConfig controls the use of read-ahead.
1263 : type ReadaheadConfig = objstorageprovider.ReadaheadConfig
1264 :
1265 : // JemallocSizeClasses exports sstable.JemallocSizeClasses.
1266 : var JemallocSizeClasses = sstable.JemallocSizeClasses
1267 :
1268 : // DebugCheckLevels calls CheckLevels on the provided database.
1269 : // It may be set in the DebugCheck field of Options to check
1270 : // level invariants whenever a new version is installed.
1271 1 : func DebugCheckLevels(db *DB) error {
1272 1 : return db.CheckLevels(nil)
1273 1 : }
1274 :
1275 : // EnsureDefaults ensures that the default values for all options are set if a
1276 : // valid value was not already specified.
1277 1 : func (o *Options) EnsureDefaults() {
1278 1 : if o.Cache == nil && o.CacheSize == 0 {
1279 1 : o.CacheSize = cacheDefaultSize
1280 1 : }
1281 1 : o.Comparer = o.Comparer.EnsureDefaults()
1282 1 :
1283 1 : if o.BytesPerSync <= 0 {
1284 1 : o.BytesPerSync = 512 << 10 // 512 KB
1285 1 : }
1286 1 : if o.Cleaner == nil {
1287 1 : o.Cleaner = DeleteCleaner{}
1288 1 : }
1289 :
1290 1 : if o.FreeSpaceThresholdBytes == 0 {
1291 1 : o.FreeSpaceThresholdBytes = 16 << 30 // 16 GB
1292 1 : }
1293 :
1294 1 : if o.FreeSpaceTimeframe == 0 {
1295 1 : o.FreeSpaceTimeframe = 10 * time.Second
1296 1 : }
1297 :
1298 1 : if o.ObsoleteBytesMaxRatio == 0 {
1299 1 : o.ObsoleteBytesMaxRatio = 0.20
1300 1 : }
1301 :
1302 1 : if o.ObsoleteBytesTimeframe == 0 {
1303 1 : o.ObsoleteBytesTimeframe = 300 * time.Second
1304 1 : }
1305 :
1306 1 : if o.Experimental.DisableIngestAsFlushable == nil {
1307 1 : o.Experimental.DisableIngestAsFlushable = func() bool { return false }
1308 : }
1309 1 : if o.Experimental.L0CompactionConcurrency <= 0 {
1310 1 : o.Experimental.L0CompactionConcurrency = 10
1311 1 : }
1312 1 : if o.Experimental.CompactionDebtConcurrency <= 0 {
1313 1 : o.Experimental.CompactionDebtConcurrency = 1 << 30 // 1 GB
1314 1 : }
1315 1 : if o.Experimental.CompactionGarbageFractionForMaxConcurrency == nil {
1316 1 : // When 40% of the DB is garbage, the compaction concurrency is at the
1317 1 : // maximum permitted.
1318 1 : o.Experimental.CompactionGarbageFractionForMaxConcurrency = func() float64 { return 0.4 }
1319 : }
1320 1 : if o.KeySchema == "" && len(o.KeySchemas) == 0 {
1321 1 : ks := colblk.DefaultKeySchema(o.Comparer, 16 /* bundleSize */)
1322 1 : o.KeySchema = ks.Name
1323 1 : o.KeySchemas = sstable.MakeKeySchemas(&ks)
1324 1 : }
1325 1 : if o.L0CompactionThreshold <= 0 {
1326 1 : o.L0CompactionThreshold = 4
1327 1 : }
1328 1 : if o.L0CompactionFileThreshold <= 0 {
1329 1 : // Some justification for the default of 500:
1330 1 : // Why not smaller?:
1331 1 : // - The default target file size for L0 is 2MB, so 500 files is <= 1GB
1332 1 : // of data. At observed compaction speeds of > 20MB/s, L0 can be
1333 1 : // cleared of all files in < 1min, so this backlog is not huge.
1334 1 : // - 500 files is low overhead for instantiating L0 sublevels from
1335 1 : // scratch.
1336 1 : // - Lower values were observed to cause excessive and inefficient
1337 1 : // compactions out of L0 in a TPCC import benchmark.
1338 1 : // Why not larger?:
1339 1 : // - More than 1min to compact everything out of L0.
1340 1 : // - CockroachDB's admission control system uses a threshold of 1000
1341 1 : // files to start throttling writes to Pebble. Using 500 here gives
1342 1 : // us headroom between when Pebble should start compacting L0 and
1343 1 : // when the admission control threshold is reached.
1344 1 : //
1345 1 : // We can revisit this default in the future based on better
1346 1 : // experimental understanding.
1347 1 : //
1348 1 : // TODO(jackson): Experiment with slightly lower thresholds [or higher
1349 1 : // admission control thresholds] to see whether a higher L0 score at the
1350 1 : // threshold (currently 2.0) is necessary for some workloads to avoid
1351 1 : // starving L0 in favor of lower-level compactions.
1352 1 : o.L0CompactionFileThreshold = 500
1353 1 : }
1354 1 : if o.L0StopWritesThreshold <= 0 {
1355 1 : o.L0StopWritesThreshold = 12
1356 1 : }
1357 1 : if o.LBaseMaxBytes <= 0 {
1358 1 : o.LBaseMaxBytes = 64 << 20 // 64 MB
1359 1 : }
1360 1 : o.Levels[0].EnsureL0Defaults()
1361 1 : for i := 1; i < len(o.Levels); i++ {
1362 1 : o.Levels[i].EnsureL1PlusDefaults(&o.Levels[i-1])
1363 1 : }
1364 1 : if o.Logger == nil {
1365 1 : o.Logger = DefaultLogger
1366 1 : }
1367 1 : if o.EventListener == nil {
1368 1 : o.EventListener = &EventListener{}
1369 1 : }
1370 1 : o.EventListener.EnsureDefaults(o.Logger)
1371 1 : if o.MaxManifestFileSize == 0 {
1372 1 : o.MaxManifestFileSize = 128 << 20 // 128 MB
1373 1 : }
1374 1 : if o.MaxOpenFiles == 0 {
1375 1 : o.MaxOpenFiles = 1000
1376 1 : }
1377 1 : if o.MemTableSize <= 0 {
1378 1 : o.MemTableSize = 4 << 20 // 4 MB
1379 1 : }
1380 1 : if o.MemTableStopWritesThreshold <= 0 {
1381 1 : o.MemTableStopWritesThreshold = 2
1382 1 : }
1383 1 : if o.Merger == nil {
1384 1 : o.Merger = DefaultMerger
1385 1 : }
1386 1 : if o.CompactionConcurrencyRange == nil {
1387 1 : o.CompactionConcurrencyRange = func() (int, int) { return 1, 1 }
1388 : }
1389 1 : if o.MaxConcurrentDownloads == nil {
1390 1 : o.MaxConcurrentDownloads = func() int { return 1 }
1391 : }
1392 1 : if o.NumPrevManifest <= 0 {
1393 1 : o.NumPrevManifest = 1
1394 1 : }
1395 :
1396 1 : if o.FormatMajorVersion == FormatDefault {
1397 1 : o.FormatMajorVersion = FormatMinSupported
1398 1 : if o.Experimental.CreateOnShared != remote.CreateOnSharedNone {
1399 1 : o.FormatMajorVersion = FormatMinForSharedObjects
1400 1 : }
1401 : }
1402 :
1403 1 : if o.FS == nil {
1404 1 : o.WithFSDefaults()
1405 1 : }
1406 1 : if o.FlushSplitBytes <= 0 {
1407 1 : o.FlushSplitBytes = 2 * o.Levels[0].TargetFileSize
1408 1 : }
1409 1 : if o.WALFailover != nil {
1410 1 : o.WALFailover.FailoverOptions.EnsureDefaults()
1411 1 : }
1412 1 : if o.Experimental.LevelMultiplier <= 0 {
1413 1 : o.Experimental.LevelMultiplier = defaultLevelMultiplier
1414 1 : }
1415 1 : if o.Experimental.ReadCompactionRate == 0 {
1416 1 : o.Experimental.ReadCompactionRate = 16000
1417 1 : }
1418 1 : if o.Experimental.ReadSamplingMultiplier == 0 {
1419 1 : o.Experimental.ReadSamplingMultiplier = 1 << 4
1420 1 : }
1421 1 : if o.Experimental.NumDeletionsThreshold == 0 {
1422 1 : o.Experimental.NumDeletionsThreshold = sstable.DefaultNumDeletionsThreshold
1423 1 : }
1424 1 : if o.Experimental.DeletionSizeRatioThreshold == 0 {
1425 1 : o.Experimental.DeletionSizeRatioThreshold = sstable.DefaultDeletionSizeRatioThreshold
1426 1 : }
1427 1 : if o.Experimental.EnableColumnarBlocks == nil {
1428 1 : o.Experimental.EnableColumnarBlocks = func() bool { return true }
1429 : }
1430 1 : if o.Experimental.TombstoneDenseCompactionThreshold == 0 {
1431 1 : o.Experimental.TombstoneDenseCompactionThreshold = 0.10
1432 1 : }
1433 1 : if o.Experimental.FileCacheShards <= 0 {
1434 1 : o.Experimental.FileCacheShards = runtime.GOMAXPROCS(0)
1435 1 : }
1436 1 : if o.Experimental.MultiLevelCompactionHeuristic == nil {
1437 1 : o.Experimental.MultiLevelCompactionHeuristic = WriteAmpHeuristic{}
1438 1 : }
1439 1 : if o.Experimental.SpanPolicyFunc == nil {
1440 1 : o.Experimental.SpanPolicyFunc = func(startKey []byte) (SpanPolicy, []byte, error) { return SpanPolicy{}, nil, nil }
1441 : }
1442 : // TODO(jackson): Enable value separation by default once we have confidence
1443 : // in a default policy.
1444 :
1445 1 : o.initMaps()
1446 : }
1447 :
1448 : // DefaultOptions returns a new Options object with the default values set.
1449 1 : func DefaultOptions() *Options {
1450 1 : o := &Options{}
1451 1 : o.EnsureDefaults()
1452 1 : return o
1453 1 : }
1454 :
1455 : // WithFSDefaults configures the Options to wrap the configured filesystem with
1456 : // the default virtual file system middleware, like disk-health checking.
1457 1 : func (o *Options) WithFSDefaults() {
1458 1 : if o.FS == nil {
1459 1 : o.FS = vfs.Default
1460 1 : }
1461 1 : o.FS, o.private.fsCloser = vfs.WithDiskHealthChecks(o.FS, 5*time.Second, nil,
1462 1 : func(info vfs.DiskSlowInfo) {
1463 0 : o.EventListener.DiskSlow(info)
1464 0 : })
1465 : }
1466 :
1467 : // AddEventListener adds the provided event listener to the Options, in addition
1468 : // to any existing event listener.
1469 1 : func (o *Options) AddEventListener(l EventListener) {
1470 1 : if o.EventListener != nil {
1471 1 : l = TeeEventListener(l, *o.EventListener)
1472 1 : }
1473 1 : o.EventListener = &l
1474 : }
1475 :
1476 : // initMaps initializes the Comparers, Filters, and Mergers maps.
1477 1 : func (o *Options) initMaps() {
1478 1 : for i := range o.Levels {
1479 1 : l := &o.Levels[i]
1480 1 : if l.FilterPolicy != NoFilterPolicy {
1481 1 : if o.Filters == nil {
1482 1 : o.Filters = make(map[string]FilterPolicy)
1483 1 : }
1484 1 : name := l.FilterPolicy.Name()
1485 1 : if _, ok := o.Filters[name]; !ok {
1486 1 : o.Filters[name] = l.FilterPolicy
1487 1 : }
1488 : }
1489 : }
1490 : }
1491 :
1492 : // Clone creates a shallow-copy of the supplied options.
1493 1 : func (o *Options) Clone() *Options {
1494 1 : n := &Options{}
1495 1 : if o != nil {
1496 1 : *n = *o
1497 1 : }
1498 1 : return n
1499 : }
1500 :
1501 1 : func (o *Options) String() string {
1502 1 : var buf bytes.Buffer
1503 1 :
1504 1 : cacheSize := o.CacheSize
1505 1 : if o.Cache != nil {
1506 1 : cacheSize = o.Cache.MaxSize()
1507 1 : }
1508 :
1509 1 : fmt.Fprintf(&buf, "[Version]\n")
1510 1 : fmt.Fprintf(&buf, " pebble_version=0.1\n")
1511 1 : fmt.Fprintf(&buf, "\n")
1512 1 : fmt.Fprintf(&buf, "[Options]\n")
1513 1 : fmt.Fprintf(&buf, " bytes_per_sync=%d\n", o.BytesPerSync)
1514 1 : fmt.Fprintf(&buf, " cache_size=%d\n", cacheSize)
1515 1 : fmt.Fprintf(&buf, " cleaner=%s\n", o.Cleaner)
1516 1 : fmt.Fprintf(&buf, " compaction_debt_concurrency=%d\n", o.Experimental.CompactionDebtConcurrency)
1517 1 : fmt.Fprintf(&buf, " compaction_garbage_fraction_for_max_concurrency=%.2f\n",
1518 1 : o.Experimental.CompactionGarbageFractionForMaxConcurrency())
1519 1 : fmt.Fprintf(&buf, " comparer=%s\n", o.Comparer.Name)
1520 1 : fmt.Fprintf(&buf, " disable_wal=%t\n", o.DisableWAL)
1521 1 : if o.Experimental.DisableIngestAsFlushable != nil && o.Experimental.DisableIngestAsFlushable() {
1522 1 : fmt.Fprintf(&buf, " disable_ingest_as_flushable=%t\n", true)
1523 1 : }
1524 1 : if o.Experimental.EnableColumnarBlocks != nil && o.Experimental.EnableColumnarBlocks() {
1525 1 : fmt.Fprintf(&buf, " enable_columnar_blocks=%t\n", true)
1526 1 : }
1527 1 : fmt.Fprintf(&buf, " flush_delay_delete_range=%s\n", o.FlushDelayDeleteRange)
1528 1 : fmt.Fprintf(&buf, " flush_delay_range_key=%s\n", o.FlushDelayRangeKey)
1529 1 : fmt.Fprintf(&buf, " flush_split_bytes=%d\n", o.FlushSplitBytes)
1530 1 : fmt.Fprintf(&buf, " format_major_version=%d\n", o.FormatMajorVersion)
1531 1 : fmt.Fprintf(&buf, " key_schema=%s\n", o.KeySchema)
1532 1 : fmt.Fprintf(&buf, " l0_compaction_concurrency=%d\n", o.Experimental.L0CompactionConcurrency)
1533 1 : fmt.Fprintf(&buf, " l0_compaction_file_threshold=%d\n", o.L0CompactionFileThreshold)
1534 1 : fmt.Fprintf(&buf, " l0_compaction_threshold=%d\n", o.L0CompactionThreshold)
1535 1 : fmt.Fprintf(&buf, " l0_stop_writes_threshold=%d\n", o.L0StopWritesThreshold)
1536 1 : fmt.Fprintf(&buf, " lbase_max_bytes=%d\n", o.LBaseMaxBytes)
1537 1 : if o.Experimental.LevelMultiplier != defaultLevelMultiplier {
1538 1 : fmt.Fprintf(&buf, " level_multiplier=%d\n", o.Experimental.LevelMultiplier)
1539 1 : }
1540 1 : lower, upper := o.CompactionConcurrencyRange()
1541 1 : fmt.Fprintf(&buf, " concurrent_compactions=%d\n", lower)
1542 1 : fmt.Fprintf(&buf, " max_concurrent_compactions=%d\n", upper)
1543 1 : fmt.Fprintf(&buf, " max_concurrent_downloads=%d\n", o.MaxConcurrentDownloads())
1544 1 : fmt.Fprintf(&buf, " max_manifest_file_size=%d\n", o.MaxManifestFileSize)
1545 1 : fmt.Fprintf(&buf, " max_open_files=%d\n", o.MaxOpenFiles)
1546 1 : fmt.Fprintf(&buf, " mem_table_size=%d\n", o.MemTableSize)
1547 1 : fmt.Fprintf(&buf, " mem_table_stop_writes_threshold=%d\n", o.MemTableStopWritesThreshold)
1548 1 : fmt.Fprintf(&buf, " min_deletion_rate=%d\n", o.TargetByteDeletionRate)
1549 1 : fmt.Fprintf(&buf, " free_space_threshold_bytes=%d\n", o.FreeSpaceThresholdBytes)
1550 1 : fmt.Fprintf(&buf, " free_space_timeframe=%s\n", o.FreeSpaceTimeframe.String())
1551 1 : fmt.Fprintf(&buf, " obsolete_bytes_max_ratio=%f\n", o.ObsoleteBytesMaxRatio)
1552 1 : fmt.Fprintf(&buf, " obsolete_bytes_timeframe=%s\n", o.ObsoleteBytesTimeframe.String())
1553 1 : fmt.Fprintf(&buf, " merger=%s\n", o.Merger.Name)
1554 1 : if o.Experimental.MultiLevelCompactionHeuristic != nil {
1555 1 : fmt.Fprintf(&buf, " multilevel_compaction_heuristic=%s\n", o.Experimental.MultiLevelCompactionHeuristic.String())
1556 1 : }
1557 1 : fmt.Fprintf(&buf, " read_compaction_rate=%d\n", o.Experimental.ReadCompactionRate)
1558 1 : fmt.Fprintf(&buf, " read_sampling_multiplier=%d\n", o.Experimental.ReadSamplingMultiplier)
1559 1 : fmt.Fprintf(&buf, " num_deletions_threshold=%d\n", o.Experimental.NumDeletionsThreshold)
1560 1 : fmt.Fprintf(&buf, " deletion_size_ratio_threshold=%f\n", o.Experimental.DeletionSizeRatioThreshold)
1561 1 : fmt.Fprintf(&buf, " tombstone_dense_compaction_threshold=%f\n", o.Experimental.TombstoneDenseCompactionThreshold)
1562 1 : // We no longer care about strict_wal_tail, but set it to true in case an
1563 1 : // older version reads the options.
1564 1 : fmt.Fprintf(&buf, " strict_wal_tail=%t\n", true)
1565 1 : fmt.Fprintf(&buf, " table_cache_shards=%d\n", o.Experimental.FileCacheShards)
1566 1 : fmt.Fprintf(&buf, " validate_on_ingest=%t\n", o.Experimental.ValidateOnIngest)
1567 1 : fmt.Fprintf(&buf, " wal_dir=%s\n", o.WALDir)
1568 1 : fmt.Fprintf(&buf, " wal_bytes_per_sync=%d\n", o.WALBytesPerSync)
1569 1 : fmt.Fprintf(&buf, " secondary_cache_size_bytes=%d\n", o.Experimental.SecondaryCacheSizeBytes)
1570 1 : fmt.Fprintf(&buf, " create_on_shared=%d\n", o.Experimental.CreateOnShared)
1571 1 :
1572 1 : // Private options.
1573 1 : //
1574 1 : // These options are only encoded if true, because we do not want them to
1575 1 : // appear in production serialized Options files, since they're testing-only
1576 1 : // options. They're only serialized when true, which still ensures that the
1577 1 : // metamorphic tests may propagate them to subprocesses.
1578 1 : if o.private.disableDeleteOnlyCompactions {
1579 1 : fmt.Fprintln(&buf, " disable_delete_only_compactions=true")
1580 1 : }
1581 1 : if o.private.disableElisionOnlyCompactions {
1582 1 : fmt.Fprintln(&buf, " disable_elision_only_compactions=true")
1583 1 : }
1584 1 : if o.private.disableLazyCombinedIteration {
1585 1 : fmt.Fprintln(&buf, " disable_lazy_combined_iteration=true")
1586 1 : }
1587 :
1588 1 : if o.Experimental.ValueSeparationPolicy != nil {
1589 1 : policy := o.Experimental.ValueSeparationPolicy()
1590 1 : fmt.Fprintln(&buf)
1591 1 : fmt.Fprintln(&buf, "[Value Separation]")
1592 1 : fmt.Fprintf(&buf, " enabled=%t\n", policy.Enabled)
1593 1 : fmt.Fprintf(&buf, " minimum_size=%d\n", policy.MinimumSize)
1594 1 : fmt.Fprintf(&buf, " max_blob_reference_depth=%d\n", policy.MaxBlobReferenceDepth)
1595 1 : }
1596 :
1597 1 : if o.WALFailover != nil {
1598 1 : unhealthyThreshold, _ := o.WALFailover.FailoverOptions.UnhealthyOperationLatencyThreshold()
1599 1 : fmt.Fprintf(&buf, "\n")
1600 1 : fmt.Fprintf(&buf, "[WAL Failover]\n")
1601 1 : fmt.Fprintf(&buf, " secondary_dir=%s\n", o.WALFailover.Secondary.Dirname)
1602 1 : fmt.Fprintf(&buf, " primary_dir_probe_interval=%s\n", o.WALFailover.FailoverOptions.PrimaryDirProbeInterval)
1603 1 : fmt.Fprintf(&buf, " healthy_probe_latency_threshold=%s\n", o.WALFailover.FailoverOptions.HealthyProbeLatencyThreshold)
1604 1 : fmt.Fprintf(&buf, " healthy_interval=%s\n", o.WALFailover.FailoverOptions.HealthyInterval)
1605 1 : fmt.Fprintf(&buf, " unhealthy_sampling_interval=%s\n", o.WALFailover.FailoverOptions.UnhealthySamplingInterval)
1606 1 : fmt.Fprintf(&buf, " unhealthy_operation_latency_threshold=%s\n", unhealthyThreshold)
1607 1 : fmt.Fprintf(&buf, " elevated_write_stall_threshold_lag=%s\n", o.WALFailover.FailoverOptions.ElevatedWriteStallThresholdLag)
1608 1 : }
1609 :
1610 1 : for i := range o.Levels {
1611 1 : l := &o.Levels[i]
1612 1 : fmt.Fprintf(&buf, "\n")
1613 1 : fmt.Fprintf(&buf, "[Level \"%d\"]\n", i)
1614 1 : fmt.Fprintf(&buf, " block_restart_interval=%d\n", l.BlockRestartInterval)
1615 1 : fmt.Fprintf(&buf, " block_size=%d\n", l.BlockSize)
1616 1 : fmt.Fprintf(&buf, " block_size_threshold=%d\n", l.BlockSizeThreshold)
1617 1 : fmt.Fprintf(&buf, " compression=%s\n", resolveDefaultCompression(l.Compression()))
1618 1 : fmt.Fprintf(&buf, " filter_policy=%s\n", l.FilterPolicy.Name())
1619 1 : fmt.Fprintf(&buf, " filter_type=%s\n", l.FilterType)
1620 1 : fmt.Fprintf(&buf, " index_block_size=%d\n", l.IndexBlockSize)
1621 1 : fmt.Fprintf(&buf, " target_file_size=%d\n", l.TargetFileSize)
1622 1 : }
1623 :
1624 1 : return buf.String()
1625 : }
1626 :
1627 : type parseOptionsFuncs struct {
1628 : visitNewSection func(i, j int, section string) error
1629 : visitKeyValue func(i, j int, section, key, value string) error
1630 : visitCommentOrWhitespace func(i, j int, whitespace string) error
1631 : }
1632 :
1633 : // parseOptions takes options serialized by Options.String() and parses them
1634 : // into keys and values. It calls fns.visitNewSection for the beginning of each
1635 : // new section, fns.visitKeyValue for each key-value pair, and
1636 : // visitCommentOrWhitespace for comments and whitespace between key-value pairs.
1637 1 : func parseOptions(s string, fns parseOptionsFuncs) error {
1638 1 : var section, mappedSection string
1639 1 : i := 0
1640 1 : for i < len(s) {
1641 1 : rem := s[i:]
1642 1 : j := strings.IndexByte(rem, '\n')
1643 1 : if j < 0 {
1644 1 : j = len(rem)
1645 1 : } else {
1646 1 : j += 1 // Include the newline.
1647 1 : }
1648 1 : line := strings.TrimSpace(s[i : i+j])
1649 1 : startOff, endOff := i, i+j
1650 1 : i += j
1651 1 :
1652 1 : if len(line) == 0 || line[0] == ';' || line[0] == '#' {
1653 1 : // Skip blank lines and comments.
1654 1 : if fns.visitCommentOrWhitespace != nil {
1655 1 : if err := fns.visitCommentOrWhitespace(startOff, endOff, line); err != nil {
1656 0 : return err
1657 0 : }
1658 : }
1659 1 : continue
1660 : }
1661 1 : n := len(line)
1662 1 : if line[0] == '[' && line[n-1] == ']' {
1663 1 : // Parse section.
1664 1 : section = line[1 : n-1]
1665 1 : // RocksDB uses a similar (INI-style) syntax for the OPTIONS file, but
1666 1 : // different section names and keys. The "CFOptions ..." paths are the
1667 1 : // RocksDB versions which we map to the Pebble paths.
1668 1 : mappedSection = section
1669 1 : if section == `CFOptions "default"` {
1670 1 : mappedSection = "Options"
1671 1 : }
1672 1 : if fns.visitNewSection != nil {
1673 1 : if err := fns.visitNewSection(startOff, endOff, mappedSection); err != nil {
1674 0 : return err
1675 0 : }
1676 : }
1677 1 : continue
1678 : }
1679 :
1680 1 : pos := strings.Index(line, "=")
1681 1 : if pos < 0 {
1682 1 : const maxLen = 50
1683 1 : if len(line) > maxLen {
1684 0 : line = line[:maxLen-3] + "..."
1685 0 : }
1686 1 : return base.CorruptionErrorf("invalid key=value syntax: %q", errors.Safe(line))
1687 : }
1688 :
1689 1 : key := strings.TrimSpace(line[:pos])
1690 1 : value := strings.TrimSpace(line[pos+1:])
1691 1 :
1692 1 : if section == `CFOptions "default"` {
1693 1 : switch key {
1694 1 : case "comparator":
1695 1 : key = "comparer"
1696 1 : case "merge_operator":
1697 1 : key = "merger"
1698 : }
1699 : }
1700 1 : if fns.visitKeyValue != nil {
1701 1 : if err := fns.visitKeyValue(startOff, endOff, mappedSection, key, value); err != nil {
1702 1 : return err
1703 1 : }
1704 : }
1705 : }
1706 1 : return nil
1707 : }
1708 :
1709 : // ParseHooks contains callbacks to create options fields which can have
1710 : // user-defined implementations.
1711 : type ParseHooks struct {
1712 : NewCleaner func(name string) (Cleaner, error)
1713 : NewComparer func(name string) (*Comparer, error)
1714 : NewFilterPolicy func(name string) (FilterPolicy, error)
1715 : NewKeySchema func(name string) (KeySchema, error)
1716 : NewMerger func(name string) (*Merger, error)
1717 : SkipUnknown func(name, value string) bool
1718 : }
1719 :
1720 : // Parse parses the options from the specified string. Note that certain
1721 : // options cannot be parsed into populated fields. For example, comparer and
1722 : // merger.
1723 1 : func (o *Options) Parse(s string, hooks *ParseHooks) error {
1724 1 : var valSepPolicy ValueSeparationPolicy
1725 1 : var valSepPolicyOk bool
1726 1 : var concurrencyLimit struct {
1727 1 : lower int
1728 1 : lowerSet bool
1729 1 : upper int
1730 1 : upperSet bool
1731 1 : }
1732 1 :
1733 1 : visitKeyValue := func(i, j int, section, key, value string) error {
1734 1 : // WARNING: DO NOT remove entries from the switches below because doing so
1735 1 : // causes a key previously written to the OPTIONS file to be considered unknown,
1736 1 : // a backwards incompatible change. Instead, leave in support for parsing the
1737 1 : // key but simply don't parse the value.
1738 1 :
1739 1 : parseComparer := func(name string) (*Comparer, error) {
1740 1 : switch name {
1741 1 : case DefaultComparer.Name:
1742 1 : return DefaultComparer, nil
1743 1 : case testkeys.Comparer.Name:
1744 1 : return testkeys.Comparer, nil
1745 1 : default:
1746 1 : if hooks != nil && hooks.NewComparer != nil {
1747 1 : return hooks.NewComparer(name)
1748 1 : }
1749 1 : return nil, nil
1750 : }
1751 : }
1752 :
1753 1 : switch {
1754 1 : case section == "Version":
1755 1 : switch key {
1756 1 : case "pebble_version":
1757 0 : default:
1758 0 : if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
1759 0 : return nil
1760 0 : }
1761 0 : return errors.Errorf("pebble: unknown option: %s.%s",
1762 0 : errors.Safe(section), errors.Safe(key))
1763 : }
1764 1 : return nil
1765 :
1766 1 : case section == "Options":
1767 1 : var err error
1768 1 : switch key {
1769 1 : case "bytes_per_sync":
1770 1 : o.BytesPerSync, err = strconv.Atoi(value)
1771 1 : case "cache_size":
1772 1 : o.CacheSize, err = strconv.ParseInt(value, 10, 64)
1773 1 : case "cleaner":
1774 1 : switch value {
1775 1 : case "archive":
1776 1 : o.Cleaner = ArchiveCleaner{}
1777 1 : case "delete":
1778 1 : o.Cleaner = DeleteCleaner{}
1779 0 : default:
1780 0 : if hooks != nil && hooks.NewCleaner != nil {
1781 0 : o.Cleaner, err = hooks.NewCleaner(value)
1782 0 : }
1783 : }
1784 1 : case "comparer":
1785 1 : var comparer *Comparer
1786 1 : comparer, err = parseComparer(value)
1787 1 : if comparer != nil {
1788 1 : o.Comparer = comparer
1789 1 : }
1790 1 : case "compaction_debt_concurrency":
1791 1 : o.Experimental.CompactionDebtConcurrency, err = strconv.ParseUint(value, 10, 64)
1792 1 : case "compaction_garbage_fraction_for_max_concurrency":
1793 1 : var frac float64
1794 1 : frac, err = strconv.ParseFloat(value, 64)
1795 1 : if err == nil {
1796 1 : o.Experimental.CompactionGarbageFractionForMaxConcurrency =
1797 1 : func() float64 { return frac }
1798 : }
1799 0 : case "delete_range_flush_delay":
1800 0 : // NB: This is a deprecated serialization of the
1801 0 : // `flush_delay_delete_range`.
1802 0 : o.FlushDelayDeleteRange, err = time.ParseDuration(value)
1803 1 : case "disable_delete_only_compactions":
1804 1 : o.private.disableDeleteOnlyCompactions, err = strconv.ParseBool(value)
1805 1 : case "disable_elision_only_compactions":
1806 1 : o.private.disableElisionOnlyCompactions, err = strconv.ParseBool(value)
1807 1 : case "disable_ingest_as_flushable":
1808 1 : var v bool
1809 1 : v, err = strconv.ParseBool(value)
1810 1 : if err == nil {
1811 1 : o.Experimental.DisableIngestAsFlushable = func() bool { return v }
1812 : }
1813 1 : case "disable_lazy_combined_iteration":
1814 1 : o.private.disableLazyCombinedIteration, err = strconv.ParseBool(value)
1815 1 : case "disable_wal":
1816 1 : o.DisableWAL, err = strconv.ParseBool(value)
1817 1 : case "enable_columnar_blocks":
1818 1 : var v bool
1819 1 : if v, err = strconv.ParseBool(value); err == nil {
1820 1 : o.Experimental.EnableColumnarBlocks = func() bool { return v }
1821 : }
1822 1 : case "flush_delay_delete_range":
1823 1 : o.FlushDelayDeleteRange, err = time.ParseDuration(value)
1824 1 : case "flush_delay_range_key":
1825 1 : o.FlushDelayRangeKey, err = time.ParseDuration(value)
1826 1 : case "flush_split_bytes":
1827 1 : o.FlushSplitBytes, err = strconv.ParseInt(value, 10, 64)
1828 1 : case "format_major_version":
1829 1 : // NB: The version written here may be stale. Open does
1830 1 : // not use the format major version encoded in the
1831 1 : // OPTIONS file other than to validate that the encoded
1832 1 : // version is valid right here.
1833 1 : var v uint64
1834 1 : v, err = strconv.ParseUint(value, 10, 64)
1835 1 : if vers := FormatMajorVersion(v); vers > internalFormatNewest || vers == FormatDefault {
1836 0 : err = errors.Newf("unsupported format major version %d", o.FormatMajorVersion)
1837 0 : }
1838 1 : if err == nil {
1839 1 : o.FormatMajorVersion = FormatMajorVersion(v)
1840 1 : }
1841 1 : case "key_schema":
1842 1 : o.KeySchema = value
1843 1 : if o.KeySchemas == nil {
1844 1 : o.KeySchemas = make(map[string]*KeySchema)
1845 1 : }
1846 1 : if _, ok := o.KeySchemas[o.KeySchema]; !ok {
1847 1 : if strings.HasPrefix(value, "DefaultKeySchema(") && strings.HasSuffix(value, ")") {
1848 1 : argsStr := strings.TrimSuffix(strings.TrimPrefix(value, "DefaultKeySchema("), ")")
1849 1 : args := strings.FieldsFunc(argsStr, func(r rune) bool {
1850 1 : return unicode.IsSpace(r) || r == ','
1851 1 : })
1852 1 : var comparer *base.Comparer
1853 1 : var bundleSize int
1854 1 : comparer, err = parseComparer(args[0])
1855 1 : if err == nil {
1856 1 : bundleSize, err = strconv.Atoi(args[1])
1857 1 : }
1858 1 : if err == nil {
1859 1 : schema := colblk.DefaultKeySchema(comparer, bundleSize)
1860 1 : o.KeySchema = schema.Name
1861 1 : o.KeySchemas[o.KeySchema] = &schema
1862 1 : }
1863 1 : } else if hooks != nil && hooks.NewKeySchema != nil {
1864 0 : var schema KeySchema
1865 0 : schema, err = hooks.NewKeySchema(value)
1866 0 : if err == nil {
1867 0 : o.KeySchemas[value] = &schema
1868 0 : }
1869 : }
1870 : }
1871 1 : case "l0_compaction_concurrency":
1872 1 : o.Experimental.L0CompactionConcurrency, err = strconv.Atoi(value)
1873 1 : case "l0_compaction_file_threshold":
1874 1 : o.L0CompactionFileThreshold, err = strconv.Atoi(value)
1875 1 : case "l0_compaction_threshold":
1876 1 : o.L0CompactionThreshold, err = strconv.Atoi(value)
1877 1 : case "l0_stop_writes_threshold":
1878 1 : o.L0StopWritesThreshold, err = strconv.Atoi(value)
1879 0 : case "l0_sublevel_compactions":
1880 : // Do nothing; option existed in older versions of pebble.
1881 1 : case "lbase_max_bytes":
1882 1 : o.LBaseMaxBytes, err = strconv.ParseInt(value, 10, 64)
1883 1 : case "level_multiplier":
1884 1 : o.Experimental.LevelMultiplier, err = strconv.Atoi(value)
1885 1 : case "concurrent_compactions":
1886 1 : concurrencyLimit.lowerSet = true
1887 1 : concurrencyLimit.lower, err = strconv.Atoi(value)
1888 1 : case "max_concurrent_compactions":
1889 1 : concurrencyLimit.upperSet = true
1890 1 : concurrencyLimit.upper, err = strconv.Atoi(value)
1891 1 : case "max_concurrent_downloads":
1892 1 : var concurrentDownloads int
1893 1 : concurrentDownloads, err = strconv.Atoi(value)
1894 1 : if concurrentDownloads <= 0 {
1895 0 : err = errors.New("max_concurrent_compactions cannot be <= 0")
1896 1 : } else {
1897 1 : o.MaxConcurrentDownloads = func() int { return concurrentDownloads }
1898 : }
1899 1 : case "max_manifest_file_size":
1900 1 : o.MaxManifestFileSize, err = strconv.ParseInt(value, 10, 64)
1901 1 : case "max_open_files":
1902 1 : o.MaxOpenFiles, err = strconv.Atoi(value)
1903 1 : case "mem_table_size":
1904 1 : o.MemTableSize, err = strconv.ParseUint(value, 10, 64)
1905 1 : case "mem_table_stop_writes_threshold":
1906 1 : o.MemTableStopWritesThreshold, err = strconv.Atoi(value)
1907 0 : case "min_compaction_rate":
1908 : // Do nothing; option existed in older versions of pebble, and
1909 : // may be meaningful again eventually.
1910 1 : case "min_deletion_rate":
1911 1 : o.TargetByteDeletionRate, err = strconv.Atoi(value)
1912 1 : case "free_space_threshold_bytes":
1913 1 : o.FreeSpaceThresholdBytes, err = strconv.ParseUint(value, 10, 64)
1914 1 : case "free_space_timeframe":
1915 1 : o.FreeSpaceTimeframe, err = time.ParseDuration(value)
1916 1 : case "obsolete_bytes_max_ratio":
1917 1 : o.ObsoleteBytesMaxRatio, err = strconv.ParseFloat(value, 64)
1918 1 : case "obsolete_bytes_timeframe":
1919 1 : o.ObsoleteBytesTimeframe, err = time.ParseDuration(value)
1920 0 : case "min_flush_rate":
1921 : // Do nothing; option existed in older versions of pebble, and
1922 : // may be meaningful again eventually.
1923 1 : case "multilevel_compaction_heuristic":
1924 1 : switch {
1925 1 : case value == "none":
1926 1 : o.Experimental.MultiLevelCompactionHeuristic = NoMultiLevel{}
1927 1 : case strings.HasPrefix(value, "wamp"):
1928 1 : fields := strings.FieldsFunc(strings.TrimPrefix(value, "wamp"), func(r rune) bool {
1929 1 : return unicode.IsSpace(r) || r == ',' || r == '(' || r == ')'
1930 1 : })
1931 1 : if len(fields) != 2 {
1932 0 : err = errors.Newf("require 2 arguments")
1933 0 : }
1934 1 : var h WriteAmpHeuristic
1935 1 : if err == nil {
1936 1 : h.AddPropensity, err = strconv.ParseFloat(fields[0], 64)
1937 1 : }
1938 1 : if err == nil {
1939 1 : h.AllowL0, err = strconv.ParseBool(fields[1])
1940 1 : }
1941 1 : if err == nil {
1942 1 : o.Experimental.MultiLevelCompactionHeuristic = h
1943 1 : } else {
1944 0 : err = errors.Wrapf(err, "unexpected wamp heuristic arguments: %s", value)
1945 0 : }
1946 0 : default:
1947 0 : err = errors.Newf("unrecognized multilevel compaction heuristic: %s", value)
1948 : }
1949 0 : case "point_tombstone_weight":
1950 : // Do nothing; deprecated.
1951 1 : case "strict_wal_tail":
1952 1 : var strictWALTail bool
1953 1 : strictWALTail, err = strconv.ParseBool(value)
1954 1 : if err == nil && !strictWALTail {
1955 0 : err = errors.Newf("reading from versions with strict_wal_tail=false no longer supported")
1956 0 : }
1957 1 : case "merger":
1958 1 : switch value {
1959 0 : case "nullptr":
1960 0 : o.Merger = nil
1961 1 : case "pebble.concatenate":
1962 1 : o.Merger = DefaultMerger
1963 1 : default:
1964 1 : if hooks != nil && hooks.NewMerger != nil {
1965 1 : o.Merger, err = hooks.NewMerger(value)
1966 1 : }
1967 : }
1968 1 : case "read_compaction_rate":
1969 1 : o.Experimental.ReadCompactionRate, err = strconv.ParseInt(value, 10, 64)
1970 1 : case "read_sampling_multiplier":
1971 1 : o.Experimental.ReadSamplingMultiplier, err = strconv.ParseInt(value, 10, 64)
1972 1 : case "num_deletions_threshold":
1973 1 : o.Experimental.NumDeletionsThreshold, err = strconv.Atoi(value)
1974 1 : case "deletion_size_ratio_threshold":
1975 1 : val, parseErr := strconv.ParseFloat(value, 32)
1976 1 : o.Experimental.DeletionSizeRatioThreshold = float32(val)
1977 1 : err = parseErr
1978 1 : case "tombstone_dense_compaction_threshold":
1979 1 : o.Experimental.TombstoneDenseCompactionThreshold, err = strconv.ParseFloat(value, 64)
1980 1 : case "table_cache_shards":
1981 1 : o.Experimental.FileCacheShards, err = strconv.Atoi(value)
1982 0 : case "table_format":
1983 0 : switch value {
1984 0 : case "leveldb":
1985 0 : case "rocksdbv2":
1986 0 : default:
1987 0 : return errors.Errorf("pebble: unknown table format: %q", errors.Safe(value))
1988 : }
1989 1 : case "table_property_collectors":
1990 : // No longer implemented; ignore.
1991 1 : case "validate_on_ingest":
1992 1 : o.Experimental.ValidateOnIngest, err = strconv.ParseBool(value)
1993 1 : case "wal_dir":
1994 1 : o.WALDir = value
1995 1 : case "wal_bytes_per_sync":
1996 1 : o.WALBytesPerSync, err = strconv.Atoi(value)
1997 1 : case "max_writer_concurrency":
1998 : // No longer implemented; ignore.
1999 1 : case "force_writer_parallelism":
2000 : // No longer implemented; ignore.
2001 1 : case "secondary_cache_size_bytes":
2002 1 : o.Experimental.SecondaryCacheSizeBytes, err = strconv.ParseInt(value, 10, 64)
2003 1 : case "create_on_shared":
2004 1 : var createOnSharedInt int64
2005 1 : createOnSharedInt, err = strconv.ParseInt(value, 10, 64)
2006 1 : o.Experimental.CreateOnShared = remote.CreateOnSharedStrategy(createOnSharedInt)
2007 0 : default:
2008 0 : if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
2009 0 : return nil
2010 0 : }
2011 0 : return errors.Errorf("pebble: unknown option: %s.%s",
2012 0 : errors.Safe(section), errors.Safe(key))
2013 : }
2014 1 : return err
2015 :
2016 1 : case section == "Value Separation":
2017 1 : valSepPolicyOk = true
2018 1 : var err error
2019 1 : switch key {
2020 1 : case "enabled":
2021 1 : valSepPolicy.Enabled, err = strconv.ParseBool(value)
2022 1 : case "minimum_size":
2023 1 : var minimumSize int
2024 1 : minimumSize, err = strconv.Atoi(value)
2025 1 : valSepPolicy.MinimumSize = minimumSize
2026 1 : case "max_blob_reference_depth":
2027 1 : valSepPolicy.MaxBlobReferenceDepth, err = strconv.Atoi(value)
2028 0 : default:
2029 0 : if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
2030 0 : return nil
2031 0 : }
2032 0 : return errors.Errorf("pebble: unknown option: %s.%s", errors.Safe(section), errors.Safe(key))
2033 : }
2034 1 : return err
2035 :
2036 1 : case section == "WAL Failover":
2037 1 : if o.WALFailover == nil {
2038 1 : o.WALFailover = new(WALFailoverOptions)
2039 1 : }
2040 1 : var err error
2041 1 : switch key {
2042 1 : case "secondary_dir":
2043 1 : o.WALFailover.Secondary = wal.Dir{Dirname: value, FS: vfs.Default}
2044 1 : case "primary_dir_probe_interval":
2045 1 : o.WALFailover.PrimaryDirProbeInterval, err = time.ParseDuration(value)
2046 1 : case "healthy_probe_latency_threshold":
2047 1 : o.WALFailover.HealthyProbeLatencyThreshold, err = time.ParseDuration(value)
2048 1 : case "healthy_interval":
2049 1 : o.WALFailover.HealthyInterval, err = time.ParseDuration(value)
2050 1 : case "unhealthy_sampling_interval":
2051 1 : o.WALFailover.UnhealthySamplingInterval, err = time.ParseDuration(value)
2052 1 : case "unhealthy_operation_latency_threshold":
2053 1 : var threshold time.Duration
2054 1 : threshold, err = time.ParseDuration(value)
2055 1 : o.WALFailover.UnhealthyOperationLatencyThreshold = func() (time.Duration, bool) {
2056 1 : return threshold, true
2057 1 : }
2058 1 : case "elevated_write_stall_threshold_lag":
2059 1 : o.WALFailover.ElevatedWriteStallThresholdLag, err = time.ParseDuration(value)
2060 0 : default:
2061 0 : if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
2062 0 : return nil
2063 0 : }
2064 0 : return errors.Errorf("pebble: unknown option: %s.%s",
2065 0 : errors.Safe(section), errors.Safe(key))
2066 : }
2067 1 : return err
2068 :
2069 1 : case strings.HasPrefix(section, "Level "):
2070 1 : m := regexp.MustCompile(`Level\s*"?(\d+)"?\s*$`).FindStringSubmatch(section)
2071 1 : if m == nil {
2072 0 : return errors.Errorf("pebble: unknown section: %q", errors.Safe(section))
2073 0 : }
2074 1 : index, _ := strconv.Atoi(m[1])
2075 1 :
2076 1 : l := &o.Levels[index]
2077 1 :
2078 1 : var err error
2079 1 : switch key {
2080 1 : case "block_restart_interval":
2081 1 : l.BlockRestartInterval, err = strconv.Atoi(value)
2082 1 : case "block_size":
2083 1 : l.BlockSize, err = strconv.Atoi(value)
2084 1 : case "block_size_threshold":
2085 1 : l.BlockSizeThreshold, err = strconv.Atoi(value)
2086 1 : case "compression":
2087 1 : switch value {
2088 0 : case "Default":
2089 0 : l.Compression = func() Compression { return DefaultCompression }
2090 1 : case "NoCompression":
2091 1 : l.Compression = func() Compression { return NoCompression }
2092 1 : case "Snappy":
2093 1 : l.Compression = func() Compression { return SnappyCompression }
2094 1 : case "ZSTD":
2095 1 : l.Compression = func() Compression { return ZstdCompression }
2096 0 : case "MinLZ":
2097 0 : l.Compression = func() Compression { return MinLZCompression }
2098 0 : default:
2099 0 : return errors.Errorf("pebble: unknown compression: %q", errors.Safe(value))
2100 : }
2101 1 : case "filter_policy":
2102 1 : if hooks != nil && hooks.NewFilterPolicy != nil {
2103 1 : l.FilterPolicy, err = hooks.NewFilterPolicy(value)
2104 1 : } else {
2105 1 : l.FilterPolicy = NoFilterPolicy
2106 1 : }
2107 1 : case "filter_type":
2108 1 : switch value {
2109 1 : case "table":
2110 1 : l.FilterType = TableFilter
2111 0 : default:
2112 0 : return errors.Errorf("pebble: unknown filter type: %q", errors.Safe(value))
2113 : }
2114 1 : case "index_block_size":
2115 1 : l.IndexBlockSize, err = strconv.Atoi(value)
2116 1 : case "target_file_size":
2117 1 : l.TargetFileSize, err = strconv.ParseInt(value, 10, 64)
2118 0 : default:
2119 0 : if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
2120 0 : return nil
2121 0 : }
2122 0 : return errors.Errorf("pebble: unknown option: %s.%s", errors.Safe(section), errors.Safe(key))
2123 : }
2124 1 : return err
2125 : }
2126 1 : if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
2127 1 : return nil
2128 1 : }
2129 0 : return errors.Errorf("pebble: unknown section %q or key %q", errors.Safe(section), errors.Safe(key))
2130 : }
2131 1 : err := parseOptions(s, parseOptionsFuncs{
2132 1 : visitKeyValue: visitKeyValue,
2133 1 : })
2134 1 : if err != nil {
2135 1 : return err
2136 1 : }
2137 1 : if valSepPolicyOk {
2138 1 : o.Experimental.ValueSeparationPolicy = func() ValueSeparationPolicy { return valSepPolicy }
2139 : }
2140 1 : if concurrencyLimit.lowerSet || concurrencyLimit.upperSet {
2141 1 : if !concurrencyLimit.lowerSet {
2142 1 : concurrencyLimit.lower = 1
2143 1 : } else if concurrencyLimit.lower < 1 {
2144 0 : return errors.New("baseline_concurrent_compactions cannot be <= 0")
2145 0 : }
2146 1 : if !concurrencyLimit.upperSet {
2147 1 : concurrencyLimit.upper = concurrencyLimit.lower
2148 1 : } else if concurrencyLimit.upper < concurrencyLimit.lower {
2149 0 : return errors.Newf("max_concurrent_compactions cannot be < %d", concurrencyLimit.lower)
2150 0 : }
2151 1 : o.CompactionConcurrencyRange = func() (int, int) {
2152 1 : return concurrencyLimit.lower, concurrencyLimit.upper
2153 1 : }
2154 : }
2155 1 : return nil
2156 : }
2157 :
2158 : // ErrMissingWALRecoveryDir is an error returned when a database is attempted to be
2159 : // opened without supplying a Options.WALRecoveryDir entry for a directory that
2160 : // may contain WALs required to recover a consistent database state.
2161 : type ErrMissingWALRecoveryDir struct {
2162 : Dir string
2163 : ExtraInfo string
2164 : }
2165 :
2166 : // Error implements error.
2167 1 : func (e ErrMissingWALRecoveryDir) Error() string {
2168 1 : return fmt.Sprintf("directory %q may contain relevant WALs%s", e.Dir, e.ExtraInfo)
2169 1 : }
2170 :
2171 : // CheckCompatibility verifies the options are compatible with the previous options
2172 : // serialized by Options.String(). For example, the Comparer and Merger must be
2173 : // the same, or data will not be able to be properly read from the DB.
2174 : //
2175 : // This function only looks at specific keys and does not error out if the
2176 : // options are newer and contain unknown keys.
2177 1 : func (o *Options) CheckCompatibility(previousOptions string) error {
2178 1 : visitKeyValue := func(i, j int, section, key, value string) error {
2179 1 : switch section + "." + key {
2180 1 : case "Options.comparer":
2181 1 : if value != o.Comparer.Name {
2182 1 : return errors.Errorf("pebble: comparer name from file %q != comparer name from options %q",
2183 1 : errors.Safe(value), errors.Safe(o.Comparer.Name))
2184 1 : }
2185 1 : case "Options.merger":
2186 1 : // RocksDB allows the merge operator to be unspecified, in which case it
2187 1 : // shows up as "nullptr".
2188 1 : if value != "nullptr" && value != o.Merger.Name {
2189 1 : return errors.Errorf("pebble: merger name from file %q != merger name from options %q",
2190 1 : errors.Safe(value), errors.Safe(o.Merger.Name))
2191 1 : }
2192 1 : case "Options.wal_dir", "WAL Failover.secondary_dir":
2193 1 : switch {
2194 1 : case value == "":
2195 1 : return nil
2196 1 : case o.WALDir == value:
2197 1 : return nil
2198 1 : case o.WALFailover != nil && o.WALFailover.Secondary.Dirname == value:
2199 1 : return nil
2200 1 : default:
2201 1 : for _, d := range o.WALRecoveryDirs {
2202 1 : if d.Dirname == value {
2203 1 : return nil
2204 1 : }
2205 : }
2206 1 : var buf bytes.Buffer
2207 1 : fmt.Fprintf(&buf, "\n OPTIONS key: %s\n", section+"."+key)
2208 1 : if o.WALDir != "" {
2209 0 : fmt.Fprintf(&buf, " o.WALDir: %s\n", o.WALDir)
2210 0 : }
2211 1 : if o.WALFailover != nil {
2212 0 : fmt.Fprintf(&buf, " o.WALFailover.Secondary.Dirname: %s\n", o.WALFailover.Secondary.Dirname)
2213 0 : }
2214 1 : for _, d := range o.WALRecoveryDirs {
2215 0 : fmt.Fprintf(&buf, " WALRecoveryDir: %s\n", d)
2216 0 : }
2217 1 : return ErrMissingWALRecoveryDir{Dir: value, ExtraInfo: buf.String()}
2218 : }
2219 : }
2220 1 : return nil
2221 : }
2222 1 : return parseOptions(previousOptions, parseOptionsFuncs{visitKeyValue: visitKeyValue})
2223 : }
2224 :
2225 : // Validate verifies that the options are mutually consistent. For example,
2226 : // L0StopWritesThreshold must be >= L0CompactionThreshold, otherwise a write
2227 : // stall would persist indefinitely.
2228 1 : func (o *Options) Validate() error {
2229 1 : // Note that we can presume Options.EnsureDefaults has been called, so there
2230 1 : // is no need to check for zero values.
2231 1 :
2232 1 : var buf strings.Builder
2233 1 : if o.Experimental.L0CompactionConcurrency < 1 {
2234 1 : fmt.Fprintf(&buf, "L0CompactionConcurrency (%d) must be >= 1\n",
2235 1 : o.Experimental.L0CompactionConcurrency)
2236 1 : }
2237 1 : if o.L0StopWritesThreshold < o.L0CompactionThreshold {
2238 1 : fmt.Fprintf(&buf, "L0StopWritesThreshold (%d) must be >= L0CompactionThreshold (%d)\n",
2239 1 : o.L0StopWritesThreshold, o.L0CompactionThreshold)
2240 1 : }
2241 1 : if uint64(o.MemTableSize) >= maxMemTableSize {
2242 1 : fmt.Fprintf(&buf, "MemTableSize (%s) must be < %s\n",
2243 1 : humanize.Bytes.Uint64(uint64(o.MemTableSize)), humanize.Bytes.Uint64(maxMemTableSize))
2244 1 : }
2245 1 : if o.MemTableStopWritesThreshold < 2 {
2246 1 : fmt.Fprintf(&buf, "MemTableStopWritesThreshold (%d) must be >= 2\n",
2247 1 : o.MemTableStopWritesThreshold)
2248 1 : }
2249 1 : if o.FormatMajorVersion < FormatMinSupported || o.FormatMajorVersion > internalFormatNewest {
2250 0 : fmt.Fprintf(&buf, "FormatMajorVersion (%d) must be between %d and %d\n",
2251 0 : o.FormatMajorVersion, FormatMinSupported, internalFormatNewest)
2252 0 : }
2253 1 : if o.Experimental.CreateOnShared != remote.CreateOnSharedNone && o.FormatMajorVersion < FormatMinForSharedObjects {
2254 0 : fmt.Fprintf(&buf, "FormatMajorVersion (%d) when CreateOnShared is set must be at least %d\n",
2255 0 : o.FormatMajorVersion, FormatMinForSharedObjects)
2256 0 : }
2257 1 : if len(o.KeySchemas) > 0 {
2258 1 : if o.KeySchema == "" {
2259 0 : fmt.Fprintf(&buf, "KeySchemas is set but KeySchema is not\n")
2260 0 : }
2261 1 : if _, ok := o.KeySchemas[o.KeySchema]; !ok {
2262 0 : fmt.Fprintf(&buf, "KeySchema %q not found in KeySchemas\n", o.KeySchema)
2263 0 : }
2264 : }
2265 1 : if buf.Len() == 0 {
2266 1 : return nil
2267 1 : }
2268 1 : return errors.New(buf.String())
2269 : }
2270 :
2271 : // MakeReaderOptions constructs sstable.ReaderOptions from the corresponding
2272 : // options in the receiver.
2273 1 : func (o *Options) MakeReaderOptions() sstable.ReaderOptions {
2274 1 : var readerOpts sstable.ReaderOptions
2275 1 : if o != nil {
2276 1 : readerOpts.Comparer = o.Comparer
2277 1 : readerOpts.Filters = o.Filters
2278 1 : readerOpts.KeySchemas = o.KeySchemas
2279 1 : readerOpts.LoadBlockSema = o.LoadBlockSema
2280 1 : readerOpts.LoggerAndTracer = o.LoggerAndTracer
2281 1 : readerOpts.Merger = o.Merger
2282 1 : }
2283 1 : return readerOpts
2284 : }
2285 :
2286 : // MakeWriterOptions constructs sstable.WriterOptions for the specified level
2287 : // from the corresponding options in the receiver.
2288 1 : func (o *Options) MakeWriterOptions(level int, format sstable.TableFormat) sstable.WriterOptions {
2289 1 : var writerOpts sstable.WriterOptions
2290 1 : writerOpts.TableFormat = format
2291 1 : if o != nil {
2292 1 : writerOpts.Comparer = o.Comparer
2293 1 : if o.Merger != nil {
2294 1 : writerOpts.MergerName = o.Merger.Name
2295 1 : }
2296 1 : writerOpts.BlockPropertyCollectors = o.BlockPropertyCollectors
2297 : }
2298 1 : if format >= sstable.TableFormatPebblev3 {
2299 1 : writerOpts.ShortAttributeExtractor = o.Experimental.ShortAttributeExtractor
2300 1 : if format >= sstable.TableFormatPebblev4 && level == numLevels-1 {
2301 1 : writerOpts.WritingToLowestLevel = true
2302 1 : }
2303 : }
2304 1 : levelOpts := o.Levels[level]
2305 1 : writerOpts.BlockRestartInterval = levelOpts.BlockRestartInterval
2306 1 : writerOpts.BlockSize = levelOpts.BlockSize
2307 1 : writerOpts.BlockSizeThreshold = levelOpts.BlockSizeThreshold
2308 1 : writerOpts.Compression = resolveDefaultCompression(levelOpts.Compression())
2309 1 : writerOpts.FilterPolicy = levelOpts.FilterPolicy
2310 1 : writerOpts.FilterType = levelOpts.FilterType
2311 1 : writerOpts.IndexBlockSize = levelOpts.IndexBlockSize
2312 1 : if o.KeySchema != "" {
2313 1 : var ok bool
2314 1 : writerOpts.KeySchema, ok = o.KeySchemas[o.KeySchema]
2315 1 : if !ok {
2316 0 : panic(fmt.Sprintf("invalid schema %q", redact.Safe(o.KeySchema)))
2317 : }
2318 : }
2319 1 : writerOpts.AllocatorSizeClasses = o.AllocatorSizeClasses
2320 1 : writerOpts.NumDeletionsThreshold = o.Experimental.NumDeletionsThreshold
2321 1 : writerOpts.DeletionSizeRatioThreshold = o.Experimental.DeletionSizeRatioThreshold
2322 1 : return writerOpts
2323 : }
2324 :
2325 : // MakeBlobWriterOptions constructs blob.FileWriterOptions from the corresponding
2326 : // options in the receiver.
2327 1 : func (o *Options) MakeBlobWriterOptions(level int) blob.FileWriterOptions {
2328 1 : lo := o.Levels[level]
2329 1 : return blob.FileWriterOptions{
2330 1 : Compression: resolveDefaultCompression(lo.Compression()),
2331 1 : ChecksumType: block.ChecksumTypeCRC32c,
2332 1 : FlushGovernor: block.MakeFlushGovernor(
2333 1 : lo.BlockSize,
2334 1 : lo.BlockSizeThreshold,
2335 1 : base.SizeClassAwareBlockSizeThreshold,
2336 1 : o.AllocatorSizeClasses,
2337 1 : ),
2338 1 : }
2339 1 : }
2340 :
2341 1 : func resolveDefaultCompression(c Compression) Compression {
2342 1 : if c <= DefaultCompression || c >= block.NCompression {
2343 1 : c = SnappyCompression
2344 1 : }
2345 1 : return c
2346 : }
2347 :
2348 1 : func (o *Options) MakeObjStorageProviderSettings(dirname string) objstorageprovider.Settings {
2349 1 : s := objstorageprovider.Settings{
2350 1 : Logger: o.Logger,
2351 1 : FS: o.FS,
2352 1 : FSDirName: dirname,
2353 1 : FSCleaner: o.Cleaner,
2354 1 : NoSyncOnClose: o.NoSyncOnClose,
2355 1 : BytesPerSync: o.BytesPerSync,
2356 1 : }
2357 1 : s.Local.ReadaheadConfig = o.Local.ReadaheadConfig
2358 1 : s.Remote.StorageFactory = o.Experimental.RemoteStorage
2359 1 : s.Remote.CreateOnShared = o.Experimental.CreateOnShared
2360 1 : s.Remote.CreateOnSharedLocator = o.Experimental.CreateOnSharedLocator
2361 1 : s.Remote.CacheSizeBytes = o.Experimental.SecondaryCacheSizeBytes
2362 1 : return s
2363 1 : }
2364 :
2365 : // UserKeyCategories describes a partitioning of the user key space. Each
2366 : // partition is a category with a name. The categories are used for informative
2367 : // purposes only (like pprof labels). Pebble does not treat keys differently
2368 : // based on the UserKeyCategories.
2369 : //
2370 : // The partitions are defined by their upper bounds. The last partition is
2371 : // assumed to go until the end of keyspace; its UpperBound is ignored. The rest
2372 : // of the partitions are ordered by their UpperBound.
2373 : type UserKeyCategories struct {
2374 : categories []UserKeyCategory
2375 : cmp base.Compare
2376 : // rangeNames[i][j] contains the string referring to the categories in the
2377 : // range [i, j], with j > i.
2378 : rangeNames [][]string
2379 : }
2380 :
2381 : // UserKeyCategory describes a partition of the user key space.
2382 : //
2383 : // User keys >= the previous category's UpperBound and < this category's
2384 : // UpperBound are part of this category.
2385 : type UserKeyCategory struct {
2386 : Name string
2387 : // UpperBound is the exclusive upper bound of the category. All user keys >= the
2388 : // previous category's UpperBound and < this UpperBound are part of this
2389 : // category.
2390 : UpperBound []byte
2391 : }
2392 :
2393 : // MakeUserKeyCategories creates a UserKeyCategories object with the given
2394 : // categories. The object is immutable and can be reused across different
2395 : // stores.
2396 1 : func MakeUserKeyCategories(cmp base.Compare, categories ...UserKeyCategory) UserKeyCategories {
2397 1 : n := len(categories)
2398 1 : if n == 0 {
2399 0 : return UserKeyCategories{}
2400 0 : }
2401 1 : if categories[n-1].UpperBound != nil {
2402 0 : panic("last category UpperBound must be nil")
2403 : }
2404 : // Verify that the partitions are ordered as expected.
2405 1 : for i := 1; i < n-1; i++ {
2406 1 : if cmp(categories[i-1].UpperBound, categories[i].UpperBound) >= 0 {
2407 0 : panic("invalid UserKeyCategories: key prefixes must be sorted")
2408 : }
2409 : }
2410 :
2411 : // Precalculate a table of range names to avoid allocations in the
2412 : // categorization path.
2413 1 : rangeNamesBuf := make([]string, n*n)
2414 1 : rangeNames := make([][]string, n)
2415 1 : for i := range rangeNames {
2416 1 : rangeNames[i] = rangeNamesBuf[:n]
2417 1 : rangeNamesBuf = rangeNamesBuf[n:]
2418 1 : for j := i + 1; j < n; j++ {
2419 1 : rangeNames[i][j] = categories[i].Name + "-" + categories[j].Name
2420 1 : }
2421 : }
2422 1 : return UserKeyCategories{
2423 1 : categories: categories,
2424 1 : cmp: cmp,
2425 1 : rangeNames: rangeNames,
2426 1 : }
2427 : }
2428 :
2429 : // Len returns the number of categories defined.
2430 1 : func (kc *UserKeyCategories) Len() int {
2431 1 : return len(kc.categories)
2432 1 : }
2433 :
2434 : // CategorizeKey returns the name of the category containing the key.
2435 1 : func (kc *UserKeyCategories) CategorizeKey(userKey []byte) string {
2436 1 : idx := sort.Search(len(kc.categories)-1, func(i int) bool {
2437 1 : return kc.cmp(userKey, kc.categories[i].UpperBound) < 0
2438 1 : })
2439 1 : return kc.categories[idx].Name
2440 : }
2441 :
2442 : // CategorizeKeyRange returns the name of the category containing the key range.
2443 : // If the key range spans multiple categories, the result shows the first and
2444 : // last category separated by a dash, e.g. `cat1-cat5`.
2445 1 : func (kc *UserKeyCategories) CategorizeKeyRange(startUserKey, endUserKey []byte) string {
2446 1 : n := len(kc.categories)
2447 1 : p := sort.Search(n-1, func(i int) bool {
2448 1 : return kc.cmp(startUserKey, kc.categories[i].UpperBound) < 0
2449 1 : })
2450 1 : if p == n-1 || kc.cmp(endUserKey, kc.categories[p].UpperBound) < 0 {
2451 1 : // Fast path for a single category.
2452 1 : return kc.categories[p].Name
2453 1 : }
2454 : // Binary search among the remaining categories.
2455 1 : q := p + 1 + sort.Search(n-2-p, func(i int) bool {
2456 1 : return kc.cmp(endUserKey, kc.categories[p+1+i].UpperBound) < 0
2457 1 : })
2458 1 : return kc.rangeNames[p][q]
2459 : }
2460 :
2461 : const storePathIdentifier = "{store_path}"
2462 :
2463 : // MakeStoreRelativePath takes a path that is relative to the store directory
2464 : // and creates a path that can be used for Options.WALDir and wal.Dir.Dirname.
2465 : //
2466 : // This is used in metamorphic tests, so that the test run directory can be
2467 : // copied or moved.
2468 1 : func MakeStoreRelativePath(fs vfs.FS, relativePath string) string {
2469 1 : if relativePath == "" {
2470 0 : return storePathIdentifier
2471 0 : }
2472 1 : return fs.PathJoin(storePathIdentifier, relativePath)
2473 : }
2474 :
2475 : // resolveStorePath is the inverse of MakeStoreRelativePath(). It replaces any
2476 : // storePathIdentifier prefix with the store dir.
2477 1 : func resolveStorePath(storeDir, path string) string {
2478 1 : if remainder, ok := strings.CutPrefix(path, storePathIdentifier); ok {
2479 1 : return storeDir + remainder
2480 1 : }
2481 1 : return path
2482 : }
|