github.com/cockroachdb/pebble@v1.1.1-0.20240513155919-3622ade60459/sstable/testdata/size_estimate (about) 1 # Sequence of ops which tests all of the code paths in the size_estimate type. 2 3 init 1 4 ---- 5 success 6 7 # Empty size should be 1 8 size 9 ---- 10 1 11 12 # There's a single inflight entry, so the size should be 4. 13 add_inflight 4 14 ---- 15 4 16 17 num_inflight_entries 18 ---- 19 1 20 21 num_entries 22 ---- 23 1 24 25 # Compression ratio defaults to 1, so the size of the inflight entry fully 26 # counts towards size. 27 size 28 ---- 29 4 30 31 # After compression, entry only had a size of 3. The total size is therefore 32 # 3, since this is the first entry. The max estimated size is 4 since we 33 # ensure that it is monotonically non decreasing. 34 entry_written 3 4 35 ---- 36 4 37 38 num_entries 39 ---- 40 1 41 42 # There should be 0 inflight entries once the previous entry has been written. 43 num_inflight_entries 44 ---- 45 0 46 47 # Compression ratio is 0.75 at this point. The total size is 3, and the inflight 48 # size is 5, so that returned size is uint64(3 + 0.75*5) = uint64(6.75). 49 add_inflight 5 50 ---- 51 6 52 53 num_entries 54 ---- 55 2 56 57 # We don't clear the empty size, so even after clearing a size of 1 is returned. 58 clear 59 ---- 60 1 61 62 # Test writing multiple inflight entries. 63 add_inflight 4 64 ---- 65 4 66 67 add_inflight 5 68 ---- 69 9 70 71 num_entries 72 ---- 73 2 74 75 num_inflight_entries 76 ---- 77 2 78 79 # First inflight entry written. The entry didn't get compressed. The total size 80 # now is less than 9, but the max estimated size should still be 9. 81 entry_written 4 4 82 ---- 83 9 84 85 num_entries 86 ---- 87 2 88 89 num_inflight_entries 90 ---- 91 1 92 93 # At this point, inflightSize is 13, the totalSize is 4. The compression ratio 94 # is 1. So, the returned size should be 17. 95 add_inflight 8 96 ---- 97 17 98 99 # One entry has been written. 100 num_written_entries 101 ---- 102 1 103 104 # The inflight entry had a size of 5, but the entry added had a size of 3 105 # because of compression/size estimation. The compression ratio is (4+3)/(4+5) 106 # = 0.77 at this point. The inflightSize is 8. The true size is 7+8*0.77 = 107 # 13.22, but the maxEstimatedSize is returned. 108 entry_written 7 5 109 ---- 110 17 111 112 # The inflight size is 0, and the total size is 11. 113 entry_written 11 8 114 ---- 115 17 116 117 num_written_entries 118 ---- 119 3 120 121 # The compression ratio is (4+3+4)/(4+5+8)=0.647, and the inflight size is 20, 122 # 20*0.64 = 12.94, so the total size is uint64(12.94 + 11) 123 add_inflight 20 124 ---- 125 23 126 127 num_inflight_entries 128 ---- 129 1 130 131 # We can write an entry, which increases the written size from 11 to 19, but 132 # it might not have an inflightSize, because it was never inflight. In such a 133 # case, the numInflightEntries, shouldn't be decreased. 134 entry_written 19 0 135 ---- 136 31 137 138 num_inflight_entries 139 ---- 140 1 141 142 num_written_entries 143 ---- 144 4