github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/internal/metamorphic/config.go (about) 1 // Copyright 2019 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 metamorphic 6 7 import "github.com/zuoyebang/bitalostable/internal/randvar" 8 9 type opType int 10 11 const ( 12 batchAbort opType = iota 13 batchCommit 14 dbCheckpoint 15 dbClose 16 dbCompact 17 dbFlush 18 dbRestart 19 iterClose 20 iterFirst 21 iterLast 22 iterNext 23 iterNextWithLimit 24 iterPrev 25 iterPrevWithLimit 26 iterSeekGE 27 iterSeekGEWithLimit 28 iterSeekLT 29 iterSeekLTWithLimit 30 iterSeekPrefixGE 31 iterSetBounds 32 iterSetOptions 33 newBatch 34 newIndexedBatch 35 newIter 36 newIterUsingClone 37 newSnapshot 38 readerGet 39 snapshotClose 40 writerApply 41 writerDelete 42 writerDeleteRange 43 writerIngest 44 writerMerge 45 writerRangeKeyDelete 46 writerRangeKeySet 47 writerRangeKeyUnset 48 writerSet 49 writerSingleDelete 50 ) 51 52 type config struct { 53 // Weights for the operation mix to generate. ops[i] corresponds to the 54 // weight for opType(i). 55 ops []int 56 57 // newPrefix configures the probability that when generating a new user key, 58 // the generated key uses a new key prefix rather than an existing prefix 59 // with a suffix. 60 newPrefix float64 61 // writeSuffixDist defines the distribution of key suffixes during writing. 62 // It's a dynamic randvar to roughly emulate workloads with MVCC timestamps, 63 // skewing towards most recent timestamps. 64 writeSuffixDist randvar.Dynamic 65 66 // TODO(peter): unimplemented 67 // keyDist randvar.Dynamic 68 // keySizeDist randvar.Static 69 // valueSizeDist randvar.Static 70 // updateFrac float64 71 // lowerBoundFrac float64 72 // upperBoundFrac float64 73 } 74 75 func defaultConfig() config { 76 return config{ 77 // dbClose is not in this list since it is deterministically generated once, at the end of the test. 78 ops: []int{ 79 batchAbort: 5, 80 batchCommit: 5, 81 dbCheckpoint: 1, 82 dbCompact: 1, 83 dbFlush: 2, 84 dbRestart: 2, 85 iterClose: 5, 86 iterFirst: 100, 87 iterLast: 100, 88 iterNext: 100, 89 iterNextWithLimit: 20, 90 iterPrev: 100, 91 iterPrevWithLimit: 20, 92 iterSeekGE: 100, 93 iterSeekGEWithLimit: 20, 94 iterSeekLT: 100, 95 iterSeekLTWithLimit: 20, 96 iterSeekPrefixGE: 100, 97 iterSetBounds: 100, 98 iterSetOptions: 10, 99 newBatch: 5, 100 newIndexedBatch: 5, 101 newIter: 10, 102 newIterUsingClone: 5, 103 newSnapshot: 10, 104 readerGet: 100, 105 snapshotClose: 10, 106 writerApply: 10, 107 writerDelete: 100, 108 writerDeleteRange: 50, 109 writerIngest: 100, 110 writerMerge: 100, 111 writerRangeKeySet: 10, 112 writerRangeKeyUnset: 10, 113 writerRangeKeyDelete: 5, 114 writerSet: 100, 115 writerSingleDelete: 50, 116 }, 117 // Use a new prefix 75% of the time (and 25% of the time use an existing 118 // prefix with an alternative suffix). 119 newPrefix: 0.75, 120 // Use a skewed distribution of suffixes to mimic MVCC timestamps. The 121 // range will be widened whenever a suffix is found to already be in use 122 // for a particular prefix. 123 writeSuffixDist: mustDynamic(randvar.NewSkewedLatest(0, 1, 0.99)), 124 } 125 } 126 127 func mustDynamic(dyn randvar.Dynamic, err error) randvar.Dynamic { 128 if err != nil { 129 panic(err) 130 } 131 return dyn 132 }